thread: Optionally allow the current time to be passed to

spdk_thread_poll()

This is an optimization if the calling function already knows the
current time.

Change-Id: I1645e08e7475ba6345a44e0f9d4b297a79f6c3c2
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443634
Tested-by: SPDK CI Jenkins <sys_sgci@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:
Ben Walker 2019-02-06 13:19:39 -07:00 committed by Jim Harris
parent 15d3631064
commit 8abfb06e31
7 changed files with 21 additions and 19 deletions

View File

@ -649,7 +649,7 @@ spdk_fio_event(struct thread_data *td, int event)
static size_t static size_t
spdk_fio_poll_thread(struct spdk_fio_thread *fio_thread) spdk_fio_poll_thread(struct spdk_fio_thread *fio_thread)
{ {
return spdk_thread_poll(fio_thread->thread, 0); return spdk_thread_poll(fio_thread->thread, 0, 0);
} }
static int static int

View File

@ -216,10 +216,12 @@ void spdk_thread_exit(struct spdk_thread *thread);
* \param thread The thread to process * \param thread The thread to process
* \param max_msgs The maximum number of messages that will be processed. * \param max_msgs The maximum number of messages that will be processed.
* Use 0 to process the default number of messages (8). * Use 0 to process the default number of messages (8).
* \param now The current time, in ticks. Optional. If 0 is passed, this
* function may call spdk_get_ticks() to get the current time.
* *
* \return 1 if work was done. 0 if no work was done. -1 if unknown. * \return 1 if work was done. 0 if no work was done. -1 if unknown.
*/ */
int spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs); int spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now);
/** /**
* Return the number of ticks until the next timed poller * Return the number of ticks until the next timed poller

View File

@ -262,7 +262,7 @@ _spdk_reactor_run(void *arg)
while (1) { while (1) {
_spdk_event_queue_run_batch(reactor, thread); _spdk_event_queue_run_batch(reactor, thread);
rc = spdk_thread_poll(thread, 0); rc = spdk_thread_poll(thread, 0, 0);
/* Determine if the thread can sleep */ /* Determine if the thread can sleep */
if (sleep_cycles && rc == 0) { if (sleep_cycles && rc == 0) {

View File

@ -372,17 +372,20 @@ _spdk_poller_insert_timer(struct spdk_thread *thread, struct spdk_poller *poller
} }
int int
spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs) spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
{ {
uint32_t msg_count; uint32_t msg_count;
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;
if (now == 0) {
now = spdk_get_ticks();
}
msg_count = _spdk_msg_queue_run_batch(thread, max_msgs); msg_count = _spdk_msg_queue_run_batch(thread, max_msgs);
if (msg_count) { if (msg_count) {
rc = 1; rc = 1;
@ -415,8 +418,6 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs)
poller = TAILQ_FIRST(&thread->timer_pollers); poller = TAILQ_FIRST(&thread->timer_pollers);
if (poller) { if (poller) {
uint64_t now = spdk_get_ticks();
if (now >= poller->next_run_tick) { if (now >= poller->next_run_tick) {
int timer_rc = 0; int timer_rc = 0;
@ -443,7 +444,6 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs)
} }
} }
now = spdk_get_ticks();
if (rc == 0) { if (rc == 0) {
/* Poller status idle */ /* Poller status idle */
thread->stats.idle_tsc += now - thread->tsc_last; thread->stats.idle_tsc += now - thread->tsc_last;

View File

@ -125,7 +125,7 @@ poll_thread(uintptr_t thread_id)
original_thread_id = g_thread_id; original_thread_id = g_thread_id;
set_thread(INVALID_THREAD); set_thread(INVALID_THREAD);
while (spdk_thread_poll(thread->thread, 0) > 0) { while (spdk_thread_poll(thread->thread, 0, 0) > 0) {
busy = true; busy = true;
} }

View File

@ -779,9 +779,9 @@ blob_snapshot_freeze_io(void)
* Flag 'frozen_io' is set in _spdk_bs_snapshot_freeze_cpl callback. * Flag 'frozen_io' is set in _spdk_bs_snapshot_freeze_cpl callback.
* Four async I/O operations happen before that. */ * Four async I/O operations happen before that. */
thread = spdk_get_thread(); thread = spdk_get_thread();
spdk_thread_poll(thread, 1); spdk_thread_poll(thread, 1, 0);
spdk_thread_poll(thread, 1); spdk_thread_poll(thread, 1, 0);
spdk_thread_poll(thread, 1); spdk_thread_poll(thread, 1, 0);
CU_ASSERT(TAILQ_EMPTY(&bs_channel->queued_io)); CU_ASSERT(TAILQ_EMPTY(&bs_channel->queued_io));

View File

@ -146,7 +146,7 @@ _fs_init(void *arg)
dev = init_dev(); dev = init_dev();
spdk_fs_init(dev, NULL, send_request, fs_op_with_handle_complete, NULL); spdk_fs_init(dev, NULL, send_request, fs_op_with_handle_complete, NULL);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
SPDK_CU_ASSERT_FATAL(g_fs != NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL);
SPDK_CU_ASSERT_FATAL(g_fs->bdev == dev); SPDK_CU_ASSERT_FATAL(g_fs->bdev == dev);
@ -161,7 +161,7 @@ _fs_unload(void *arg)
g_fserrno = -1; g_fserrno = -1;
spdk_fs_unload(g_fs, fs_op_complete, NULL); spdk_fs_unload(g_fs, fs_op_complete, NULL);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
CU_ASSERT(g_fserrno == 0); CU_ASSERT(g_fserrno == 0);
g_fs = NULL; g_fs = NULL;
} }
@ -235,7 +235,7 @@ cache_write_null_buffer(void)
spdk_fs_free_io_channel(channel); spdk_fs_free_io_channel(channel);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
ut_send_request(_fs_unload, NULL); ut_send_request(_fs_unload, NULL);
} }
@ -265,7 +265,7 @@ fs_create_sync(void)
spdk_fs_free_io_channel(channel); spdk_fs_free_io_channel(channel);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
ut_send_request(_fs_unload, NULL); ut_send_request(_fs_unload, NULL);
} }
@ -306,7 +306,7 @@ cache_append_no_cache(void)
spdk_fs_free_io_channel(channel); spdk_fs_free_io_channel(channel);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
ut_send_request(_fs_unload, NULL); ut_send_request(_fs_unload, NULL);
} }
@ -343,7 +343,7 @@ fs_delete_file_without_close(void)
spdk_fs_free_io_channel(channel); spdk_fs_free_io_channel(channel);
thread = spdk_get_thread(); thread = spdk_get_thread();
while (spdk_thread_poll(thread, 0) > 0) {} while (spdk_thread_poll(thread, 0, 0) > 0) {}
ut_send_request(_fs_unload, NULL); ut_send_request(_fs_unload, NULL);
@ -378,7 +378,7 @@ spdk_thread(void *arg)
} }
pthread_mutex_unlock(&g_mutex); pthread_mutex_unlock(&g_mutex);
spdk_thread_poll(thread, 0); spdk_thread_poll(thread, 0, 0);
} }
return NULL; return NULL;