thread: Move stats to thread
Change-Id: I351626355c45d0a3e66fec2688191429781e5952 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/443633 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
8a1acca65d
commit
15d3631064
@ -128,12 +128,6 @@ struct spdk_app_opts {
|
|||||||
uint64_t num_entries;
|
uint64_t num_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spdk_reactor_tsc_stats {
|
|
||||||
uint64_t busy_tsc;
|
|
||||||
uint64_t idle_tsc;
|
|
||||||
uint64_t unknown_tsc;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the default value of opts
|
* Initialize the default value of opts
|
||||||
*
|
*
|
||||||
@ -291,15 +285,6 @@ void spdk_reactor_enable_context_switch_monitor(bool enabled);
|
|||||||
*/
|
*/
|
||||||
bool spdk_reactor_context_switch_monitor_enabled(void);
|
bool spdk_reactor_context_switch_monitor_enabled(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get tsc stats from a given reactor
|
|
||||||
* Copy cumulative reactor tsc values to user's tsc_stats structure.
|
|
||||||
*
|
|
||||||
* \param tsc_stats User's tsc_stats structure.
|
|
||||||
* \param core_id Get tsc data on this Reactor core id.
|
|
||||||
*/
|
|
||||||
int spdk_reactor_get_tsc_stats(struct spdk_reactor_tsc_stats *tsc_stats, uint32_t core_id);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -268,6 +268,21 @@ struct spdk_thread *spdk_get_thread(void);
|
|||||||
*/
|
*/
|
||||||
const char *spdk_thread_get_name(const struct spdk_thread *thread);
|
const char *spdk_thread_get_name(const struct spdk_thread *thread);
|
||||||
|
|
||||||
|
struct spdk_thread_stats {
|
||||||
|
uint64_t busy_tsc;
|
||||||
|
uint64_t idle_tsc;
|
||||||
|
uint64_t unknown_tsc;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get statistics about the current thread.
|
||||||
|
*
|
||||||
|
* Copy cumulative thread stats values to the provided thread stats structure.
|
||||||
|
*
|
||||||
|
* \param stats User's thread_stats structure.
|
||||||
|
*/
|
||||||
|
int spdk_thread_get_stats(struct spdk_thread_stats *stats);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the given thread.
|
* Send a message to the given thread.
|
||||||
*
|
*
|
||||||
|
@ -60,11 +60,6 @@ struct spdk_reactor {
|
|||||||
/* Poller for get the rusage for the reactor. */
|
/* Poller for get the rusage for the reactor. */
|
||||||
struct spdk_poller *rusage_poller;
|
struct spdk_poller *rusage_poller;
|
||||||
|
|
||||||
/* Reactor tsc stats */
|
|
||||||
struct spdk_reactor_tsc_stats tsc_stats;
|
|
||||||
|
|
||||||
uint64_t tsc_last;
|
|
||||||
|
|
||||||
/* The last known rusage values */
|
/* The last known rusage values */
|
||||||
struct rusage rusage;
|
struct rusage rusage;
|
||||||
|
|
||||||
@ -239,55 +234,15 @@ spdk_reactor_context_switch_monitor_enabled(void)
|
|||||||
return g_context_switch_monitor_enabled;
|
return g_context_switch_monitor_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
spdk_reactor_add_tsc_stats(void *arg, int rc, uint64_t now)
|
|
||||||
{
|
|
||||||
struct spdk_reactor *reactor = arg;
|
|
||||||
struct spdk_reactor_tsc_stats *tsc_stats = &reactor->tsc_stats;
|
|
||||||
|
|
||||||
if (rc == 0) {
|
|
||||||
/* Poller status idle */
|
|
||||||
tsc_stats->idle_tsc += now - reactor->tsc_last;
|
|
||||||
} else if (rc > 0) {
|
|
||||||
/* Poller status busy */
|
|
||||||
tsc_stats->busy_tsc += now - reactor->tsc_last;
|
|
||||||
} else {
|
|
||||||
/* Poller status unknown */
|
|
||||||
tsc_stats->unknown_tsc += now - reactor->tsc_last;
|
|
||||||
}
|
|
||||||
|
|
||||||
reactor->tsc_last = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
spdk_reactor_get_tsc_stats(struct spdk_reactor_tsc_stats *tsc_stats, uint32_t core)
|
|
||||||
{
|
|
||||||
struct spdk_reactor *reactor;
|
|
||||||
|
|
||||||
if (!spdk_cpuset_get_cpu(g_spdk_app_core_mask, core)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
reactor = spdk_reactor_get(core);
|
|
||||||
if (!reactor) {
|
|
||||||
SPDK_ERRLOG("Unable to get reactor for core %u\n", core);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*tsc_stats = reactor->tsc_stats;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_spdk_reactor_run(void *arg)
|
_spdk_reactor_run(void *arg)
|
||||||
{
|
{
|
||||||
struct spdk_reactor *reactor = arg;
|
struct spdk_reactor *reactor = arg;
|
||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
uint32_t event_count;
|
|
||||||
uint64_t now;
|
uint64_t now;
|
||||||
uint64_t sleep_cycles;
|
uint64_t sleep_cycles;
|
||||||
uint32_t sleep_us;
|
uint32_t sleep_us;
|
||||||
int rc = -1;
|
int rc;
|
||||||
char thread_name[32];
|
char thread_name[32];
|
||||||
|
|
||||||
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
|
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
|
||||||
@ -303,29 +258,14 @@ _spdk_reactor_run(void *arg)
|
|||||||
_spdk_reactor_context_switch_monitor_start(reactor, NULL);
|
_spdk_reactor_context_switch_monitor_start(reactor, NULL);
|
||||||
spdk_set_thread(NULL);
|
spdk_set_thread(NULL);
|
||||||
}
|
}
|
||||||
now = spdk_get_ticks();
|
|
||||||
reactor->tsc_last = now;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bool took_action = false;
|
_spdk_event_queue_run_batch(reactor, thread);
|
||||||
|
|
||||||
event_count = _spdk_event_queue_run_batch(reactor, thread);
|
|
||||||
if (event_count > 0) {
|
|
||||||
rc = 1;
|
|
||||||
now = spdk_get_ticks();
|
|
||||||
spdk_reactor_add_tsc_stats(reactor, rc, now);
|
|
||||||
took_action = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = spdk_thread_poll(thread, 0);
|
rc = spdk_thread_poll(thread, 0);
|
||||||
if (rc != 0) {
|
|
||||||
now = spdk_get_ticks();
|
|
||||||
spdk_reactor_add_tsc_stats(reactor, rc, now);
|
|
||||||
took_action = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine if the thread can sleep */
|
/* Determine if the thread can sleep */
|
||||||
if (sleep_cycles && !took_action) {
|
if (sleep_cycles && rc == 0) {
|
||||||
uint64_t next_run_tick;
|
uint64_t next_run_tick;
|
||||||
|
|
||||||
now = spdk_get_ticks();
|
now = spdk_get_ticks();
|
||||||
|
@ -112,6 +112,9 @@ struct spdk_thread {
|
|||||||
TAILQ_ENTRY(spdk_thread) tailq;
|
TAILQ_ENTRY(spdk_thread) tailq;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
uint64_t tsc_last;
|
||||||
|
struct spdk_thread_stats stats;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Contains pollers actively running on this thread. Pollers
|
* Contains pollers actively running on this thread. Pollers
|
||||||
* are run round-robin. The thread takes one poller from the head
|
* are run round-robin. The thread takes one poller from the head
|
||||||
@ -209,6 +212,8 @@ spdk_thread_create(const char *name)
|
|||||||
SLIST_INIT(&thread->msg_cache);
|
SLIST_INIT(&thread->msg_cache);
|
||||||
thread->msg_cache_count = 0;
|
thread->msg_cache_count = 0;
|
||||||
|
|
||||||
|
thread->tsc_last = spdk_get_ticks();
|
||||||
|
|
||||||
thread->messages = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
|
thread->messages = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
|
||||||
if (!thread->messages) {
|
if (!thread->messages) {
|
||||||
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
|
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
|
||||||
@ -373,6 +378,7 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs)
|
|||||||
struct spdk_thread *orig_thread;
|
struct spdk_thread *orig_thread;
|
||||||
struct spdk_poller *poller;
|
struct spdk_poller *poller;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
uint64_t now;
|
||||||
|
|
||||||
orig_thread = _get_thread();
|
orig_thread = _get_thread();
|
||||||
tls_thread = thread;
|
tls_thread = thread;
|
||||||
@ -437,6 +443,19 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now = spdk_get_ticks();
|
||||||
|
if (rc == 0) {
|
||||||
|
/* Poller status idle */
|
||||||
|
thread->stats.idle_tsc += now - thread->tsc_last;
|
||||||
|
} else if (rc > 0) {
|
||||||
|
/* Poller status busy */
|
||||||
|
thread->stats.busy_tsc += now - thread->tsc_last;
|
||||||
|
} else {
|
||||||
|
/* Poller status unknown */
|
||||||
|
thread->stats.unknown_tsc += now - thread->tsc_last;
|
||||||
|
}
|
||||||
|
thread->tsc_last = now;
|
||||||
|
|
||||||
tls_thread = orig_thread;
|
tls_thread = orig_thread;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -491,6 +510,26 @@ spdk_thread_get_name(const struct spdk_thread *thread)
|
|||||||
return thread->name;
|
return thread->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_thread_get_stats(struct spdk_thread_stats *stats)
|
||||||
|
{
|
||||||
|
struct spdk_thread *thread;
|
||||||
|
|
||||||
|
thread = _get_thread();
|
||||||
|
if (!thread) {
|
||||||
|
SPDK_ERRLOG("No thread allocated\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats == NULL) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*stats = thread->stats;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx)
|
spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user