Commit 5deb90b0 authored by Jim Harris's avatar Jim Harris
Browse files

event: simplify sleep code in _spdk_reactor_run



This sleep functionality is only really used by the stub
app currently.  nvmf target enables it, but it never
gets exercised since there is always a poller running on
each core.  So don't bother trying to count how long
the reactor didn't take action - try to sleep any time
where the loop did not take action.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: If48cc3f989347811190de67a6423932d0b77cf45

Reviewed-on: https://review.gerrithub.io/423577


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
parent e87352fa
Loading
Loading
Loading
Loading
+19 −33
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@

#define SPDK_MAX_SOCKET		64

#define SPDK_REACTOR_SPIN_TIME_USEC	1000
#define SPDK_EVENT_BATCH_SIZE		8

enum spdk_poller_state {
@@ -463,7 +462,7 @@ spdk_reactor_get_tsc_stats(struct spdk_reactor_tsc_stats *tsc_stats, uint32_t co
 *	if (first timer poller has expired)
 *		run the first timer poller and reinsert it in the timer list
 *
 *	if (idle for at least SPDK_REACTOR_SPIN_TIME_USEC)
 *	if (no action taken and sleep enabled)
 *		sleep until next timer poller is scheduled to expire
 * \endcode
 *
@@ -474,8 +473,8 @@ _spdk_reactor_run(void *arg)
	struct spdk_reactor	*reactor = arg;
	struct spdk_poller	*poller;
	uint32_t		event_count;
	uint64_t		idle_started, now;
	uint64_t		spin_cycles, sleep_cycles;
	uint64_t		now;
	uint64_t		sleep_cycles;
	uint32_t		sleep_us;
	int			rc = -1;
	char			thread_name[32];
@@ -490,9 +489,7 @@ _spdk_reactor_run(void *arg)
	SPDK_NOTICELOG("Reactor started on core %u on socket %u\n", reactor->lcore,
		       reactor->socket_id);

	spin_cycles = SPDK_REACTOR_SPIN_TIME_USEC * spdk_get_ticks_hz() / SPDK_SEC_TO_USEC;
	sleep_cycles = reactor->max_delay_us * spdk_get_ticks_hz() / SPDK_SEC_TO_USEC;
	idle_started = 0;
	if (g_context_switch_monitor_enabled) {
		_spdk_reactor_context_switch_monitor_start(reactor, NULL);
	}
@@ -554,18 +551,9 @@ _spdk_reactor_run(void *arg)
			}
		}

		if (took_action) {
			/* We were busy this loop iteration. Reset the idle timer. */
			idle_started = 0;
		} else if (idle_started == 0) {
			/* We were previously busy, but this loop we took no actions. */
			idle_started = spdk_get_ticks();
		}

		/* Determine if the thread can sleep */
		if (sleep_cycles && idle_started) {
		if (sleep_cycles && !took_action) {
			now = spdk_get_ticks();
			if (now >= (idle_started + spin_cycles)) {
			sleep_us = reactor->max_delay_us;

			poller = TAILQ_FIRST(&reactor->timer_pollers);
@@ -585,8 +573,6 @@ _spdk_reactor_run(void *arg)
			if (sleep_us > 0) {
				usleep(sleep_us);
			}

			}
		}

		if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING) {