Lines Matching defs:poller

52 	/* The poller is registered with a thread but not currently executing its fn. */
55 /* The poller is currently running its fn. */
58 /* The poller was unregistered during the execution of its fn. */
61 /* The poller is in the process of being paused. It will be paused
66 /* The poller is registered but currently paused. It's on the
76 /* Current state of the poller; should only be accessed from the poller's thread. */
95 /* The thread is processing poller and message by spdk_thread_poll(). */
99 * poller are releasing I/O channel.
119 * are run round-robin. The thread takes one poller from the head
391 struct spdk_poller *poller, *ptmp;
398 TAILQ_FOREACH_SAFE(poller, &thread->active_pollers, tailq, ptmp) {
399 if (poller->state != SPDK_POLLER_STATE_UNREGISTERED) {
401 poller->name);
403 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
404 free(poller);
407 RB_FOREACH_SAFE(poller, timed_pollers_tree, &thread->timed_pollers, ptmp) {
408 if (poller->state != SPDK_POLLER_STATE_UNREGISTERED) {
410 poller->name);
412 RB_REMOVE(timed_pollers_tree, &thread->timed_pollers, poller);
413 free(poller);
416 TAILQ_FOREACH_SAFE(poller, &thread->paused_pollers, tailq, ptmp) {
417 SPDK_WARNLOG("paused_poller %s still registered at thread exit\n", poller->name);
418 TAILQ_REMOVE(&thread->paused_pollers, poller, tailq);
419 free(poller);
544 /* Monotonic increasing ID is set to each created poller beginning at 1. Once the
660 struct spdk_poller *poller;
680 TAILQ_FOREACH(poller, &thread->active_pollers, tailq) {
681 if (poller->state != SPDK_POLLER_STATE_UNREGISTERED) {
683 "thread %s still has active poller %s\n",
684 thread->name, poller->name);
689 RB_FOREACH(poller, timed_pollers_tree, &thread->timed_pollers) {
690 if (poller->state != SPDK_POLLER_STATE_UNREGISTERED) {
692 "thread %s still has active timed poller %s\n",
693 thread->name, poller->name);
698 TAILQ_FOREACH(poller, &thread->paused_pollers, tailq) {
700 "thread %s still has paused poller %s\n",
701 thread->name, poller->name);
901 poller_insert_timer(struct spdk_thread *thread, struct spdk_poller *poller, uint64_t now)
905 poller->next_run_tick = now + poller->period_ticks;
908 * Insert poller in the thread's timed_pollers tree by next scheduled run time
911 tmp = RB_INSERT(timed_pollers_tree, &thread->timed_pollers, poller);
914 /* Update the cache only if it is empty or the inserted poller is earlier than it.
916 * next_run_tick as the existing poller, are inserted on the right side.
919 poller->next_run_tick < thread->first_timed_poller->next_run_tick) {
920 thread->first_timed_poller = poller;
925 poller_remove_timer(struct spdk_thread *thread, struct spdk_poller *poller)
929 tmp = RB_REMOVE(timed_pollers_tree, &thread->timed_pollers, poller);
935 if (thread->first_timed_poller == poller) {
941 thread_insert_poller(struct spdk_thread *thread, struct spdk_poller *poller)
943 if (poller->period_ticks) {
944 poller_insert_timer(thread, poller, spdk_get_ticks());
946 TAILQ_INSERT_TAIL(&thread->active_pollers, poller, tailq);
966 thread_execute_poller(struct spdk_thread *thread, struct spdk_poller *poller)
970 switch (poller->state) {
972 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
973 free(poller);
976 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
977 TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
978 poller->state = SPDK_POLLER_STATE_PAUSED;
987 poller->state = SPDK_POLLER_STATE_RUNNING;
988 rc = poller->fn(poller->arg);
992 poller->run_count++;
994 poller->busy_count++;
999 SPDK_DEBUGLOG(thread, "Poller %s returned -1\n", poller->name);
1003 switch (poller->state) {
1005 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
1006 free(poller);
1009 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
1010 TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
1011 poller->state = SPDK_POLLER_STATE_PAUSED;
1017 poller->state = SPDK_POLLER_STATE_WAITING;
1028 thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poller,
1033 switch (poller->state) {
1035 free(poller);
1038 TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
1039 poller->state = SPDK_POLLER_STATE_PAUSED;
1048 poller->state = SPDK_POLLER_STATE_RUNNING;
1049 rc = poller->fn(poller->arg);
1053 poller->run_count++;
1055 poller->busy_count++;
1060 SPDK_DEBUGLOG(thread, "Timed poller %s returned -1\n", poller->name);
1064 switch (poller->state) {
1066 free(poller);
1069 TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
1070 poller->state = SPDK_POLLER_STATE_PAUSED;
1075 poller->state = SPDK_POLLER_STATE_WAITING;
1078 poller_insert_timer(thread, poller, now);
1108 struct spdk_poller *poller, *tmp;
1126 TAILQ_FOREACH_REVERSE_SAFE(poller, &thread->active_pollers,
1130 poller_rc = thread_execute_poller(thread, poller);
1139 poller = thread->first_timed_poller;
1140 while (poller != NULL) {
1143 if (now < poller->next_run_tick) {
1147 tmp = RB_NEXT(timed_pollers_tree, &thread->timed_pollers, poller);
1148 RB_REMOVE(timed_pollers_tree, &thread->timed_pollers, poller);
1150 /* Update the cache to the next timed poller in the list
1151 * only if the current poller is still the closest, otherwise,
1154 if (thread->first_timed_poller == poller) {
1158 timer_rc = thread_execute_timed_poller(thread, poller, now);
1163 poller = tmp;
1173 struct spdk_poller *poller, *tmp;
1175 TAILQ_FOREACH_REVERSE_SAFE(poller, &thread->active_pollers,
1177 if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
1178 TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
1179 free(poller);
1183 RB_FOREACH_SAFE(poller, timed_pollers_tree, &thread->timed_pollers, tmp) {
1184 if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
1185 poller_remove_timer(thread, poller);
1186 free(poller);
1248 struct spdk_poller *poller;
1250 poller = thread->first_timed_poller;
1251 if (poller) {
1252 return poller->next_run_tick;
1466 struct spdk_poller *poller = arg;
1471 rc = read(poller->intr->efd, &exp, sizeof(exp));
1480 SPDK_DTRACE_PROBE2(timerfd_exec, poller->fn, poller->arg);
1482 return poller->fn(poller->arg);
1486 period_poller_interrupt_init(struct spdk_poller *poller)
1490 SPDK_DEBUGLOG(thread, "timerfd init for periodic poller %s\n", poller->name);
1496 poller->intr = spdk_interrupt_register(timerfd, interrupt_timerfd_process, poller, poller->name);
1497 if (poller->intr == NULL) {
1506 period_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool interrupt_mode)
1515 assert(poller->intr != NULL);
1516 assert(poller->period_ticks != 0);
1518 timerfd = poller->intr->efd;
1522 SPDK_DEBUGLOG(thread, "timerfd set poller %s into %s mode\n", poller->name,
1527 new_tv.it_interval.tv_sec = poller->period_ticks / ticks;
1528 new_tv.it_interval.tv_nsec = poller->period_ticks % ticks * SPDK_SEC_TO_NSEC / ticks;
1531 if (poller->next_run_tick == 0) {
1532 poller->next_run_tick = now_tick + poller->period_ticks;
1533 } else if (poller->next_run_tick < now_tick) {
1534 poller->next_run_tick = now_tick;
1537 new_tv.it_value.tv_sec = (poller->next_run_tick - now_tick) / ticks;
1538 new_tv.it_value.tv_nsec = (poller->next_run_tick - now_tick) % ticks * SPDK_SEC_TO_NSEC / ticks;
1557 now_tick = now_tick - poller->period_ticks + ticks * old_tv.it_value.tv_sec + \
1559 poller_remove_timer(poller->thread, poller);
1560 poller_insert_timer(poller->thread, poller, now_tick);
1565 poller_interrupt_fini(struct spdk_poller *poller)
1569 SPDK_DEBUGLOG(thread, "interrupt fini for poller %s\n", poller->name);
1570 assert(poller->intr != NULL);
1571 fd = poller->intr->efd;
1572 spdk_interrupt_unregister(&poller->intr);
1577 busy_poller_interrupt_init(struct spdk_poller *poller)
1581 SPDK_DEBUGLOG(thread, "busy_efd init for busy poller %s\n", poller->name);
1584 SPDK_ERRLOG("Failed to create eventfd for Poller(%s).\n", poller->name);
1588 poller->intr = spdk_interrupt_register(busy_efd, poller->fn, poller->arg, poller->name);
1589 if (poller->intr == NULL) {
1598 busy_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool interrupt_mode)
1600 int busy_efd = poller->intr->efd;
1609 SPDK_ERRLOG("Failed to set busy wait for Poller(%s).\n", poller->name);
1620 period_poller_interrupt_init(struct spdk_poller *poller)
1626 period_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool interrupt_mode)
1631 poller_interrupt_fini(struct spdk_poller *poller)
1636 busy_poller_interrupt_init(struct spdk_poller *poller)
1642 busy_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool interrupt_mode)
1649 spdk_poller_register_interrupt(struct spdk_poller *poller,
1653 assert(poller != NULL);
1654 assert(spdk_get_thread() == poller->thread);
1660 /* If this poller already had an interrupt, clean the old one up. */
1661 if (poller->intr != NULL) {
1662 poller_interrupt_fini(poller);
1665 poller->set_intr_cb_fn = cb_fn;
1666 poller->set_intr_cb_arg = cb_arg;
1668 /* Set poller into interrupt mode if thread is in interrupt. */
1669 if (poller->thread->in_interrupt && poller->set_intr_cb_fn) {
1670 poller->set_intr_cb_fn(poller, poller->set_intr_cb_arg, true);
1697 struct spdk_poller *poller;
1710 poller = calloc(1, sizeof(*poller));
1711 if (poller == NULL) {
1717 snprintf(poller->name, sizeof(poller->name), "%s", name);
1719 snprintf(poller->name, sizeof(poller->name), "%p", fn);
1722 poller->state = SPDK_POLLER_STATE_WAITING;
1723 poller->fn = fn;
1724 poller->arg = arg;
1725 poller->thread = thread;
1726 poller->intr = NULL;
1731 poller->id = thread->next_poller_id++;
1733 poller->period_ticks = convert_us_to_ticks(period_microseconds);
1739 rc = period_poller_interrupt_init(poller);
1741 SPDK_ERRLOG("Failed to register interruptfd for periodic poller: %s\n", spdk_strerror(-rc));
1742 free(poller);
1746 poller->set_intr_cb_fn = period_poller_set_interrupt_mode;
1747 poller->set_intr_cb_arg = NULL;
1750 /* If the poller doesn't have a period, create interruptfd that's always
1753 rc = busy_poller_interrupt_init(poller);
1755 SPDK_ERRLOG("Failed to register interruptfd for busy poller: %s\n", spdk_strerror(-rc));
1756 free(poller);
1760 poller->set_intr_cb_fn = busy_poller_set_interrupt_mode;
1761 poller->set_intr_cb_arg = NULL;
1764 /* Set poller into interrupt mode if thread is in interrupt. */
1765 if (poller->thread->in_interrupt) {
1766 poller->set_intr_cb_fn(poller, poller->set_intr_cb_arg, true);
1770 thread_insert_poller(thread, poller);
1772 return poller;
1810 struct spdk_poller *poller;
1812 poller = *ppoller;
1813 if (poller == NULL) {
1825 if (poller->thread != thread) {
1826 wrong_thread(__func__, poller->name, poller->thread, thread);
1831 /* Release the interrupt resource for period or busy poller */
1832 if (poller->intr != NULL) {
1833 poller_interrupt_fini(poller);
1836 /* If there is not already a pending poller removal, generate
1844 /* If the poller was paused, put it on the active_pollers list so that
1847 if (poller->state == SPDK_POLLER_STATE_PAUSED) {
1848 TAILQ_REMOVE(&thread->paused_pollers, poller, tailq);
1849 TAILQ_INSERT_TAIL(&thread->active_pollers, poller, tailq);
1850 poller->period_ticks = 0;
1853 /* Simply set the state to unregistered. The poller will get cleaned up
1856 poller->state = SPDK_POLLER_STATE_UNREGISTERED;
1860 spdk_poller_pause(struct spdk_poller *poller)
1870 if (poller->thread != thread) {
1871 wrong_thread(__func__, poller->name, poller->thread, thread);
1876 * spdk_thread_poll() move it. It allows a poller to be paused from
1879 * remove the closest timed poller in the TAILQ_FOREACH_SAFE iteration.
1881 switch (poller->state) {
1887 poller->state = SPDK_POLLER_STATE_PAUSING;
1896 spdk_poller_resume(struct spdk_poller *poller)
1906 if (poller->thread != thread) {
1907 wrong_thread(__func__, poller->name, poller->thread, thread);
1911 /* If a poller is paused it has to be removed from the paused pollers
1913 * period_ticks. If a poller is still in the process of being paused,
1917 switch (poller->state) {
1919 TAILQ_REMOVE(&thread->paused_pollers, poller, tailq);
1920 thread_insert_poller(thread, poller);
1923 poller->state = SPDK_POLLER_STATE_WAITING;
1935 spdk_poller_get_name(struct spdk_poller *poller)
1937 return poller->name;
1941 spdk_poller_get_id(struct spdk_poller *poller)
1943 return poller->id;
1947 spdk_poller_get_state_str(struct spdk_poller *poller)
1949 switch (poller->state) {
1966 spdk_poller_get_period_ticks(struct spdk_poller *poller)
1968 return poller->period_ticks;
1972 spdk_poller_get_stats(struct spdk_poller *poller, struct spdk_poller_stats *stats)
1974 stats->run_count = poller->run_count;
1975 stats->busy_count = poller->busy_count;
2124 poller_set_interrupt_mode(struct spdk_poller *poller, bool interrupt_mode)
2126 if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
2130 if (poller->set_intr_cb_fn) {
2131 poller->set_intr_cb_fn(poller, poller->set_intr_cb_arg, interrupt_mode);
2139 struct spdk_poller *poller, *tmp;
2153 RB_FOREACH_SAFE(poller, timed_pollers_tree, &thread->timed_pollers, tmp) {
2154 poller_set_interrupt_mode(poller, enable_interrupt);
2156 TAILQ_FOREACH_SAFE(poller, &thread->active_pollers, tailq, tmp) {
2157 poller_set_interrupt_mode(poller, enable_interrupt);
2160 TAILQ_FOREACH_SAFE(poller, &thread->paused_pollers, tailq, tmp) {
2161 poller_set_interrupt_mode(poller, enable_interrupt);