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/clock.h>
45 #include <machine/smp.h>
48 #include <net/if_poll.h>
49 #include <net/netmsg2.h>
52 * Polling support for network device drivers.
54 * Drivers which support this feature try to register one status polling
55 * handler and several TX/RX polling handlers with the polling code.
56 * If interface's if_npoll is called with non-NULL second argument, then
57 * a register operation is requested, else a deregister operation is
58 * requested. If the requested operation is "register", driver should
59 * setup the ifpoll_info passed in accoding its own needs:
60 * ifpoll_info.ifpi_status.status_func == NULL
61 * No status polling handler will be installed on CPU(0)
62 * ifpoll_info.ifpi_rx[n].poll_func == NULL
63 * No RX polling handler will be installed on CPU(n)
64 * ifpoll_info.ifpi_tx[n].poll_func == NULL
65 * No TX polling handler will be installed on CPU(n)
67 * RX is polled at the specified polling frequency (net.ifpoll.X.pollhz).
68 * TX and status polling could be done at lower frequency than RX frequency
69 * (net.ifpoll.0.status_frac and net.ifpoll.X.tx_frac). To avoid systimer
70 * staggering at high frequency, RX systimer gives TX and status polling a
73 * All of the registered polling handlers are called only if the interface
74 * is marked as 'IFF_RUNNING and IFF_NPOLLING'. However, the interface's
75 * register and deregister function (ifnet.if_npoll) will be called even
76 * if interface is not marked with 'IFF_RUNNING'.
78 * If registration is successful, the driver must disable interrupts,
79 * and further I/O is performed through the TX/RX polling handler, which
80 * are invoked (at least once per clock tick) with 3 arguments: the "arg"
81 * passed at register time, a struct ifnet pointer, and a "count" limit.
82 * The registered serializer will be held before calling the related
85 * The count limit specifies how much work the handler can do during the
86 * call -- typically this is the number of packets to be received, or
87 * transmitted, etc. (drivers are free to interpret this number, as long
88 * as the max time spent in the function grows roughly linearly with the
91 * A second variable controls the sharing of CPU between polling/kernel
92 * network processing, and other activities (typically userlevel tasks):
93 * net.ifpoll.X.{rx,tx}.user_frac (between 0 and 100, default 50) sets the
94 * share of CPU allocated to user tasks. CPU is allocated proportionally
95 * to the shares, by dynamically adjusting the "count" (poll_burst).
97 * Other parameters can should be left to their default values.
98 * The following constraints hold
100 * 1 <= poll_burst <= poll_burst_max
101 * 1 <= poll_each_burst <= poll_burst_max
102 * MIN_POLL_BURST_MAX <= poll_burst_max <= MAX_POLL_BURST_MAX
105 #define IFPOLL_LIST_LEN 128
106 #define IFPOLL_FREQ_MAX 30000
108 #define MIN_IOPOLL_BURST_MAX 10
109 #define MAX_IOPOLL_BURST_MAX 5000
110 #define IOPOLL_BURST_MAX 375 /* good for 1000Mbit net and HZ=4000 */
112 #define IOPOLL_EACH_BURST 15
114 #define IFPOLL_FREQ_DEFAULT 4000
116 #define IFPOLL_TXFRAC_DEFAULT 1 /* 1/1 of the pollhz */
117 #define IFPOLL_STFRAC_DEFAULT 80 /* 1/80 of the pollhz */
119 #define IFPOLL_RX 0x1
120 #define IFPOLL_TX 0x2
128 struct lwkt_serialize *serializer;
131 ifpoll_iofn_t poll_func;
135 union ifpoll_time prev_t;
136 u_long short_ticks; /* statistics */
137 u_long lost_polls; /* statistics */
138 u_long suspect; /* statistics */
139 u_long stalled; /* statistics */
140 uint32_t pending_polls; /* state */
142 struct netmsg_base poll_netmsg;
143 struct netmsg_base poll_more_netmsg;
147 uint32_t phase; /* state */
148 int residual_burst; /* state */
149 uint32_t poll_each_burst; /* tunable */
150 union ifpoll_time poll_start_t; /* state */
152 uint32_t poll_burst; /* state */
153 uint32_t poll_burst_max; /* tunable */
154 uint32_t user_frac; /* tunable */
155 uint32_t kern_frac; /* state */
157 uint32_t poll_handlers; /* next free entry in pr[]. */
158 struct iopoll_rec pr[IFPOLL_LIST_LEN];
160 struct sysctl_ctx_list poll_sysctl_ctx;
161 struct sysctl_oid *poll_sysctl_tree;
165 struct systimer pollclock;
168 int stfrac_count; /* state */
169 int poll_stfrac; /* tunable */
171 int txfrac_count; /* state */
172 int poll_txfrac; /* tunable */
174 int pollhz; /* tunable */
176 struct sysctl_ctx_list sysctl_ctx;
177 struct sysctl_oid *sysctl_tree;
181 struct lwkt_serialize *serializer;
183 ifpoll_stfn_t status_func;
187 struct netmsg_base poll_netmsg;
189 uint32_t poll_handlers; /* next free entry in pr[]. */
190 struct stpoll_rec pr[IFPOLL_LIST_LEN];
192 struct sysctl_ctx_list poll_sysctl_ctx;
193 struct sysctl_oid *poll_sysctl_tree;
196 struct iopoll_sysctl_netmsg {
197 struct netmsg_base base;
198 struct iopoll_ctx *ctx;
201 void ifpoll_init_pcpu(int);
202 static void ifpoll_register_handler(netmsg_t);
203 static void ifpoll_deregister_handler(netmsg_t);
208 static void stpoll_init(void);
209 static void stpoll_handler(netmsg_t);
210 static void stpoll_clock(struct stpoll_ctx *);
211 static int stpoll_register(struct ifnet *, const struct ifpoll_status *);
212 static int stpoll_deregister(struct ifnet *);
217 static struct iopoll_ctx *iopoll_ctx_create(int, int);
218 static void iopoll_init(int);
219 static void rxpoll_handler(netmsg_t);
220 static void txpoll_handler(netmsg_t);
221 static void rxpollmore_handler(netmsg_t);
222 static void txpollmore_handler(netmsg_t);
223 static void iopoll_clock(struct iopoll_ctx *);
224 static int iopoll_register(struct ifnet *, struct iopoll_ctx *,
225 const struct ifpoll_io *);
226 static int iopoll_deregister(struct ifnet *, struct iopoll_ctx *);
228 static void iopoll_add_sysctl(struct sysctl_ctx_list *,
229 struct sysctl_oid_list *, struct iopoll_ctx *, int);
230 static void sysctl_burstmax_handler(netmsg_t);
231 static int sysctl_burstmax(SYSCTL_HANDLER_ARGS);
232 static void sysctl_eachburst_handler(netmsg_t);
233 static int sysctl_eachburst(SYSCTL_HANDLER_ARGS);
238 static void poll_comm_init(int);
239 static void poll_comm_start(int);
240 static void poll_comm_adjust_pollhz(struct poll_comm *);
241 static void poll_comm_systimer0(systimer_t, int, struct intrframe *);
242 static void poll_comm_systimer(systimer_t, int, struct intrframe *);
243 static void sysctl_pollhz_handler(netmsg_t);
244 static void sysctl_stfrac_handler(netmsg_t);
245 static void sysctl_txfrac_handler(netmsg_t);
246 static int sysctl_pollhz(SYSCTL_HANDLER_ARGS);
247 static int sysctl_stfrac(SYSCTL_HANDLER_ARGS);
248 static int sysctl_txfrac(SYSCTL_HANDLER_ARGS);
249 static int sysctl_compat_npoll_stfrac(SYSCTL_HANDLER_ARGS);
250 static int sysctl_compat_npoll_cpuid(SYSCTL_HANDLER_ARGS);
252 static struct stpoll_ctx stpoll_context;
253 static struct poll_comm *poll_common[MAXCPU];
254 static struct iopoll_ctx *rxpoll_context[MAXCPU];
255 static struct iopoll_ctx *txpoll_context[MAXCPU];
257 SYSCTL_NODE(_net, OID_AUTO, ifpoll, CTLFLAG_RW, 0,
258 "Network device polling parameters");
260 static int iopoll_burst_max = IOPOLL_BURST_MAX;
261 static int iopoll_each_burst = IOPOLL_EACH_BURST;
263 static int ifpoll_pollhz = IFPOLL_FREQ_DEFAULT;
264 static int ifpoll_stfrac = IFPOLL_STFRAC_DEFAULT;
265 static int ifpoll_txfrac = IFPOLL_TXFRAC_DEFAULT;
267 TUNABLE_INT("net.ifpoll.burst_max", &iopoll_burst_max);
268 TUNABLE_INT("net.ifpoll.each_burst", &iopoll_each_burst);
269 TUNABLE_INT("net.ifpoll.pollhz", &ifpoll_pollhz);
270 TUNABLE_INT("net.ifpoll.status_frac", &ifpoll_stfrac);
271 TUNABLE_INT("net.ifpoll.tx_frac", &ifpoll_txfrac);
274 ifpoll_sendmsg_oncpu(netmsg_t msg)
276 if (msg->lmsg.ms_flags & MSGF_DONE)
277 lwkt_sendmsg(netisr_portfn(mycpuid), &msg->lmsg);
281 sched_stpoll(struct stpoll_ctx *st_ctx)
283 ifpoll_sendmsg_oncpu((netmsg_t)&st_ctx->poll_netmsg);
287 sched_iopoll(struct iopoll_ctx *io_ctx)
289 ifpoll_sendmsg_oncpu((netmsg_t)&io_ctx->poll_netmsg);
293 sched_iopollmore(struct iopoll_ctx *io_ctx)
295 ifpoll_sendmsg_oncpu((netmsg_t)&io_ctx->poll_more_netmsg);
299 ifpoll_time_get(union ifpoll_time *t)
301 if (__predict_true(tsc_present))
307 /* Return time diff in us */
309 ifpoll_time_diff(const union ifpoll_time *s, const union ifpoll_time *e)
311 if (__predict_true(tsc_present)) {
312 return (((e->tsc - s->tsc) * 1000000) / tsc_frequency);
314 return ((e->tv.tv_usec - s->tv.tv_usec) +
315 (e->tv.tv_sec - s->tv.tv_sec) * 1000000);
320 * Initialize per-cpu qpolling(4) context. Called from kern_clock.c:
323 ifpoll_init_pcpu(int cpuid)
328 poll_comm_init(cpuid);
334 poll_comm_start(cpuid);
338 ifpoll_register(struct ifnet *ifp)
340 struct ifpoll_info *info;
341 struct netmsg_base nmsg;
344 if (ifp->if_npoll == NULL) {
345 /* Device does not support polling */
349 info = kmalloc(sizeof(*info), M_TEMP, M_WAITOK | M_ZERO);
352 * Attempt to register. Interlock with IFF_NPOLLING.
355 ifnet_serialize_all(ifp);
357 if (ifp->if_flags & IFF_NPOLLING) {
358 /* Already polling */
359 ifnet_deserialize_all(ifp);
364 info->ifpi_ifp = ifp;
366 ifp->if_flags |= IFF_NPOLLING;
367 ifp->if_npoll(ifp, info);
368 KASSERT(ifp->if_npoll_cpuid >= 0, ("invalid npoll cpuid"));
370 ifnet_deserialize_all(ifp);
372 netmsg_init(&nmsg, NULL, &curthread->td_msgport,
373 0, ifpoll_register_handler);
374 nmsg.lmsg.u.ms_resultp = info;
376 error = lwkt_domsg(netisr_portfn(0), &nmsg.lmsg, 0);
378 if (!ifpoll_deregister(ifp)) {
379 if_printf(ifp, "ifpoll_register: "
380 "ifpoll_deregister failed!\n");
389 ifpoll_deregister(struct ifnet *ifp)
391 struct netmsg_base nmsg;
394 if (ifp->if_npoll == NULL)
397 ifnet_serialize_all(ifp);
399 if ((ifp->if_flags & IFF_NPOLLING) == 0) {
400 ifnet_deserialize_all(ifp);
403 ifp->if_flags &= ~IFF_NPOLLING;
405 ifnet_deserialize_all(ifp);
407 netmsg_init(&nmsg, NULL, &curthread->td_msgport,
408 0, ifpoll_deregister_handler);
409 nmsg.lmsg.u.ms_resultp = ifp;
411 error = lwkt_domsg(netisr_portfn(0), &nmsg.lmsg, 0);
413 ifnet_serialize_all(ifp);
414 ifp->if_npoll(ifp, NULL);
415 KASSERT(ifp->if_npoll_cpuid < 0, ("invalid npoll cpuid"));
416 ifnet_deserialize_all(ifp);
422 ifpoll_register_handler(netmsg_t nmsg)
424 const struct ifpoll_info *info = nmsg->lmsg.u.ms_resultp;
425 int cpuid = mycpuid, nextcpu;
428 KKASSERT(cpuid < ncpus2);
429 KKASSERT(&curthread->td_msgport == netisr_portfn(cpuid));
432 error = stpoll_register(info->ifpi_ifp, &info->ifpi_status);
437 error = iopoll_register(info->ifpi_ifp, rxpoll_context[cpuid],
438 &info->ifpi_rx[cpuid]);
442 error = iopoll_register(info->ifpi_ifp, txpoll_context[cpuid],
443 &info->ifpi_tx[cpuid]);
447 /* Adjust polling frequency, after all registration is done */
448 poll_comm_adjust_pollhz(poll_common[cpuid]);
451 if (nextcpu < ncpus2)
452 lwkt_forwardmsg(netisr_portfn(nextcpu), &nmsg->lmsg);
454 lwkt_replymsg(&nmsg->lmsg, 0);
457 lwkt_replymsg(&nmsg->lmsg, error);
461 ifpoll_deregister_handler(netmsg_t nmsg)
463 struct ifnet *ifp = nmsg->lmsg.u.ms_resultp;
464 int cpuid = mycpuid, nextcpu;
466 KKASSERT(cpuid < ncpus2);
467 KKASSERT(&curthread->td_msgport == netisr_portfn(cpuid));
471 stpoll_deregister(ifp);
472 iopoll_deregister(ifp, rxpoll_context[cpuid]);
473 iopoll_deregister(ifp, txpoll_context[cpuid]);
475 /* Adjust polling frequency, after all deregistration is done */
476 poll_comm_adjust_pollhz(poll_common[cpuid]);
479 if (nextcpu < ncpus2)
480 lwkt_forwardmsg(netisr_portfn(nextcpu), &nmsg->lmsg);
482 lwkt_replymsg(&nmsg->lmsg, 0);
488 struct stpoll_ctx *st_ctx = &stpoll_context;
489 const struct poll_comm *comm = poll_common[0];
491 sysctl_ctx_init(&st_ctx->poll_sysctl_ctx);
492 st_ctx->poll_sysctl_tree = SYSCTL_ADD_NODE(&st_ctx->poll_sysctl_ctx,
493 SYSCTL_CHILDREN(comm->sysctl_tree),
494 OID_AUTO, "status", CTLFLAG_RD, 0, "");
496 SYSCTL_ADD_UINT(&st_ctx->poll_sysctl_ctx,
497 SYSCTL_CHILDREN(st_ctx->poll_sysctl_tree),
498 OID_AUTO, "handlers", CTLFLAG_RD,
499 &st_ctx->poll_handlers, 0,
500 "Number of registered status poll handlers");
502 netmsg_init(&st_ctx->poll_netmsg, NULL, &netisr_adone_rport,
507 * stpoll_handler is scheduled by sched_stpoll when appropriate, typically
508 * once per polling systimer tick.
511 stpoll_handler(netmsg_t msg)
513 struct stpoll_ctx *st_ctx = &stpoll_context;
514 struct thread *td = curthread;
517 KKASSERT(&td->td_msgport == netisr_portfn(0));
519 crit_enter_quick(td);
522 lwkt_replymsg(&msg->lmsg, 0);
524 if (st_ctx->poll_handlers == 0) {
529 for (i = 0; i < st_ctx->poll_handlers; ++i) {
530 const struct stpoll_rec *rec = &st_ctx->pr[i];
531 struct ifnet *ifp = rec->ifp;
533 if (!lwkt_serialize_try(rec->serializer))
536 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) ==
537 (IFF_RUNNING | IFF_NPOLLING))
538 rec->status_func(ifp);
540 lwkt_serialize_exit(rec->serializer);
547 * Hook from status poll systimer. Tries to schedule an status poll.
548 * NOTE: Caller should hold critical section.
551 stpoll_clock(struct stpoll_ctx *st_ctx)
553 KKASSERT(mycpuid == 0);
555 if (st_ctx->poll_handlers == 0)
557 sched_stpoll(st_ctx);
561 stpoll_register(struct ifnet *ifp, const struct ifpoll_status *st_rec)
563 struct stpoll_ctx *st_ctx = &stpoll_context;
566 KKASSERT(&curthread->td_msgport == netisr_portfn(0));
568 if (st_rec->status_func == NULL)
572 * Check if there is room.
574 if (st_ctx->poll_handlers >= IFPOLL_LIST_LEN) {
576 * List full, cannot register more entries.
577 * This should never happen; if it does, it is probably a
578 * broken driver trying to register multiple times. Checking
579 * this at runtime is expensive, and won't solve the problem
580 * anyways, so just report a few times and then give up.
582 static int verbose = 10; /* XXX */
585 kprintf("status poll handlers list full, "
586 "maybe a broken driver ?\n");
591 struct stpoll_rec *rec = &st_ctx->pr[st_ctx->poll_handlers];
594 rec->serializer = st_rec->serializer;
595 rec->status_func = st_rec->status_func;
597 st_ctx->poll_handlers++;
604 stpoll_deregister(struct ifnet *ifp)
606 struct stpoll_ctx *st_ctx = &stpoll_context;
609 KKASSERT(&curthread->td_msgport == netisr_portfn(0));
611 for (i = 0; i < st_ctx->poll_handlers; ++i) {
612 if (st_ctx->pr[i].ifp == ifp) /* Found it */
615 if (i == st_ctx->poll_handlers) {
618 st_ctx->poll_handlers--;
619 if (i < st_ctx->poll_handlers) {
620 /* Last entry replaces this one. */
621 st_ctx->pr[i] = st_ctx->pr[st_ctx->poll_handlers];
629 iopoll_reset_state(struct iopoll_ctx *io_ctx)
632 io_ctx->poll_burst = io_ctx->poll_each_burst;
633 io_ctx->pending_polls = 0;
634 io_ctx->residual_burst = 0;
636 io_ctx->kern_frac = 0;
637 bzero(&io_ctx->poll_start_t, sizeof(io_ctx->poll_start_t));
638 bzero(&io_ctx->prev_t, sizeof(io_ctx->prev_t));
643 iopoll_init(int cpuid)
645 KKASSERT(cpuid < ncpus2);
647 rxpoll_context[cpuid] = iopoll_ctx_create(cpuid, IFPOLL_RX);
648 txpoll_context[cpuid] = iopoll_ctx_create(cpuid, IFPOLL_TX);
651 static struct iopoll_ctx *
652 iopoll_ctx_create(int cpuid, int poll_type)
654 struct poll_comm *comm;
655 struct iopoll_ctx *io_ctx;
656 const char *poll_type_str;
657 netisr_fn_t handler, more_handler;
659 KKASSERT(poll_type == IFPOLL_RX || poll_type == IFPOLL_TX);
662 * Make sure that tunables are in sane state
664 if (iopoll_burst_max < MIN_IOPOLL_BURST_MAX)
665 iopoll_burst_max = MIN_IOPOLL_BURST_MAX;
666 else if (iopoll_burst_max > MAX_IOPOLL_BURST_MAX)
667 iopoll_burst_max = MAX_IOPOLL_BURST_MAX;
669 if (iopoll_each_burst > iopoll_burst_max)
670 iopoll_each_burst = iopoll_burst_max;
672 comm = poll_common[cpuid];
675 * Create the per-cpu polling context
677 io_ctx = kmalloc_cachealign(sizeof(*io_ctx), M_DEVBUF,
680 io_ctx->poll_each_burst = iopoll_each_burst;
681 io_ctx->poll_burst_max = iopoll_burst_max;
682 io_ctx->user_frac = 50;
683 if (poll_type == IFPOLL_RX)
684 io_ctx->pollhz = comm->pollhz;
686 io_ctx->pollhz = comm->pollhz / (comm->poll_txfrac + 1);
687 io_ctx->poll_cpuid = cpuid;
688 iopoll_reset_state(io_ctx);
690 if (poll_type == IFPOLL_RX) {
691 handler = rxpoll_handler;
692 more_handler = rxpollmore_handler;
694 handler = txpoll_handler;
695 more_handler = txpollmore_handler;
698 netmsg_init(&io_ctx->poll_netmsg, NULL, &netisr_adone_rport,
700 io_ctx->poll_netmsg.lmsg.u.ms_resultp = io_ctx;
702 netmsg_init(&io_ctx->poll_more_netmsg, NULL, &netisr_adone_rport,
704 io_ctx->poll_more_netmsg.lmsg.u.ms_resultp = io_ctx;
707 * Initialize per-cpu sysctl nodes
709 if (poll_type == IFPOLL_RX)
710 poll_type_str = "rx";
712 poll_type_str = "tx";
714 sysctl_ctx_init(&io_ctx->poll_sysctl_ctx);
715 io_ctx->poll_sysctl_tree = SYSCTL_ADD_NODE(&io_ctx->poll_sysctl_ctx,
716 SYSCTL_CHILDREN(comm->sysctl_tree),
717 OID_AUTO, poll_type_str, CTLFLAG_RD, 0, "");
718 iopoll_add_sysctl(&io_ctx->poll_sysctl_ctx,
719 SYSCTL_CHILDREN(io_ctx->poll_sysctl_tree), io_ctx, poll_type);
725 * Hook from iopoll systimer. Tries to schedule an iopoll, but keeps
726 * track of lost ticks due to the previous handler taking too long.
727 * Normally, this should not happen, because polling handler should
728 * run for a short time. However, in some cases (e.g. when there are
729 * changes in link status etc.) the drivers take a very long time
730 * (even in the order of milliseconds) to reset and reconfigure the
731 * device, causing apparent lost polls.
733 * The first part of the code is just for debugging purposes, and tries
734 * to count how often hardclock ticks are shorter than they should,
735 * meaning either stray interrupts or delayed events.
737 * WARNING! called from fastint or IPI, the MP lock might not be held.
738 * NOTE: Caller should hold critical section.
741 iopoll_clock(struct iopoll_ctx *io_ctx)
746 KKASSERT(mycpuid == io_ctx->poll_cpuid);
748 if (io_ctx->poll_handlers == 0)
752 delta = ifpoll_time_diff(&io_ctx->prev_t, &t);
753 if (delta * io_ctx->pollhz < 500000)
754 io_ctx->short_ticks++;
758 if (io_ctx->pending_polls > 100) {
760 * Too much, assume it has stalled (not always true
761 * see comment above).
764 io_ctx->pending_polls = 0;
768 if (io_ctx->phase <= 2) {
769 if (io_ctx->phase != 0)
772 sched_iopoll(io_ctx);
775 if (io_ctx->pending_polls++ > 0)
776 io_ctx->lost_polls++;
780 * rxpoll_handler and txpoll_handler are scheduled by sched_iopoll when
781 * appropriate, typically once per polling systimer tick.
783 * Note that the message is replied immediately in order to allow a new
784 * ISR to be scheduled in the handler.
787 rxpoll_handler(netmsg_t msg)
789 struct iopoll_ctx *io_ctx;
790 struct thread *td = curthread;
793 io_ctx = msg->lmsg.u.ms_resultp;
794 KKASSERT(&td->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
796 crit_enter_quick(td);
799 lwkt_replymsg(&msg->lmsg, 0);
801 if (io_ctx->poll_handlers == 0) {
807 if (io_ctx->residual_burst == 0) {
808 /* First call in this tick */
809 ifpoll_time_get(&io_ctx->poll_start_t);
810 io_ctx->residual_burst = io_ctx->poll_burst;
812 cycles = (io_ctx->residual_burst < io_ctx->poll_each_burst) ?
813 io_ctx->residual_burst : io_ctx->poll_each_burst;
814 io_ctx->residual_burst -= cycles;
816 for (i = 0; i < io_ctx->poll_handlers; i++) {
817 const struct iopoll_rec *rec = &io_ctx->pr[i];
818 struct ifnet *ifp = rec->ifp;
820 if (!lwkt_serialize_try(rec->serializer))
823 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) ==
824 (IFF_RUNNING | IFF_NPOLLING))
825 rec->poll_func(ifp, rec->arg, cycles);
827 lwkt_serialize_exit(rec->serializer);
831 * Do a quick exit/enter to catch any higher-priority
835 crit_enter_quick(td);
837 sched_iopollmore(io_ctx);
844 txpoll_handler(netmsg_t msg)
846 struct iopoll_ctx *io_ctx;
847 struct thread *td = curthread;
850 io_ctx = msg->lmsg.u.ms_resultp;
851 KKASSERT(&td->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
853 crit_enter_quick(td);
856 lwkt_replymsg(&msg->lmsg, 0);
858 if (io_ctx->poll_handlers == 0) {
865 for (i = 0; i < io_ctx->poll_handlers; i++) {
866 const struct iopoll_rec *rec = &io_ctx->pr[i];
867 struct ifnet *ifp = rec->ifp;
869 if (!lwkt_serialize_try(rec->serializer))
872 if ((ifp->if_flags & (IFF_RUNNING | IFF_NPOLLING)) ==
873 (IFF_RUNNING | IFF_NPOLLING))
874 rec->poll_func(ifp, rec->arg, -1);
876 lwkt_serialize_exit(rec->serializer);
880 * Do a quick exit/enter to catch any higher-priority
884 crit_enter_quick(td);
886 sched_iopollmore(io_ctx);
893 * rxpollmore_handler and txpollmore_handler are called after other netisr's,
894 * possibly scheduling another rxpoll_handler or txpoll_handler call, or
895 * adapting the burst size for the next cycle.
897 * It is very bad to fetch large bursts of packets from a single card at once,
898 * because the burst could take a long time to be completely processed leading
899 * to unfairness. To reduce the problem, and also to account better for time
900 * spent in network-related processing, we split the burst in smaller chunks
901 * of fixed size, giving control to the other netisr's between chunks. This
902 * helps in improving the fairness, reducing livelock and accounting for the
903 * work performed in low level handling.
906 rxpollmore_handler(netmsg_t msg)
908 struct thread *td = curthread;
909 struct iopoll_ctx *io_ctx;
912 uint32_t pending_polls;
914 io_ctx = msg->lmsg.u.ms_resultp;
915 KKASSERT(&td->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
917 crit_enter_quick(td);
920 lwkt_replymsg(&msg->lmsg, 0);
922 if (io_ctx->poll_handlers == 0) {
928 if (io_ctx->residual_burst > 0) {
929 sched_iopoll(io_ctx);
931 /* Will run immediately on return, followed by netisrs */
935 /* Here we can account time spent in iopoll's in this tick */
937 kern_load = ifpoll_time_diff(&io_ctx->poll_start_t, &t);
938 kern_load = (kern_load * io_ctx->pollhz) / 10000; /* 0..100 */
939 io_ctx->kern_frac = kern_load;
941 if (kern_load > (100 - io_ctx->user_frac)) {
942 /* Try decrease ticks */
943 if (io_ctx->poll_burst > 1)
944 io_ctx->poll_burst--;
946 if (io_ctx->poll_burst < io_ctx->poll_burst_max)
947 io_ctx->poll_burst++;
950 io_ctx->pending_polls--;
951 pending_polls = io_ctx->pending_polls;
953 if (pending_polls == 0) {
958 * Last cycle was long and caused us to miss one or more
959 * hardclock ticks. Restart processing again, but slightly
960 * reduce the burst size to prevent that this happens again.
962 io_ctx->poll_burst -= (io_ctx->poll_burst / 8);
963 if (io_ctx->poll_burst < 1)
964 io_ctx->poll_burst = 1;
965 sched_iopoll(io_ctx);
973 txpollmore_handler(netmsg_t msg)
975 struct thread *td = curthread;
976 struct iopoll_ctx *io_ctx;
977 uint32_t pending_polls;
979 io_ctx = msg->lmsg.u.ms_resultp;
980 KKASSERT(&td->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
982 crit_enter_quick(td);
985 lwkt_replymsg(&msg->lmsg, 0);
987 if (io_ctx->poll_handlers == 0) {
994 io_ctx->pending_polls--;
995 pending_polls = io_ctx->pending_polls;
997 if (pending_polls == 0) {
1002 * Last cycle was long and caused us to miss one or more
1003 * hardclock ticks. Restart processing again.
1005 sched_iopoll(io_ctx);
1009 crit_exit_quick(td);
1013 iopoll_add_sysctl(struct sysctl_ctx_list *ctx, struct sysctl_oid_list *parent,
1014 struct iopoll_ctx *io_ctx, int poll_type)
1016 if (poll_type == IFPOLL_RX) {
1017 SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, "burst_max",
1018 CTLTYPE_UINT | CTLFLAG_RW, io_ctx, 0, sysctl_burstmax,
1019 "IU", "Max Polling burst size");
1021 SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, "each_burst",
1022 CTLTYPE_UINT | CTLFLAG_RW, io_ctx, 0, sysctl_eachburst,
1023 "IU", "Max size of each burst");
1025 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "burst", CTLFLAG_RD,
1026 &io_ctx->poll_burst, 0, "Current polling burst size");
1028 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "user_frac", CTLFLAG_RW,
1029 &io_ctx->user_frac, 0, "Desired user fraction of cpu time");
1031 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "kern_frac", CTLFLAG_RD,
1032 &io_ctx->kern_frac, 0, "Kernel fraction of cpu time");
1034 SYSCTL_ADD_INT(ctx, parent, OID_AUTO, "residual_burst", CTLFLAG_RD,
1035 &io_ctx->residual_burst, 0,
1036 "# of residual cycles in burst");
1039 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "phase", CTLFLAG_RD,
1040 &io_ctx->phase, 0, "Polling phase");
1042 SYSCTL_ADD_ULONG(ctx, parent, OID_AUTO, "suspect", CTLFLAG_RW,
1043 &io_ctx->suspect, "Suspected events");
1045 SYSCTL_ADD_ULONG(ctx, parent, OID_AUTO, "stalled", CTLFLAG_RW,
1046 &io_ctx->stalled, "Potential stalls");
1048 SYSCTL_ADD_ULONG(ctx, parent, OID_AUTO, "short_ticks", CTLFLAG_RW,
1049 &io_ctx->short_ticks,
1050 "Hardclock ticks shorter than they should be");
1052 SYSCTL_ADD_ULONG(ctx, parent, OID_AUTO, "lost_polls", CTLFLAG_RW,
1053 &io_ctx->lost_polls,
1054 "How many times we would have lost a poll tick");
1056 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "pending_polls", CTLFLAG_RD,
1057 &io_ctx->pending_polls, 0, "Do we need to poll again");
1059 SYSCTL_ADD_UINT(ctx, parent, OID_AUTO, "handlers", CTLFLAG_RD,
1060 &io_ctx->poll_handlers, 0, "Number of registered poll handlers");
1064 sysctl_burstmax_handler(netmsg_t nmsg)
1066 struct iopoll_sysctl_netmsg *msg = (struct iopoll_sysctl_netmsg *)nmsg;
1067 struct iopoll_ctx *io_ctx;
1070 KKASSERT(&curthread->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
1072 io_ctx->poll_burst_max = nmsg->lmsg.u.ms_result;
1073 if (io_ctx->poll_each_burst > io_ctx->poll_burst_max)
1074 io_ctx->poll_each_burst = io_ctx->poll_burst_max;
1075 if (io_ctx->poll_burst > io_ctx->poll_burst_max)
1076 io_ctx->poll_burst = io_ctx->poll_burst_max;
1077 if (io_ctx->residual_burst > io_ctx->poll_burst_max)
1078 io_ctx->residual_burst = io_ctx->poll_burst_max;
1080 lwkt_replymsg(&nmsg->lmsg, 0);
1084 sysctl_burstmax(SYSCTL_HANDLER_ARGS)
1086 struct iopoll_ctx *io_ctx = arg1;
1087 struct iopoll_sysctl_netmsg msg;
1091 burst_max = io_ctx->poll_burst_max;
1092 error = sysctl_handle_int(oidp, &burst_max, 0, req);
1093 if (error || req->newptr == NULL)
1095 if (burst_max < MIN_IOPOLL_BURST_MAX)
1096 burst_max = MIN_IOPOLL_BURST_MAX;
1097 else if (burst_max > MAX_IOPOLL_BURST_MAX)
1098 burst_max = MAX_IOPOLL_BURST_MAX;
1100 netmsg_init(&msg.base, NULL, &curthread->td_msgport,
1101 0, sysctl_burstmax_handler);
1102 msg.base.lmsg.u.ms_result = burst_max;
1105 return lwkt_domsg(netisr_portfn(io_ctx->poll_cpuid), &msg.base.lmsg, 0);
1109 sysctl_eachburst_handler(netmsg_t nmsg)
1111 struct iopoll_sysctl_netmsg *msg = (struct iopoll_sysctl_netmsg *)nmsg;
1112 struct iopoll_ctx *io_ctx;
1113 uint32_t each_burst;
1116 KKASSERT(&curthread->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
1118 each_burst = nmsg->lmsg.u.ms_result;
1119 if (each_burst > io_ctx->poll_burst_max)
1120 each_burst = io_ctx->poll_burst_max;
1121 else if (each_burst < 1)
1123 io_ctx->poll_each_burst = each_burst;
1125 lwkt_replymsg(&nmsg->lmsg, 0);
1129 sysctl_eachburst(SYSCTL_HANDLER_ARGS)
1131 struct iopoll_ctx *io_ctx = arg1;
1132 struct iopoll_sysctl_netmsg msg;
1133 uint32_t each_burst;
1136 each_burst = io_ctx->poll_each_burst;
1137 error = sysctl_handle_int(oidp, &each_burst, 0, req);
1138 if (error || req->newptr == NULL)
1141 netmsg_init(&msg.base, NULL, &curthread->td_msgport,
1142 0, sysctl_eachburst_handler);
1143 msg.base.lmsg.u.ms_result = each_burst;
1146 return lwkt_domsg(netisr_portfn(io_ctx->poll_cpuid), &msg.base.lmsg, 0);
1150 iopoll_register(struct ifnet *ifp, struct iopoll_ctx *io_ctx,
1151 const struct ifpoll_io *io_rec)
1155 KKASSERT(&curthread->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
1157 if (io_rec->poll_func == NULL)
1161 * Check if there is room.
1163 if (io_ctx->poll_handlers >= IFPOLL_LIST_LEN) {
1165 * List full, cannot register more entries.
1166 * This should never happen; if it does, it is probably a
1167 * broken driver trying to register multiple times. Checking
1168 * this at runtime is expensive, and won't solve the problem
1169 * anyways, so just report a few times and then give up.
1171 static int verbose = 10; /* XXX */
1173 kprintf("io poll handlers list full, "
1174 "maybe a broken driver ?\n");
1179 struct iopoll_rec *rec = &io_ctx->pr[io_ctx->poll_handlers];
1182 rec->serializer = io_rec->serializer;
1183 rec->arg = io_rec->arg;
1184 rec->poll_func = io_rec->poll_func;
1186 io_ctx->poll_handlers++;
1193 iopoll_deregister(struct ifnet *ifp, struct iopoll_ctx *io_ctx)
1197 KKASSERT(&curthread->td_msgport == netisr_portfn(io_ctx->poll_cpuid));
1199 for (i = 0; i < io_ctx->poll_handlers; ++i) {
1200 if (io_ctx->pr[i].ifp == ifp) /* Found it */
1203 if (i == io_ctx->poll_handlers) {
1206 io_ctx->poll_handlers--;
1207 if (i < io_ctx->poll_handlers) {
1208 /* Last entry replaces this one. */
1209 io_ctx->pr[i] = io_ctx->pr[io_ctx->poll_handlers];
1212 if (io_ctx->poll_handlers == 0)
1213 iopoll_reset_state(io_ctx);
1220 poll_comm_init(int cpuid)
1222 struct poll_comm *comm;
1225 comm = kmalloc_cachealign(sizeof(*comm), M_DEVBUF, M_WAITOK | M_ZERO);
1227 if (ifpoll_stfrac < 1)
1228 ifpoll_stfrac = IFPOLL_STFRAC_DEFAULT;
1229 if (ifpoll_txfrac < 1)
1230 ifpoll_txfrac = IFPOLL_TXFRAC_DEFAULT;
1232 comm->pollhz = ifpoll_pollhz;
1233 comm->poll_cpuid = cpuid;
1234 comm->poll_stfrac = ifpoll_stfrac - 1;
1235 comm->poll_txfrac = ifpoll_txfrac - 1;
1237 ksnprintf(cpuid_str, sizeof(cpuid_str), "%d", cpuid);
1239 sysctl_ctx_init(&comm->sysctl_ctx);
1240 comm->sysctl_tree = SYSCTL_ADD_NODE(&comm->sysctl_ctx,
1241 SYSCTL_STATIC_CHILDREN(_net_ifpoll),
1242 OID_AUTO, cpuid_str, CTLFLAG_RD, 0, "");
1244 SYSCTL_ADD_PROC(&comm->sysctl_ctx, SYSCTL_CHILDREN(comm->sysctl_tree),
1245 OID_AUTO, "pollhz", CTLTYPE_INT | CTLFLAG_RW,
1246 comm, 0, sysctl_pollhz,
1247 "I", "Device polling frequency");
1250 SYSCTL_ADD_PROC(&comm->sysctl_ctx,
1251 SYSCTL_CHILDREN(comm->sysctl_tree),
1252 OID_AUTO, "status_frac",
1253 CTLTYPE_INT | CTLFLAG_RW,
1254 comm, 0, sysctl_stfrac,
1255 "I", "# of cycles before status is polled");
1257 SYSCTL_ADD_PROC(&comm->sysctl_ctx, SYSCTL_CHILDREN(comm->sysctl_tree),
1258 OID_AUTO, "tx_frac", CTLTYPE_INT | CTLFLAG_RW,
1259 comm, 0, sysctl_txfrac,
1260 "I", "# of cycles before TX is polled");
1262 poll_common[cpuid] = comm;
1266 poll_comm_start(int cpuid)
1268 struct poll_comm *comm = poll_common[cpuid];
1269 systimer_func_t func;
1272 * Initialize systimer
1275 func = poll_comm_systimer0;
1277 func = poll_comm_systimer;
1278 systimer_init_periodic_nq(&comm->pollclock, func, comm, 1);
1282 _poll_comm_systimer(struct poll_comm *comm)
1284 if (comm->txfrac_count-- == 0) {
1285 comm->txfrac_count = comm->poll_txfrac;
1286 iopoll_clock(txpoll_context[comm->poll_cpuid]);
1288 iopoll_clock(rxpoll_context[comm->poll_cpuid]);
1292 poll_comm_systimer0(systimer_t info, int in_ipi __unused,
1293 struct intrframe *frame __unused)
1295 struct poll_comm *comm = info->data;
1296 globaldata_t gd = mycpu;
1298 KKASSERT(comm->poll_cpuid == gd->gd_cpuid && gd->gd_cpuid == 0);
1302 if (comm->stfrac_count-- == 0) {
1303 comm->stfrac_count = comm->poll_stfrac;
1304 stpoll_clock(&stpoll_context);
1306 _poll_comm_systimer(comm);
1312 poll_comm_systimer(systimer_t info, int in_ipi __unused,
1313 struct intrframe *frame __unused)
1315 struct poll_comm *comm = info->data;
1316 globaldata_t gd = mycpu;
1318 KKASSERT(comm->poll_cpuid == gd->gd_cpuid && gd->gd_cpuid != 0);
1321 _poll_comm_systimer(comm);
1326 poll_comm_adjust_pollhz(struct poll_comm *comm)
1331 KKASSERT(&curthread->td_msgport == netisr_portfn(comm->poll_cpuid));
1334 * If there is no polling handler registered, set systimer
1335 * frequency to the lowest value. Polling systimer frequency
1336 * will be adjusted to the requested value, once there are
1337 * registered handlers.
1339 handlers = rxpoll_context[mycpuid]->poll_handlers +
1340 txpoll_context[mycpuid]->poll_handlers;
1341 if (comm->poll_cpuid == 0)
1342 handlers += stpoll_context.poll_handlers;
1344 pollhz = comm->pollhz;
1345 systimer_adjust_periodic(&comm->pollclock, pollhz);
1349 sysctl_pollhz(SYSCTL_HANDLER_ARGS)
1351 struct poll_comm *comm = arg1;
1352 struct netmsg_base nmsg;
1356 error = sysctl_handle_int(oidp, &phz, 0, req);
1357 if (error || req->newptr == NULL)
1361 else if (phz > IFPOLL_FREQ_MAX)
1362 phz = IFPOLL_FREQ_MAX;
1364 netmsg_init(&nmsg, NULL, &curthread->td_msgport,
1365 0, sysctl_pollhz_handler);
1366 nmsg.lmsg.u.ms_result = phz;
1368 return lwkt_domsg(netisr_portfn(comm->poll_cpuid), &nmsg.lmsg, 0);
1372 sysctl_pollhz_handler(netmsg_t nmsg)
1374 struct poll_comm *comm = poll_common[mycpuid];
1376 KKASSERT(&curthread->td_msgport == netisr_portfn(comm->poll_cpuid));
1378 /* Save polling frequency */
1379 comm->pollhz = nmsg->lmsg.u.ms_result;
1382 * Adjust cached pollhz
1384 rxpoll_context[mycpuid]->pollhz = comm->pollhz;
1385 txpoll_context[mycpuid]->pollhz =
1386 comm->pollhz / (comm->poll_txfrac + 1);
1389 * Adjust polling frequency
1391 poll_comm_adjust_pollhz(comm);
1393 lwkt_replymsg(&nmsg->lmsg, 0);
1397 sysctl_stfrac(SYSCTL_HANDLER_ARGS)
1399 struct poll_comm *comm = arg1;
1400 struct netmsg_base nmsg;
1403 KKASSERT(comm->poll_cpuid == 0);
1405 stfrac = comm->poll_stfrac + 1;
1406 error = sysctl_handle_int(oidp, &stfrac, 0, req);
1407 if (error || req->newptr == NULL)
1412 netmsg_init(&nmsg, NULL, &curthread->td_msgport,
1413 0, sysctl_stfrac_handler);
1414 nmsg.lmsg.u.ms_result = stfrac - 1;
1416 return lwkt_domsg(netisr_portfn(comm->poll_cpuid), &nmsg.lmsg, 0);
1420 sysctl_stfrac_handler(netmsg_t nmsg)
1422 struct poll_comm *comm = poll_common[mycpuid];
1423 int stfrac = nmsg->lmsg.u.ms_result;
1425 KKASSERT(&curthread->td_msgport == netisr_portfn(comm->poll_cpuid));
1428 comm->poll_stfrac = stfrac;
1429 if (comm->stfrac_count > comm->poll_stfrac)
1430 comm->stfrac_count = comm->poll_stfrac;
1433 lwkt_replymsg(&nmsg->lmsg, 0);
1437 sysctl_txfrac(SYSCTL_HANDLER_ARGS)
1439 struct poll_comm *comm = arg1;
1440 struct netmsg_base nmsg;
1443 txfrac = comm->poll_txfrac + 1;
1444 error = sysctl_handle_int(oidp, &txfrac, 0, req);
1445 if (error || req->newptr == NULL)
1450 netmsg_init(&nmsg, NULL, &curthread->td_msgport,
1451 0, sysctl_txfrac_handler);
1452 nmsg.lmsg.u.ms_result = txfrac - 1;
1454 return lwkt_domsg(netisr_portfn(comm->poll_cpuid), &nmsg.lmsg, 0);
1458 sysctl_txfrac_handler(netmsg_t nmsg)
1460 struct poll_comm *comm = poll_common[mycpuid];
1461 int txfrac = nmsg->lmsg.u.ms_result;
1463 KKASSERT(&curthread->td_msgport == netisr_portfn(comm->poll_cpuid));
1466 comm->poll_txfrac = txfrac;
1467 if (comm->txfrac_count > comm->poll_txfrac)
1468 comm->txfrac_count = comm->poll_txfrac;
1471 lwkt_replymsg(&nmsg->lmsg, 0);
1475 ifpoll_compat_setup(struct ifpoll_compat *cp,
1476 struct sysctl_ctx_list *sysctl_ctx,
1477 struct sysctl_oid *sysctl_tree,
1478 int unit, struct lwkt_serialize *slz)
1480 cp->ifpc_stcount = 0;
1481 cp->ifpc_stfrac = ((poll_common[0]->poll_stfrac + 1) *
1482 howmany(IOPOLL_BURST_MAX, IOPOLL_EACH_BURST)) - 1;
1484 cp->ifpc_cpuid = unit % ncpus2;
1485 cp->ifpc_serializer = slz;
1487 if (sysctl_ctx != NULL && sysctl_tree != NULL) {
1488 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
1489 OID_AUTO, "npoll_stfrac", CTLTYPE_INT | CTLFLAG_RW,
1490 cp, 0, sysctl_compat_npoll_stfrac, "I",
1491 "polling status frac");
1492 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
1493 OID_AUTO, "npoll_cpuid", CTLTYPE_INT | CTLFLAG_RW,
1494 cp, 0, sysctl_compat_npoll_cpuid, "I",
1500 sysctl_compat_npoll_stfrac(SYSCTL_HANDLER_ARGS)
1502 struct ifpoll_compat *cp = arg1;
1503 int error = 0, stfrac;
1505 lwkt_serialize_enter(cp->ifpc_serializer);
1507 stfrac = cp->ifpc_stfrac + 1;
1508 error = sysctl_handle_int(oidp, &stfrac, 0, req);
1509 if (!error && req->newptr != NULL) {
1513 cp->ifpc_stfrac = stfrac - 1;
1514 if (cp->ifpc_stcount > cp->ifpc_stfrac)
1515 cp->ifpc_stcount = cp->ifpc_stfrac;
1519 lwkt_serialize_exit(cp->ifpc_serializer);
1524 sysctl_compat_npoll_cpuid(SYSCTL_HANDLER_ARGS)
1526 struct ifpoll_compat *cp = arg1;
1527 int error = 0, cpuid;
1529 lwkt_serialize_enter(cp->ifpc_serializer);
1531 cpuid = cp->ifpc_cpuid;
1532 error = sysctl_handle_int(oidp, &cpuid, 0, req);
1533 if (!error && req->newptr != NULL) {
1534 if (cpuid < 0 || cpuid >= ncpus2)
1537 cp->ifpc_cpuid = cpuid;
1540 lwkt_serialize_exit(cp->ifpc_serializer);