Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/ocf_lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ static int ocf_lru_populate_handle(ocf_parallelize_t parallelize,
uint32_t partial_chunk_lines = 0;
uint32_t num_chunks, chunk_idx, chunk_lines;
uint32_t ci, j;
int result;

/* Check if this shard has a partial last chunk */
if (remainder > (uint32_t)shard_id * OCF_LRU_CHUNK_SIZE) {
Expand All @@ -1044,7 +1045,9 @@ static int ocf_lru_populate_handle(ocf_parallelize_t parallelize,
if (num_chunks == 0)
return 0;

ocf_generator_bisect_init(&generator, num_chunks, 0);
result = ocf_generator_bisect_init(&generator, num_chunks, 0);
if (result)
return result;

list = ocf_lru_get_list(&cache->free, shard_id, true);

Expand Down
24 changes: 20 additions & 4 deletions src/utils/utils_generator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2022 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -29,20 +30,32 @@ static inline uint32_t bitreverse32(register uint32_t x)
* returned by the generator is limit - 1)
* @param[in] offset Offset at which generator should start
*
* @return Reversed value
* @return Zero when success, otherwise an error
*/
void ocf_generator_bisect_init(
int ocf_generator_bisect_init(
struct ocf_generator_bisect_state *generator,
uint32_t limit, uint32_t offset)
{
unsigned clz;
uint32_t maplen;

clz = __builtin_clz(limit - 1);
maplen = 1 << (32 - clz);
if (limit == 0)
return -OCF_ERR_INVAL;

if (offset >= limit)
return -OCF_ERR_INVAL;

if (limit > 1) {
clz = __builtin_clz(limit - 1);
maplen = 1 << (32 - clz);
} else {
maplen = 1;
}

generator->curr = (uint64_t)offset * maplen / limit;
generator->limit = limit;

return 0;
}

/**
Expand Down Expand Up @@ -180,6 +193,9 @@ uint32_t ocf_generator_bisect_next(
uint32_t maplen;
uint32_t value;

if (generator->limit == 1)
return 0;

clz = __builtin_clz(generator->limit - 1);
maplen = 1 << (32 - clz);

Expand Down
3 changes: 2 additions & 1 deletion src/utils/utils_generator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2022 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -13,7 +14,7 @@ struct ocf_generator_bisect_state {
uint32_t limit;
};

void ocf_generator_bisect_init(
int ocf_generator_bisect_init(
struct ocf_generator_bisect_state *generator,
uint32_t limit, uint32_t offset);

Expand Down
Loading