lib/trace: records num-trace-entries for lcores
With the trace_size records for each lcore, spdk_trace can read trace_file in which each lcore has different number of trace entries. Offset of each trace_history from the beginning of this data structure. Change-Id: I06afaba129812fe40ed000265fc66b02c5d9e3d9 Signed-off-by: Liu Xiaodong <xiaodong.liu@intel.com> Reviewed-on: https://review.gerrithub.io/433503 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
fd4c75721e
commit
9d2f39ab0b
@ -169,7 +169,7 @@ int main(int argc, char **argv)
|
||||
memset(last_tasks_done, 0, sizeof(last_tasks_done));
|
||||
|
||||
for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
|
||||
history = spdk_get_per_lcore_history(histories, i, histories->flags.num_entries);
|
||||
history = spdk_get_per_lcore_history(histories, i);
|
||||
last_tasks_done[i] = history->tpoint_count[TRACE_ISCSI_TASK_DONE];
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ int main(int argc, char **argv)
|
||||
printf("=============\n");
|
||||
total_tasks_done_per_sec = 0;
|
||||
for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
|
||||
history = spdk_get_per_lcore_history(histories, i, histories->flags.num_entries);
|
||||
history = spdk_get_per_lcore_history(histories, i);
|
||||
tasks_done = history->tpoint_count[TRACE_ISCSI_TASK_DONE];
|
||||
tasks_done_delta = tasks_done - last_tasks_done[i];
|
||||
if (tasks_done_delta == 0) {
|
||||
|
@ -284,7 +284,8 @@ static void usage(void)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *history_ptr;
|
||||
struct spdk_trace_history *history_entries, *history;
|
||||
struct spdk_trace_history *history;
|
||||
struct spdk_trace_histories *histories;
|
||||
int fd, i;
|
||||
int lcore = SPDK_TRACE_MAX_LCORE;
|
||||
uint64_t tsc_offset;
|
||||
@ -293,9 +294,7 @@ int main(int argc, char **argv)
|
||||
int op;
|
||||
char shm_name[64];
|
||||
int shm_id = -1, shm_pid = -1;
|
||||
uint64_t num_entries;
|
||||
uint64_t trace_histories_size;
|
||||
uint64_t lcore_history_size;
|
||||
|
||||
g_exe_name = argv[0];
|
||||
while ((op = getopt(argc, argv, "c:f:i:p:qs:")) != -1) {
|
||||
@ -375,15 +374,12 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
num_entries = g_histories->flags.num_entries;
|
||||
|
||||
if (g_verbose) {
|
||||
printf("TSC Rate: %ju\n", g_tsc_rate);
|
||||
printf("Number Trace Entries per lcore: %ju\n", num_entries);
|
||||
}
|
||||
|
||||
/* Remap the entire trace file */
|
||||
trace_histories_size = spdk_get_trace_histories_size(num_entries);
|
||||
trace_histories_size = spdk_get_trace_histories_size(g_histories);
|
||||
munmap(history_ptr, sizeof(*g_histories));
|
||||
history_ptr = mmap(NULL, trace_histories_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (history_ptr == MAP_FAILED) {
|
||||
@ -394,26 +390,34 @@ int main(int argc, char **argv)
|
||||
|
||||
g_histories = (struct spdk_trace_histories *)history_ptr;
|
||||
|
||||
lcore_history_size = spdk_get_trace_history_size(num_entries);
|
||||
history_entries = (struct spdk_trace_history *)malloc(lcore_history_size * SPDK_TRACE_MAX_LCORE);
|
||||
if (history_entries == NULL) {
|
||||
histories = (struct spdk_trace_histories *)malloc(trace_histories_size);
|
||||
if (histories == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
memcpy(history_entries, g_histories->per_lcore_history,
|
||||
lcore_history_size * SPDK_TRACE_MAX_LCORE);
|
||||
|
||||
memcpy(histories, g_histories, trace_histories_size);
|
||||
|
||||
if (lcore == SPDK_TRACE_MAX_LCORE) {
|
||||
for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
|
||||
history = spdk_get_per_lcore_history(g_histories, i, num_entries);
|
||||
history = spdk_get_per_lcore_history(histories, i);
|
||||
if (history->entries[0].tsc == 0) {
|
||||
continue;
|
||||
}
|
||||
populate_events(history, num_entries);
|
||||
|
||||
if (g_verbose && history->num_entries) {
|
||||
printf("Trace Size of lcore (%d): %ju\n", i, history->num_entries);
|
||||
}
|
||||
|
||||
populate_events(history, history->num_entries);
|
||||
}
|
||||
} else {
|
||||
history = spdk_get_per_lcore_history(g_histories, lcore, num_entries);
|
||||
history = spdk_get_per_lcore_history(histories, lcore);
|
||||
if (history->entries[0].tsc != 0) {
|
||||
populate_events(history, num_entries);
|
||||
if (g_verbose && history->num_entries) {
|
||||
printf("Trace Size of lcore (%d): %ju\n", lcore, history->num_entries);
|
||||
}
|
||||
|
||||
populate_events(history, history->num_entries);
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +429,7 @@ int main(int argc, char **argv)
|
||||
process_event(it->second, g_tsc_rate, tsc_offset, it->first.lcore);
|
||||
}
|
||||
|
||||
free(history_entries);
|
||||
free(histories);
|
||||
|
||||
cleanup:
|
||||
munmap(history_ptr, trace_histories_size);
|
||||
|
@ -92,6 +92,9 @@ struct spdk_trace_history {
|
||||
/** Logical core number associated with this structure instance. */
|
||||
int lcore;
|
||||
|
||||
/** Number of trace_entries contained in each trace_history. */
|
||||
uint64_t num_entries;
|
||||
|
||||
/**
|
||||
* Running count of number of occurrences of each tracepoint on this
|
||||
* lcore. Debug tools can use this to easily count tracepoints such as
|
||||
@ -115,11 +118,15 @@ struct spdk_trace_history {
|
||||
|
||||
struct spdk_trace_flags {
|
||||
uint64_t tsc_rate;
|
||||
uint64_t num_entries;
|
||||
uint64_t tpoint_mask[SPDK_TRACE_MAX_GROUP_ID];
|
||||
struct spdk_trace_owner owner[UCHAR_MAX + 1];
|
||||
struct spdk_trace_object object[UCHAR_MAX + 1];
|
||||
struct spdk_trace_tpoint tpoint[SPDK_TRACE_MAX_TPOINT_ID];
|
||||
|
||||
/** Offset of each trace_history from the beginning of this data structure.
|
||||
* The last one is the offset of the file end.
|
||||
*/
|
||||
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;
|
||||
@ -144,24 +151,22 @@ spdk_get_trace_history_size(uint64_t num_entries)
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
spdk_get_trace_histories_size(uint64_t num_entries)
|
||||
spdk_get_trace_histories_size(struct spdk_trace_histories *trace_histories)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = sizeof(struct spdk_trace_flags);
|
||||
size += spdk_get_trace_history_size(num_entries) * SPDK_TRACE_MAX_LCORE;
|
||||
|
||||
return size;
|
||||
return trace_histories->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,
|
||||
uint64_t num_entries)
|
||||
spdk_get_per_lcore_history(struct spdk_trace_histories *trace_histories, unsigned lcore)
|
||||
{
|
||||
char *lcore_history_offset;
|
||||
|
||||
lcore_history_offset = (char *)trace_histories->per_lcore_history;
|
||||
lcore_history_offset += lcore * spdk_get_trace_history_size(num_entries);
|
||||
if (lcore >= SPDK_TRACE_MAX_LCORE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lcore_history_offset = (char *)trace_histories;
|
||||
lcore_history_offset += trace_histories->flags.lcore_history_offsets[lcore];
|
||||
|
||||
return (struct spdk_trace_history *)lcore_history_offset;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/trace.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
static int g_trace_fd = -1;
|
||||
static char g_shm_name[64];
|
||||
@ -55,8 +56,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_
|
||||
return;
|
||||
}
|
||||
|
||||
lcore_history = spdk_get_per_lcore_history(g_trace_histories, lcore,
|
||||
g_trace_histories->flags.num_entries);
|
||||
lcore_history = spdk_get_per_lcore_history(g_trace_histories, lcore);
|
||||
if (tsc == 0) {
|
||||
tsc = spdk_get_ticks();
|
||||
}
|
||||
@ -72,7 +72,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_
|
||||
next_entry->arg1 = arg1;
|
||||
|
||||
lcore_history->next_entry++;
|
||||
if (lcore_history->next_entry == g_trace_histories->flags.num_entries) {
|
||||
if (lcore_history->next_entry == lcore_history->num_entries) {
|
||||
lcore_history->next_entry = 0;
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,14 @@ int
|
||||
spdk_trace_init(const char *shm_name, uint64_t num_entries)
|
||||
{
|
||||
int i = 0;
|
||||
int histories_size = spdk_get_trace_histories_size(num_entries);
|
||||
int histories_size;
|
||||
uint64_t lcore_offsets[SPDK_TRACE_MAX_LCORE + 1];
|
||||
|
||||
lcore_offsets[0] = sizeof(struct spdk_trace_flags);
|
||||
for (i = 1; i < (int)SPDK_COUNTOF(lcore_offsets); i++) {
|
||||
lcore_offsets[i] = spdk_get_trace_history_size(num_entries) + lcore_offsets[i - 1];
|
||||
}
|
||||
histories_size = sizeof(struct spdk_trace_flags) + lcore_offsets[SPDK_TRACE_MAX_LCORE];
|
||||
|
||||
snprintf(g_shm_name, sizeof(g_shm_name), "%s", shm_name);
|
||||
|
||||
@ -123,14 +130,16 @@ spdk_trace_init(const char *shm_name, uint64_t num_entries)
|
||||
g_trace_flags = &g_trace_histories->flags;
|
||||
|
||||
g_trace_flags->tsc_rate = spdk_get_ticks_hz();
|
||||
g_trace_flags->num_entries = num_entries;
|
||||
|
||||
for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
|
||||
struct spdk_trace_history *lcore_history;
|
||||
|
||||
lcore_history = spdk_get_per_lcore_history(g_trace_histories, i, num_entries);
|
||||
g_trace_flags->lcore_history_offsets[i] = lcore_offsets[i];
|
||||
lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
|
||||
lcore_history->lcore = i;
|
||||
lcore_history->num_entries = num_entries;
|
||||
}
|
||||
g_trace_flags->lcore_history_offsets[SPDK_TRACE_MAX_LCORE] = lcore_offsets[SPDK_TRACE_MAX_LCORE];
|
||||
|
||||
spdk_trace_flags_init();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user