2 * Copyright (c) 2001-2002 Luigi Rizzo
4 * Supported by: the Xorp Project (www.xorp.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/kern/kern_poll.c,v 1.2.2.4 2002/06/27 23:26:33 luigi Exp $
30 #include "opt_ifpoll.h"
32 #include <sys/param.h>
33 #include <sys/kernel.h>
35 #include <sys/malloc.h>
36 #include <sys/serialize.h>
37 #include <sys/socket.h>
38 #include <sys/sysctl.h>
40 #include <sys/thread2.h>
41 #include <sys/msgport2.h>
43 #include <machine/atomic.h>
44 #include <machine/smp.h>
47 #include <net/if_poll.h>
48 #include <net/netmsg2.h>
51 * Polling support for network device drivers.
53 * Drivers which support this feature try to register one status polling
54 * handler and several TX/RX polling handlers with the polling code.
55 * If interface's if_qpoll is called with non-NULL second argument, then
56 * a register operation is requested, else a deregister operation is
57 * requested. If the requested operation is "register", driver should
58 * setup the ifpoll_info passed in accoding its own needs:
59 * ifpoll_info.ifpi_status.status_func == NULL
60 * No status polling handler will be installed on CPU(0)
61 * ifpoll_info.ifpi_rx[n].poll_func == NULL
62 * No RX polling handler will be installed on CPU(n)
63 * ifpoll_info.ifpi_tx[n].poll_func == NULL
64 * No TX polling handler will be installed on CPU(n)
66 * All of the registered polling handlers are called only if the interface
67 * is marked as 'IFF_RUNNING and IFF_NPOLLING'. However, the interface's
68 * register and deregister function (ifnet.if_qpoll) will be called even
69 * if interface is not marked with 'IFF_RUNNING'.
71 * If registration is successful, the driver must disable interrupts,
72 * and further I/O is performed through the TX/RX polling handler, which
73 * are invoked (at least once per clock tick) with 3 arguments: the "arg"
74 * passed at register time, a struct ifnet pointer, and a "count" limit.
75 * The registered serializer will be held before calling the related
78 * The count limit specifies how much work the handler can do during the
79 * call -- typically this is the number of packets to be received, or
80 * transmitted, etc. (drivers are free to interpret this number, as long
81 * as the max time spent in the function grows roughly linearly with the
84 * A second variable controls the sharing of CPU between polling/kernel
85 * network processing, and other activities (typically userlevel tasks):
86 * net.ifpoll.{rxX,txX}.user_frac (between 0 and 100, default 50) sets the
87 * share of CPU allocated to user tasks. CPU is allocated proportionally
88 * to the shares, by dynamically adjusting the "count" (poll_burst).
90 * Other parameters can should be left to their default values.
91 * The following constraints hold
93 * 1 <= poll_burst <= poll_burst_max
94 * 1 <= poll_each_burst <= poll_burst_max
95 * MIN_POLL_BURST_MAX <= poll_burst_max <= MAX_POLL_BURST_MAX
98 #define IFPOLL_LIST_LEN 128
99 #define IFPOLL_FREQ_MAX 30000
101 #define MIN_IOPOLL_BURST_MAX 10
102 #define MAX_IOPOLL_BURST_MAX 1000
103 #define IOPOLL_BURST_MAX 150 /* good for 100Mbit net and HZ=1000 */
105 #define IOPOLL_EACH_BURST 5
107 #define IFPOLL_FREQ_DEFAULT 2000
108 #define IOPOLL_FREQ_DEFAULT IFPOLL_FREQ_DEFAULT
109 #define STPOLL_FREQ_DEFAULT 100
111 #define IFPOLL_TXFRAC_DEFAULT 1
112 #define IFPOLL_STFRAC_DEFAULT 20
114 #define IFPOLL_RX 0x1
115 #define IFPOLL_TX 0x2
118 struct lwkt_serialize *serializer;
121 ifpoll_iofn_t poll_func;
125 #ifdef IFPOLL_MULTI_SYSTIMER
126 struct systimer pollclock;
129 struct timeval prev_t; /* state */
130 uint32_t short_ticks; /* statistics */
131 uint32_t lost_polls; /* statistics */
132 uint32_t suspect; /* statistics */
133 uint32_t stalled; /* statistics */
134 uint32_t pending_polls; /* state */
136 struct netmsg poll_netmsg;
139 #ifdef IFPOLL_MULTI_SYSTIMER
140 int pollhz; /* tunable */
142 int poll_type; /* IFPOLL_{RX,TX} */
144 uint32_t phase; /* state */
145 int residual_burst; /* state */
146 uint32_t poll_each_burst; /* tunable */
147 struct timeval poll_start_t; /* state */
149 uint32_t poll_handlers; /* next free entry in pr[]. */
150 struct iopoll_rec pr[IFPOLL_LIST_LEN];
152 struct netmsg poll_more_netmsg;
154 uint32_t poll_burst; /* state */
155 uint32_t poll_burst_max; /* tunable */
156 uint32_t user_frac; /* tunable */
158 struct sysctl_ctx_list poll_sysctl_ctx;
159 struct sysctl_oid *poll_sysctl_tree;
163 struct lwkt_serialize *serializer;
165 ifpoll_stfn_t status_func;
169 #ifdef IFPOLL_MULTI_SYSTIMER
170 struct systimer pollclock;
173 struct netmsg poll_netmsg;
175 #ifdef IFPOLL_MULTI_SYSTIMER
176 int pollhz; /* tunable */
178 uint32_t poll_handlers; /* next free entry in pr[]. */
179 struct stpoll_rec pr[IFPOLL_LIST_LEN];
181 struct sysctl_ctx_list poll_sysctl_ctx;
182 struct sysctl_oid *poll_sysctl_tree;
185 struct iopoll_sysctl_netmsg {
187 struct iopoll_ctx *ctx;
190 #ifndef IFPOLL_MULTI_SYSTIMER
193 struct systimer clock;
202 static struct stpoll_ctx stpoll_context;
203 static struct iopoll_ctx *rxpoll_context[IFPOLL_CTX_MAX];
204 static struct iopoll_ctx *txpoll_context[IFPOLL_CTX_MAX];
206 SYSCTL_NODE(_net, OID_AUTO, ifpoll, CTLFLAG_RW, 0,
207 "Network device polling parameters");
209 static int ifpoll_ncpus = IFPOLL_CTX_MAX;
211 static int iopoll_burst_max = IOPOLL_BURST_MAX;
212 static int iopoll_each_burst = IOPOLL_EACH_BURST;
214 TUNABLE_INT("net.ifpoll.burst_max", &iopoll_burst_max);
215 TUNABLE_INT("net.ifpoll.each_burst", &iopoll_each_burst);
217 #ifdef IFPOLL_MULTI_SYSTIMER
219 static int stpoll_hz = STPOLL_FREQ_DEFAULT;
220 static int iopoll_hz = IOPOLL_FREQ_DEFAULT;
222 TUNABLE_INT("net.ifpoll.stpoll_hz", &stpoll_hz);
223 TUNABLE_INT("net.ifpoll.iopoll_hz", &iopoll_hz);
225 #else /* !IFPOLL_MULTI_SYSTIMER */
227 static struct ifpoll_data ifpoll0;
228 static int ifpoll_pollhz = IFPOLL_FREQ_DEFAULT;
229 static int ifpoll_stfrac = IFPOLL_STFRAC_DEFAULT;
230 static int ifpoll_txfrac = IFPOLL_TXFRAC_DEFAULT;
231 static int ifpoll_handlers;
233 TUNABLE_INT("net.ifpoll.pollhz", &ifpoll_pollhz);
234 TUNABLE_INT("net.ifpoll.status_frac", &ifpoll_stfrac);
235 TUNABLE_INT("net.ifpoll.tx_frac", &ifpoll_txfrac);
237 static void sysctl_ifpollhz_handler(struct netmsg *);
238 static int sysctl_ifpollhz(SYSCTL_HANDLER_ARGS);
240 SYSCTL_PROC(_net_ifpoll, OID_AUTO, pollhz, CTLTYPE_INT | CTLFLAG_RW,
241 0, 0, sysctl_ifpollhz, "I", "Polling frequency");
242 SYSCTL_INT(_net_ifpoll, OID_AUTO, tx_frac, CTLFLAG_RW,
243 &ifpoll_txfrac, 0, "Every this many cycles poll transmit");
244 SYSCTL_INT(_net_ifpoll, OID_AUTO, st_frac, CTLFLAG_RW,
245 &ifpoll_stfrac, 0, "Every this many cycles poll status");
247 #endif /* IFPOLL_MULTI_SYSTIMER */
249 void ifpoll_init_pcpu(int);
251 #ifndef IFPOLL_MULTI_SYSTIMER
252 static void ifpoll_start_handler(struct netmsg *);
253 static void ifpoll_stop_handler(struct netmsg *);
254 static void ifpoll_handler_addevent(void);
255 static void ifpoll_handler_delevent(void);
256 static void ifpoll_ipi_handler(void *, int);
257 static void ifpoll_systimer(systimer_t, struct intrframe *);
260 static void ifpoll_register_handler(struct netmsg *);
261 static void ifpoll_deregister_handler(struct netmsg *);
266 static void stpoll_init(void);
267 static void stpoll_handler(struct netmsg *);
268 static void stpoll_clock(struct stpoll_ctx *);
269 #ifdef IFPOLL_MULTI_SYSTIMER
270 static void stpoll_systimer(systimer_t, struct intrframe *);
272 static int stpoll_register(struct ifnet *, const struct ifpoll_status *);
273 static int stpoll_deregister(struct ifnet *);
275 #ifdef IFPOLL_MULTI_SYSTIMER
276 static void sysctl_stpollhz_handler(struct netmsg *);
277 static int sysctl_stpollhz(SYSCTL_HANDLER_ARGS);
283 static struct iopoll_ctx *iopoll_ctx_create(int, int);
284 static void iopoll_init(int);
285 static void iopoll_handler(struct netmsg *);
286 static void iopollmore_handler(struct netmsg *);
287 static void iopoll_clock(struct iopoll_ctx *);
288 #ifdef IFPOLL_MULTI_SYSTIMER
289 static void iopoll_systimer(systimer_t, struct intrframe *);
291 static int iopoll_register(struct ifnet *, struct iopoll_ctx *,
292 const struct ifpoll_io *);
293 static int iopoll_deregister(struct ifnet *, struct iopoll_ctx *);
295 static void iopoll_add_sysctl(struct sysctl_ctx_list *,
296 struct sysctl_oid_list *, struct iopoll_ctx *);
297 #ifdef IFPOLL_MULTI_SYSTIMER
298 static void sysctl_iopollhz_handler(struct netmsg *);
299 static int sysctl_iopollhz(SYSCTL_HANDLER_ARGS);
301 static void sysctl_burstmax_handler(struct netmsg *);
302 static int sysctl_burstmax(SYSCTL_HANDLER_ARGS);
303 static void sysctl_eachburst_handler(struct netmsg *);
304 static int sysctl_eachburst(SYSCTL_HANDLER_ARGS);
307 ifpoll_sendmsg_oncpu(struct netmsg *msg)
309 if (msg->nm_lmsg.ms_flags & MSGF_DONE)
310 ifnet_sendmsg(&msg->nm_lmsg, mycpuid);
314 sched_stpoll(struct stpoll_ctx *st_ctx)
316 ifpoll_sendmsg_oncpu(&st_ctx->poll_netmsg);
320 sched_iopoll(struct iopoll_ctx *io_ctx)
322 ifpoll_sendmsg_oncpu(&io_ctx->poll_netmsg);
326 sched_iopollmore(struct iopoll_ctx *io_ctx)
328 ifpoll_sendmsg_oncpu(&io_ctx->poll_more_netmsg);
332 * Initialize per-cpu qpolling(4) context. Called from kern_clock.c:
335 ifpoll_init_pcpu(int cpuid)
337 if (cpuid >= IFPOLL_CTX_MAX) {
339 } else if (cpuid == 0) {
340 if (ifpoll_ncpus > ncpus)
341 ifpoll_ncpus = ncpus;
342 kprintf("ifpoll_ncpus %d\n", ifpoll_ncpus);
344 #ifndef IFPOLL_MULTI_SYSTIMER
345 systimer_init_periodic_nq(&ifpoll0.clock,
346 ifpoll_systimer, NULL, 1);
354 #ifndef IFPOLL_MULTI_SYSTIMER
357 ifpoll_ipi_handler(void *arg __unused, int poll)
359 KKASSERT(mycpuid < ifpoll_ncpus);
361 if (poll & IFPOLL_TX)
362 iopoll_clock(txpoll_context[mycpuid]);
363 if (poll & IFPOLL_RX)
364 iopoll_clock(rxpoll_context[mycpuid]);
368 ifpoll_systimer(systimer_t info __unused, struct intrframe *frame __unused)
370 uint32_t cpumask = 0;
372 KKASSERT(mycpuid == 0);
374 if (ifpoll0.stfrac_count-- == 0) {
375 ifpoll0.stfrac_count = ifpoll_stfrac;
376 stpoll_clock(&stpoll_context);
379 if (ifpoll0.txfrac_count-- == 0) {
380 ifpoll0.txfrac_count = ifpoll_txfrac;
382 /* TODO: We may try to piggyback TX on RX */
383 cpumask = smp_active_mask & ifpoll0.tx_cpumask;
385 lwkt_send_ipiq2_mask(cpumask, ifpoll_ipi_handler,
390 cpumask = smp_active_mask & ifpoll0.rx_cpumask;
392 lwkt_send_ipiq2_mask(cpumask, ifpoll_ipi_handler,
398 ifpoll_start_handler(struct netmsg *nmsg)
400 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
402 kprintf("ifpoll: start\n");
403 systimer_adjust_periodic(&ifpoll0.clock, ifpoll_pollhz);
404 lwkt_replymsg(&nmsg->nm_lmsg, 0);
408 ifpoll_stop_handler(struct netmsg *nmsg)
410 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
412 kprintf("ifpoll: stop\n");
413 systimer_adjust_periodic(&ifpoll0.clock, 1);
414 lwkt_replymsg(&nmsg->nm_lmsg, 0);
418 ifpoll_handler_addevent(void)
420 if (atomic_fetchadd_int(&ifpoll_handlers, 1) == 0) {
424 nmsg = kmalloc(sizeof(*nmsg), M_LWKTMSG, M_WAITOK);
425 netmsg_init(nmsg, &netisr_afree_rport, 0, ifpoll_start_handler);
426 ifnet_sendmsg(&nmsg->nm_lmsg, 0);
431 ifpoll_handler_delevent(void)
433 KKASSERT(ifpoll_handlers > 0);
434 if (atomic_fetchadd_int(&ifpoll_handlers, -1) == 1) {
438 nmsg = kmalloc(sizeof(*nmsg), M_LWKTMSG, M_WAITOK);
439 netmsg_init(nmsg, &netisr_afree_rport, 0, ifpoll_stop_handler);
440 ifnet_sendmsg(&nmsg->nm_lmsg, 0);
445 sysctl_ifpollhz_handler(struct netmsg *nmsg)
447 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
450 * If there is no handler registered, don't adjust polling
451 * systimer frequency; polling systimer frequency will be
452 * adjusted once there is registered handler.
454 ifpoll_pollhz = nmsg->nm_lmsg.u.ms_result;
456 systimer_adjust_periodic(&ifpoll0.clock, ifpoll_pollhz);
458 lwkt_replymsg(&nmsg->nm_lmsg, 0);
462 sysctl_ifpollhz(SYSCTL_HANDLER_ARGS)
468 error = sysctl_handle_int(oidp, &phz, 0, req);
469 if (error || req->newptr == NULL)
473 else if (phz > IFPOLL_FREQ_MAX)
474 phz = IFPOLL_FREQ_MAX;
476 netmsg_init(&nmsg, &curthread->td_msgport, MSGF_MPSAFE,
477 sysctl_ifpollhz_handler);
478 nmsg.nm_lmsg.u.ms_result = phz;
480 return ifnet_domsg(&nmsg.nm_lmsg, 0);
483 #endif /* !IFPOLL_MULTI_SYSTIMER */
486 ifpoll_register(struct ifnet *ifp)
488 struct ifpoll_info info;
492 if (ifp->if_qpoll == NULL) {
493 /* Device does not support polling */
498 * Attempt to register. Interlock with IFF_NPOLLING.
501 ifnet_serialize_all(ifp);
503 if (ifp->if_flags & IFF_NPOLLING) {
504 /* Already polling */
505 ifnet_deserialize_all(ifp);
509 bzero(&info, sizeof(info));
512 ifp->if_flags |= IFF_NPOLLING;
513 ifp->if_qpoll(ifp, &info);
515 ifnet_deserialize_all(ifp);
517 netmsg_init(&nmsg, &curthread->td_msgport, MSGF_MPSAFE,
518 ifpoll_register_handler);
519 nmsg.nm_lmsg.u.ms_resultp = &info;
521 error = ifnet_domsg(&nmsg.nm_lmsg, 0);
523 if (!ifpoll_deregister(ifp)) {
524 if_printf(ifp, "ifpoll_register: "
525 "ifpoll_deregister failed!\n");
532 ifpoll_deregister(struct ifnet *ifp)
537 if (ifp->if_qpoll == NULL)
540 ifnet_serialize_all(ifp);
542 if ((ifp->if_flags & IFF_NPOLLING) == 0) {
543 ifnet_deserialize_all(ifp);
546 ifp->if_flags &= ~IFF_NPOLLING;
548 ifnet_deserialize_all(ifp);
550 netmsg_init(&nmsg, &curthread->td_msgport, MSGF_MPSAFE,
551 ifpoll_deregister_handler);
552 nmsg.nm_lmsg.u.ms_resultp = ifp;
554 error = ifnet_domsg(&nmsg.nm_lmsg, 0);
556 ifnet_serialize_all(ifp);
557 ifp->if_qpoll(ifp, NULL);
558 ifnet_deserialize_all(ifp);
564 ifpoll_register_handler(struct netmsg *nmsg)
566 const struct ifpoll_info *info = nmsg->nm_lmsg.u.ms_resultp;
567 int cpuid = mycpuid, nextcpu;
570 KKASSERT(cpuid < ifpoll_ncpus);
571 KKASSERT(&curthread->td_msgport == ifnet_portfn(cpuid));
574 error = stpoll_register(info->ifpi_ifp, &info->ifpi_status);
579 error = iopoll_register(info->ifpi_ifp, rxpoll_context[cpuid],
580 &info->ifpi_rx[cpuid]);
584 error = iopoll_register(info->ifpi_ifp, txpoll_context[cpuid],
585 &info->ifpi_tx[cpuid]);
590 if (nextcpu < ifpoll_ncpus)
591 ifnet_forwardmsg(&nmsg->nm_lmsg, nextcpu);
593 lwkt_replymsg(&nmsg->nm_lmsg, 0);
596 lwkt_replymsg(&nmsg->nm_lmsg, error);
600 ifpoll_deregister_handler(struct netmsg *nmsg)
602 struct ifnet *ifp = nmsg->nm_lmsg.u.ms_resultp;
603 int cpuid = mycpuid, nextcpu;
605 KKASSERT(cpuid < ifpoll_ncpus);
606 KKASSERT(&curthread->td_msgport == ifnet_portfn(cpuid));
610 stpoll_deregister(ifp);
611 iopoll_deregister(ifp, rxpoll_context[cpuid]);
612 iopoll_deregister(ifp, txpoll_context[cpuid]);
615 if (nextcpu < ifpoll_ncpus)
616 ifnet_forwardmsg(&nmsg->nm_lmsg, nextcpu);
618 lwkt_replymsg(&nmsg->nm_lmsg, 0);
624 struct stpoll_ctx *st_ctx = &stpoll_context;
626 #ifdef IFPOLL_MULTI_SYSTIMER
627 st_ctx->pollhz = stpoll_hz;
630 sysctl_ctx_init(&st_ctx->poll_sysctl_ctx);
631 st_ctx->poll_sysctl_tree = SYSCTL_ADD_NODE(&st_ctx->poll_sysctl_ctx,
632 SYSCTL_STATIC_CHILDREN(_net_ifpoll),
633 OID_AUTO, "status", CTLFLAG_RD, 0, "");
635 #ifdef IFPOLL_MULTI_SYSTIMER
636 SYSCTL_ADD_PROC(&st_ctx->poll_sysctl_ctx,
637 SYSCTL_CHILDREN(st_ctx->poll_sysctl_tree),
638 OID_AUTO, "pollhz", CTLTYPE_INT | CTLFLAG_RW,
639 st_ctx, 0, sysctl_stpollhz, "I",
640 "Status polling frequency");
643 SYSCTL_ADD_UINT(&st_ctx->poll_sysctl_ctx,
644 SYSCTL_CHILDREN(st_ctx->poll_sysctl_tree),
645 OID_AUTO, "handlers", CTLFLAG_RD,
646 &st_ctx->poll_handlers, 0,
647 "Number of registered status poll handlers");
649 netmsg_init(&st_ctx->poll_netmsg, &netisr_adone_rport, MSGF_MPSAFE,
652 #ifdef IFPOLL_MULTI_SYSTIMER
653 systimer_init_periodic_nq(&st_ctx->pollclock,
654 stpoll_systimer, st_ctx, 1);
658 #ifdef IFPOLL_MULTI_SYSTIMER
661 sysctl_stpollhz_handler(struct netmsg *msg)
663 struct stpoll_ctx *st_ctx = &stpoll_context;
665 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
668 * If there is no handler registered, don't adjust polling
669 * systimer frequency; polling systimer frequency will be
670 * adjusted once there is registered handler.
672 st_ctx->pollhz = msg->nm_lmsg.u.ms_result;
673 if (st_ctx->poll_handlers)
674 systimer_adjust_periodic(&st_ctx->pollclock, st_ctx->pollhz);
676 lwkt_replymsg(&msg->nm_lmsg, 0);
680 sysctl_stpollhz(SYSCTL_HANDLER_ARGS)
682 struct stpoll_ctx *st_ctx = arg1;
686 phz = st_ctx->pollhz;
687 error = sysctl_handle_int(oidp, &phz, 0, req);
688 if (error || req->newptr == NULL)
692 else if (phz > IFPOLL_FREQ_MAX)
693 phz = IFPOLL_FREQ_MAX;
695 netmsg_init(&msg, &curthread->td_msgport, MSGF_MPSAFE,
696 sysctl_stpollhz_handler);
697 msg.nm_lmsg.u.ms_result = phz;
699 return ifnet_domsg(&msg.nm_lmsg, 0);
702 #endif /* IFPOLL_MULTI_SYSTIMER */
705 * stpoll_handler is scheduled by sched_stpoll when appropriate, typically
706 * once per polling systimer tick.
709 stpoll_handler(struct netmsg *msg)
711 struct stpoll_ctx *st_ctx = &stpoll_context;
712 struct thread *td = curthread;
715 KKASSERT(&td->td_msgport == ifnet_portfn(0));
717 crit_enter_quick(td);
720 lwkt_replymsg(&msg->nm_lmsg, 0);
722 if (st_ctx->poll_handlers == 0) {
727 #ifdef IFPOLL_MULTI_SYSTIMER
728 poll_hz = st_ctx->pollhz;
730 poll_hz = ifpoll_pollhz / (ifpoll_stfrac + 1);
733 for (i = 0; i < st_ctx->poll_handlers; ++i) {
734 const struct stpoll_rec *rec = &st_ctx->pr[i];
735 struct ifnet *ifp = rec->ifp;
737 if (!lwkt_serialize_try(rec->serializer))
740 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) ==
741 (IFF_RUNNING | IFF_NPOLLING))
742 rec->status_func(ifp, poll_hz);
744 lwkt_serialize_exit(rec->serializer);
751 * Hook from status poll systimer. Tries to schedule an status poll.
754 stpoll_clock(struct stpoll_ctx *st_ctx)
756 globaldata_t gd = mycpu;
758 KKASSERT(gd->gd_cpuid == 0);
760 if (st_ctx->poll_handlers == 0)
764 sched_stpoll(st_ctx);
768 #ifdef IFPOLL_MULTI_SYSTIMER
770 stpoll_systimer(systimer_t info, struct intrframe *frame __unused)
772 stpoll_clock(info->data);
777 stpoll_register(struct ifnet *ifp, const struct ifpoll_status *st_rec)
779 struct stpoll_ctx *st_ctx = &stpoll_context;
782 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
784 if (st_rec->status_func == NULL)
788 * Check if there is room.
790 if (st_ctx->poll_handlers >= IFPOLL_LIST_LEN) {
792 * List full, cannot register more entries.
793 * This should never happen; if it does, it is probably a
794 * broken driver trying to register multiple times. Checking
795 * this at runtime is expensive, and won't solve the problem
796 * anyways, so just report a few times and then give up.
798 static int verbose = 10; /* XXX */
801 kprintf("status poll handlers list full, "
802 "maybe a broken driver ?\n");
807 struct stpoll_rec *rec = &st_ctx->pr[st_ctx->poll_handlers];
810 rec->serializer = st_rec->serializer;
811 rec->status_func = st_rec->status_func;
813 st_ctx->poll_handlers++;
815 #ifdef IFPOLL_MULTI_SYSTIMER
816 if (st_ctx->poll_handlers == 1) {
817 systimer_adjust_periodic(&st_ctx->pollclock,
821 ifpoll_handler_addevent();
829 stpoll_deregister(struct ifnet *ifp)
831 struct stpoll_ctx *st_ctx = &stpoll_context;
834 KKASSERT(&curthread->td_msgport == ifnet_portfn(0));
836 for (i = 0; i < st_ctx->poll_handlers; ++i) {
837 if (st_ctx->pr[i].ifp == ifp) /* Found it */
840 if (i == st_ctx->poll_handlers) {
841 kprintf("stpoll_deregister: ifp not found!!!\n");
844 st_ctx->poll_handlers--;
845 if (i < st_ctx->poll_handlers) {
846 /* Last entry replaces this one. */
847 st_ctx->pr[i] = st_ctx->pr[st_ctx->poll_handlers];
850 #ifdef IFPOLL_MULTI_SYSTIMER
851 if (st_ctx->poll_handlers == 0)
852 systimer_adjust_periodic(&st_ctx->pollclock, 1);
854 ifpoll_handler_delevent();
861 #ifndef IFPOLL_MULTI_SYSTIMER
863 iopoll_hz(struct iopoll_ctx *io_ctx)
867 poll_hz = ifpoll_pollhz;
868 if (io_ctx->poll_type == IFPOLL_TX)
869 poll_hz /= ifpoll_txfrac + 1;
875 iopoll_reset_state(struct iopoll_ctx *io_ctx)
878 io_ctx->poll_burst = 5;
879 io_ctx->pending_polls = 0;
880 io_ctx->residual_burst = 0;
882 bzero(&io_ctx->poll_start_t, sizeof(io_ctx->poll_start_t));
883 bzero(&io_ctx->prev_t, sizeof(io_ctx->prev_t));
888 iopoll_init(int cpuid)
890 KKASSERT(cpuid < IFPOLL_CTX_MAX);
892 rxpoll_context[cpuid] = iopoll_ctx_create(cpuid, IFPOLL_RX);
893 txpoll_context[cpuid] = iopoll_ctx_create(cpuid, IFPOLL_TX);
896 static struct iopoll_ctx *
897 iopoll_ctx_create(int cpuid, int poll_type)
899 struct iopoll_ctx *io_ctx;
900 const char *poll_type_str;
903 KKASSERT(poll_type == IFPOLL_RX || poll_type == IFPOLL_TX);
906 * Make sure that tunables are in sane state
908 if (iopoll_burst_max < MIN_IOPOLL_BURST_MAX)
909 iopoll_burst_max = MIN_IOPOLL_BURST_MAX;
910 else if (iopoll_burst_max > MAX_IOPOLL_BURST_MAX)
911 iopoll_burst_max = MAX_IOPOLL_BURST_MAX;
913 if (iopoll_each_burst > iopoll_burst_max)
914 iopoll_each_burst = iopoll_burst_max;
917 * Create the per-cpu polling context
919 io_ctx = kmalloc(sizeof(*io_ctx), M_DEVBUF, M_WAITOK | M_ZERO);
921 io_ctx->poll_each_burst = iopoll_each_burst;
922 io_ctx->poll_burst_max = iopoll_burst_max;
923 io_ctx->user_frac = 50;
924 #ifdef IFPOLL_MULTI_SYSTIMER
925 io_ctx->pollhz = iopoll_hz;
927 io_ctx->poll_type = poll_type;
929 io_ctx->poll_cpuid = cpuid;
930 iopoll_reset_state(io_ctx);
932 netmsg_init(&io_ctx->poll_netmsg, &netisr_adone_rport, MSGF_MPSAFE,
934 io_ctx->poll_netmsg.nm_lmsg.u.ms_resultp = io_ctx;
936 netmsg_init(&io_ctx->poll_more_netmsg, &netisr_adone_rport, MSGF_MPSAFE,
938 io_ctx->poll_more_netmsg.nm_lmsg.u.ms_resultp = io_ctx;
941 * Initialize per-cpu sysctl nodes
943 if (poll_type == IFPOLL_RX)
944 poll_type_str = "rx";
946 poll_type_str = "tx";
947 ksnprintf(cpuid_str, sizeof(cpuid_str), "%s%d",
948 poll_type_str, io_ctx->poll_cpuid);
950 sysctl_ctx_init(&io_ctx->poll_sysctl_ctx);
951 io_ctx->poll_sysctl_tree = SYSCTL_ADD_NODE(&io_ctx->poll_sysctl_ctx,
952 SYSCTL_STATIC_CHILDREN(_net_ifpoll),
953 OID_AUTO, cpuid_str, CTLFLAG_RD, 0, "");
954 iopoll_add_sysctl(&io_ctx->poll_sysctl_ctx,
955 SYSCTL_CHILDREN(io_ctx->poll_sysctl_tree), io_ctx);
957 #ifdef IFPOLL_MULTI_SYSTIMER
959 * Initialize systimer
961 systimer_init_periodic_nq(&io_ctx->pollclock,
962 iopoll_systimer, io_ctx, 1);
969 * Hook from iopoll systimer. Tries to schedule an iopoll, but keeps
970 * track of lost ticks due to the previous handler taking too long.
971 * Normally, this should not happen, because polling handler should
972 * run for a short time. However, in some cases (e.g. when there are
973 * changes in link status etc.) the drivers take a very long time
974 * (even in the order of milliseconds) to reset and reconfigure the
975 * device, causing apparent lost polls.
977 * The first part of the code is just for debugging purposes, and tries
978 * to count how often hardclock ticks are shorter than they should,
979 * meaning either stray interrupts or delayed events.
981 * WARNING! called from fastint or IPI, the MP lock might not be held.
984 iopoll_clock(struct iopoll_ctx *io_ctx)
986 globaldata_t gd = mycpu;
990 KKASSERT(gd->gd_cpuid == io_ctx->poll_cpuid);
992 if (io_ctx->poll_handlers == 0)
995 #ifdef IFPOLL_MULTI_SYSTIMER
996 poll_hz = io_ctx->pollhz;
998 poll_hz = iopoll_hz(io_ctx);
1002 delta = (t.tv_usec - io_ctx->prev_t.tv_usec) +
1003 (t.tv_sec - io_ctx->prev_t.tv_sec) * 1000000;
1004 if (delta * poll_hz < 500000)
1005 io_ctx->short_ticks++;
1009 if (io_ctx->pending_polls > 100) {
1011 * Too much, assume it has stalled (not always true
1012 * see comment above).
1015 io_ctx->pending_polls = 0;
1019 if (io_ctx->phase <= 2) {
1020 if (io_ctx->phase != 0)
1024 sched_iopoll(io_ctx);
1028 if (io_ctx->pending_polls++ > 0)
1029 io_ctx->lost_polls++;
1032 #ifdef IFPOLL_MULTI_SYSTIMER
1034 iopoll_systimer(systimer_t info, struct intrframe *frame __unused)
1036 iopoll_clock(info->data);
1041 * iopoll_handler is scheduled by sched_iopoll when appropriate, typically
1042 * once per polling systimer tick.
1044 * Note that the message is replied immediately in order to allow a new
1045 * ISR to be scheduled in the handler.
1048 iopoll_handler(struct netmsg *msg)
1050 struct iopoll_ctx *io_ctx;
1051 struct thread *td = curthread;
1054 io_ctx = msg->nm_lmsg.u.ms_resultp;
1055 KKASSERT(&td->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1057 crit_enter_quick(td);
1060 lwkt_replymsg(&msg->nm_lmsg, 0);
1062 if (io_ctx->poll_handlers == 0) {
1063 crit_exit_quick(td);
1068 if (io_ctx->residual_burst == 0) {
1069 /* First call in this tick */
1070 microuptime(&io_ctx->poll_start_t);
1071 io_ctx->residual_burst = io_ctx->poll_burst;
1073 cycles = (io_ctx->residual_burst < io_ctx->poll_each_burst) ?
1074 io_ctx->residual_burst : io_ctx->poll_each_burst;
1075 io_ctx->residual_burst -= cycles;
1077 for (i = 0; i < io_ctx->poll_handlers; i++) {
1078 const struct iopoll_rec *rec = &io_ctx->pr[i];
1079 struct ifnet *ifp = rec->ifp;
1081 if (!lwkt_serialize_try(rec->serializer))
1084 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) ==
1085 (IFF_RUNNING | IFF_NPOLLING))
1086 rec->poll_func(ifp, rec->arg, cycles);
1088 lwkt_serialize_exit(rec->serializer);
1092 * Do a quick exit/enter to catch any higher-priority
1093 * interrupt sources.
1095 crit_exit_quick(td);
1096 crit_enter_quick(td);
1098 sched_iopollmore(io_ctx);
1101 crit_exit_quick(td);
1105 * iopollmore_handler is called after other netisr's, possibly scheduling
1106 * another iopoll_handler call, or adapting the burst size for the next cycle.
1108 * It is very bad to fetch large bursts of packets from a single card at once,
1109 * because the burst could take a long time to be completely processed leading
1110 * to unfairness. To reduce the problem, and also to account better for time
1111 * spent in network-related processing, we split the burst in smaller chunks
1112 * of fixed size, giving control to the other netisr's between chunks. This
1113 * helps in improving the fairness, reducing livelock and accounting for the
1114 * work performed in low level handling.
1117 iopollmore_handler(struct netmsg *msg)
1119 struct thread *td = curthread;
1120 struct iopoll_ctx *io_ctx;
1122 int kern_load, poll_hz;
1123 uint32_t pending_polls;
1125 io_ctx = msg->nm_lmsg.u.ms_resultp;
1126 KKASSERT(&td->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1128 crit_enter_quick(td);
1131 lwkt_replymsg(&msg->nm_lmsg, 0);
1133 if (io_ctx->poll_handlers == 0) {
1134 crit_exit_quick(td);
1138 #ifdef IFPOLL_MULTI_SYSTIMER
1139 poll_hz = io_ctx->pollhz;
1141 poll_hz = iopoll_hz(io_ctx);
1145 if (io_ctx->residual_burst > 0) {
1146 sched_iopoll(io_ctx);
1147 crit_exit_quick(td);
1148 /* Will run immediately on return, followed by netisrs */
1152 /* Here we can account time spent in iopoll's in this tick */
1154 kern_load = (t.tv_usec - io_ctx->poll_start_t.tv_usec) +
1155 (t.tv_sec - io_ctx->poll_start_t.tv_sec) * 1000000; /* us */
1156 kern_load = (kern_load * poll_hz) / 10000; /* 0..100 */
1157 if (kern_load > (100 - io_ctx->user_frac)) {
1158 /* Try decrease ticks */
1159 if (io_ctx->poll_burst > 1)
1160 io_ctx->poll_burst--;
1162 if (io_ctx->poll_burst < io_ctx->poll_burst_max)
1163 io_ctx->poll_burst++;
1166 io_ctx->pending_polls--;
1167 pending_polls = io_ctx->pending_polls;
1169 if (pending_polls == 0) {
1174 * Last cycle was long and caused us to miss one or more
1175 * hardclock ticks. Restart processing again, but slightly
1176 * reduce the burst size to prevent that this happens again.
1178 io_ctx->poll_burst -= (io_ctx->poll_burst / 8);
1179 if (io_ctx->poll_burst < 1)
1180 io_ctx->poll_burst = 1;
1181 sched_iopoll(io_ctx);
1185 crit_exit_quick(td);
1189 iopoll_add_sysctl(struct sysctl_ctx_list *ctx, struct sysctl_oid_list *parent,
1190 struct iopoll_ctx *io_ctx)
1192 #ifdef IFPOLL_MULTI_SYSTIMER
1193 SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, "pollhz",
1194 CTLTYPE_INT | CTLFLAG_RW, io_ctx, 0, sysctl_iopollhz,
1195 "I", "Device polling frequency");
1198 SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, "burst_max",
1199 CTLTYPE_UINT | CTLFLAG_RW, io_ctx, 0, sysctl_burstmax,
1200 "IU", "Max Polling burst size");
1202 SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, "each_burst",
1203 CTLTYPE_UINT | CTLFLAG_RW, io_ctx, 0, sysctl_eachburst,
1204 "IU", "Max size of each burst");
1206 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "phase", CTLFLAG_RD,
1207 &io_ctx->phase, 0, "Polling phase");
1209 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "suspect", CTLFLAG_RW,
1210 &io_ctx->suspect, 0, "suspect event");
1212 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "stalled", CTLFLAG_RW,
1213 &io_ctx->stalled, 0, "potential stalls");
1215 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "burst", CTLFLAG_RD,
1216 &io_ctx->poll_burst, 0, "Current polling burst size");
1218 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "user_frac", CTLFLAG_RW,
1219 &io_ctx->user_frac, 0,
1220 "Desired user fraction of cpu time");
1222 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "short_ticks", CTLFLAG_RW,
1223 &io_ctx->short_ticks, 0,
1224 "Hardclock ticks shorter than they should be");
1226 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "lost_polls", CTLFLAG_RW,
1227 &io_ctx->lost_polls, 0,
1228 "How many times we would have lost a poll tick");
1230 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "pending_polls", CTLFLAG_RD,
1231 &io_ctx->pending_polls, 0, "Do we need to poll again");
1233 SYSCTL_ADD_INT(ctx, parent, OID_AUTO, "residual_burst", CTLFLAG_RD,
1234 &io_ctx->residual_burst, 0,
1235 "# of residual cycles in burst");
1237 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "handlers", CTLFLAG_RD,
1238 &io_ctx->poll_handlers, 0,
1239 "Number of registered poll handlers");
1242 #ifdef IFPOLL_MULTI_SYSTIMER
1245 sysctl_iopollhz(SYSCTL_HANDLER_ARGS)
1247 struct iopoll_ctx *io_ctx = arg1;
1248 struct iopoll_sysctl_netmsg msg;
1249 struct netmsg *nmsg;
1252 phz = io_ctx->pollhz;
1253 error = sysctl_handle_int(oidp, &phz, 0, req);
1254 if (error || req->newptr == NULL)
1258 else if (phz > IFPOLL_FREQ_MAX)
1259 phz = IFPOLL_FREQ_MAX;
1262 netmsg_init(nmsg, &curthread->td_msgport, MSGF_MPSAFE,
1263 sysctl_iopollhz_handler);
1264 nmsg->nm_lmsg.u.ms_result = phz;
1267 return ifnet_domsg(&nmsg->nm_lmsg, io_ctx->poll_cpuid);
1271 sysctl_iopollhz_handler(struct netmsg *nmsg)
1273 struct iopoll_sysctl_netmsg *msg = (struct iopoll_sysctl_netmsg *)nmsg;
1274 struct iopoll_ctx *io_ctx;
1277 KKASSERT(&curthread->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1280 * If polling is disabled or there is no polling handler
1281 * registered, don't adjust polling systimer frequency.
1282 * Polling systimer frequency will be adjusted once there
1283 * are registered handlers.
1285 io_ctx->pollhz = nmsg->nm_lmsg.u.ms_result;
1286 if (io_ctx->poll_handlers)
1287 systimer_adjust_periodic(&io_ctx->pollclock, io_ctx->pollhz);
1289 lwkt_replymsg(&nmsg->nm_lmsg, 0);
1292 #endif /* IFPOLL_MULTI_SYSTIMER */
1295 sysctl_burstmax_handler(struct netmsg *nmsg)
1297 struct iopoll_sysctl_netmsg *msg = (struct iopoll_sysctl_netmsg *)nmsg;
1298 struct iopoll_ctx *io_ctx;
1301 KKASSERT(&curthread->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1303 io_ctx->poll_burst_max = nmsg->nm_lmsg.u.ms_result;
1304 if (io_ctx->poll_each_burst > io_ctx->poll_burst_max)
1305 io_ctx->poll_each_burst = io_ctx->poll_burst_max;
1306 if (io_ctx->poll_burst > io_ctx->poll_burst_max)
1307 io_ctx->poll_burst = io_ctx->poll_burst_max;
1308 if (io_ctx->residual_burst > io_ctx->poll_burst_max)
1309 io_ctx->residual_burst = io_ctx->poll_burst_max;
1311 lwkt_replymsg(&nmsg->nm_lmsg, 0);
1315 sysctl_burstmax(SYSCTL_HANDLER_ARGS)
1317 struct iopoll_ctx *io_ctx = arg1;
1318 struct iopoll_sysctl_netmsg msg;
1319 struct netmsg *nmsg;
1323 burst_max = io_ctx->poll_burst_max;
1324 error = sysctl_handle_int(oidp, &burst_max, 0, req);
1325 if (error || req->newptr == NULL)
1327 if (burst_max < MIN_IOPOLL_BURST_MAX)
1328 burst_max = MIN_IOPOLL_BURST_MAX;
1329 else if (burst_max > MAX_IOPOLL_BURST_MAX)
1330 burst_max = MAX_IOPOLL_BURST_MAX;
1333 netmsg_init(nmsg, &curthread->td_msgport, MSGF_MPSAFE,
1334 sysctl_burstmax_handler);
1335 nmsg->nm_lmsg.u.ms_result = burst_max;
1338 return ifnet_domsg(&nmsg->nm_lmsg, io_ctx->poll_cpuid);
1342 sysctl_eachburst_handler(struct netmsg *nmsg)
1344 struct iopoll_sysctl_netmsg *msg = (struct iopoll_sysctl_netmsg *)nmsg;
1345 struct iopoll_ctx *io_ctx;
1346 uint32_t each_burst;
1349 KKASSERT(&curthread->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1351 each_burst = nmsg->nm_lmsg.u.ms_result;
1352 if (each_burst > io_ctx->poll_burst_max)
1353 each_burst = io_ctx->poll_burst_max;
1354 else if (each_burst < 1)
1356 io_ctx->poll_each_burst = each_burst;
1358 lwkt_replymsg(&nmsg->nm_lmsg, 0);
1362 sysctl_eachburst(SYSCTL_HANDLER_ARGS)
1364 struct iopoll_ctx *io_ctx = arg1;
1365 struct iopoll_sysctl_netmsg msg;
1366 struct netmsg *nmsg;
1367 uint32_t each_burst;
1370 each_burst = io_ctx->poll_each_burst;
1371 error = sysctl_handle_int(oidp, &each_burst, 0, req);
1372 if (error || req->newptr == NULL)
1376 netmsg_init(nmsg, &curthread->td_msgport, MSGF_MPSAFE,
1377 sysctl_eachburst_handler);
1378 nmsg->nm_lmsg.u.ms_result = each_burst;
1381 return ifnet_domsg(&nmsg->nm_lmsg, io_ctx->poll_cpuid);
1385 iopoll_register(struct ifnet *ifp, struct iopoll_ctx *io_ctx,
1386 const struct ifpoll_io *io_rec)
1390 KKASSERT(&curthread->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1392 if (io_rec->poll_func == NULL)
1396 * Check if there is room.
1398 if (io_ctx->poll_handlers >= IFPOLL_LIST_LEN) {
1400 * List full, cannot register more entries.
1401 * This should never happen; if it does, it is probably a
1402 * broken driver trying to register multiple times. Checking
1403 * this at runtime is expensive, and won't solve the problem
1404 * anyways, so just report a few times and then give up.
1406 static int verbose = 10; /* XXX */
1408 kprintf("io poll handlers list full, "
1409 "maybe a broken driver ?\n");
1414 struct iopoll_rec *rec = &io_ctx->pr[io_ctx->poll_handlers];
1417 rec->serializer = io_rec->serializer;
1418 rec->arg = io_rec->arg;
1419 rec->poll_func = io_rec->poll_func;
1421 io_ctx->poll_handlers++;
1422 if (io_ctx->poll_handlers == 1) {
1423 #ifdef IFPOLL_MULTI_SYSTIMER
1424 systimer_adjust_periodic(&io_ctx->pollclock,
1429 if (io_ctx->poll_type == IFPOLL_RX)
1430 mask = &ifpoll0.rx_cpumask;
1432 mask = &ifpoll0.tx_cpumask;
1433 KKASSERT((*mask & mycpu->gd_cpumask) == 0);
1434 atomic_set_int(mask, mycpu->gd_cpumask);
1437 #ifndef IFPOLL_MULTI_SYSTIMER
1438 ifpoll_handler_addevent();
1446 iopoll_deregister(struct ifnet *ifp, struct iopoll_ctx *io_ctx)
1450 KKASSERT(&curthread->td_msgport == ifnet_portfn(io_ctx->poll_cpuid));
1452 for (i = 0; i < io_ctx->poll_handlers; ++i) {
1453 if (io_ctx->pr[i].ifp == ifp) /* Found it */
1456 if (i == io_ctx->poll_handlers) {
1459 io_ctx->poll_handlers--;
1460 if (i < io_ctx->poll_handlers) {
1461 /* Last entry replaces this one. */
1462 io_ctx->pr[i] = io_ctx->pr[io_ctx->poll_handlers];
1465 if (io_ctx->poll_handlers == 0) {
1466 #ifdef IFPOLL_MULTI_SYSTIMER
1467 systimer_adjust_periodic(&io_ctx->pollclock, 1);
1471 if (io_ctx->poll_type == IFPOLL_RX)
1472 mask = &ifpoll0.rx_cpumask;
1474 mask = &ifpoll0.tx_cpumask;
1475 KKASSERT(*mask & mycpu->gd_cpumask);
1476 atomic_clear_int(mask, mycpu->gd_cpumask);
1478 iopoll_reset_state(io_ctx);
1480 #ifndef IFPOLL_MULTI_SYSTIMER
1481 ifpoll_handler_delevent();