Merge pull request #567 from robertbaldyga/optimize-out-recovery-sector-loop

Optimize out looping over cache line sectors in recovery
This commit is contained in:
Robert Baldyga 2021-09-08 13:57:32 +02:00 committed by GitHub
commit 7587bec07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 41 deletions

View File

@ -1540,6 +1540,32 @@ bool ocf_metadata_##what(struct ocf_cache *cache, \
_ocf_metadata_funcs(dirty) _ocf_metadata_funcs(dirty)
_ocf_metadata_funcs(valid) _ocf_metadata_funcs(valid)
bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop)
{
switch (cache->metadata.line_size) {
case ocf_cache_line_size_4:
return _ocf_metadata_clear_valid_if_clean_u8(cache,
line, start, stop);
case ocf_cache_line_size_8:
return _ocf_metadata_clear_valid_if_clean_u16(cache,
line, start, stop);
case ocf_cache_line_size_16:
return _ocf_metadata_clear_valid_if_clean_u32(cache,
line, start, stop);
case ocf_cache_line_size_32:
return _ocf_metadata_clear_valid_if_clean_u64(cache,
line, start, stop);
case ocf_cache_line_size_64:
return _ocf_metadata_clear_valid_if_clean_u128(cache,
line, start, stop);
case ocf_cache_line_size_none:
default:
ENV_BUG_ON(1);
return false;
}
}
int ocf_metadata_init(struct ocf_cache *cache, int ocf_metadata_init(struct ocf_cache *cache,
ocf_cache_line_size_t cache_line_size) ocf_cache_line_size_t cache_line_size)
{ {

View File

@ -221,20 +221,39 @@ static bool _ocf_metadata_test_and_clear_##what##_##type( \
return test; \ return test; \
} \ } \
ocf_metadata_bit_struct(u8); #define ocf_metadata_bit_func_basic(type) \
ocf_metadata_bit_struct(u16); static bool _ocf_metadata_clear_valid_if_clean_##type(struct ocf_cache *cache, \
ocf_metadata_bit_struct(u32); ocf_cache_line_t line, uint8_t start, uint8_t stop) \
ocf_metadata_bit_struct(u64); { \
ocf_metadata_bit_struct(u128); type mask = _get_mask_##type(start, stop); \
\
struct ocf_metadata_ctrl *ctrl = \
(struct ocf_metadata_ctrl *) cache->metadata.priv; \
\
struct ocf_metadata_raw *raw = \
&ctrl->raw_desc[metadata_segment_collision]; \
\
struct ocf_metadata_map_##type *map = raw->mem_pool; \
\
_raw_bug_on(raw, line); \
\
map[line].valid &= ~mask & map[line].dirty; \
\
if (map[line].valid) { \
return true; \
} else { \
return false; \
} \
} \
ocf_metadata_bit_func(dirty, u8); #define ocf_metadata_bit_funcs(type) \
ocf_metadata_bit_func(dirty, u16); ocf_metadata_bit_struct(type); \
ocf_metadata_bit_func(dirty, u32); ocf_metadata_bit_func(dirty, type); \
ocf_metadata_bit_func(dirty, u64); ocf_metadata_bit_func(valid, type); \
ocf_metadata_bit_func(dirty, u128); ocf_metadata_bit_func_basic(type); \
ocf_metadata_bit_func(valid, u8); ocf_metadata_bit_funcs(u8);
ocf_metadata_bit_func(valid, u16); ocf_metadata_bit_funcs(u16);
ocf_metadata_bit_func(valid, u32); ocf_metadata_bit_funcs(u32);
ocf_metadata_bit_func(valid, u64); ocf_metadata_bit_funcs(u64);
ocf_metadata_bit_func(valid, u128); ocf_metadata_bit_funcs(u128);

View File

@ -13,19 +13,33 @@
* Dirty * Dirty
******************************************************************************/ ******************************************************************************/
bool ocf_metadata_test_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_test_dirty(struct ocf_cache *cache,
bool ocf_metadata_test_out_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); bool ocf_metadata_test_out_dirty(struct ocf_cache *cache,
bool ocf_metadata_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_clear_dirty(struct ocf_cache *cache,
bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_set_dirty(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_test_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_test_valid(struct ocf_cache *cache,
bool ocf_metadata_test_out_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); bool ocf_metadata_test_out_valid(struct ocf_cache *cache,
bool ocf_metadata_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); bool ocf_metadata_clear_valid(struct ocf_cache *cache,
bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_set_valid(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop);
bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all);
bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache,
ocf_cache_line_t line, uint8_t start, uint8_t stop);
static inline void metadata_init_status_bits(struct ocf_cache *cache, static inline void metadata_init_status_bits(struct ocf_cache *cache,
ocf_cache_line_t line) ocf_cache_line_t line)
@ -214,6 +228,13 @@ static inline void metadata_clear_valid(struct ocf_cache *cache,
ocf_metadata_clear_valid(cache, line, 0, ocf_line_end_sector(cache)); ocf_metadata_clear_valid(cache, line, 0, ocf_line_end_sector(cache));
} }
static inline void metadata_clear_valid_if_clean(struct ocf_cache *cache,
ocf_cache_line_t line)
{
ocf_metadata_clear_valid_if_clean(cache, line, 0,
ocf_line_end_sector(cache));
}
static inline bool metadata_test_and_clear_valid( static inline bool metadata_test_and_clear_valid(
struct ocf_cache *cache, ocf_cache_line_t line) struct ocf_cache *cache, ocf_cache_line_t line)
{ {

View File

@ -509,19 +509,6 @@ static void _recovery_rebuild_cline_metadata(ocf_cache_t cache,
} }
} }
static void _recovery_invalidate_clean_sec(struct ocf_cache *cache,
ocf_cache_line_t cline)
{
uint8_t i;
for (i = 0; i <= ocf_line_sectors(cache); i++) {
if (!metadata_test_dirty_one(cache, cline, i)) {
/* Invalidate clear sectors */
metadata_clear_valid_sec_one(cache, cline, i);
}
}
}
static void _recovery_reset_cline_metadata(struct ocf_cache *cache, static void _recovery_reset_cline_metadata(struct ocf_cache *cache,
ocf_cache_line_t cline) ocf_cache_line_t cline)
{ {
@ -553,7 +540,7 @@ static void _ocf_mngt_recovery_rebuild_metadata(ocf_cache_t cache)
_recovery_rebuild_cline_metadata(cache, core_id, _recovery_rebuild_cline_metadata(cache, core_id,
core_line, cline); core_line, cline);
if (dirty_only) if (dirty_only)
_recovery_invalidate_clean_sec(cache, cline); metadata_clear_valid_if_clean(cache, cline);
} else { } else {
/* Reset metadata for not mapped or clean cache line */ /* Reset metadata for not mapped or clean cache line */
_recovery_reset_cline_metadata(cache, cline); _recovery_reset_cline_metadata(cache, cline);