Commit e464823a authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

event: Don't check timers on every iteration



Instead, check them every 5 iterations by default.

Change-Id: I9c42922868f8e965a0c801109e59e06aff5adf62
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 4f752e1d
Loading
Loading
Loading
Loading
+25 −15
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@
#define SPDK_MAX_SOCKET		64

#define SPDK_REACTOR_SPIN_TIME_US	1000

#define SPDK_TIMER_POLL_ITERATIONS	5
#define SPDK_EVENT_BATCH_SIZE		8

enum spdk_poller_state {
@@ -312,6 +312,7 @@ _spdk_reactor_run(void *arg)
	uint64_t		idle_started, now;
	uint64_t		spin_cycles, sleep_cycles;
	uint32_t		sleep_us;
	uint32_t 		timer_poll_count;

	spdk_allocate_thread();
	set_reactor_thread_name(reactor->lcore);
@@ -321,6 +322,7 @@ _spdk_reactor_run(void *arg)
	spin_cycles = SPDK_REACTOR_SPIN_TIME_US * spdk_get_ticks_hz() / 1000000ULL;
	sleep_cycles = reactor->max_delay_us * spdk_get_ticks_hz() / 1000000ULL;
	idle_started = 0;
	timer_poll_count = 0;

	while (1) {
		bool took_action = false;
@@ -344,6 +346,7 @@ _spdk_reactor_run(void *arg)
			took_action = true;
		}

		if (timer_poll_count >= SPDK_TIMER_POLL_ITERATIONS) {
			poller = TAILQ_FIRST(&reactor->timer_pollers);
			if (poller) {
				now = spdk_get_ticks();
@@ -361,6 +364,10 @@ _spdk_reactor_run(void *arg)
					took_action = true;
				}
			}
			timer_poll_count = 0;
		} else {
			timer_poll_count++;
		}

		if (took_action) {
			/* We were busy this loop iteration. Reset the idle timer. */
@@ -392,6 +399,9 @@ _spdk_reactor_run(void *arg)
				if (sleep_us > 0) {
					usleep(sleep_us);
				}

				/* After sleeping, always poll for timers */
				timer_poll_count = SPDK_TIMER_POLL_ITERATIONS;
			}
		}