From cd9e42f987e3f230847fd9df908a8b0566012d16 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 15 Feb 2021 19:42:42 -0600 Subject: [PATCH] Properly lock hash bucket for status bits operations Signed-off-by: Adam Rutkowski --- src/engine/engine_rd.c | 4 ++-- src/engine/engine_wb.c | 22 ++++++++++++---------- src/engine/engine_wo.c | 14 ++++++++++++++ src/engine/engine_wt.c | 33 +++++++++++++++------------------ 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/engine/engine_rd.c b/src/engine/engine_rd.c index 3c8160e..b18369a 100644 --- a/src/engine/engine_rd.c +++ b/src/engine/engine_rd.c @@ -164,12 +164,12 @@ static int _ocf_read_generic_do(struct ocf_request *req) return 0; } - ocf_hb_req_prot_lock_rd(req); + ocf_hb_req_prot_lock_wr(req); /* Set valid status bits map */ ocf_set_valid_map_info(req); - ocf_hb_req_prot_unlock_rd(req); + ocf_hb_req_prot_unlock_wr(req); } if (ocf_engine_needs_repart(req)) { diff --git a/src/engine/engine_wb.c b/src/engine/engine_wb.c index 8c9c296..95bd8ee 100644 --- a/src/engine/engine_wb.c +++ b/src/engine/engine_wb.c @@ -27,22 +27,24 @@ static const struct ocf_io_if _io_if_wb_resume = { static void _ocf_write_wb_update_bits(struct ocf_request *req) { - if (ocf_engine_is_miss(req)) { - ocf_hb_req_prot_lock_rd(req); + bool miss = ocf_engine_is_miss(req); + bool clean_any = !ocf_engine_is_dirty_all(req); + + if (!miss && !clean_any) { + ocf_req_set_cleaning_hot(req); + return; + } + + ocf_hb_req_prot_lock_wr(req); + if (miss) { /* Update valid status bits */ ocf_set_valid_map_info(req); - - ocf_hb_req_prot_unlock_rd(req); } - - if (!ocf_engine_is_dirty_all(req)) { - ocf_hb_req_prot_lock_wr(req); - + if (clean_any) { /* set dirty bits, and mark if metadata flushing is required */ ocf_set_dirty_map_info(req); - - ocf_hb_req_prot_unlock_wr(req); } + ocf_hb_req_prot_unlock_wr(req); ocf_req_set_cleaning_hot(req); } diff --git a/src/engine/engine_wo.c b/src/engine/engine_wo.c index 777df45..0b4a4bc 100644 --- a/src/engine/engine_wo.c +++ b/src/engine/engine_wo.c @@ -71,6 +71,10 @@ static int ocf_read_wo_cache_do(struct ocf_request *req) s = ocf_map_line_start_sector(req, line); e = ocf_map_line_end_sector(req, line); + ocf_hb_cline_prot_lock_rd(&cache->metadata.lock, + req->lock_idx, entry->core_id, + entry->core_line); + /* if cacheline mapping is not sequential, send cache IO to * previous cacheline(s) */ phys_prev = phys_curr; @@ -112,6 +116,10 @@ static int ocf_read_wo_cache_do(struct ocf_request *req) == valid); } + ocf_hb_cline_prot_unlock_rd(&cache->metadata.lock, + req->lock_idx, entry->core_id, + entry->core_line); + if (io && !valid) { /* end of sequential valid region */ ocf_read_wo_cache_io(req, io_start, @@ -126,6 +134,12 @@ static int ocf_read_wo_cache_do(struct ocf_request *req) } offset += increment; + + if (i <= e) { + ocf_hb_cline_prot_lock_rd(&cache->metadata.lock, + req->lock_idx, entry->core_id, + entry->core_line); + } } while (i <= e); } diff --git a/src/engine/engine_wt.c b/src/engine/engine_wt.c index 83b0176..d786a0f 100644 --- a/src/engine/engine_wt.c +++ b/src/engine/engine_wt.c @@ -97,39 +97,36 @@ static inline void _ocf_write_wt_submit(struct ocf_request *req) static void _ocf_write_wt_update_bits(struct ocf_request *req) { - if (ocf_engine_is_miss(req)) { - ocf_hb_req_prot_lock_rd(req); + bool miss = ocf_engine_is_miss(req); + bool dirty_any = req->info.dirty_any; + bool repart = ocf_engine_needs_repart(req); + if (!miss && !dirty_any && !repart) + return; + + ocf_hb_req_prot_lock_wr(req); + + if (miss) { /* Update valid status bits */ ocf_set_valid_map_info(req); - - ocf_hb_req_prot_unlock_rd(req); } - if (req->info.dirty_any) { - ocf_hb_req_prot_lock_wr(req); - - /* Writes goes to SDD and HDD, need to update status bits from - * dirty to clean + if (dirty_any) { + /* Writes goes to both cache and core, need to update + * status bits from dirty to clean */ - ocf_set_clean_map_info(req); - - ocf_hb_req_prot_unlock_wr(req); } - if (ocf_engine_needs_repart(req)) { + if (repart) { OCF_DEBUG_RQ(req, "Re-Part"); - - ocf_hb_req_prot_lock_wr(req); - /* Probably some cache lines are assigned into wrong * partition. Need to move it to new one */ ocf_part_move(req); - - ocf_hb_req_prot_unlock_wr(req); } + + ocf_hb_req_prot_unlock_wr(req); } static int _ocf_write_wt_do(struct ocf_request *req)