Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions env/posix/ocf_env.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2019-2022 Intel Corporation
* Copyright(c) 2023-2025 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -84,7 +85,7 @@ void env_stack_trace(void);
const typeof(((type *)0)->member)*__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); })

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))

/* STRING OPERATIONS */
#define env_memcpy(dest, dmax, src, slen) ({ \
Expand Down Expand Up @@ -597,31 +598,37 @@ static inline int env_in_interrupt(void)
return 0;
}

/* TIME */
#define ENV_SEC_TO_NSEC(_sec) ((_sec) * 1000000000)
#define ENV_NSEC_TO_SEC(_sec) ((_sec) / 1000000000)
#define ENV_NSEC_TO_MSEC(_sec) ((_sec) / 1000000)

static inline uint64_t env_get_tick_count(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
struct timespec tv;

return clock_gettime(CLOCK_REALTIME, &tv) ?
0 : ENV_SEC_TO_NSEC(tv.tv_sec) + tv.tv_nsec;
}

static inline uint64_t env_ticks_to_nsecs(uint64_t j)
{
return j * 1000;
return j;
}

static inline uint64_t env_ticks_to_msecs(uint64_t j)
{
return j / 1000;
return ENV_NSEC_TO_MSEC(j);
}

static inline uint64_t env_ticks_to_secs(uint64_t j)
{
return j / 1000000;
return ENV_NSEC_TO_SEC(j);
}

static inline uint64_t env_secs_to_ticks(uint64_t j)
{
return j * 1000000;
return ENV_SEC_TO_NSEC(j);
}

/* SORTING */
Expand Down
10 changes: 10 additions & 0 deletions inc/ocf_cache.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2023-2025 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -193,6 +194,15 @@ ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache);
*/
ocf_cache_line_size_t ocf_cache_get_line_size(ocf_cache_t cache);

/**
* @brief Get number of cache lines of given cache object
*
* @param[in] cache Cache object
*
* @retval Number of cache lines
*/
ocf_cache_line_t ocf_cache_get_line_count(ocf_cache_t cache);

/**
* @brief Convert bytes to cache lines
*
Expand Down
13 changes: 13 additions & 0 deletions inc/ocf_volume.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 @@ -409,5 +410,17 @@ unsigned int ocf_volume_get_max_io_size(ocf_volume_t volume);
* @return Length of volume in bytes
*/
uint64_t ocf_volume_get_length(ocf_volume_t volume);
/*
* @brief Check if uuid instances contain the same data
*
* @param[in] a first uuid
* @param[in] b second uuid
* @param[out] diff 0 if equal, non-0 otherwise
*
* @retval 0 if comparison successful
* @retval other value if comparison failed
*/
int ocf_uuid_compare(const struct ocf_volume_uuid * const a,
const struct ocf_volume_uuid * const b, int *diff);

#endif /* __OCF_VOLUME_H__ */
2 changes: 1 addition & 1 deletion src/cleaning/acp.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache,
ocf_engine_lookup_map_entry(cache, &info, core_id,
core_line);

if (info.status == LOOKUP_HIT &&
if ((info.status == LOOKUP_HIT || info.status == LOOKUP_HIT_INVALID) &&
metadata_test_dirty(cache, info.coll_idx)) {
locked = ocf_cache_line_try_lock_rd(
ocf_cache_line_concurrency(cache),
Expand Down
3 changes: 2 additions & 1 deletion src/engine/cache_engine.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024-2025 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -171,7 +172,7 @@ void ocf_resolve_effective_cache_mode(ocf_cache_t cache,
return;
}

if (unlikely(req->core_line_count > cache->conf_meta->cachelines)) {
if (unlikely(req->core_line_count > ocf_cache_get_line_count(cache))) {
req->cache_mode = ocf_req_cache_mode_pt;
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/engine/cache_engine.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 All @@ -14,6 +15,7 @@ struct ocf_thread_priv;
#define LOOKUP_HIT 5
#define LOOKUP_MISS 6
#define LOOKUP_REMAPPED 8
#define LOOKUP_HIT_INVALID 9

static inline ocf_req_cache_mode_t ocf_cache_mode_to_req_cache_mode(
ocf_cache_mode_t mode)
Expand Down
76 changes: 75 additions & 1 deletion src/engine/engine_bf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024-2025 Huawei Technologies
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -85,13 +86,86 @@ static void _ocf_backfill_complete(struct ocf_request *req, int error)

static int _ocf_backfill_do(struct ocf_request *req)
{
ocf_cache_t cache = req->cache;
uint64_t addr, bytes, total_bytes = 0, addr_next = 0;
uint64_t end = req->addr + req->bytes;
ocf_cache_line_size_t line_size = ocf_line_size(cache);
uint64_t seek, skip;
uint32_t i;

req->data = req->cp_data;
if (unlikely(req->data == NULL)) {
_ocf_backfill_complete(req, -OCF_ERR_NO_MEM);
return 0;
}

ocf_engine_forward_cache_io_req(req, OCF_WRITE, _ocf_backfill_complete);
ocf_req_forward_cache_init(req, _ocf_backfill_complete);

if (ocf_engine_is_sequential(req)) {
addr = cache->device->metadata_offset;
addr += req->map[0].coll_idx * line_size;
addr += req->addr % line_size;

ocf_core_stats_cache_block_update(req->core, req->part_id,
OCF_WRITE, req->bytes);
ocf_req_forward_cache_io(req, OCF_WRITE, addr, req->bytes,
req->offset);
return 0;
}

ocf_req_forward_cache_get(req);
for (i = 0; i < req->core_line_count; i++) {
if (addr_next) {
addr = addr_next;
} else {
addr = req->map[i].coll_idx;
addr *= line_size;
addr += cache->device->metadata_offset;
}
bytes = line_size;

if (i == 0) {
seek = req->addr % line_size;
addr += seek;
bytes -= seek;
}

if (req->map[i].status == LOOKUP_HIT) {
/* This is the 1st cache line in the interval,
* and it's a hit. Don't write it to the cache.
*/
addr_next = 0;
total_bytes += bytes;
continue;
}

for (; i < (req->core_line_count - 1); i++) {
addr_next = req->map[i + 1].coll_idx;
addr_next *= line_size;
addr_next += cache->device->metadata_offset;

if (addr_next != (addr + bytes))
break;

bytes += line_size;
}

if (i == (req->core_line_count - 1)) {
skip = (line_size - (end % line_size)) % line_size;
bytes -= skip;
}

bytes = OCF_MIN(bytes, req->bytes - total_bytes);

ocf_core_stats_cache_block_update(req->core, req->part_id,
OCF_WRITE, bytes);
ocf_req_forward_cache_io(req, OCF_WRITE, addr, bytes,
req->offset + total_bytes);

total_bytes += bytes;
}

ocf_req_forward_cache_put(req);

return 0;
}
Expand Down
14 changes: 10 additions & 4 deletions src/engine/engine_common.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 @@ -143,7 +144,8 @@ static void ocf_engine_update_req_info(struct ocf_cache *cache,

ENV_BUG_ON(entry->status != LOOKUP_HIT &&
entry->status != LOOKUP_MISS &&
entry->status != LOOKUP_REMAPPED);
entry->status != LOOKUP_REMAPPED &&
entry->status != LOOKUP_HIT_INVALID);

/* Handle return value */
if (entry->status == LOOKUP_HIT) {
Expand All @@ -152,6 +154,7 @@ static void ocf_engine_update_req_info(struct ocf_cache *cache,
req->info.hit_no++;
} else {
req->info.invalid_no++;
entry->status = LOOKUP_HIT_INVALID;
}

/* Check request is dirty */
Expand All @@ -165,7 +168,9 @@ static void ocf_engine_update_req_info(struct ocf_cache *cache,
}
}

if (entry->status == LOOKUP_HIT || entry->status == LOOKUP_REMAPPED) {
if (entry->status == LOOKUP_HIT ||
entry->status == LOOKUP_HIT_INVALID ||
entry->status == LOOKUP_REMAPPED) {
if (req->part_id != ocf_metadata_get_partition_id(cache,
entry->coll_idx)) {
/*
Expand Down Expand Up @@ -201,7 +206,7 @@ void ocf_engine_set_hot(struct ocf_request *req)
entry = &(req->map[i]);
status = entry->status;

if (status == LOOKUP_HIT) {
if (status == LOOKUP_HIT || status == LOOKUP_HIT_INVALID) {
/* Update eviction (LRU) */
ocf_lru_hot_cline(cache, entry->coll_idx);
}
Expand Down Expand Up @@ -341,6 +346,7 @@ static void ocf_engine_map_hndl_error(struct ocf_cache *cache,

switch (entry->status) {
case LOOKUP_HIT:
case LOOKUP_HIT_INVALID:
case LOOKUP_MISS:
break;

Expand Down Expand Up @@ -548,7 +554,7 @@ static int _ocf_engine_clean_getter(struct ocf_cache *cache,

entry = &req->map[item];

if (entry->status != LOOKUP_HIT)
if (entry->status != LOOKUP_HIT && entry->status != LOOKUP_HIT_INVALID)
return -1;

if (!metadata_test_dirty(cache, entry->coll_idx))
Expand Down
7 changes: 7 additions & 0 deletions src/metadata/metadata_cache_line.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 All @@ -11,6 +13,11 @@ static inline ocf_cache_line_size_t ocf_line_size(struct ocf_cache *cache)
return cache->metadata.line_size;
}

static inline ocf_cache_line_t ocf_line_count(struct ocf_cache *cache)
{
return cache->conf_meta->cachelines;
}

static inline uint64_t ocf_line_sectors(struct ocf_cache *cache)
{
return BYTES_TO_SECTORS(cache->metadata.line_size);
Expand Down
2 changes: 1 addition & 1 deletion src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ static void _ocf_mngt_load_superblock_complete(void *priv, int error)
OCF_PL_FINISH_RET(context->pipeline, error);
}

if (cache->conf_meta->cachelines !=
if (ocf_cache_get_line_count(cache) !=
ocf_metadata_get_cachelines_count(cache)) {
ocf_cache_log(cache, log_err,
"ERROR: Cache device size mismatch!\n");
Expand Down
Loading
Loading