Cache lock cleanup and API improvements

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-01-21 13:46:28 +01:00
parent 0abb4dbbca
commit 03c2f142b3
13 changed files with 325 additions and 621 deletions

View File

@ -203,7 +203,7 @@ int main(int argc, char *argv[])
perform_workload(core1); perform_workload(core1);
/* Remove core from cache */ /* Remove core from cache */
if (ocf_mngt_cache_remove_core(cache1, ocf_core_get_id(core1), false)) if (ocf_mngt_cache_remove_core(core1))
error("Unable to remove core\n"); error("Unable to remove core\n");
/* Stop cache */ /* Stop cache */

View File

@ -333,17 +333,6 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
*/ */
int ocf_mngt_cache_stop(ocf_cache_t cache); int ocf_mngt_cache_stop(ocf_cache_t cache);
/**
* @brief Stop cache instance without acquiring cache lock - caller is
* required to hold cache write lock when calling this
*
* @param[in] cache Cache handle
*
* @retval 0 Cache successfully stopped
* @retval Non-zero Error occurred during stopping cache
*/
int ocf_mngt_cache_stop_nolock(ocf_cache_t cache);
/** /**
* @brief Attach caching device to cache instance * @brief Attach caching device to cache instance
* *
@ -356,19 +345,6 @@ int ocf_mngt_cache_stop_nolock(ocf_cache_t cache);
int ocf_mngt_cache_attach(ocf_cache_t cache, int ocf_mngt_cache_attach(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *device_cfg); struct ocf_mngt_cache_device_config *device_cfg);
/**
* @brief Attach caching device to cache instance without acquiring cache lock
* - caller is required to hold cache write lock when calling this
*
* @param[in] cache Cache handle
* @param[in] device_cfg Caching device configuration
*
* @retval 0 Cache cache successfully attached
* @retval Non-zero Error occurred during attaching cache
*/
int ocf_mngt_cache_attach_nolock(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *device_cfg);
/** /**
* @brief Detach caching cache * @brief Detach caching cache
* *
@ -382,7 +358,8 @@ int ocf_mngt_cache_detach(ocf_cache_t cache);
/** /**
* @brief Load cache instance * @brief Load cache instance
* *
* @param[in] cache Cache handle * @param[in] ctx OCF context
* @param[out] cache Cache handle
* @param[in] cfg Cache configuration * @param[in] cfg Cache configuration
* @param[in] device_cfg Caching device configuration * @param[in] device_cfg Caching device configuration
* *
@ -399,7 +376,7 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache,
* @brief Add core to cache instance * @brief Add core to cache instance
* *
* @param[in] cache Cache handle * @param[in] cache Cache handle
* @param[in] core Core object handle * @param[out] core Core object handle
* @param[in] cfg Core configuration * @param[in] cfg Core configuration
* *
* @retval 0 Core successfully added core to cache * @retval 0 Core successfully added core to cache
@ -408,46 +385,25 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache,
int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core, int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg); struct ocf_mngt_core_config *cfg);
/**
* @brief Add core to cache instance without acquiring cache lock - caller is
required to hold cache write lock when calling this
*
* @param[in] cache Cache handle
* @param[in] core Core object handle
* @param[in] cfg Core configuration
*
* @retval 0 Core successfully added core to cache
* @retval Non-zero Error occurred and adding core failed
*/
int ocf_mngt_cache_add_core_nolock(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg);
/** /**
* @brief Remove core from cache instance * @brief Remove core from cache instance
* *
* @param[in] cache Cache handle * @param[in] cache Core handle
* @param[in] core_id Core ID
* @param[in] detach only detach core without removing it from cache metadata
* *
* @retval 0 Core successfully removed core from cache * @retval 0 Core successfully removed from cache
* @retval Non-zero Error occurred and removing core failed * @retval Non-zero Error occurred and removing core failed
*/ */
int ocf_mngt_cache_remove_core(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_cache_remove_core(ocf_core_t core);
bool detach);
/** /**
* @brief Remove core from cache instance without acquiring cache lock - caller * @brief Detach core from cache instance
* is required to hold cache write lock when calling this
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] core_id Core ID
* @param[in] detach only detach core without removing it from cache metadata
* *
* @retval 0 Core successfully removed core from cache * @retval 0 Core successfully detached from cache
* @retval Non-zero Error occurred and removing core failed * @retval Non-zero Error occurred and detaching core failed
*/ */
int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_cache_detach_core(ocf_core_t core);
bool detach);
/* Flush operations */ /* Flush operations */
@ -462,45 +418,19 @@ int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id,
*/ */
int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption); int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption);
/**
* @brief Flush data from given cache without acquiring cache lock - caller is
* required to hold cache write OR read lock when calling this
*
* @param[in] cache Cache handle
* @param[in] interruption Allow for interruption
*
* @retval 0 Successfully flushed given cache
* @retval Non-zero Error occurred and flushing cache failed
*/
int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption);
/** /**
* @brief Flush data to given core * @brief Flush data to given core
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] id Core ID
* @param[in] interruption Allow for interruption * @param[in] interruption Allow for interruption
* *
* @retval 0 Successfully flushed data to given core * @retval 0 Successfully flushed data to given core
* @retval Non-zero Error occurred and flushing data to core failed * @retval Non-zero Error occurred and flushing data to core failed
*/ */
int ocf_mngt_core_flush(ocf_cache_t cache, ocf_core_id_t id, bool interruption); int ocf_mngt_core_flush(ocf_core_t core, bool interruption);
/** /**
* @brief Flush data to given core without acquiring cache lock - caller is * @brief Interrupt existing flushing of cache or core
* required to hold cache write OR read lock when calling this
*
* @param[in] cache Cache handle
* @param[in] id Core ID
* @param[in] interruption Allow for interruption
*
* @retval 0 Successfully flushed data to given core
* @retval Non-zero Error occurred and flushing data to core failed
*/
int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id,
bool interruption);
/**
* @brief Interrupt existing flushing of cache or cache
* *
* @param[in] cache Cache instance * @param[in] cache Cache instance
* *
@ -512,14 +442,13 @@ int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache);
/** /**
* @brief Purge data to given core * @brief Purge data to given core
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] id Core ID
* @param[in] interruption Allow for interruption * @param[in] interruption Allow for interruption
* *
* @retval 0 Successfully purged data to given core * @retval 0 Successfully purged data to given core
* @retval Non-zero Error occurred and purging data to core failed * @retval Non-zero Error occurred and purging data to core failed
*/ */
int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t id, bool interruption); int ocf_mngt_core_purge(ocf_core_t core, bool interruption);
/** /**
* @brief Purge data from given cache * @brief Purge data from given cache
* *
@ -629,53 +558,71 @@ int ocf_mngt_io_class_configure(ocf_cache_t cache,
/** /**
* @brief Set core sequential cutoff threshold * @brief Set core sequential cutoff threshold
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] core_id Core ID
* @param[in] thresh threshold in bytes for sequential cutoff * @param[in] thresh threshold in bytes for sequential cutoff
* *
* @retval 0 Sequential cutoff threshold has been set successfully * @retval 0 Sequential cutoff threshold has been set successfully
* @retval Non-zero Error occured and threshold hasn't been updated * @retval Non-zero Error occured and threshold hasn't been updated
*/ */
int ocf_mngt_set_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh);
uint32_t thresh);
/** /**
* @brief Set core sequential cutoff policy * @brief Set sequential cutoff threshold for all cores in cache
* *
* @param[in] cache Cache handle * @param[in] cache Cache handle
* @param[in] core_id Core ID * @param[in] thresh threshold in bytes for sequential cutoff
* @param[in] policy sequential cutoff policy
* *
* @retval 0 Sequential cutoff policy has been set successfully * @retval 0 Sequential cutoff threshold has been set successfully
* @retval Non-zero Error occured and policy hasn't been updated * @retval Non-zero Error occured and threshold hasn't been updated
*/ */
int ocf_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
ocf_seq_cutoff_policy policy); uint32_t thresh);
/** /**
* @brief Get core sequential cutoff threshold * @brief Get core sequential cutoff threshold
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] core_id Core ID
* @param[in] thresh threshold in bytes for sequential cutoff * @param[in] thresh threshold in bytes for sequential cutoff
* *
* @retval 0 Sequential cutoff threshold has been get successfully * @retval 0 Sequential cutoff threshold has been get successfully
* @retval Non-zero Error occured * @retval Non-zero Error occured
*/ */
int ocf_mngt_get_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh);
uint32_t *thresh);
/**
* @brief Set core sequential cutoff policy
*
* @param[in] core Core handle
* @param[in] policy sequential cutoff policy
*
* @retval 0 Sequential cutoff policy has been set successfully
* @retval Non-zero Error occured and policy hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy policy);
/**
* @brief Set sequential cutoff policy for all cores in cache
*
* @param[in] cache Cache handle
* @param[in] policy sequential cutoff policy
*
* @retval 0 Sequential cutoff policy has been set successfully
* @retval Non-zero Error occured and policy hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
ocf_seq_cutoff_policy policy);
/** /**
* @brief Get core sequential cutoff policy * @brief Get core sequential cutoff policy
* *
* @param[in] cache Cache handle * @param[in] core Core handle
* @param[in] core_id Core ID
* @param[in] policy sequential cutoff policy * @param[in] policy sequential cutoff policy
* *
* @retval 0 Sequential cutoff policy has been get successfully * @retval 0 Sequential cutoff policy has been get successfully
* @retval Non-zero Error occured * @retval Non-zero Error occured
*/ */
int ocf_mngt_get_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy); ocf_seq_cutoff_policy *policy);
/** /**

View File

@ -155,14 +155,22 @@ struct ocf_stats_core {
}; };
/** /**
* @brief Initialize or reset statistics. * @brief Initialize or reset core statistics
* *
* Initialize or reset counters used for statistics. * Initialize or reset counters used for statistics.
* *
* @param[in] cache OCF cache device handle * @param[in] core Core handle
* @param[in] core_id Id of core for which statistics should be initialized.
*/ */
int ocf_stats_initialize(ocf_cache_t cache, ocf_core_id_t core_id); void ocf_core_stats_initialize(ocf_core_t core);
/**
* @brief Initialize or reset statistics of all cores in cache
*
* Initialize or reset counters used for statistics.
*
* @param[in] cache Cache handle
*/
void ocf_core_stats_initialize_all(ocf_cache_t cache);
/** /**
* @brief ocf_io_class_get_stats retrieve cache statistics * @brief ocf_io_class_get_stats retrieve cache statistics

View File

@ -1479,7 +1479,7 @@ int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
return result; return result;
} }
int ocf_mngt_cache_attach_nolock(ocf_cache_t cache, int ocf_mngt_cache_attach(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *device_cfg) struct ocf_mngt_cache_device_config *device_cfg)
{ {
int result; int result;
@ -1502,25 +1502,6 @@ int ocf_mngt_cache_attach_nolock(ocf_cache_t cache,
return result; return result;
} }
int ocf_mngt_cache_attach(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *device_cfg)
{
int result;
if (!cache || !device_cfg)
return -OCF_ERR_INVAL;
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = ocf_mngt_cache_attach_nolock(cache, device_cfg);
ocf_mngt_cache_unlock(cache);
return result;
}
/** /**
* @brief Unplug caching device from cache instance. Variable size metadata * @brief Unplug caching device from cache instance. Variable size metadata
* containers are deinitialiazed as well as other cacheline related * containers are deinitialiazed as well as other cacheline related
@ -1696,15 +1677,19 @@ int ocf_mngt_cache_load(ocf_ctx_t ctx, ocf_cache_t *cache,
return 0; return 0;
} }
int ocf_mngt_cache_stop_nolock(ocf_cache_t cache) int ocf_mngt_cache_stop(ocf_cache_t cache)
{ {
int result; int result;
const char *cache_name; char cache_name[OCF_CACHE_NAME_SIZE];
ocf_ctx_t context; ocf_ctx_t context;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
cache_name = ocf_cache_get_name(cache); result = env_strncpy(cache_name, sizeof(cache_name),
ocf_cache_get_name(cache), sizeof(cache_name));
if (result)
return result;
context = ocf_cache_get_ctx(cache); context = ocf_cache_get_ctx(cache);
ocf_cache_log(cache, log_info, "Stopping cache\n"); ocf_cache_log(cache, log_info, "Stopping cache\n");
@ -1725,201 +1710,6 @@ int ocf_mngt_cache_stop_nolock(ocf_cache_t cache)
return result; return result;
} }
int ocf_mngt_cache_stop(ocf_cache_t cache)
{
int result;
OCF_CHECK_NULL(cache);
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = ocf_mngt_cache_stop_nolock(cache);
ocf_mngt_cache_unlock(cache);
return result;
}
static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx)
{
uint32_t threshold = *(uint32_t*) cntx;
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_id_t core_id = ocf_core_get_id(core);
uint32_t threshold_old = cache->core_conf_meta[core_id].
seq_cutoff_threshold;
if (threshold_old == threshold) {
ocf_core_log(core, log_info,
"Sequential cutoff threshold %u bytes is "
"already set\n", threshold);
return 0;
}
cache->core_conf_meta[core_id].seq_cutoff_threshold = threshold;
if (ocf_metadata_flush_superblock(cache)) {
ocf_core_log(core, log_err, "Failed to store sequential "
"cutoff threshold change. Reverting\n");
cache->core_conf_meta[core_id].seq_cutoff_threshold =
threshold_old;
return -OCF_ERR_WRITE_CACHE;
}
ocf_core_log(core, log_info, "Changing sequential cutoff "
"threshold from %u to %u bytes successful\n",
threshold_old, threshold);
return 0;
}
int ocf_mngt_set_seq_cutoff_threshold(ocf_cache_t cache,
ocf_core_id_t core_id, uint32_t thresh)
{
int result = ocf_mngt_cache_lock(cache);
if (result)
return result;
if (core_id == OCF_CORE_ID_INVALID) {
/* Core id was not specified so threshold will be set
* for cache and all attached cores.
*/
result = ocf_core_visit(cache,
_cache_mng_set_core_seq_cutoff_threshold,
&thresh,
true);
} else {
/* Setting threshold for specified core. */
ocf_core_t core;
result = ocf_core_get(cache, core_id, &core);
if (result)
goto END;
result = _cache_mng_set_core_seq_cutoff_threshold(core, &thresh);
}
END:
ocf_mngt_cache_unlock(cache);
return result;
}
static const char *_ocf_seq_cutoff_policy_names[ocf_seq_cutoff_policy_max] = {
[ocf_seq_cutoff_policy_always] = "always",
[ocf_seq_cutoff_policy_full] = "full",
[ocf_seq_cutoff_policy_never] = "never",
};
static const char *_cache_mng_seq_cutoff_policy_get_name(
ocf_seq_cutoff_policy policy)
{
if (policy < 0 || policy >= ocf_seq_cutoff_policy_max)
return NULL;
return _ocf_seq_cutoff_policy_names[policy];
}
static int _cache_mng_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx)
{
ocf_seq_cutoff_policy policy = *(ocf_seq_cutoff_policy*) cntx;
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_id_t core_id = ocf_core_get_id(core);
uint32_t policy_old = cache->core_conf_meta[core_id].seq_cutoff_policy;
if (policy_old == policy) {
ocf_core_log(core, log_info,
"Sequential cutoff policy %s is already set\n",
_cache_mng_seq_cutoff_policy_get_name(policy));
return 0;
}
cache->core_conf_meta[core_id].seq_cutoff_policy = policy;
if (ocf_metadata_flush_superblock(cache)) {
ocf_core_log(core, log_err, "Failed to store sequential "
"cutoff policy change. Reverting\n");
cache->core_conf_meta[core_id].seq_cutoff_policy = policy_old;
return -OCF_ERR_WRITE_CACHE;
}
ocf_core_log(core, log_info,
"Changing sequential cutoff policy from %s to %s\n",
_cache_mng_seq_cutoff_policy_get_name(policy_old),
_cache_mng_seq_cutoff_policy_get_name(policy));
return 0;
}
int ocf_mngt_set_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id,
ocf_seq_cutoff_policy policy)
{
ocf_core_t core;
int result = ocf_mngt_cache_lock(cache);
if (result)
return result;
if (core_id == OCF_CORE_ID_INVALID) {
/* Core id was not specified so policy will be set
* for cache and all attached cores.
*/
result = ocf_core_visit(cache,
_cache_mng_set_core_seq_cutoff_policy,
&policy,
true);
} else {
/* Setting policy for specified core. */
result = ocf_core_get(cache, core_id, &core);
if (result)
goto END;
result = _cache_mng_set_core_seq_cutoff_policy(core, &policy);
}
END:
ocf_mngt_cache_unlock(cache);
return result;
}
int ocf_mngt_get_seq_cutoff_threshold(ocf_cache_t cache, ocf_core_id_t core_id,
uint32_t *thresh)
{
ocf_core_t core;
int result;
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = ocf_core_get(cache, core_id, &core);
if (result)
goto out;
*thresh = ocf_core_get_seq_cutoff_threshold(core);
out:
ocf_mngt_cache_unlock(cache);
return result;
}
int ocf_mngt_get_seq_cutoff_policy(ocf_cache_t cache, ocf_core_id_t core_id,
ocf_seq_cutoff_policy *policy)
{
ocf_core_t core;
int result;
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = ocf_core_get(cache, core_id, &core);
if (result)
goto out;
*policy = ocf_core_get_seq_cutoff_policy(core);
out:
ocf_mngt_cache_unlock(cache);
return result;
}
static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode, static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
uint8_t flush) uint8_t flush)
{ {
@ -1941,7 +1731,7 @@ static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
if (flush) { if (flush) {
/* Flush required, do it, do it, do it... */ /* Flush required, do it, do it, do it... */
result = ocf_mngt_cache_flush_nolock(cache, true); result = ocf_mngt_cache_flush(cache, true);
if (result) { if (result) {
cache->conf_meta->cache_mode = mode_old; cache->conf_meta->cache_mode = mode_old;
@ -1987,10 +1777,6 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
} }
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = _cache_mng_set_cache_mode(cache, mode, flush); result = _cache_mng_set_cache_mode(cache, mode, flush);
if (result) { if (result) {
@ -2000,8 +1786,6 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
"failed\n", name); "failed\n", name);
} }
ocf_mngt_cache_unlock(cache);
return result; return result;
} }
@ -2065,22 +1849,18 @@ int ocf_mngt_cache_detach(ocf_cache_t cache)
int result; int result;
ocf_cache_mode_t mode; ocf_cache_mode_t mode;
OCF_CHECK_NULL(cache);
no = cache->conf_meta->core_count; no = cache->conf_meta->core_count;
result = ocf_mngt_cache_lock(cache); if (!env_atomic_read(&cache->attached))
if (result) return -EINVAL;
return result;
if (!env_atomic_read(&cache->attached)) {
result = -EINVAL;
goto unlock;
}
/* temporarily switch to PT */ /* temporarily switch to PT */
mode = cache->conf_meta->cache_mode; mode = cache->conf_meta->cache_mode;
result = _cache_mng_set_cache_mode(cache, ocf_cache_mode_pt, true); result = _cache_mng_set_cache_mode(cache, ocf_cache_mode_pt, true);
if (result) if (result)
goto unlock; return result;
/* wait for all requests referencing cacheline metadata to finish */ /* wait for all requests referencing cacheline metadata to finish */
env_atomic_set(&cache->attached, 0); env_atomic_set(&cache->attached, 0);
@ -2117,8 +1897,5 @@ int ocf_mngt_cache_detach(ocf_cache_t cache)
} }
} }
unlock:
ocf_mngt_cache_unlock(cache);
return result; return result;
} }

View File

@ -129,7 +129,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
goto error_after_clean_pol; goto error_after_clean_pol;
} }
/* When adding new core to cache, reset all core/cache statistics */ /* When adding new core to cache, reset all core/cache statistics */
ocf_stats_init(tmp_core); ocf_core_stats_initialize(tmp_core);
env_atomic_set(&cache->core_runtime_meta[cfg->core_id]. env_atomic_set(&cache->core_runtime_meta[cfg->core_id].
cached_clines, 0); cached_clines, 0);
env_atomic_set(&cache->core_runtime_meta[cfg->core_id]. env_atomic_set(&cache->core_runtime_meta[cfg->core_id].
@ -362,7 +362,7 @@ int ocf_mngt_core_init_front_dobj(ocf_core_t core)
return ocf_dobj_open(&core->front_obj); return ocf_dobj_open(&core->front_obj);
} }
int ocf_mngt_cache_add_core_nolock(ocf_cache_t cache, ocf_core_t *core, int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg) struct ocf_mngt_core_config *cfg)
{ {
int result; int result;
@ -419,24 +419,6 @@ out:
return result; return result;
} }
int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg)
{
int result;
OCF_CHECK_NULL(cache);
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
result = ocf_mngt_cache_add_core_nolock(cache, core, cfg);
ocf_mngt_cache_unlock(cache);
return result;
}
static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach) static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
{ {
struct ocf_cache *cache = core->obj.cache; struct ocf_cache *cache = core->obj.cache;
@ -470,24 +452,17 @@ static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
return 0; return 0;
} }
int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_cache_remove_core(ocf_core_t core)
bool detach)
{ {
ocf_cache_t cache = ocf_core_get_cache(core);
const char *core_name = ocf_core_get_name(core);
int result; int result;
ocf_core_t core;
const char *core_name;
OCF_CHECK_NULL(cache);
result = ocf_core_get(cache, core_id, &core);
if (result < 0)
return -OCF_ERR_CORE_NOT_AVAIL;
ocf_core_log(core, log_debug, "Removing core\n"); ocf_core_log(core, log_debug, "Removing core\n");
core_name = ocf_core_get_name(core); core_name = ocf_core_get_name(core);
result = _ocf_mngt_cache_remove_core(core, detach); result = _ocf_mngt_cache_remove_core(core, false);
if (!result) { if (!result) {
ocf_cache_log(cache, log_info, "Core %s successfully removed\n", ocf_cache_log(cache, log_info, "Core %s successfully removed\n",
core_name); core_name);
@ -499,20 +474,152 @@ int ocf_mngt_cache_remove_core_nolock(ocf_cache_t cache, ocf_core_id_t core_id,
return result; return result;
} }
int ocf_mngt_cache_remove_core(ocf_cache_t cache, ocf_core_id_t core_id, int ocf_mngt_cache_detach_core(ocf_core_t core)
bool detach)
{ {
ocf_cache_t cache = ocf_core_get_cache(core);
const char *core_name = ocf_core_get_name(core);
int result; int result;
OCF_CHECK_NULL(cache); ocf_core_log(core, log_debug, "Detaching core\n");
result = ocf_mngt_cache_lock(cache); result = _ocf_mngt_cache_remove_core(core, true);
if (result) if (!result) {
return result; ocf_cache_log(cache, log_info, "Core %s successfully detached\n",
core_name);
result = ocf_mngt_cache_remove_core_nolock(cache, core_id, detach); } else {
ocf_cache_log(cache, log_err, "Detaching core %s failed\n",
ocf_mngt_cache_unlock(cache); core_name);
}
return result; return result;
} }
static int _cache_mng_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx)
{
uint32_t threshold = *(uint32_t*) cntx;
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_id_t core_id = ocf_core_get_id(core);
uint32_t threshold_old = cache->core_conf_meta[core_id].
seq_cutoff_threshold;
if (threshold_old == threshold) {
ocf_core_log(core, log_info,
"Sequential cutoff threshold %u bytes is "
"already set\n", threshold);
return 0;
}
cache->core_conf_meta[core_id].seq_cutoff_threshold = threshold;
if (ocf_metadata_flush_superblock(cache)) {
ocf_core_log(core, log_err, "Failed to store sequential "
"cutoff threshold change. Reverting\n");
cache->core_conf_meta[core_id].seq_cutoff_threshold =
threshold_old;
return -OCF_ERR_WRITE_CACHE;
}
ocf_core_log(core, log_info, "Changing sequential cutoff "
"threshold from %u to %u bytes successful\n",
threshold_old, threshold);
return 0;
}
int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh)
{
OCF_CHECK_NULL(core);
return _cache_mng_set_core_seq_cutoff_threshold(core, &thresh);
}
int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
uint32_t thresh)
{
OCF_CHECK_NULL(cache);
return ocf_core_visit(cache, _cache_mng_set_core_seq_cutoff_threshold,
&thresh, true);
}
int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh)
{
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(thresh);
*thresh = ocf_core_get_seq_cutoff_threshold(core);
return 0;
}
static const char *_ocf_seq_cutoff_policy_names[ocf_seq_cutoff_policy_max] = {
[ocf_seq_cutoff_policy_always] = "always",
[ocf_seq_cutoff_policy_full] = "full",
[ocf_seq_cutoff_policy_never] = "never",
};
static const char *_cache_mng_seq_cutoff_policy_get_name(
ocf_seq_cutoff_policy policy)
{
if (policy < 0 || policy >= ocf_seq_cutoff_policy_max)
return NULL;
return _ocf_seq_cutoff_policy_names[policy];
}
static int _cache_mng_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx)
{
ocf_seq_cutoff_policy policy = *(ocf_seq_cutoff_policy*) cntx;
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_id_t core_id = ocf_core_get_id(core);
uint32_t policy_old = cache->core_conf_meta[core_id].seq_cutoff_policy;
if (policy_old == policy) {
ocf_core_log(core, log_info,
"Sequential cutoff policy %s is already set\n",
_cache_mng_seq_cutoff_policy_get_name(policy));
return 0;
}
cache->core_conf_meta[core_id].seq_cutoff_policy = policy;
if (ocf_metadata_flush_superblock(cache)) {
ocf_core_log(core, log_err, "Failed to store sequential "
"cutoff policy change. Reverting\n");
cache->core_conf_meta[core_id].seq_cutoff_policy = policy_old;
return -OCF_ERR_WRITE_CACHE;
}
ocf_core_log(core, log_info,
"Changing sequential cutoff policy from %s to %s\n",
_cache_mng_seq_cutoff_policy_get_name(policy_old),
_cache_mng_seq_cutoff_policy_get_name(policy));
return 0;
}
int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy policy)
{
OCF_CHECK_NULL(core);
return _cache_mng_set_core_seq_cutoff_policy(core, &policy);
}
int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
ocf_seq_cutoff_policy policy)
{
OCF_CHECK_NULL(cache);
return ocf_core_visit(cache, _cache_mng_set_core_seq_cutoff_policy,
&policy, true);
}
int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy)
{
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(policy);
*policy = ocf_core_get_seq_cutoff_policy(core);
return 0;
}

View File

@ -35,6 +35,8 @@ bool ocf_mngt_cache_is_dirty(ocf_cache_t cache)
{ {
uint32_t i; uint32_t i;
OCF_CHECK_NULL(cache);
for (i = 0; i < OCF_CORE_MAX; ++i) { for (i = 0; i < OCF_CORE_MAX; ++i) {
if (!cache->core_conf_meta[i].added) if (!cache->core_conf_meta[i].added)
continue; continue;
@ -430,7 +432,7 @@ out:
* @param allow_interruption whenever to allow interruption of flushing process. * @param allow_interruption whenever to allow interruption of flushing process.
* if set to 0, all requests to interrupt flushing will be ignored * if set to 0, all requests to interrupt flushing will be ignored
*/ */
static int _ocf_mng_cache_flush_nolock(ocf_cache_t cache, bool interruption) static int _ocf_mng_cache_flush(ocf_cache_t cache, bool interruption)
{ {
int result = 0; int result = 0;
int i, j; int i, j;
@ -460,12 +462,18 @@ static int _ocf_mng_cache_flush_nolock(ocf_cache_t cache, bool interruption)
return result; return result;
} }
int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
{ {
int result = 0; int result = 0;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache device is detached\n");
return -OCF_ERR_INVAL;
}
if (ocf_cache_is_incomplete(cache)) { if (ocf_cache_is_incomplete(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - " ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache is in incomplete state\n"); "cache is in incomplete state\n");
@ -476,7 +484,7 @@ int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption)
_ocf_mngt_begin_flush(cache); _ocf_mngt_begin_flush(cache);
result = _ocf_mng_cache_flush_nolock(cache, interruption); result = _ocf_mng_cache_flush(cache, interruption);
_ocf_mngt_end_flush(cache); _ocf_mngt_end_flush(cache);
@ -486,9 +494,9 @@ int ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption)
return result; return result;
} }
static int _ocf_mng_core_flush_nolock(ocf_core_t core, bool interruption) static int _ocf_mng_core_flush(ocf_core_t core, bool interruption)
{ {
struct ocf_cache *cache = core->obj.cache; ocf_cache_t cache = ocf_core_get_cache(core);
ocf_core_id_t core_id = ocf_core_get_id(core); ocf_core_id_t core_id = ocf_core_get_id(core);
int ret; int ret;
@ -508,17 +516,20 @@ static int _ocf_mng_core_flush_nolock(ocf_core_t core, bool interruption)
return ret; return ret;
} }
int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id, int ocf_mngt_core_flush(ocf_core_t core, bool interruption)
bool interruption)
{ {
ocf_core_t core; ocf_cache_t cache;
int ret = 0; int ret = 0;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(core);
ret = ocf_core_get(cache, id, &core); cache = ocf_core_get_cache(core);
if (ret < 0)
return -OCF_ERR_CORE_NOT_AVAIL; if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush core - "
"cache device is detached\n");
return -OCF_ERR_INVAL;
}
if (!core->opened) { if (!core->opened) {
ocf_core_log(core, log_err, "Cannot flush - core is in " ocf_core_log(core, log_err, "Cannot flush - core is in "
@ -530,7 +541,7 @@ int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id,
_ocf_mngt_begin_flush(cache); _ocf_mngt_begin_flush(cache);
ret = _ocf_mng_core_flush_nolock(core, interruption); ret = _ocf_mng_core_flush(core, interruption);
_ocf_mngt_end_flush(cache); _ocf_mngt_end_flush(cache);
@ -540,63 +551,17 @@ int ocf_mngt_core_flush_nolock(ocf_cache_t cache, ocf_core_id_t id,
return ret; return ret;
} }
int ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption) int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
{
int result = ocf_mngt_cache_read_lock(cache);
if (result)
return result;
if (!ocf_cache_is_device_attached(cache)) {
result = -OCF_ERR_INVAL;
goto unlock;
}
result = ocf_mngt_cache_flush_nolock(cache, interruption);
unlock:
ocf_mngt_cache_read_unlock(cache);
return result;
}
int ocf_mngt_core_flush(ocf_cache_t cache, ocf_core_id_t id, bool interruption)
{
int result;
/* lock read only */
result = ocf_mngt_cache_read_lock(cache);
if (result)
return result;
if (!ocf_cache_is_device_attached(cache)) {
result = -OCF_ERR_INVAL;
goto unlock;
}
result = ocf_mngt_core_flush_nolock(cache, id, interruption);
unlock:
ocf_mngt_cache_read_unlock(cache);
return result;
}
int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t core_id, bool interruption)
{ {
ocf_cache_t cache;
ocf_core_id_t core_id;
int result = 0; int result = 0;
uint64_t core_size = ~0ULL; uint64_t core_size = ~0ULL;
ocf_core_t core;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(core);
result = ocf_mngt_cache_read_lock(cache); cache = ocf_core_get_cache(core);
if (result) core_id = ocf_core_get_id(core);
return result;
result = ocf_core_get(cache, core_id, &core);
if (result < 0) {
ocf_mngt_cache_unlock(cache);
return -OCF_ERR_CORE_NOT_AVAIL;
}
core_size = ocf_dobj_get_length(&cache->core[core_id].obj); core_size = ocf_dobj_get_length(&cache->core[core_id].obj);
core_size = core_size ?: ~0ULL; core_size = core_size ?: ~0ULL;
@ -605,21 +570,19 @@ int ocf_mngt_core_purge(ocf_cache_t cache, ocf_core_id_t core_id, bool interrupt
ocf_core_log(core, log_info, "Purging\n"); ocf_core_log(core, log_info, "Purging\n");
result = _ocf_mng_core_flush_nolock(core, interruption); result = _ocf_mng_core_flush(core, interruption);
if (result) if (result)
goto err; goto out;
OCF_METADATA_LOCK_WR(); OCF_METADATA_LOCK_WR();
result = ocf_metadata_sparse_range(cache, core_id, 0, result = ocf_metadata_sparse_range(cache, core_id, 0,
core_size); core_size);
OCF_METADATA_UNLOCK_WR(); OCF_METADATA_UNLOCK_WR();
err: out:
_ocf_mngt_end_flush(cache); _ocf_mngt_end_flush(cache);
ocf_mngt_cache_read_unlock(cache);
return result; return result;
} }
@ -627,35 +590,32 @@ int ocf_mngt_cache_purge(ocf_cache_t cache, bool interruption)
{ {
int result = 0; int result = 0;
result = ocf_mngt_cache_read_lock(cache); OCF_CHECK_NULL(cache);
if (result)
return result;
_ocf_mngt_begin_flush(cache); _ocf_mngt_begin_flush(cache);
ocf_cache_log(cache, log_info, "Purging\n"); ocf_cache_log(cache, log_info, "Purging\n");
result = _ocf_mng_cache_flush_nolock(cache, interruption); result = _ocf_mng_cache_flush(cache, interruption);
if (result) if (result)
goto err; goto out;
OCF_METADATA_LOCK_WR(); OCF_METADATA_LOCK_WR();
result = ocf_metadata_sparse_range(cache, OCF_CORE_ID_INVALID, 0, result = ocf_metadata_sparse_range(cache, OCF_CORE_ID_INVALID, 0,
~0ULL); ~0ULL);
OCF_METADATA_UNLOCK_WR(); OCF_METADATA_UNLOCK_WR();
err: out:
_ocf_mngt_end_flush(cache); _ocf_mngt_end_flush(cache);
ocf_mngt_cache_read_unlock(cache);
return result; return result;
} }
int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache) int ocf_mngt_cache_flush_interrupt(ocf_cache_t cache)
{ {
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
ocf_cache_log(cache, log_alert, "Flushing interrupt\n"); ocf_cache_log(cache, log_alert, "Flushing interrupt\n");
cache->flushing_interrupted = 1; cache->flushing_interrupted = 1;
return 0; return 0;
@ -667,20 +627,17 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
ocf_cleaning_t old_type; ocf_cleaning_t old_type;
int ret; int ret;
OCF_CHECK_NULL(cache);
if (type < 0 || type >= ocf_cleaning_max) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
ret = ocf_mngt_cache_lock(cache);
if (ret)
return ret;
old_type = cache->conf_meta->cleaning_policy_type; old_type = cache->conf_meta->cleaning_policy_type;
if (type == old_type) { if (type == old_type) {
ocf_cache_log(cache, log_info, "Cleaning policy %s is already " ocf_cache_log(cache, log_info, "Cleaning policy %s is already "
"set\n", cleaning_policy_ops[old_type].name); "set\n", cleaning_policy_ops[old_type].name);
goto out; return 0;
} }
ocf_metadata_lock(cache, OCF_METADATA_WR); ocf_metadata_lock(cache, OCF_METADATA_WR);
@ -719,24 +676,16 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
ocf_metadata_unlock(cache, OCF_METADATA_WR); ocf_metadata_unlock(cache, OCF_METADATA_WR);
out:
ocf_mngt_cache_unlock(cache);
return ret; return ret;
} }
int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type) int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type)
{ {
int ret; OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(type);
ret = ocf_mngt_cache_read_lock(cache);
if (ret)
return ret;
*type = cache->conf_meta->cleaning_policy_type; *type = cache->conf_meta->cleaning_policy_type;
ocf_mngt_cache_read_unlock(cache);
return 0; return 0;
} }
@ -745,16 +694,14 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
{ {
int ret; int ret;
OCF_CHECK_NULL(cache);
if (type < 0 || type >= ocf_cleaning_max) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (!cleaning_policy_ops[type].set_cleaning_param) if (!cleaning_policy_ops[type].set_cleaning_param)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
ret = ocf_mngt_cache_lock(cache);
if (ret)
return ret;
ocf_metadata_lock(cache, OCF_METADATA_WR); ocf_metadata_lock(cache, OCF_METADATA_WR);
ret = cleaning_policy_ops[type].set_cleaning_param(cache, ret = cleaning_policy_ops[type].set_cleaning_param(cache,
@ -774,8 +721,6 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
ocf_metadata_unlock(cache, OCF_METADATA_WR); ocf_metadata_unlock(cache, OCF_METADATA_WR);
ocf_mngt_cache_unlock(cache);
return ret; return ret;
} }
@ -784,20 +729,17 @@ int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type,
{ {
int ret; int ret;
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(param_value);
if (type < 0 || type >= ocf_cleaning_max) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (!cleaning_policy_ops[type].get_cleaning_param) if (!cleaning_policy_ops[type].get_cleaning_param)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
ret = ocf_mngt_cache_read_lock(cache);
if (ret)
return ret;
ret = cleaning_policy_ops[type].get_cleaning_param(cache, ret = cleaning_policy_ops[type].get_cleaning_param(cache,
param_id, param_value); param_id, param_value);
ocf_mngt_cache_read_unlock(cache);
return ret; return ret;
} }

View File

@ -261,14 +261,6 @@ int ocf_mngt_io_class_configure(ocf_cache_t cache,
if (result) if (result)
return result; return result;
result = ocf_mngt_cache_lock(cache); return _ocf_mngt_io_class_configure(cache, cfg);
if (result)
return result;
result = _ocf_mngt_io_class_configure(cache, cfg);
ocf_mngt_cache_unlock(cache);
return result;
} }

View File

@ -77,17 +77,12 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
uint64_t core_dirty_since; uint64_t core_dirty_since;
uint32_t dirty_blocks_inactive = 0; uint32_t dirty_blocks_inactive = 0;
uint32_t cache_occupancy_inactive = 0; uint32_t cache_occupancy_inactive = 0;
int result;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
if (!info) if (!info)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
result = ocf_mngt_cache_read_lock(cache);
if (result)
return result;
ENV_BUG_ON(env_memset(info, sizeof(*info), 0)); ENV_BUG_ON(env_memset(info, sizeof(*info), 0));
info->attached = ocf_cache_is_device_attached(cache); info->attached = ocf_cache_is_device_attached(cache);
@ -172,8 +167,6 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
ocf_metadata_size_of(cache) : 0; ocf_metadata_size_of(cache) : 0;
info->cache_line_size = ocf_line_size(cache); info->cache_line_size = ocf_line_size(cache);
ocf_mngt_cache_read_unlock(cache);
return 0; return 0;
} }

View File

@ -12,8 +12,7 @@
int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class, int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class,
struct ocf_io_class_info *info) struct ocf_io_class_info *info)
{ {
ocf_part_id_t part_id; ocf_part_id_t part_id = io_class;
int result;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
@ -22,23 +21,16 @@ int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class,
if (io_class >= OCF_IO_CLASS_MAX) if (io_class >= OCF_IO_CLASS_MAX)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
part_id = io_class;
result = ocf_mngt_cache_read_lock(cache);
if (result)
return result;
if (!ocf_part_is_valid(&cache->user_parts[part_id])) { if (!ocf_part_is_valid(&cache->user_parts[part_id])) {
/* Partition does not exist */ /* Partition does not exist */
result = -OCF_ERR_IO_CLASS_NOT_EXIST; return -OCF_ERR_IO_CLASS_NOT_EXIST;
goto unlock;
} }
if (env_strncpy(info->name, sizeof(info->name), if (env_strncpy(info->name, sizeof(info->name),
cache->user_parts[part_id].config->name, cache->user_parts[part_id].config->name,
sizeof(cache->user_parts[part_id].config->name))) { sizeof(cache->user_parts[part_id].config->name))) {
result = -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
goto unlock;
} }
info->priority = cache->user_parts[part_id].config->priority; info->priority = cache->user_parts[part_id].config->priority;
@ -52,10 +44,7 @@ int ocf_io_class_get_info(ocf_cache_t cache, uint32_t io_class,
info->cache_mode = cache->user_parts[part_id].config->cache_mode; info->cache_mode = cache->user_parts[part_id].config->cache_mode;
unlock: return 0;
ocf_mngt_cache_read_unlock(cache);
return result;
} }
int ocf_io_class_visit(ocf_cache_t cache, ocf_io_class_visitor_t visitor, int ocf_io_class_visit(ocf_cache_t cache, ocf_io_class_visitor_t visitor,

View File

@ -55,10 +55,25 @@ static void ocf_stats_error_init(struct ocf_counters_error *stats)
env_atomic_set(&stats->write, 0); env_atomic_set(&stats->write, 0);
} }
void ocf_stats_init(ocf_core_t core)
/********************************************************************
* Function that resets stats, debug and breakdown counters.
* If reset is set the following stats won't be reset:
* - cache_occupancy
* - queue_length
* - debug_counters_read_reqs_issued_seq_hits
* - debug_counters_read_reqs_issued_not_seq_hits
* - debug_counters_read_reqs_issued_read_miss_schedule
* - debug_counters_write_reqs_thread
* - debug_counters_write_reqs_issued_only_hdd
* - debug_counters_write_reqs_issued_both_devs
*********************************************************************/
void ocf_core_stats_initialize(ocf_core_t core)
{ {
int i;
struct ocf_counters_core *exp_obj_stats; struct ocf_counters_core *exp_obj_stats;
int i;
OCF_CHECK_NULL(core);
exp_obj_stats = core->counters; exp_obj_stats = core->counters;
@ -76,47 +91,16 @@ void ocf_stats_init(ocf_core_t core)
#endif #endif
} }
/******************************************************************** void ocf_core_stats_initialize_all(ocf_cache_t cache)
* Function that resets stats, debug and breakdown counters.
* If reset is set the following stats won't be reset:
* - cache_occupancy
* - queue_length
* - debug_counters_read_reqs_issued_seq_hits
* - debug_counters_read_reqs_issued_not_seq_hits
* - debug_counters_read_reqs_issued_read_miss_schedule
* - debug_counters_write_reqs_thread
* - debug_counters_write_reqs_issued_only_hdd
* - debug_counters_write_reqs_issued_both_devs
*********************************************************************/
int ocf_stats_initialize(ocf_cache_t cache, ocf_core_id_t core_id)
{ {
ocf_core_t core;
ocf_core_id_t id; ocf_core_id_t id;
int result;
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
if (core_id != OCF_CORE_ID_INVALID) {
result = ocf_core_get(cache, core_id, &core);
if (!result)
ocf_stats_init(core);
ocf_mngt_cache_unlock(cache);
return result;
}
for (id = 0; id < OCF_CORE_MAX; id++) { for (id = 0; id < OCF_CORE_MAX; id++) {
if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap)) if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap))
continue; continue;
ocf_stats_init(&cache->core[id]); ocf_core_stats_initialize(&cache->core[id]);
} }
ocf_mngt_cache_unlock(cache);
return 0;
} }
static void copy_req_stats(struct ocf_stats_req *dest, static void copy_req_stats(struct ocf_stats_req *dest,
@ -179,8 +163,7 @@ static void copy_debug_stats(struct ocf_stats_core_debug *dest,
int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class, int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class,
struct ocf_stats_io_class *stats) struct ocf_stats_io_class *stats)
{ {
int result; ocf_part_id_t part_id = io_class;
uint32_t part_id;
uint32_t i; uint32_t i;
uint32_t cache_occupancy_total = 0; uint32_t cache_occupancy_total = 0;
struct ocf_counters_part *part_stat; struct ocf_counters_part *part_stat;
@ -195,21 +178,12 @@ int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class,
if (!stats) if (!stats)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
result = ocf_mngt_cache_read_lock(cache); if (io_class >= OCF_IO_CLASS_MAX)
if (result) return -OCF_ERR_INVAL;
return result;
if (io_class >= OCF_IO_CLASS_MAX) {
result = -OCF_ERR_INVAL;
goto unlock;
}
part_id = io_class;
if (!ocf_part_is_valid(&cache->user_parts[part_id])) { if (!ocf_part_is_valid(&cache->user_parts[part_id])) {
/* Partition does not exist */ /* Partition does not exist */
result = -OCF_ERR_IO_CLASS_NOT_EXIST; return -OCF_ERR_IO_CLASS_NOT_EXIST;
goto unlock;
} }
for (i = 0; i != OCF_CORE_MAX; ++i) { for (i = 0; i != OCF_CORE_MAX; ++i) {
@ -238,9 +212,7 @@ int ocf_io_class_get_stats(ocf_core_t core, uint32_t io_class,
copy_block_stats(&stats->blocks, &part_stat->blocks); copy_block_stats(&stats->blocks, &part_stat->blocks);
unlock: return 0;
ocf_mngt_cache_read_unlock(cache);
return result;
} }
static uint32_t _calc_dirty_for(uint64_t dirty_since) static uint32_t _calc_dirty_for(uint64_t dirty_since)
@ -252,7 +224,6 @@ static uint32_t _calc_dirty_for(uint64_t dirty_since)
int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats)
{ {
int result;
uint32_t i; uint32_t i;
ocf_core_id_t core_id; ocf_core_id_t core_id;
ocf_cache_t cache; ocf_cache_t cache;
@ -267,10 +238,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats)
if (!stats) if (!stats)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
result = ocf_mngt_cache_read_lock(cache);
if (result)
return result;
core_stats = core->counters; core_stats = core->counters;
ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0)); ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0));
@ -321,8 +288,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats)
stats->dirty_for = _calc_dirty_for( stats->dirty_for = _calc_dirty_for(
env_atomic64_read(&cache->core_runtime_meta[core_id].dirty_since)); env_atomic64_read(&cache->core_runtime_meta[core_id].dirty_since));
ocf_mngt_cache_read_unlock(cache);
return 0; return 0;
} }

View File

@ -56,6 +56,4 @@ struct ocf_counters_core {
#endif #endif
}; };
void ocf_stats_init(ocf_core_t core);
#endif #endif

View File

@ -85,15 +85,10 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx,
if (!trace_callback) if (!trace_callback)
return -EINVAL; return -EINVAL;
result = ocf_mngt_cache_lock(cache);
if (result)
return result;
if (cache->trace.trace_callback) { if (cache->trace.trace_callback) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
"Tracing already started for cache %u\n", "Tracing already started for cache %u\n",
ocf_cache_get_id(cache)); ocf_cache_get_id(cache));
ocf_mngt_cache_unlock(cache);
return -EINVAL; return -EINVAL;
} }
@ -106,36 +101,28 @@ int ocf_mngt_start_trace(ocf_cache_t cache, void *trace_ctx,
for (i = 0; i < cache->io_queues_no; i++) { for (i = 0; i < cache->io_queues_no; i++) {
result = _ocf_trace_cache_info(cache, i); result = _ocf_trace_cache_info(cache, i);
if (result) if (result) {
goto trace_deinit; cache->trace.trace_callback = NULL;
return result;
}
} }
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Tracing started for cache %u\n", ocf_cache_get_id(cache)); "Tracing started for cache %u\n", ocf_cache_get_id(cache));
ocf_mngt_cache_unlock(cache);
return result;
trace_deinit:
cache->trace.trace_callback = NULL;
ocf_mngt_cache_unlock(cache);
return result; return result;
} }
int ocf_mngt_stop_trace(ocf_cache_t cache) int ocf_mngt_stop_trace(ocf_cache_t cache)
{ {
int queue, result; int queue;
result = ocf_mngt_cache_lock(cache); OCF_CHECK_NULL(cache);
if (result)
return result;
if (!cache->trace.trace_callback) { if (!cache->trace.trace_callback) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
"Tracing not started for cache %u\n", "Tracing not started for cache %u\n",
ocf_cache_get_id(cache)); ocf_cache_get_id(cache));
ocf_mngt_cache_unlock(cache);
return -EINVAL; return -EINVAL;
} }
@ -151,7 +138,6 @@ int ocf_mngt_stop_trace(ocf_cache_t cache)
// Poll for all ongoing traces completion // Poll for all ongoing traces completion
while (ocf_is_trace_ongoing(cache)) while (ocf_is_trace_ongoing(cache))
env_msleep(20); env_msleep(20);
ocf_mngt_cache_unlock(cache);
return result; return 0;
} }

View File

@ -65,7 +65,7 @@ int __wrap_ocf_log_raw(const struct ocf_logger *logger, ocf_logger_lvl_t lvl,
return mock(); return mock();
} }
int __wrap_ocf_mngt_cache_flush_nolock(ocf_cache_t cache, bool interruption) int __wrap_ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
{ {
function_called(); function_called();
return mock(); return mock();
@ -186,8 +186,8 @@ static void _cache_mng_set_cache_mode_test03(void **state)
expect_function_call(__wrap_ocf_cache_mode_is_valid); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 1); will_return(__wrap_ocf_cache_mode_is_valid, 1);
expect_function_call(__wrap_ocf_mngt_cache_flush_nolock); expect_function_call(__wrap_ocf_mngt_cache_flush);
will_return(__wrap_ocf_mngt_cache_flush_nolock, -OCF_ERR_NO_MEM); will_return(__wrap_ocf_mngt_cache_flush, -OCF_ERR_NO_MEM);
result = _cache_mng_set_cache_mode(&cache, mode_new, flush); result = _cache_mng_set_cache_mode(&cache, mode_new, flush);
@ -334,8 +334,8 @@ static void _cache_mng_set_cache_mode_test07(void **state)
expect_function_call(__wrap_ocf_cache_mode_is_valid); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 1); will_return(__wrap_ocf_cache_mode_is_valid, 1);
expect_function_call(__wrap_ocf_mngt_cache_flush_nolock); expect_function_call(__wrap_ocf_mngt_cache_flush);
will_return(__wrap_ocf_mngt_cache_flush_nolock, 0); will_return(__wrap_ocf_mngt_cache_flush, 0);
expect_function_call(__wrap_ocf_metadata_flush_superblock); expect_function_call(__wrap_ocf_metadata_flush_superblock);
will_return(__wrap_ocf_metadata_flush_superblock, 0); will_return(__wrap_ocf_metadata_flush_superblock, 0);