Commit 14e26b9d authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

trace: rename spdk_trace_histories to spdk_trace_file.



The new name is obviously a better fit for what this structure has
become.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I91e96bea1d1d507b601e131e222f3181909f35de
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21826


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent d53fcd40
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ static int g_verbose = 1;
static uint64_t g_tsc_rate;
static uint64_t g_utsc_rate;
static bool g_shutdown = false;
static uint64_t g_histories_size;
static uint64_t g_file_size;

struct lcore_trace_record_ctx {
	char lcore_file[TRACE_PATH_MAX];
@@ -44,7 +44,7 @@ struct aggr_trace_record_ctx {
	int out_fd;
	int shm_fd;
	struct lcore_trace_record_ctx lcore_ports[SPDK_TRACE_MAX_LCORE];
	struct spdk_trace_histories *trace_histories;
	struct spdk_trace_file *trace_file;
};

static int
@@ -60,7 +60,7 @@ input_trace_file_mmap(struct aggr_trace_record_ctx *ctx, const char *shm_name)
	}

	/* Map the header of trace file */
	history_ptr = mmap(NULL, sizeof(struct spdk_trace_histories), PROT_READ, MAP_SHARED, ctx->shm_fd,
	history_ptr = mmap(NULL, sizeof(struct spdk_trace_file), PROT_READ, MAP_SHARED, ctx->shm_fd,
			   0);
	if (history_ptr == MAP_FAILED) {
		fprintf(stderr, "Could not mmap shm %s.\n", shm_name);
@@ -68,13 +68,13 @@ input_trace_file_mmap(struct aggr_trace_record_ctx *ctx, const char *shm_name)
		return -1;
	}

	ctx->trace_histories = (struct spdk_trace_histories *)history_ptr;
	ctx->trace_file = (struct spdk_trace_file *)history_ptr;

	g_tsc_rate = ctx->trace_histories->flags.tsc_rate;
	g_tsc_rate = ctx->trace_file->flags.tsc_rate;
	g_utsc_rate = g_tsc_rate / 1000;
	if (g_tsc_rate == 0) {
		fprintf(stderr, "Invalid tsc_rate %ju\n", g_tsc_rate);
		munmap(history_ptr, sizeof(struct spdk_trace_histories));
		munmap(history_ptr, sizeof(struct spdk_trace_file));
		close(ctx->shm_fd);
		return -1;
	}
@@ -84,20 +84,20 @@ input_trace_file_mmap(struct aggr_trace_record_ctx *ctx, const char *shm_name)
	}

	/* Remap the entire trace file */
	g_histories_size = spdk_get_trace_histories_size(ctx->trace_histories);
	munmap(history_ptr, sizeof(struct spdk_trace_histories));
	history_ptr = mmap(NULL, g_histories_size, PROT_READ, MAP_SHARED, ctx->shm_fd, 0);
	g_file_size = spdk_get_trace_file_size(ctx->trace_file);
	munmap(history_ptr, sizeof(struct spdk_trace_file));
	history_ptr = mmap(NULL, g_file_size, PROT_READ, MAP_SHARED, ctx->shm_fd, 0);
	if (history_ptr == MAP_FAILED) {
		fprintf(stderr, "Could not remmap shm %s.\n", shm_name);
		close(ctx->shm_fd);
		return -1;
	}

	ctx->trace_histories = (struct spdk_trace_histories *)history_ptr;
	ctx->trace_file = (struct spdk_trace_file *)history_ptr;
	for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
		struct spdk_trace_history *history;

		history = spdk_get_per_lcore_history(ctx->trace_histories, i);
		history = spdk_get_per_lcore_history(ctx->trace_file, i);
		ctx->lcore_ports[i].in_history = history;
		ctx->lcore_ports[i].valid = (history != NULL);

@@ -455,8 +455,8 @@ trace_files_aggregate(struct aggr_trace_record_ctx *ctx)
	}

	/* Write flags of histories into head of converged trace file, except num_entriess */
	rc = cont_write(ctx->out_fd, ctx->trace_histories,
			sizeof(struct spdk_trace_histories) - sizeof(lcore_offsets));
	rc = cont_write(ctx->out_fd, ctx->trace_file,
			sizeof(struct spdk_trace_file) - sizeof(lcore_offsets));
	if (rc < 0) {
		fprintf(stderr, "Failed to write trace header into trace file\n");
		goto out;
@@ -697,7 +697,7 @@ main(int argc, char **argv)

	}

	munmap(ctx.trace_histories, g_histories_size);
	munmap(ctx.trace_file, g_file_size);
	close(ctx.shm_fd);

	output_trace_files_finish(&ctx);
+9 −9
Original line number Diff line number Diff line
@@ -129,10 +129,10 @@ struct spdk_trace_flags {
	uint64_t			lcore_history_offsets[SPDK_TRACE_MAX_LCORE + 1];
};
extern struct spdk_trace_flags *g_trace_flags;
extern struct spdk_trace_histories *g_trace_histories;
extern struct spdk_trace_file *g_trace_file;


struct spdk_trace_histories {
struct spdk_trace_file {
	struct spdk_trace_flags flags;

	/**
@@ -151,13 +151,13 @@ spdk_get_trace_history_size(uint64_t num_entries)
}

static inline uint64_t
spdk_get_trace_histories_size(struct spdk_trace_histories *trace_histories)
spdk_get_trace_file_size(struct spdk_trace_file *trace_file)
{
	return trace_histories->flags.lcore_history_offsets[SPDK_TRACE_MAX_LCORE];
	return trace_file->flags.lcore_history_offsets[SPDK_TRACE_MAX_LCORE];
}

static inline struct spdk_trace_history *
spdk_get_per_lcore_history(struct spdk_trace_histories *trace_histories, unsigned lcore)
spdk_get_per_lcore_history(struct spdk_trace_file *trace_file, unsigned lcore)
{
	uint64_t lcore_history_offset;

@@ -165,12 +165,12 @@ spdk_get_per_lcore_history(struct spdk_trace_histories *trace_histories, unsigne
		return NULL;
	}

	lcore_history_offset = trace_histories->flags.lcore_history_offsets[lcore];
	lcore_history_offset = trace_file->flags.lcore_history_offsets[lcore];
	if (lcore_history_offset == 0) {
		return NULL;
	}

	return (struct spdk_trace_history *)(((char *)trace_histories) + lcore_history_offset);
	return (struct spdk_trace_history *)(((char *)trace_file) + lcore_history_offset);
}

void _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
@@ -179,9 +179,9 @@ void _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
#define _spdk_trace_record_tsc(tsc, tpoint_id, poller_id, size, object_id, num_args, ...)	\
	do {											\
		assert(tpoint_id < SPDK_TRACE_MAX_TPOINT_ID);					\
		if (g_trace_histories == NULL ||						\
		if (g_trace_file == NULL ||						\
		    !((1ULL << (tpoint_id & 0x3F)) &						\
		      g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) {			\
		      g_trace_file->flags.tpoint_mask[tpoint_id >> 6])) {			\
			break;									\
		}										\
		_spdk_trace_record(tsc, tpoint_id, poller_id, size, object_id,			\
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
	spdk_trace_create_tpoint_group_mask;

	# public variables
	g_trace_histories;
	g_trace_file;

	local: *;
};
+26 −26
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ static __thread uint32_t t_ut_array_index;
static __thread struct spdk_trace_history *t_ut_lcore_history;

uint32_t g_user_thread_index_start;
struct spdk_trace_histories *g_trace_histories;
struct spdk_trace_file *g_trace_file;
struct spdk_bit_array *g_ut_array;
pthread_mutex_t g_ut_array_mutex;

@@ -49,7 +49,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_

	lcore = spdk_env_get_current_core();
	if (spdk_likely(lcore != SPDK_ENV_LCORE_ID_ANY)) {
		lcore_history = spdk_get_per_lcore_history(g_trace_histories, lcore);
		lcore_history = spdk_get_per_lcore_history(g_trace_file, lcore);
	} else if (t_ut_lcore_history != NULL) {
		lcore_history = t_ut_lcore_history;
	} else {
@@ -181,7 +181,7 @@ spdk_trace_register_user_thread(void)

	ut_index = t_ut_array_index + g_user_thread_index_start;

	t_ut_lcore_history = spdk_get_per_lcore_history(g_trace_histories, ut_index);
	t_ut_lcore_history = spdk_get_per_lcore_history(g_trace_file, ut_index);

	assert(t_ut_lcore_history != NULL);

@@ -229,7 +229,7 @@ int
spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads)
{
	uint32_t i = 0, max_dedicated_cpu = 0;
	int histories_size;
	int file_size;
	uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE + 1] = { 0 };
	struct spdk_cpuset cpuset = {};

@@ -245,11 +245,11 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
	}

	spdk_cpuset_zero(&cpuset);
	histories_size = sizeof(struct spdk_trace_flags);
	file_size = sizeof(struct spdk_trace_flags);
	SPDK_ENV_FOREACH_CORE(i) {
		spdk_cpuset_set_cpu(&cpuset, i, true);
		lcore_offsets[i] = histories_size;
		histories_size += spdk_get_trace_history_size(num_entries);
		lcore_offsets[i] = file_size;
		file_size += spdk_get_trace_history_size(num_entries);
		max_dedicated_cpu = i;
	}

@@ -267,11 +267,11 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
	}

	for (i = g_user_thread_index_start; i < g_user_thread_index_start + num_threads; i++) {
		lcore_offsets[i] = histories_size;
		histories_size += spdk_get_trace_history_size(num_entries);
		lcore_offsets[i] = file_size;
		file_size += spdk_get_trace_history_size(num_entries);
	}

	lcore_offsets[SPDK_TRACE_MAX_LCORE] = histories_size;
	lcore_offsets[SPDK_TRACE_MAX_LCORE] = file_size;

	snprintf(g_shm_name, sizeof(g_shm_name), "%s", shm_name);

@@ -283,14 +283,14 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
		return 1;
	}

	if (ftruncate(g_trace_fd, histories_size) != 0) {
	if (ftruncate(g_trace_fd, file_size) != 0) {
		SPDK_ERRLOG("could not truncate shm\n");
		goto trace_init_err;
	}

	g_trace_histories = mmap(NULL, histories_size, PROT_READ | PROT_WRITE,
	g_trace_file = mmap(NULL, file_size, PROT_READ | PROT_WRITE,
			    MAP_SHARED, g_trace_fd, 0);
	if (g_trace_histories == MAP_FAILED) {
	if (g_trace_file == MAP_FAILED) {
		SPDK_ERRLOG("could not mmap shm\n");
		goto trace_init_err;
	}
@@ -300,7 +300,7 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
	 * altogether.
	 */
#if defined(__linux__)
	if (mlock(g_trace_histories, histories_size) != 0) {
	if (mlock(g_trace_file, file_size) != 0) {
		SPDK_ERRLOG("Could not mlock shm for tracing - %s.\n", spdk_strerror(errno));
		if (errno == ENOMEM) {
			SPDK_ERRLOG("Check /dev/shm for old tracing files that can be deleted.\n");
@@ -309,9 +309,9 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
	}
#endif

	memset(g_trace_histories, 0, histories_size);
	memset(g_trace_file, 0, file_size);

	g_trace_flags = &g_trace_histories->flags;
	g_trace_flags = &g_trace_file->flags;

	g_trace_flags->tsc_rate = spdk_get_ticks_hz();

@@ -327,7 +327,7 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
			assert(spdk_cpuset_get_cpu(&cpuset, i));
		}

		lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
		lcore_history = spdk_get_per_lcore_history(g_trace_file, i);
		lcore_history->lcore = i;
		lcore_history->num_entries = num_entries;
	}
@@ -338,14 +338,14 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_threads
	return 0;

trace_init_err:
	if (g_trace_histories != MAP_FAILED) {
		munmap(g_trace_histories, histories_size);
	if (g_trace_file != MAP_FAILED) {
		munmap(g_trace_file, file_size);
	}
	close(g_trace_fd);
	g_trace_fd = -1;
	shm_unlink(shm_name);
	spdk_bit_array_free(&g_ut_array);
	g_trace_histories = NULL;
	g_trace_file = NULL;

	return 1;

@@ -358,17 +358,17 @@ spdk_trace_cleanup(void)
	int i;
	struct spdk_trace_history *lcore_history;

	if (g_trace_histories == NULL) {
	if (g_trace_file == NULL) {
		return;
	}

	/*
	 * Only unlink the shm if there were no trace_entry recorded. This ensures the file
	 * can be used after this process exits/crashes for debugging.
	 * Note that we have to calculate this value before g_trace_histories gets unmapped.
	 * Note that we have to calculate this value before g_trace_file gets unmapped.
	 */
	for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
		lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
		lcore_history = spdk_get_per_lcore_history(g_trace_file, i);
		if (lcore_history == NULL) {
			continue;
		}
@@ -378,8 +378,8 @@ spdk_trace_cleanup(void)
		}
	}

	munmap(g_trace_histories, sizeof(struct spdk_trace_histories));
	g_trace_histories = NULL;
	munmap(g_trace_file, sizeof(struct spdk_trace_file));
	g_trace_file = NULL;
	close(g_trace_fd);
	spdk_bit_array_free(&g_ut_array);

+21 −21
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ struct spdk_trace_parser {
	~spdk_trace_parser();
	spdk_trace_parser(const spdk_trace_parser &) = delete;
	spdk_trace_parser &operator=(const spdk_trace_parser &) = delete;
	const spdk_trace_flags *flags() const { return &_histories->flags; }
	const spdk_trace_flags *flags() const { return &_trace_file->flags; }
	uint64_t tsc_offset() const { return _tsc_offset; }
	bool next_entry(spdk_trace_parser_entry *entry);
	uint64_t entry_count(uint16_t lcore) const;
@@ -78,7 +78,7 @@ private:
	bool init(const spdk_trace_parser_opts *opts);
	void cleanup();

	spdk_trace_histories	*_histories;
	spdk_trace_file		*_trace_file;
	size_t			_map_size;
	int			_fd;
	uint64_t		_tsc_offset;
@@ -96,7 +96,7 @@ spdk_trace_parser::entry_count(uint16_t lcore) const
		return 0;
	}

	history = spdk_get_per_lcore_history(_histories, lcore);
	history = spdk_get_per_lcore_history(_trace_file, lcore);

	return history == NULL ? 0 : history->num_entries;
}
@@ -106,7 +106,7 @@ spdk_trace_parser::get_next_buffer(spdk_trace_entry_buffer *buf, uint16_t lcore)
{
	spdk_trace_history *history;

	history = spdk_get_per_lcore_history(_histories, lcore);
	history = spdk_get_per_lcore_history(_trace_file, lcore);
	assert(history);

	if (spdk_unlikely(static_cast<void *>(buf) ==
@@ -172,7 +172,7 @@ spdk_trace_parser::next_entry(spdk_trace_parser_entry *pe)
	/* Set related index to the max value to indicate "empty" state */
	pe->related_index = UINT64_MAX;
	pe->related_type = OBJECT_NONE;
	tpoint = &_histories->flags.tpoint[entry->tpoint_id];
	tpoint = &_trace_file->flags.tpoint[entry->tpoint_id];
	stats = &_stats[tpoint->object_type];

	if (tpoint->new_object) {
@@ -305,40 +305,40 @@ spdk_trace_parser::init(const spdk_trace_parser_opts *opts)
		return false;
	}

	if ((size_t)st.st_size < sizeof(*_histories)) {
	if ((size_t)st.st_size < sizeof(*_trace_file)) {
		SPDK_ERRLOG("Invalid trace file: %s\n", opts->filename);
		return false;
	}

	/* Map the header of trace file */
	_map_size = sizeof(*_histories);
	_histories = static_cast<spdk_trace_histories *>(mmap(NULL, _map_size, PROT_READ,
	_map_size = sizeof(*_trace_file);
	_trace_file = static_cast<spdk_trace_file *>(mmap(NULL, _map_size, PROT_READ,
			MAP_SHARED, _fd, 0));
	if (_histories == MAP_FAILED) {
	if (_trace_file == MAP_FAILED) {
		SPDK_ERRLOG("Could not mmap trace file: %s\n", opts->filename);
		_histories = NULL;
		_trace_file = NULL;
		return false;
	}

	/* Remap the entire trace file */
	_map_size = spdk_get_trace_histories_size(_histories);
	munmap(_histories, sizeof(*_histories));
	_map_size = spdk_get_trace_file_size(_trace_file);
	munmap(_trace_file, sizeof(*_trace_file));
	if ((size_t)st.st_size < _map_size) {
		SPDK_ERRLOG("Trace file %s is not valid\n", opts->filename);
		_histories = NULL;
		_trace_file = NULL;
		return false;
	}
	_histories = static_cast<spdk_trace_histories *>(mmap(NULL, _map_size, PROT_READ,
	_trace_file = static_cast<spdk_trace_file *>(mmap(NULL, _map_size, PROT_READ,
			MAP_SHARED, _fd, 0));
	if (_histories == MAP_FAILED) {
	if (_trace_file == MAP_FAILED) {
		SPDK_ERRLOG("Could not mmap trace file: %s\n", opts->filename);
		_histories = NULL;
		_trace_file = NULL;
		return false;
	}

	if (opts->lcore == SPDK_TRACE_MAX_LCORE) {
		for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
			history = spdk_get_per_lcore_history(_histories, i);
			history = spdk_get_per_lcore_history(_trace_file, i);
			if (history == NULL || history->num_entries == 0 || history->entries[0].tsc == 0) {
				continue;
			}
@@ -346,7 +346,7 @@ spdk_trace_parser::init(const spdk_trace_parser_opts *opts)
			populate_events(history, history->num_entries);
		}
	} else {
		history = spdk_get_per_lcore_history(_histories, opts->lcore);
		history = spdk_get_per_lcore_history(_trace_file, opts->lcore);
		if (history == NULL) {
			SPDK_ERRLOG("Trace file %s has no trace history for lcore %d\n",
				    opts->filename, opts->lcore);
@@ -364,8 +364,8 @@ spdk_trace_parser::init(const spdk_trace_parser_opts *opts)
void
spdk_trace_parser::cleanup()
{
	if (_histories != NULL) {
		munmap(_histories, _map_size);
	if (_trace_file != NULL) {
		munmap(_trace_file, _map_size);
	}

	if (_fd > 0) {
@@ -374,7 +374,7 @@ spdk_trace_parser::cleanup()
}

spdk_trace_parser::spdk_trace_parser(const spdk_trace_parser_opts *opts) :
	_histories(NULL),
	_trace_file(NULL),
	_map_size(0),
	_fd(-1),
	_tsc_offset(0)