Commit c22f12c8 authored by GangCao's avatar GangCao Committed by Jim Harris
Browse files

event: update the poller's period_ticks calculation



There existing an overflow for the large value of sleeping time
for the poller and the actual time may be incorrect setting due
to this overflow. Update the calculation here.

Change-Id: I14fe21d3f0e1abaa9d13d3d6254aff254d2dfcc3
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.gerrithub.io/392127


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatar <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9c1d97a2
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -43,9 +43,10 @@
#define SPDK_MAX_SOCKET		64

#define SPDK_MAX_REACTORS		128
#define SPDK_REACTOR_SPIN_TIME_US	1000
#define SPDK_REACTOR_SPIN_TIME_USEC	1000
#define SPDK_TIMER_POLL_ITERATIONS	5
#define SPDK_EVENT_BATCH_SIZE		8
#define SPDK_SEC_TO_USEC		1000000ULL

enum spdk_poller_state {
	/* The poller is registered with a reactor but not currently executing its fn. */
@@ -252,6 +253,7 @@ _spdk_reactor_start_poller(void *thread_ctx,
{
	struct spdk_poller *poller;
	struct spdk_reactor *reactor;
	uint64_t quotient, remainder, ticks;

	reactor = thread_ctx;

@@ -267,7 +269,11 @@ _spdk_reactor_start_poller(void *thread_ctx,
	poller->arg = arg;

	if (period_microseconds) {
		poller->period_ticks = (spdk_get_ticks_hz() * period_microseconds) / 1000000ULL;
		quotient = period_microseconds / SPDK_SEC_TO_USEC;
		remainder = period_microseconds % SPDK_SEC_TO_USEC;
		ticks = spdk_get_ticks_hz();

		poller->period_ticks = ticks * quotient + (ticks * remainder) / SPDK_SEC_TO_USEC;
	} else {
		poller->period_ticks = 0;
	}
@@ -391,7 +397,7 @@ spdk_reactor_context_switch_monitor_enabled(void)
 *	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_US)
 *	if (idle for at least SPDK_REACTOR_SPIN_TIME_USEC)
 *		sleep until next timer poller is scheduled to expire
 * \endcode
 *
@@ -418,8 +424,8 @@ _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_US * spdk_get_ticks_hz() / 1000000ULL;
	sleep_cycles = reactor->max_delay_us * spdk_get_ticks_hz() / 1000000ULL;
	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;
	timer_poll_count = 0;
	if (g_context_switch_monitor_enabled) {
@@ -492,7 +498,8 @@ _spdk_reactor_run(void *arg)
						if (poller->next_run_tick <= now) {
							sleep_us = 0;
						} else {
							sleep_us = ((poller->next_run_tick - now) * 1000000ULL) / spdk_get_ticks_hz();
							sleep_us = ((poller->next_run_tick - now) *
								    SPDK_SEC_TO_USEC) / spdk_get_ticks_hz();
						}
					}
				}