Associate core metadata with core object

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2019-05-24 17:56:21 +02:00
parent 8f681e28c5
commit 711de86bff
19 changed files with 334 additions and 385 deletions

View File

@@ -282,21 +282,19 @@ static void __init_metadata_version(ocf_cache_t cache)
static void __reset_stats(ocf_cache_t cache)
{
int core_id;
ocf_core_t core;
ocf_core_id_t core_id;
ocf_part_id_t i;
for (core_id = 0; core_id < OCF_CORE_MAX; core_id++) {
env_atomic_set(&cache->core_runtime_meta[core_id].
cached_clines, 0);
env_atomic_set(&cache->core_runtime_meta[core_id].
dirty_clines, 0);
env_atomic64_set(&cache->core_runtime_meta[core_id].
dirty_since, 0);
for_each_core_all(cache, core, core_id) {
env_atomic_set(&core->runtime_meta->cached_clines, 0);
env_atomic_set(&core->runtime_meta->dirty_clines, 0);
env_atomic64_set(&core->runtime_meta->dirty_since, 0);
for (i = 0; i != OCF_IO_CLASS_MAX; i++) {
env_atomic_set(&cache->core_runtime_meta[core_id].
env_atomic_set(&core->runtime_meta->
part_counters[i].cached_clines, 0);
env_atomic_set(&cache->core_runtime_meta[core_id].
env_atomic_set(&core->runtime_meta->
part_counters[i].dirty_clines, 0);
}
}
@@ -365,7 +363,9 @@ static int _ocf_mngt_init_instance_add_cores(
ocf_cache_t cache = context->cache;
/* FIXME: This is temporary hack. Remove after storing name it meta. */
char core_name[OCF_CORE_NAME_SIZE];
int ret = -1, i;
ocf_core_t core;
ocf_core_id_t core_id;
int ret = -1;
uint64_t hd_lines = 0;
OCF_ASSERT_PLUGGED(cache);
@@ -381,17 +381,13 @@ static int _ocf_mngt_init_instance_add_cores(
cache->conf_meta->core_count = 0;
/* Check in metadata which cores were added into cache */
for (i = 0; i < OCF_CORE_MAX; i++) {
for_each_core(cache, core, core_id) {
ocf_volume_t tvolume = NULL;
ocf_core_t core = &cache->core[i];
if (!cache->core_conf_meta[i].added)
continue;
if (!cache->core[i].volume.type)
if (!core->volume.type)
goto err;
ret = snprintf(core_name, sizeof(core_name), "core%d", i);
ret = snprintf(core_name, sizeof(core_name), "core%d", core_id);
if (ret < 0 || ret >= sizeof(core_name))
goto err;
@@ -411,22 +407,23 @@ static int _ocf_mngt_init_instance_add_cores(
core->opened = true;
ocf_cache_log(cache, log_info,
"Attached core %u from pool\n", i);
"Attached core %u from pool\n",
core_id);
} else if (context->cfg.open_cores) {
ret = ocf_volume_open(&core->volume, NULL);
if (ret == -OCF_ERR_NOT_OPEN_EXC) {
ocf_cache_log(cache, log_warn,
"Cannot open core %u. "
"Cache is busy", i);
"Cache is busy", core_id);
} else if (ret) {
ocf_cache_log(cache, log_warn,
"Cannot open core %u", i);
"Cannot open core %u", core_id);
} else {
core->opened = true;
}
}
env_bit_set(i, cache->conf_meta->valid_core_bitmap);
env_bit_set(core_id, cache->conf_meta->valid_core_bitmap);
cache->conf_meta->core_count++;
core->volume.cache = cache;
@@ -444,13 +441,12 @@ static int _ocf_mngt_init_instance_add_cores(
cache->ocf_core_inactive_count++;
ocf_cache_log(cache, log_warn,
"Cannot find core %u in pool"
", core added as inactive\n", i);
", core added as inactive\n", core_id);
continue;
}
hd_lines = ocf_bytes_2_lines(cache,
ocf_volume_get_length(
&cache->core[i].volume));
ocf_volume_get_length(&core->volume));
if (hd_lines) {
ocf_cache_log(cache, log_info,
@@ -1884,19 +1880,18 @@ static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline,
{
struct ocf_mngt_cache_stop_context *context = priv;
ocf_cache_t cache = context->cache;
int i, j, no;
no = cache->conf_meta->core_count;
ocf_core_t core;
ocf_core_id_t core_id;
int no = cache->conf_meta->core_count;
/* All exported objects removed, cleaning up rest. */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
cache_mng_core_remove_from_cache(cache, i);
for_each_core(cache, core, core_id) {
cache_mng_core_remove_from_cache(core);
if (context->cache_attached)
cache_mng_core_remove_from_cleaning_pol(cache, i);
cache_mng_core_close(cache, i);
j++;
cache_mng_core_remove_from_cleaning_pol(core);
cache_mng_core_close(core);
if (--no == 0)
break;
}
ENV_BUG_ON(cache->conf_meta->core_count != 0);
@@ -2114,6 +2109,19 @@ void ocf_mngt_cache_save(ocf_cache_t cache,
ocf_mngt_cache_save_flush_sb_complete, context);
}
static void _cache_mng_update_initial_dirty_clines(ocf_cache_t cache)
{
ocf_core_t core;
ocf_core_id_t core_id;
for_each_core(cache, core, core_id) {
env_atomic_set(&core->runtime_meta->initial_dirty_clines,
env_atomic_read(&core->runtime_meta->
dirty_clines));
}
}
static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
{
ocf_cache_mode_t mode_old = cache->conf_meta->cache_mode;
@@ -2130,18 +2138,8 @@ static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
cache->conf_meta->cache_mode = mode;
if (ocf_cache_mode_wb == mode_old) {
int i;
for (i = 0; i != OCF_CORE_MAX; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
env_atomic_set(&cache->core_runtime_meta[i].
initial_dirty_clines,
env_atomic_read(&cache->
core_runtime_meta[i].dirty_clines));
}
}
if (mode_old == ocf_cache_mode_wb)
_cache_mng_update_initial_dirty_clines(cache);
ocf_cache_log(cache, log_info, "Changing cache mode from '%s' to '%s' "
"successful\n", ocf_get_io_iface_name(mode_old),
@@ -2300,17 +2298,16 @@ static void ocf_mngt_cache_detach_update_metadata(ocf_pipeline_t pipeline,
{
struct ocf_mngt_cache_detach_context *context = priv;
ocf_cache_t cache = context->cache;
int i, j, no;
no = cache->conf_meta->core_count;
ocf_core_t core;
ocf_core_id_t core_id;
int no = cache->conf_meta->core_count;
/* remove cacheline metadata and cleaning policy meta for all cores */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
cache_mng_core_deinit_attached_meta(cache, i);
cache_mng_core_remove_from_cleaning_pol(cache, i);
j++;
for_each_core(cache, core, core_id) {
cache_mng_core_deinit_attached_meta(core);
cache_mng_core_remove_from_cleaning_pol(core);
if (--no == 0)
break;
}
ocf_pipeline_next(context->pipeline);