Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign queue API #800

Merged
merged 4 commits into from
Aug 2, 2024
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
41 changes: 5 additions & 36 deletions src/engine/cache_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const char *ocf_get_io_iface_name(ocf_req_cache_mode_t cache_mode)
return cache_mode_io_if_map[cache_mode]->name;
}

static ocf_engine_cb ocf_io_if_type_to_engine_cb(
static ocf_req_cb ocf_io_if_type_to_engine_cb(
enum ocf_io_if_type io_if_type, int rw)
{
if (unlikely(io_if_type == OCF_IO_MAX_IF ||
Expand All @@ -149,7 +149,7 @@ static ocf_engine_cb ocf_io_if_type_to_engine_cb(
return IO_IFS[io_if_type].cbs[rw];
}

static ocf_engine_cb ocf_cache_mode_to_engine_cb(
static ocf_req_cb ocf_cache_mode_to_engine_cb(
ocf_req_cache_mode_t req_cache_mode, int rw)
{
if (req_cache_mode == ocf_req_cache_mode_max)
Expand All @@ -158,37 +158,6 @@ static ocf_engine_cb ocf_cache_mode_to_engine_cb(
return cache_mode_io_if_map[req_cache_mode]->cbs[rw];
}

struct ocf_request *ocf_engine_pop_req(ocf_queue_t q)
{
unsigned long lock_flags = 0;
struct ocf_request *req;

OCF_CHECK_NULL(q);

/* LOCK */
env_spinlock_lock_irqsave(&q->io_list_lock, lock_flags);

if (list_empty(&q->io_list)) {
/* No items on the list */
env_spinlock_unlock_irqrestore(&q->io_list_lock,
lock_flags);
return NULL;
}

/* Get the first request and remove it from the list */
req = list_first_entry(&q->io_list, struct ocf_request, list);

env_atomic_dec(&q->io_no);
list_del(&req->list);

/* UNLOCK */
env_spinlock_unlock_irqrestore(&q->io_list_lock, lock_flags);

OCF_CHECK_NULL(req);

return req;
}

bool ocf_fallback_pt_is_on(ocf_cache_t cache)
{
ENV_BUG_ON(env_atomic_read(&cache->fallback_pt_error_counter) < 0);
Expand Down Expand Up @@ -264,14 +233,14 @@ int ocf_engine_hndl_req(struct ocf_request *req)
* to into OCF workers
*/

ocf_engine_push_req_back(req, true);
ocf_queue_push_req(req, OCF_QUEUE_ALLOW_SYNC);

return 0;
}

int ocf_engine_hndl_fast_req(struct ocf_request *req)
{
ocf_engine_cb engine_cb;
ocf_req_cb engine_cb;
int ret;

engine_cb = ocf_cache_mode_to_engine_cb(req->cache_mode, req->rw);
Expand Down Expand Up @@ -313,7 +282,7 @@ void ocf_engine_hndl_ops_req(struct ocf_request *req)
ocf_io_if_type_to_engine_cb(OCF_IO_D2C_IF, req->rw) :
ocf_io_if_type_to_engine_cb(OCF_IO_OPS_IF, req->rw);

ocf_engine_push_req_back(req, true);
ocf_queue_push_req(req, OCF_QUEUE_ALLOW_SYNC);
}

bool ocf_req_cache_mode_has_lazy_write(ocf_req_cache_mode_t mode)
Expand Down
28 changes: 3 additions & 25 deletions src/engine/cache_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,22 @@
#ifndef __CACHE_ENGINE_H_
#define __CACHE_ENGINE_H_

#include "../ocf_request.h"

struct ocf_thread_priv;
struct ocf_request;

#define LOOKUP_HIT 5
#define LOOKUP_MISS 6
#define LOOKUP_REMAPPED 8

typedef enum {
/* modes inherited from user API */
ocf_req_cache_mode_wt = ocf_cache_mode_wt,
ocf_req_cache_mode_wb = ocf_cache_mode_wb,
ocf_req_cache_mode_wa = ocf_cache_mode_wa,
ocf_req_cache_mode_pt = ocf_cache_mode_pt,
ocf_req_cache_mode_wi = ocf_cache_mode_wi,
ocf_req_cache_mode_wo = ocf_cache_mode_wo,

/* internal modes */
ocf_req_cache_mode_fast,
/*!< Fast path */
ocf_req_cache_mode_d2c,
/*!< Direct to Core - pass through to core without
touching cacheline metadata */

ocf_req_cache_mode_max,
} ocf_req_cache_mode_t;

static inline ocf_req_cache_mode_t ocf_cache_mode_to_req_cache_mode(
ocf_cache_mode_t mode)
{
return (ocf_req_cache_mode_t)mode;
}

typedef int (*ocf_engine_cb)(struct ocf_request *req);

struct ocf_io_if {
ocf_engine_cb cbs[2]; /* READ and WRITE */
ocf_req_cb cbs[2]; /* READ and WRITE */

const char *name;
};
Expand All @@ -56,8 +36,6 @@ bool ocf_req_cache_mode_has_lazy_write(ocf_req_cache_mode_t mode);

bool ocf_fallback_pt_is_on(ocf_cache_t cache);

struct ocf_request *ocf_engine_pop_req(struct ocf_queue *q);

int ocf_engine_hndl_req(struct ocf_request *req);

#define OCF_FAST_PATH_YES 7
Expand Down
4 changes: 3 additions & 1 deletion src/engine/engine_bf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -94,5 +95,6 @@ static int _ocf_backfill_do(struct ocf_request *req)
void ocf_engine_backfill(struct ocf_request *req)
{
backfill_queue_inc_block(req->cache);
ocf_engine_push_req_front_cb(req, _ocf_backfill_do, true);
ocf_queue_push_req_cb(req, _ocf_backfill_do,
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}
76 changes: 4 additions & 72 deletions src/engine/engine_common.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies Co., Ltd.
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -381,7 +381,8 @@ static void _ocf_engine_clean_end(void *private_data, int error)
} else {
req->info.dirty_any = 0;
req->info.dirty_all = 0;
ocf_engine_push_req_front(req, true);
ocf_queue_push_req(req,
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}
}

Expand Down Expand Up @@ -584,75 +585,6 @@ void ocf_engine_update_request_stats(struct ocf_request *req)
req->info.hit_no, req->core_line_count);
}

void ocf_engine_push_req_back(struct ocf_request *req, bool allow_sync)
{
ocf_cache_t cache = req->cache;
ocf_queue_t q = NULL;
unsigned long lock_flags = 0;

INIT_LIST_HEAD(&req->list);

ENV_BUG_ON(!req->io_queue);
q = req->io_queue;

if (!req->info.internal) {
env_atomic_set(&cache->last_access_ms,
env_ticks_to_msecs(env_get_tick_count()));
}

env_spinlock_lock_irqsave(&q->io_list_lock, lock_flags);

list_add_tail(&req->list, &q->io_list);
env_atomic_inc(&q->io_no);

env_spinlock_unlock_irqrestore(&q->io_list_lock, lock_flags);

/* NOTE: do not dereference @req past this line, it might
* be picked up by concurrent io thread and deallocated
* at this point */

ocf_queue_kick(q, allow_sync);
}

void ocf_engine_push_req_front(struct ocf_request *req, bool allow_sync)
{
ocf_cache_t cache = req->cache;
ocf_queue_t q = NULL;
unsigned long lock_flags = 0;

ENV_BUG_ON(!req->io_queue);
INIT_LIST_HEAD(&req->list);

q = req->io_queue;

if (!req->info.internal) {
env_atomic_set(&cache->last_access_ms,
env_ticks_to_msecs(env_get_tick_count()));
}

env_spinlock_lock_irqsave(&q->io_list_lock, lock_flags);

list_add(&req->list, &q->io_list);
env_atomic_inc(&q->io_no);

env_spinlock_unlock_irqrestore(&q->io_list_lock, lock_flags);

/* NOTE: do not dereference @req past this line, it might
* be picked up by concurrent io thread and deallocated
* at this point */

ocf_queue_kick(q, allow_sync);
}

void ocf_engine_push_req_front_cb(struct ocf_request *req,
ocf_engine_cb engine_cb,
bool allow_sync)
{
req->error = 0; /* Please explain why!!! */
req->engine_handler = engine_cb;
ocf_engine_push_req_front(req, allow_sync);
}

void inc_fallback_pt_error_counter(ocf_cache_t cache)
{
ENV_BUG_ON(env_atomic_read(&cache->fallback_pt_error_counter) < 0);
Expand Down Expand Up @@ -712,5 +644,5 @@ void ocf_engine_on_resume(struct ocf_request *req)

OCF_DEBUG_RQ(req, "On resume");

ocf_engine_push_req_front_cb(req, _ocf_engine_refresh, false);
ocf_queue_push_req_cb(req, _ocf_engine_refresh, OCF_QUEUE_PRIO_HIGH);
}
33 changes: 1 addition & 32 deletions src/engine/engine_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -280,38 +281,6 @@ void ocf_engine_update_block_stats(struct ocf_request *req);
*/
void ocf_engine_update_request_stats(struct ocf_request *req);

/**
* @brief Push front OCF request to the OCF thread worker queue
*
* @param req OCF request
* @param allow_sync caller allows for request from queue to be ran immediately
from push function in caller context
*/
void ocf_engine_push_req_back(struct ocf_request *req,
bool allow_sync);

/**
* @brief Push back OCF request to the OCF thread worker queue
*
* @param req OCF request
* @param allow_sync caller allows for request from queue to be ran immediately
from push function in caller context
*/
void ocf_engine_push_req_front(struct ocf_request *req,
bool allow_sync);

/**
* @brief Set interface and push from request to the OCF thread worker queue
*
* @param req OCF request
* @param engine_cb IO engine handler callback
* @param allow_sync caller allows for request from queue to be ran immediately
from push function in caller context
*/
void ocf_engine_push_req_front_cb(struct ocf_request *req,
ocf_engine_cb engine_cb,
bool allow_sync);

void inc_fallback_pt_error_counter(ocf_cache_t cache);

void ocf_engine_on_resume(struct ocf_request *req);
Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void _ocf_discard_cache_flush_complete(struct ocf_io *io, int error)
}

req->engine_handler = _ocf_discard_core;
ocf_engine_push_req_front(req, true);
ocf_queue_push_req(req, OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);

ocf_io_put(io);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ static void _ocf_discard_finish_step(struct ocf_request *req)
else
req->engine_handler = _ocf_discard_core;

ocf_engine_push_req_front(req, true);
ocf_queue_push_req(req, OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}

static void _ocf_discard_step_complete(struct ocf_request *req, int error)
Expand Down Expand Up @@ -182,7 +182,7 @@ static int _ocf_discard_step_do(struct ocf_request *req)
static void _ocf_discard_on_resume(struct ocf_request *req)
{
OCF_DEBUG_RQ(req, "On resume");
ocf_engine_push_req_front(req, true);
ocf_queue_push_req(req, OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}

static int _ocf_discard_step(struct ocf_request *req)
Expand Down
3 changes: 2 additions & 1 deletion src/engine/engine_fast.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -45,7 +46,7 @@ static void _ocf_read_fast_complete(struct ocf_request *req, int error)
if (req->error) {
OCF_DEBUG_RQ(req, "ERROR");

ocf_engine_push_req_front_pt(req);
ocf_queue_push_req_pt(req);
} else {
ocf_req_unlock(ocf_cache_line_concurrency(req->cache), req);

Expand Down
4 changes: 3 additions & 1 deletion src/engine/engine_inv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -62,5 +63,6 @@ static int _ocf_invalidate_do(struct ocf_request *req)

void ocf_engine_invalidate(struct ocf_request *req)
{
ocf_engine_push_req_front_cb(req, _ocf_invalidate_do, true);
ocf_queue_push_req_cb(req, _ocf_invalidate_do,
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}
7 changes: 4 additions & 3 deletions src/engine/engine_pt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2023 Huawei Technologies
* Copyright(c) 2023-2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "ocf/ocf.h"
Expand Down Expand Up @@ -165,8 +165,9 @@ int ocf_read_pt(struct ocf_request *req)
return 0;
}

void ocf_engine_push_req_front_pt(struct ocf_request *req)
void ocf_queue_push_req_pt(struct ocf_request *req)
{
ocf_engine_push_req_front_cb(req, ocf_read_pt_do, true);
ocf_queue_push_req_cb(req, ocf_read_pt_do,
OCF_QUEUE_ALLOW_SYNC | OCF_QUEUE_PRIO_HIGH);
}

3 changes: 2 additions & 1 deletion src/engine/engine_pt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -10,6 +11,6 @@ int ocf_read_pt(struct ocf_request *req);

int ocf_read_pt_do(struct ocf_request *req);

void ocf_engine_push_req_front_pt(struct ocf_request *req);
void ocf_queue_push_req_pt(struct ocf_request *req);

#endif /* ENGINE_OFF_H_ */
Loading
Loading