Commit 54215a1e authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

thread: Factor out executing poller or timed poller into helper functions



Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I8792b698f5de85c24482d6781fc3d47afce0c414
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7663


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 84ec9989
Loading
Loading
Loading
Loading
+85 −66
Original line number Diff line number Diff line
@@ -603,53 +603,32 @@ thread_update_stats(struct spdk_thread *thread, uint64_t end,
	thread->tsc_last = end;
}

static int
thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
static inline int
thread_execute_poller(struct spdk_thread *thread, struct spdk_poller *poller)
{
	uint32_t msg_count;
	struct spdk_poller *poller, *tmp;
	spdk_msg_fn critical_msg;
	int rc = 0;

	thread->tsc_last = now;

	critical_msg = thread->critical_msg;
	if (spdk_unlikely(critical_msg != NULL)) {
		critical_msg(NULL);
		thread->critical_msg = NULL;
		rc = 1;
	}

	msg_count = msg_queue_run_batch(thread, max_msgs);
	if (msg_count) {
		rc = 1;
	}

	TAILQ_FOREACH_REVERSE_SAFE(poller, &thread->active_pollers,
				   active_pollers_head, tailq, tmp) {
		int poller_rc;
	int rc;

	if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
		TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
		free(poller);
			continue;
		return 0;
	} else if (poller->state == SPDK_POLLER_STATE_PAUSING) {
		TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
		TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
		poller->state = SPDK_POLLER_STATE_PAUSED;
			continue;
		return 0;
	}

	poller->state = SPDK_POLLER_STATE_RUNNING;
		poller_rc = poller->fn(poller->arg);
	rc = poller->fn(poller->arg);

	poller->run_count++;
		if (poller_rc > 0) {
	if (rc > 0) {
		poller->busy_count++;
	}

#ifdef DEBUG
		if (poller_rc == -1) {
	if (rc == -1) {
		SPDK_DEBUGLOG(thread, "Poller %s returned -1\n", poller->name);
	}
#endif
@@ -661,39 +640,36 @@ thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
		poller->state = SPDK_POLLER_STATE_WAITING;
	}

		if (poller_rc > rc) {
			rc = poller_rc;
		}
	return rc;
}

	TAILQ_FOREACH_SAFE(poller, &thread->timed_pollers, tailq, tmp) {
		int timer_rc = 0;

		if (now < poller->next_run_tick) {
			break;
		}
static inline int
thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poller,
			    uint64_t now)
{
	int rc;

	if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
		TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
		free(poller);
			continue;
		return 0;
	} else if (poller->state == SPDK_POLLER_STATE_PAUSING) {
		TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
		TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
		poller->state = SPDK_POLLER_STATE_PAUSED;
			continue;
		return 0;
	}

	poller->state = SPDK_POLLER_STATE_RUNNING;
		timer_rc = poller->fn(poller->arg);
	rc = poller->fn(poller->arg);

	poller->run_count++;
		if (timer_rc > 0) {
	if (rc > 0) {
		poller->busy_count++;
	}

#ifdef DEBUG
		if (timer_rc == -1) {
	if (rc == -1) {
		SPDK_DEBUGLOG(thread, "Timed poller %s returned -1\n", poller->name);
	}
#endif
@@ -707,6 +683,49 @@ thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
		poller_insert_timer(thread, poller, now);
	}

	return rc;
}

static int
thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
{
	uint32_t msg_count;
	struct spdk_poller *poller, *tmp;
	spdk_msg_fn critical_msg;
	int rc = 0;

	thread->tsc_last = now;

	critical_msg = thread->critical_msg;
	if (spdk_unlikely(critical_msg != NULL)) {
		critical_msg(NULL);
		thread->critical_msg = NULL;
		rc = 1;
	}

	msg_count = msg_queue_run_batch(thread, max_msgs);
	if (msg_count) {
		rc = 1;
	}

	TAILQ_FOREACH_REVERSE_SAFE(poller, &thread->active_pollers,
				   active_pollers_head, tailq, tmp) {
		int poller_rc;

		poller_rc = thread_execute_poller(thread, poller);
		if (poller_rc > rc) {
			rc = poller_rc;
		}
	}

	TAILQ_FOREACH_SAFE(poller, &thread->timed_pollers, tailq, tmp) {
		int timer_rc = 0;

		if (now < poller->next_run_tick) {
			break;
		}

		timer_rc = thread_execute_timed_poller(thread, poller, now);
		if (timer_rc > rc) {
			rc = timer_rc;
		}