Skip to content

Commit

Permalink
fixup! :Introduce optimistic fast path for engine_rd
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Mielewczyk <[email protected]>
  • Loading branch information
mmichal10 committed Sep 10, 2024
1 parent 4caf2f3 commit 0ed191f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 50 deletions.
11 changes: 6 additions & 5 deletions src/engine/engine_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ int ocf_read_generic(struct ocf_request *req)
return 0;
}

bool ocf_read_generic_fast(struct ocf_request *req)
int ocf_read_generic_try_fast(struct ocf_request *req)
{
struct ocf_alock *c = ocf_cache_line_concurrency(req->cache);

Expand All @@ -277,6 +277,8 @@ bool ocf_read_generic_fast(struct ocf_request *req)
if (ocf_engine_is_mapped(req) && ocf_engine_is_hit(req) &&
ocf_cl_lock_line_fast(c, req, OCF_READ) == OCF_LOCK_ACQUIRED) {

OCF_DEBUG_RQ(req, "Submit read generic fast");

ocf_req_get(req);
ocf_engine_set_hot(req);
ocf_hb_req_prot_unlock_rd(req);
Expand All @@ -289,14 +291,13 @@ bool ocf_read_generic_fast(struct ocf_request *req)

ocf_read_generic_submit_hit(req);

ocf_req_get(req);
ocf_read_generic_submit_hit(req);
/* Update statistics */
ocf_engine_update_request_stats(req);
ocf_engine_update_block_stats(req);
return true;
return OCF_FAST_PATH_YES;
} else {
ocf_hb_req_prot_unlock_rd(req);
return false;
OCF_DEBUG_RQ(req, "Failed to read generic fast");
return OCF_FAST_PATH_NO;
}
}
2 changes: 1 addition & 1 deletion src/engine/engine_rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
int ocf_read_generic(struct ocf_request *req);

void ocf_read_generic_submit_hit(struct ocf_request *req);
bool ocf_read_generic_fast(struct ocf_request *req);
int ocf_read_generic_try_fast(struct ocf_request *req);

#endif /* ENGINE_RD_H_ */
105 changes: 61 additions & 44 deletions src/ocf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,62 +221,79 @@ static void ocf_req_complete(struct ocf_request *req, int error)
ocf_io_put(&req->ioi.io);
}

static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req,
ocf_core_t core, ocf_cache_t cache)
static inline int _ocf_core_submit_io_fast_rd_generic(struct ocf_io *io,
struct ocf_request *req)
{
ocf_req_cache_mode_t original_cache_mode;
int fast;

if (req->d2c) {
return -OCF_ERR_IO;
}
int res;

switch (req->cache_mode) {
case ocf_req_cache_mode_wt:
case ocf_req_cache_mode_wa:
case ocf_req_cache_mode_wi:
if (io->dir == OCF_READ && req->core_line_count <= MAX_FAST_PATH_CACHE_LINES) {
if (ocf_read_generic_fast(req))
return 0;
ocf_req_clear_map(req);
}
break;

case ocf_req_cache_mode_wb:
case ocf_req_cache_mode_wo:
if (io->dir == OCF_READ && req->core_line_count <= MAX_FAST_PATH_CACHE_LINES)
return ocf_read_generic_fast(req) ? 0 : -OCF_ERR_IO;
break;
default:
break;
case ocf_req_cache_mode_wt:
case ocf_req_cache_mode_wa:
case ocf_req_cache_mode_wi:
case ocf_req_cache_mode_wb:
case ocf_req_cache_mode_wo:
res = ocf_read_generic_try_fast(req);
break;
default:
break;
}

original_cache_mode = req->cache_mode;
if (res == OCF_FAST_PATH_NO)
ocf_req_clear_map(req);

return res;
}

static inline ocf_req_cache_mode_t _ocf_core_req_resolve_fast_mode(
ocf_cache_t cache, struct ocf_request *req)
{
switch (req->cache_mode) {
case ocf_req_cache_mode_pt:
return -OCF_ERR_IO;
case ocf_req_cache_mode_wb:
case ocf_req_cache_mode_wo:
if (io->dir == OCF_WRITE)
req->cache_mode = ocf_req_cache_mode_fast;
break;
default:
if (cache->use_submit_io_fast)
case ocf_req_cache_mode_wb:
case ocf_req_cache_mode_wo:
return ocf_req_cache_mode_fast;
default:
break;
}

if (io->dir == OCF_WRITE)
return -OCF_ERR_IO;
if (!cache->use_submit_io_fast)
return ocf_req_cache_mode_max;

req->cache_mode = ocf_req_cache_mode_fast;
return ocf_req_cache_mode_fast;
}

static int ocf_core_submit_io_fast(struct ocf_io *io, struct ocf_request *req,
ocf_cache_t cache)
{
ocf_req_cache_mode_t original_mode, resolved_mode;
int ret;

if (req->d2c) {
return OCF_FAST_PATH_NO;
}

fast = ocf_engine_hndl_fast_req(req);
if (fast != OCF_FAST_PATH_NO)
return 0;
if (req->cache_mode == ocf_req_cache_mode_pt)
return OCF_FAST_PATH_NO;

/* If a read request isn't too big for a lookup in submission context,
check it is a read-hit and if cache line lock could be acquired
without waiting. If so, submit immediately */
if (req->rw == OCF_READ) {
if (req->core_line_count <= MAX_FAST_PATH_CACHE_LINES)
return _ocf_core_submit_io_fast_rd_generic(io, req);
}

resolved_mode = _ocf_core_req_resolve_fast_mode(cache, req);
if (resolved_mode == ocf_req_cache_mode_max)
return OCF_FAST_PATH_NO;

original_mode = req->cache_mode;
req->cache_mode = resolved_mode;

ret = ocf_engine_hndl_fast_req(req);
if (ret == OCF_FAST_PATH_NO)
req->cache_mode = original_mode;

req->cache_mode = original_cache_mode;
return -OCF_ERR_IO;
return ret;
}

static void ocf_core_volume_submit_io(struct ocf_io *io)
Expand Down Expand Up @@ -321,7 +338,7 @@ static void ocf_core_volume_submit_io(struct ocf_io *io)
/* Prevent race condition */
ocf_req_get(req);

if (!ocf_core_submit_io_fast(io, req, core, cache)) {
if (ocf_core_submit_io_fast(io, req, cache) == OCF_FAST_PATH_YES) {
ocf_core_seq_cutoff_update(core, req);
ocf_req_put(req);
return;
Expand Down

0 comments on commit 0ed191f

Please sign in to comment.