Skip to content
5 changes: 3 additions & 2 deletions example/simple/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2019-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -315,7 +316,7 @@ void perform_workload(ocf_core_t core)
}
strcpy(data1->ptr, "This is some test data");
/* Prepare and submit write IO to the core */
submit_io(core, data1, 0, 512, OCF_WRITE, complete_write);
submit_io(core, data1, 0, 4096, OCF_WRITE, complete_write);
/* After write completes, complete_write() callback will be called. */

/*
Expand All @@ -330,7 +331,7 @@ void perform_workload(ocf_core_t core)
return;
}
/* Prepare and submit read IO to the core */
submit_io(core, data2, 0, 512, OCF_READ, complete_read);
submit_io(core, data2, 0, 4096, OCF_READ, complete_read);
/* After read completes, complete_read() callback will be called,
* where we print our example data to stdout.
*/
Expand Down
14 changes: 11 additions & 3 deletions inc/ocf_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef __OCF_DEF_H__
#define __OCF_DEF_H__

#include "ocf_env.h"
#include "ocf_cfg.h"
/**
* @file
Expand Down Expand Up @@ -58,22 +59,29 @@
/**
* @name OCF cores definitions
*/
/**
* Number of core id bits
*/
#define OCF_CORE_ID_BITS 14
/**
* Maximum numbers of cores per cache instance
* Must be smaller than (1 << OCF_CORE_ID_BITS) to leave space
* for invalid OCF_CORE_ID_INVALID.
*/
#define OCF_CORE_MAX OCF_CONFIG_MAX_CORES
#define OCF_CORE_NUM OCF_CONFIG_MAX_CORES
_Static_assert(OCF_CORE_NUM < (1 << OCF_CORE_ID_BITS));
/**
* Minimum value of a valid core ID
*/
#define OCF_CORE_ID_MIN 0
/**
* Maximum value of a valid core ID
*/
#define OCF_CORE_ID_MAX (OCF_CORE_MAX - 1)
#define OCF_CORE_ID_MAX (OCF_CORE_NUM - 1)
/**
* Invalid value of core id
*/
#define OCF_CORE_ID_INVALID OCF_CORE_MAX
#define OCF_CORE_ID_INVALID OCF_CORE_NUM
/**
* Size of core name
*/
Expand Down
14 changes: 8 additions & 6 deletions inc/ocf_metadata.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2023 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -93,21 +95,21 @@ void ocf_metadata_probe(ocf_ctx_t ctx, ocf_volume_t volume,
ocf_metadata_probe_end_t cmpl, void *priv);

/**
* @brief Check if sectors in cache line before given address are invalid
* @brief Check if blocks in cache line before given address are invalid
*
* It might be used by volume which supports
* atomic writes - (write of data and metadata in one buffer)
*
* @param[in] cache OCF cache instance
* @param[in] addr Sector address in bytes
*
* @retval 0 Not all sectors before given address are invalid
* @retval Non-zero Number of sectors before given address
* @retval 0 Not all blocks before given address are invalid
* @retval Non-zero Number of blocks before given address
*/
int ocf_metadata_check_invalid_before(ocf_cache_t cache, uint64_t addr);

/**
* @brief Check if sectors in cache line after given end address are invalid
* @brief Check if blocks in cache line after given end address are invalid
*
* It might be used by volume which supports
* atomic writes - (write of data and metadata in one buffer)
Expand All @@ -116,8 +118,8 @@ int ocf_metadata_check_invalid_before(ocf_cache_t cache, uint64_t addr);
* @param[in] addr Sector address in bytes
* @param[in] bytes IO size in bytes
*
* @retval 0 Not all sectors after given end address are invalid
* @retval Non-zero Number of sectors after given end address
* @retval 0 Not all blocks after given end address are invalid
* @retval Non-zero Number of blocks after given end address
*/
int ocf_metadata_check_invalid_after(ocf_cache_t cache, uint64_t addr,
uint32_t bytes);
Expand Down
8 changes: 4 additions & 4 deletions src/cleaning/acp.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ struct acp_context {
env_rwsem chunks_lock;

/* number of chunks per core */
uint64_t num_chunks[OCF_CORE_MAX];
uint64_t num_chunks[OCF_CORE_NUM];

/* per core array of all chunks */
struct acp_chunk_info *chunk_info[OCF_CORE_MAX];
struct acp_chunk_info *chunk_info[OCF_CORE_NUM];

struct acp_bucket bucket_info[ACP_MAX_BUCKETS];

Expand Down Expand Up @@ -302,7 +302,7 @@ struct ocf_acp_populate_context {
ocf_cache_t cache;

struct {
uint16_t *chunk[OCF_CORE_MAX];
uint16_t *chunk[OCF_CORE_NUM];
struct {
struct list_head chunk_list;
} bucket[ACP_MAX_BUCKETS];
Expand Down Expand Up @@ -334,7 +334,7 @@ static int ocf_acp_populate_handle(ocf_parallelize_t parallelize,

OCF_COND_RESCHED_DEFAULT(step);

if (core_id == OCF_CORE_MAX)
if (core_id == OCF_CORE_NUM)
continue;

if (!metadata_test_dirty(cache, cline)) {
Expand Down
2 changes: 1 addition & 1 deletion src/cleaning/alru.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ static int ocf_alru_populate_handle(ocf_parallelize_t parallelize,

OCF_COND_RESCHED_DEFAULT(step);

if (core_id == OCF_CORE_MAX)
if (core_id == OCF_CORE_NUM)
continue;

if (!metadata_test_dirty(cache, cline)) {
Expand Down
19 changes: 9 additions & 10 deletions src/engine/engine_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ void ocf_engine_error(struct ocf_request *req,

if (ocf_cache_log_rl(cache)) {
ocf_core_log(req->core, log_err,
"%s sector: %" ENV_PRIu64 ", bytes: %u\n", msg,
BYTES_TO_SECTORS(req->addr),
req->bytes);
"%s addr: %" ENV_PRIu64 ", bytes: %u\n", msg,
req->addr, req->bytes);
}
}

Expand Down Expand Up @@ -135,12 +134,12 @@ void ocf_engine_patch_req_info(struct ocf_cache *cache,
static void ocf_engine_update_req_info(struct ocf_cache *cache,
struct ocf_request *req, uint32_t idx)
{
uint8_t start_sector = 0;
uint8_t end_sector = ocf_line_end_sector(cache);
uint8_t start_block = 0;
uint8_t end_block = ocf_line_end_block(cache);
struct ocf_map_info *entry = &(req->map[idx]);

start_sector = ocf_map_line_start_sector(req, idx);
end_sector = ocf_map_line_end_sector(req, idx);
start_block = ocf_map_line_start_block(req, idx);
end_block = ocf_map_line_end_block(req, idx);

ENV_BUG_ON(entry->status != LOOKUP_HIT &&
entry->status != LOOKUP_MISS &&
Expand All @@ -150,7 +149,7 @@ static void ocf_engine_update_req_info(struct ocf_cache *cache,
/* Handle return value */
if (entry->status == LOOKUP_HIT) {
if (metadata_test_valid_sec(cache, entry->coll_idx,
start_sector, end_sector)) {
start_block, end_block)) {
req->info.hit_no++;
} else {
req->info.invalid_no++;
Expand All @@ -163,7 +162,7 @@ static void ocf_engine_update_req_info(struct ocf_cache *cache,

/* Check if cache line is fully dirty */
if (metadata_test_dirty_all_sec(cache, entry->coll_idx,
start_sector, end_sector))
start_block, end_block))
req->info.dirty_all++;
}
}
Expand Down Expand Up @@ -360,7 +359,7 @@ static void ocf_engine_map_hndl_error(struct ocf_cache *cache,
entry->coll_idx);

set_cache_line_invalid_no_flush(cache, 0,
ocf_line_end_sector(cache),
ocf_line_end_block(cache),
entry->coll_idx);

ocf_metadata_end_collision_shared_access(cache,
Expand Down
13 changes: 7 additions & 6 deletions src/engine/engine_common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -150,8 +151,8 @@ static inline uint32_t ocf_engine_io_count(struct ocf_request *req)
static inline
bool ocf_engine_map_all_sec_dirty(struct ocf_request *req, uint32_t line)
{
uint8_t start = ocf_map_line_start_sector(req, line);
uint8_t end = ocf_map_line_end_sector(req, line);
uint8_t start = ocf_map_line_start_block(req, line);
uint8_t end = ocf_map_line_end_block(req, line);

if (req->map[line].status != LOOKUP_HIT)
return false;
Expand All @@ -163,8 +164,8 @@ bool ocf_engine_map_all_sec_dirty(struct ocf_request *req, uint32_t line)
static inline
bool ocf_engine_map_all_sec_clean(struct ocf_request *req, uint32_t line)
{
uint8_t start = ocf_map_line_start_sector(req, line);
uint8_t end = ocf_map_line_end_sector(req, line);
uint8_t start = ocf_map_line_start_block(req, line);
uint8_t end = ocf_map_line_end_block(req, line);

if (req->map[line].status != LOOKUP_HIT)
return false;
Expand All @@ -181,8 +182,8 @@ bool ocf_engine_map_all_sec_clean(struct ocf_request *req, uint32_t line)
static inline
bool ocf_engine_map_all_sec_valid(struct ocf_request *req, uint32_t line)
{
uint8_t start = ocf_map_line_start_sector(req, line);
uint8_t end = ocf_map_line_end_sector(req, line);
uint8_t start = ocf_map_line_start_block(req, line);
uint8_t end = ocf_map_line_end_block(req, line);

if (req->map[line].status != LOOKUP_HIT)
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/engine/engine_wi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -32,8 +33,8 @@ static int _ocf_write_wi_next_pass(struct ocf_request *req)
only if concurrent I/O had inserted target LBAs to cache after
this request did traversation. These LBAs might have been
written by this request behind the concurrent I/O's back,
resulting in making these sectors effectively invalid.
In this case we must update these sectors metadata to
resulting in making these blocks effectively invalid.
In this case we must update these blocks metadata to
reflect this. However we won't know about this after we
traverse the request again - hence calling ocf_write_wi
again with req->wi_second_pass set to indicate that this
Expand Down
19 changes: 10 additions & 9 deletions src/engine/engine_wo.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2019-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -68,8 +69,8 @@ static int ocf_read_wo_cache_do(struct ocf_request *req)

for (line = 0; line < req->core_line_count; ++line) {
entry = &req->map[line];
s = ocf_map_line_start_sector(req, line);
e = ocf_map_line_end_sector(req, line);
s = ocf_map_line_start_block(req, line);
e = ocf_map_line_end_block(req, line);

ocf_hb_cline_prot_lock_rd(&cache->metadata.lock,
req->lock_idx, entry->core_id,
Expand All @@ -85,20 +86,20 @@ static int ocf_read_wo_cache_do(struct ocf_request *req)
io = false;
}

/* try to seek directly to the last sector */
/* try to seek directly to the last block */
if (entry->status == LOOKUP_MISS) {
/* all sectors invalid */
/* all blocks invalid */
i = e + 1;
increment = SECTORS_TO_BYTES(e - s + 1);
increment = BLOCKS_TO_BYTES(e - s + 1);
valid = false;
}
else if (ocf_engine_map_all_sec_valid(req, line)) {
/* all sectors valid */
/* all blocks valid */
i = e + 1;
increment = SECTORS_TO_BYTES(e - s + 1);
increment = BLOCKS_TO_BYTES(e - s + 1);
valid = true;
} else {
/* need to iterate through CL sector by sector */
/* need to iterate through CL block by block */
i = s;
}

Expand All @@ -109,7 +110,7 @@ static int ocf_read_wo_cache_do(struct ocf_request *req)
increment = 0;
do {
++i;
increment += SECTORS_TO_BYTES(1);
increment += BLOCKS_TO_BYTES(1);
} while (i <= e && metadata_test_valid_one(
cache, entry->coll_idx, i)
== valid);
Expand Down
13 changes: 7 additions & 6 deletions src/engine/engine_zero.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -72,19 +73,19 @@ static inline void ocf_zero_map_info(struct ocf_request *req)
continue;

start_bit = 0;
end_bit = ocf_line_end_sector(cache);
end_bit = ocf_line_end_block(cache);

if (map_idx == 0) {
/* First */
start_bit = (BYTES_TO_SECTORS(req->addr)
% ocf_line_sectors(cache));
start_bit = BYTES_TO_BLOCKS_ROUND_DOWN(req->addr)
% ocf_line_blocks(cache);
}

if (map_idx == (count - 1)) {
/* Last */
end_bit = (BYTES_TO_SECTORS(req->addr +
req->bytes - 1) %
ocf_line_sectors(cache));
end_bit = BYTES_TO_BLOCKS_ROUND_DOWN(req->addr +
req->bytes - 1) %
ocf_line_blocks(cache);
}

ocf_metadata_flush_mark(cache, req, map_idx, INVALID,
Expand Down
Loading
Loading