Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Paste
P728
(An Untitled Masterwork)
Active
Public
Actions
Authored by
rcm
on Thu, Dec 3, 1:55 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Project Tags
None
Referenced Files
F178273345: raw-paste-data.txt
Thu, Dec 3, 1:55 PM
2026-12-03 13:55:34 (UTC+0)
Subscribers
None
diff --git a/sys/net/netisr.c b/sys/net/netisr.c
index 93166bf..257ae89 100644
--- a/sys/net/netisr.c
+++ b/sys/net/netisr.c
@@ -103,6 +103,7 @@ struct netisr_proto {
u_int np_qlimit; /* Maximum per-CPU queue depth. */
u_int np_policy; /* Work placement policy. */
u_int np_dispatch; /* Work dispatch policy. */
+ counter_u64_t np_dispatched; /* Number of direct dispatches. */
};
/*
@@ -143,7 +144,6 @@ struct netisr_workstream {
u_int nw_qlimit;
u_int nw_watermark;
- counter_u64_t nw_dispatched; /* Number of direct dispatches. */
counter_u64_t nw_hybrid_dispatched; /* "" hybrid dispatches. */
counter_u64_t nw_qdrops; /* "" drops. */
counter_u64_t nw_queued; /* "" enqueues. */
@@ -437,6 +437,22 @@ netisr_register(const struct netisr_handler *nhp)
KASSERT(proto < NETISR_MAXPROT,
("%s(%u, %s): protocol too big", __func__, proto, name));
+ /*
+ * counter(9) allocation may sleep, so allocate the statistics before
+ * taking the write lock. Nothing reads them until the protocol is
+ * registered below, and the workstreams already exist: netisr_init()
+ * runs before any protocol registers.
+ */
+ netisr_proto[proto].np_dispatched = counter_u64_alloc(M_WAITOK);
+ for (u_int i = 0; i < nws_count; i++) {
+ struct netisr_work *nw = &nws_array[i]->nws_work[proto];
+
+ nw->nw_hybrid_dispatched = counter_u64_alloc(M_WAITOK);
+ nw->nw_qdrops = counter_u64_alloc(M_WAITOK);
+ nw->nw_queued = counter_u64_alloc(M_WAITOK);
+ nw->nw_handled = counter_u64_alloc(M_WAITOK);
+ }
+
/*
* Test that no existing registration exists for this protocol.
*/
@@ -462,16 +478,9 @@ netisr_register(const struct netisr_handler *nhp)
netisr_proto[proto].np_qlimit = nhp->nh_qlimit;
netisr_proto[proto].np_policy = nhp->nh_policy;
netisr_proto[proto].np_dispatch = nhp->nh_dispatch;
- for (u_int i = 0; i < nws_count; i++) {
- struct netisr_work *nw = &nws_array[i]->nws_work[proto];
-
- nw->nw_qlimit = netisr_proto[proto].np_qlimit;
- nw->nw_dispatched = counter_u64_alloc(M_WAITOK);
- nw->nw_hybrid_dispatched = counter_u64_alloc(M_WAITOK);
- nw->nw_qdrops = counter_u64_alloc(M_WAITOK);
- nw->nw_queued = counter_u64_alloc(M_WAITOK);
- nw->nw_handled = counter_u64_alloc(M_WAITOK);
- }
+ for (u_int i = 0; i < nws_count; i++)
+ nws_array[i]->nws_work[proto].nw_qlimit =
+ netisr_proto[proto].np_qlimit;
#ifdef VIMAGE
V_netisr_enable[proto] = 1;
@@ -645,12 +654,12 @@ netisr_unregister(const struct netisr_handler *nhp)
struct netisr_work *nw = &nws_array[i]->nws_work[proto];
netisr_drain_proto(nw);
- counter_u64_free(nw->nw_dispatched);
counter_u64_free(nw->nw_hybrid_dispatched);
counter_u64_free(nw->nw_qdrops);
counter_u64_free(nw->nw_queued);
counter_u64_free(nw->nw_handled);
}
+ counter_u64_free(netisr_proto[proto].np_dispatched);
NETISR_WUNLOCK();
}
@@ -1107,17 +1116,16 @@ netisr_dispatch_src(u_int proto, uintptr_t source, struct mbuf *m)
/*
* If direct dispatch is forced, then unconditionally dispatch
- * without a formal CPU selection. Borrow the current CPU's stats,
- * without pinning, though. In this case we don't update nws_flags
- * because all netisr processing will be source ordered due to always
- * being forced to directly dispatch.
+ * without a formal CPU selection. No workstream is involved, so
+ * the dispatch is counted with the protocol; the counter is per-CPU
+ * and sysctl_netisr_work() reports it with the CPU's workstream.
+ * In this case we don't update nws_flags because all netisr
+ * processing will be source ordered due to always being forced to
+ * directly dispatch.
*/
if (dispatch_policy == NETISR_DISPATCH_DIRECT) {
- nwsp = nws_array[curcpu % nws_count];
- npwp = &nwsp->nws_work[proto];
- counter_u64_add(npwp->nw_dispatched, 1);
- counter_u64_add(npwp->nw_handled, 1);
- netisr_proto[proto].np_handler(m);
+ counter_u64_add(npp->np_dispatched, 1);
+ npp->np_handler(m);
error = 0;
goto out_unlock;
}
@@ -1137,9 +1145,9 @@ netisr_dispatch_src(u_int proto, uintptr_t source, struct mbuf *m)
error = ENOBUFS;
goto out_unpin;
}
- if (netisr_bindthreads && nws_id != curcpu % nws_count)
- goto queue_fallback;
nwsp = nws_array[nws_id];
+ if (nwsp->nws_cpu != curcpu)
+ goto queue_fallback;
npwp = &nwsp->nws_work[proto];
/*-
@@ -1241,8 +1249,8 @@ netisr_start_swi(u_int cpuid, struct pcpu *pc)
error = swi_add(&nws->nws_intr_event, swiname, swi_net, nws,
SWI_NET, INTR_TYPE_NET | INTR_MPSAFE, &nws->nws_swi_cookie);
MPASS(!error);
+ nws->nws_cpu = cpuid;
if (netisr_bindthreads) {
- nws->nws_cpu = cpuid;
error = intr_event_bind(nws->nws_intr_event, cpuid);
MPASS(!error);
}
@@ -1401,6 +1409,23 @@ SYSCTL_PROC(_net_isr, OID_AUTO, workstream,
"S,sysctl_netisr_workstream",
"Return list of workstreams implemented by netisr");
+/*
+ * Direct dispatches are counted per protocol, in a per-CPU counter. Report
+ * those done on a CPU with the workstream that CPU maps to.
+ */
+static uint64_t
+netisr_dispatched(const struct netisr_proto *npp, u_int nws_id)
+{
+ uint64_t v;
+ u_int cpu;
+
+ v = 0;
+ CPU_FOREACH(cpu)
+ if (cpu % nws_count == nws_id)
+ v += *zpcpu_get_cpu(npp->np_dispatched, cpu);
+ return (v);
+}
+
/*
* Sysctl monitoring for netisr: query per-protocol data across all
* workstreams.
@@ -1436,13 +1461,13 @@ sysctl_netisr_work(SYSCTL_HANDLER_ARGS)
snwp->snw_proto = proto;
snwp->snw_len = nwp->nw_len;
snwp->snw_watermark = nwp->nw_watermark;
- snwp->snw_dispatched =
- counter_u64_fetch(nwp->nw_dispatched);
+ snwp->snw_dispatched = netisr_dispatched(npp, i);
snwp->snw_hybrid_dispatched =
counter_u64_fetch(nwp->nw_hybrid_dispatched);
snwp->snw_qdrops = counter_u64_fetch(nwp->nw_qdrops);
snwp->snw_queued = counter_u64_fetch(nwp->nw_queued);
- snwp->snw_handled = counter_u64_fetch(nwp->nw_handled);
+ snwp->snw_handled = counter_u64_fetch(nwp->nw_handled) +
+ snwp->snw_dispatched;
counter++;
}
NWS_UNLOCK(nwsp);
Event Timeline
rcm
created this paste.
Thu, Dec 3, 1:55 PM
2026-12-03 13:55:34 (UTC+0)
rcm
created this object in space
S1 Global
.
rcm
mentioned this in
D62261: netisr: allocate workstreams dynamically
.
Thu, Dec 3, 2:07 PM
2026-12-03 14:07:31 (UTC+0)
Log In to Comment