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
2 changes: 2 additions & 0 deletions inc/ocf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -26,6 +27,7 @@
#include "cleaning/alru.h"
#include "cleaning/acp.h"
#include "promotion/nhit.h"
#include "prefetch/readahead.h"
#include "ocf_metadata.h"
#include "ocf_io_class.h"
#include "ocf_stats.h"
Expand Down
31 changes: 31 additions & 0 deletions inc/ocf_mngt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,37 @@ int ocf_mngt_cache_prefetch_set_policy(ocf_cache_t cache, ocf_pf_mask_t mask);
*/
int ocf_mngt_cache_prefetch_get_policy(ocf_cache_t cache, ocf_pf_mask_t *mask);

/**
* @brief Set prefetch policy parameter in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] pf_id Prefetch policy id
* @param[in] param_id Prefetch policy parameter id
* @param[in] param_value Prefetch policy parameter value
*
* @retval 0 Parameter has been set successfully
* @retval Non-zero Error occurred and parameter has not been set
*/
int ocf_mngt_cache_prefetch_set_param(ocf_cache_t cache, ocf_pf_id_t pf_id,
uint32_t param_id, uint32_t param_value);

/**
* @brief Get prefetch policy parameter from given cache
*
* @param[in] cache Cache handle
* @param[in] pf_id Prefetch policy id
* @param[in] param_id Prefetch policy parameter id
* @param[out] param_value Variable to store parameter value
*
* @retval 0 Parameter has been get successfully
* @retval Non-zero Error occurred and parameter has not been get
*/
int ocf_mngt_cache_prefetch_get_param(ocf_cache_t cache, ocf_pf_id_t pf_id,
uint32_t param_id, uint32_t *param_value);

/**
* @brief IO class configuration
*/
Expand Down
38 changes: 38 additions & 0 deletions inc/prefetch/readahead.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright(c) 2026 Unvertical
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef __OCF_PREFETCH_READAHEAD_H__
#define __OCF_PREFETCH_READAHEAD_H__

/**
* @file
* @brief Readahead prefetch policy API
*/

enum ocf_prefetch_readahead_parameters {
ocf_readahead_threshold,
};

/**
* @name Readahead prefetch policy parameters
* @{
*/

/**
* Readahead threshold - minimum sequential stream bytes before prefetching
*/

/** Threshold minimum value (bytes) */
#define OCF_PF_READAHEAD_MIN_THRESHOLD 0
/** Threshold maximum value (bytes) */
#define OCF_PF_READAHEAD_MAX_THRESHOLD 4294967295U
/** Threshold default value (bytes) */
#define OCF_PF_READAHEAD_DEFAULT_THRESHOLD (64 * KiB)

/**
* @}
*/

#endif /* __OCF_PREFETCH_READAHEAD_H__ */
2 changes: 2 additions & 0 deletions src/metadata/metadata_superblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "metadata_segment.h"
#include "../promotion/promotion.h"
#include "ocf/ocf_prefetch.h"
#include "../prefetch/ocf_prefetch_priv.h"

#define CACHE_MAGIC_NUMBER 0x187E1CA6

Expand Down Expand Up @@ -56,6 +57,7 @@ struct ocf_superblock_config {
struct promotion_policy_config promotion[PROMOTION_POLICY_TYPE_MAX];

ocf_pf_mask_t prefetch_mask;
struct prefetch_policy_config prefetch[PREFETCH_POLICY_TYPE_MAX];

/*
* Checksum for each metadata region.
Expand Down
66 changes: 66 additions & 0 deletions src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "../promotion/ops.h"
#include "../concurrency/ocf_pio_concurrency.h"
#include "../ocf_seq_cutoff.h"
#include "../prefetch/ocf_prefetch_priv.h"

#define OCF_ASSERT_PLUGGED(cache) ENV_BUG_ON(!(cache)->device)

Expand Down Expand Up @@ -402,6 +403,7 @@ static void _ocf_mngt_deinit_added_cores(
ocf_volume_deinit(&core->front_volume);
}

ocf_prefetch_deinit(cache, core);
ocf_core_seq_cutoff_deinit(core);
ocf_core_seq_detect_deinit(core);

Expand Down Expand Up @@ -494,6 +496,8 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
goto err;

ocf_core_seq_cutoff_init(core);
ocf_prefetch_init(cache, core);

if (!core->opened) {
env_bit_set(ocf_cache_state_incomplete,
&cache->cache_state);
Expand Down Expand Up @@ -1582,6 +1586,7 @@ static void _ocf_mngt_cache_init(ocf_cache_t cache,
cache->conf_meta->cache_mode = params->metadata.cache_mode;
cache->conf_meta->promotion_policy_type = params->metadata.promotion_policy;
cache->conf_meta->prefetch_mask = OCF_PF_MASK_DEFAULT;
ocf_prefetch_setup(cache);
__set_cleaning_policy(cache, ocf_cleaning_default);

/* Init Partitions */
Expand Down Expand Up @@ -3747,6 +3752,10 @@ int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
int ocf_mngt_cache_prefetch_set_policy(ocf_cache_t cache, ocf_pf_mask_t mask)
{
ocf_pf_mask_t valid_mask = (1 << ocf_pf_num) - 1;
ocf_pf_mask_t old_mask;
ocf_pf_mask_t enabled, disabled;
ocf_core_t core;
ocf_core_id_t core_id;

if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
Expand All @@ -3756,8 +3765,25 @@ int ocf_mngt_cache_prefetch_set_policy(ocf_cache_t cache, ocf_pf_mask_t mask)

ocf_metadata_start_exclusive_access(&cache->metadata.lock);

old_mask = cache->conf_meta->prefetch_mask;
cache->conf_meta->prefetch_mask = mask;

/* Newly enabled prefetchers need initialization */
enabled = mask & ~old_mask;
/* Newly disabled prefetchers need deinitialization */
disabled = old_mask & ~mask;

if (enabled || disabled) {
for_each_core(cache, core, core_id) {
ocf_pf_id_t pf_id;

for_each_pf_mask(pf_id, enabled)
ocf_prefetch_init_one(core, pf_id);
for_each_pf_mask(pf_id, disabled)
ocf_prefetch_deinit_one(core, pf_id);
}
}

ocf_metadata_end_exclusive_access(&cache->metadata.lock);

return 0;
Expand All @@ -3779,6 +3805,46 @@ int ocf_mngt_cache_prefetch_get_policy(ocf_cache_t cache, ocf_pf_mask_t *mask)
return 0;
}

int ocf_mngt_cache_prefetch_set_param(ocf_cache_t cache, ocf_pf_id_t pf_id,
uint32_t param_id, uint32_t param_value)
{
int ret;

OCF_CHECK_NULL(cache);

if (!OCF_PF_ID_VALID(pf_id))
return -OCF_ERR_INVAL;

if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

ocf_metadata_start_exclusive_access(&cache->metadata.lock);

ret = ocf_prefetch_set_param(cache, pf_id, param_id, param_value);

ocf_metadata_end_exclusive_access(&cache->metadata.lock);

return ret;
}

int ocf_mngt_cache_prefetch_get_param(ocf_cache_t cache, ocf_pf_id_t pf_id,
uint32_t param_id, uint32_t *param_value)
{
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(param_value);

if (!OCF_PF_ID_VALID(pf_id))
return -OCF_ERR_INVAL;

if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

return ocf_prefetch_get_param(cache, pf_id, param_id, param_value);
}

int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
Expand Down
2 changes: 2 additions & 0 deletions src/mngt/ocf_mngt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../ocf_queue_priv.h"
#include "../engine/engine_common.h"
#include "../ocf_seq_cutoff.h"
#include "../prefetch/ocf_prefetch_priv.h"

/* Close if opened */
void cache_mngt_core_deinit(ocf_core_t core)
Expand Down Expand Up @@ -132,6 +133,7 @@ void cache_mngt_core_remove_from_cache(ocf_core_t core)
{
ocf_cache_t cache = ocf_core_get_cache(core);

ocf_prefetch_deinit(cache, core);
ocf_core_seq_cutoff_deinit(core);
ocf_core_seq_detect_deinit(core);
env_free(core->counters);
Expand Down
3 changes: 3 additions & 0 deletions src/mngt/ocf_mngt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "../ocf_def_priv.h"
#include "../cleaning/cleaning_ops.h"
#include "../ocf_seq_cutoff.h"
#include "../prefetch/ocf_prefetch_priv.h"

ocf_seq_no_t ocf_mngt_get_core_seq_no(ocf_cache_t cache)
{
Expand Down Expand Up @@ -156,6 +157,7 @@ static void _ocf_mngt_cache_add_core_handle_error(
if (context->flags.clean_pol_added)
ocf_cleaning_remove_core(cache, core_id);

ocf_prefetch_deinit(cache, core);
ocf_core_seq_cutoff_deinit(core);
ocf_core_seq_detect_deinit(core);

Expand Down Expand Up @@ -486,6 +488,7 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,

/* Register seq detect consumers for default config */
ocf_core_seq_cutoff_init(core);
ocf_prefetch_init(cache, core);

/* When adding new core to cache, allocate stat counters */
core->counters =
Expand Down
4 changes: 2 additions & 2 deletions src/ocf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ static void ocf_core_volume_submit_io(ocf_io_t io)

fastpath = ocf_core_submit_io_fast(req, cache);

ocf_core_seq_detect_update(core, req);

if (fastpath == OCF_FAST_PATH_YES)
goto prefetch;

Expand All @@ -322,6 +320,8 @@ static void ocf_core_volume_submit_io(ocf_io_t io)
prefetch:
ocf_prefetch(req);

ocf_core_seq_detect_update(core, req);

ocf_req_put(req);

return;
Expand Down
2 changes: 2 additions & 0 deletions src/ocf_core_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ocf_ctx_priv.h"
#include "ocf_volume_priv.h"
#include "ocf_seq_detect.h"
#include "ocf/ocf_prefetch.h"

#define ocf_core_log_prefix(core, lvl, prefix, fmt, ...) \
ocf_cache_log_prefix(ocf_core_get_cache(core), lvl, ".%s" prefix, \
Expand Down Expand Up @@ -92,6 +93,7 @@ struct ocf_core {

struct ocf_seq_detect *seq_detect;

void *pf_priv[ocf_pf_num];
bool seq_cutoff_active;

env_atomic flushed;
Expand Down
14 changes: 6 additions & 8 deletions src/ocf_seq_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,13 @@ void ocf_core_seq_detect_update(ocf_core_t core, struct ocf_request *req)
ocf_seq_detect_sync_config(queue_sd, core);
ocf_seq_detect_sync_config(core_sd, core);

if (req->seq_cutoff_core) {
env_rwlock_write_lock(&core_sd->lock);
stream = ocf_seq_detect_update(core_sd,
req->addr, req->bytes, req->rw, false);
env_rwlock_write_unlock(&core_sd->lock);
env_rwlock_write_lock(&core_sd->lock);
stream = ocf_seq_detect_update(core_sd,
req->addr, req->bytes, req->rw, false);
env_rwlock_write_unlock(&core_sd->lock);

if (stream)
return;
}
if (stream)
return;

env_rwlock_write_lock(&queue_sd->lock);
stream = ocf_seq_detect_update(queue_sd,
Expand Down
Loading
Loading