Commit 28fef38c authored by Mateusz Kozlowski's avatar Mateusz Kozlowski Committed by Ben Walker
Browse files

lib/ftl: Add cache properties



In expert mode FTL cache properties are available. The following
info of chunks is reported: id, state, and utilization.

Change-Id: I6e11566036b3be72b2a538c8afa889e95f735aea
Signed-off-by: default avatarMariusz Barczak <Mariusz.Barczak@solidigmtechnology.com>
Signed-off-by: default avatarMateusz Kozlowski <mateusz.kozlowski@solidigm.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19133


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Community-CI: Mellanox Build Bot
parent b5cf795b
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ static struct ftl_nv_cache_compactor *compactor_alloc(struct spdk_ftl_dev *dev);
static void compactor_free(struct spdk_ftl_dev *dev, struct ftl_nv_cache_compactor *compactor);
static void compaction_process_ftl_done(struct ftl_rq *rq);
static void compaction_process_read_entry(void *arg);
static void ftl_property_dump_cache_dev(struct spdk_ftl_dev *dev,
					const struct ftl_property *property,
					struct spdk_json_write_ctx *w);

static inline const struct ftl_layout_region *
nvc_data_region(struct ftl_nv_cache *nv_cache)
@@ -203,6 +206,9 @@ ftl_nv_cache_init(struct spdk_ftl_dev *dev)
	nv_cache->chunk_free_target = spdk_divide_round_up(nv_cache->chunk_count *
				      dev->conf.nv_cache.chunk_free_target,
				      100);

	ftl_property_register(dev, "cache_device", NULL, 0, NULL, NULL, ftl_property_dump_cache_dev, NULL,
			      NULL, true);
	return 0;
}

@@ -2354,3 +2360,49 @@ ftl_nv_cache_acquire_trim_seq_id(struct ftl_nv_cache *nv_cache)
	seq_id++;
	return seq_id;
}

static double
ftl_nv_cache_get_chunk_utilization(struct ftl_nv_cache *nv_cache,
				   struct ftl_nv_cache_chunk *chunk)
{
	double capacity = nv_cache->chunk_blocks;
	double used = chunk->md->blocks_written + chunk->md->blocks_skipped;

	return used / capacity;
}

static const char *
ftl_nv_cache_get_chunk_state_name(struct ftl_nv_cache_chunk *chunk)
{
	static const char *names[] = {
		"FREE", "OPEN", "CLOSED",
	};

	assert(chunk->md->state < SPDK_COUNTOF(names));
	if (chunk->md->state < SPDK_COUNTOF(names)) {
		return names[chunk->md->state];
	} else {
		assert(false);
		return "?";
	}
}

static void
ftl_property_dump_cache_dev(struct spdk_ftl_dev *dev, const struct ftl_property *property,
			    struct spdk_json_write_ctx *w)
{
	uint64_t i;
	struct ftl_nv_cache_chunk *chunk;

	spdk_json_write_named_string(w, "type", dev->nv_cache.nvc_desc->name);
	spdk_json_write_named_array_begin(w, "chunks");
	for (i = 0, chunk = dev->nv_cache.chunks; i < dev->nv_cache.chunk_count; i++, chunk++) {
		spdk_json_write_object_begin(w);
		spdk_json_write_named_uint64(w, "id", i);
		spdk_json_write_named_string(w, "state", ftl_nv_cache_get_chunk_state_name(chunk));
		spdk_json_write_named_double(w, "utilization",
					     ftl_nv_cache_get_chunk_utilization(&dev->nv_cache, chunk));
		spdk_json_write_object_end(w);
	}
	spdk_json_write_array_end(w);
}