[rtems-libbsd commit] Avoid per-CPU NETISR(9)

Sebastian Huber sebh at rtems.org
Thu Oct 10 07:13:10 UTC 2013


Module:    rtems-libbsd
Branch:    master
Commit:    d652c3bafd98cb574f17127815d3024362aed891
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=d652c3bafd98cb574f17127815d3024362aed891

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Oct  9 14:03:56 2013 +0200

Avoid per-CPU NETISR(9)

SMP support should be enabled once the new stack is ready for this.

---

 freebsd/sys/net/netisr.c |   41 +++++++++++++++++++++++++++++++++++++++--
 freebsd/sys/sys/pcpu.h   |    6 ++++--
 libbsd.txt               |    4 ++++
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/freebsd/sys/net/netisr.c b/freebsd/sys/net/netisr.c
index b82c1f0..465b0b2 100644
--- a/freebsd/sys/net/netisr.c
+++ b/freebsd/sys/net/netisr.c
@@ -260,6 +260,7 @@ struct netisr_workstream {
 	struct netisr_work	nws_work[NETISR_MAXPROT];
 } __aligned(CACHE_LINE_SIZE);
 
+#ifndef __rtems__
 /*
  * Per-CPU workstream data.
  */
@@ -279,6 +280,9 @@ static u_int				 nws_array[MAXCPU];
 static u_int				 nws_count;
 SYSCTL_INT(_net_isr, OID_AUTO, numthreads, CTLFLAG_RD,
     &nws_count, 0, "Number of extant netisr threads.");
+#else /* __rtems__ */
+static struct netisr_workstream rtems_bsd_nws;
+#endif /* __rtems__ */
 
 /*
  * Per-workstream flags.
@@ -318,7 +322,6 @@ netisr_get_cpuid(u_int cpunumber)
 
 	return (nws_array[cpunumber]);
 }
-#endif  /* __rtems__ */
 
 /*
  * The default implementation of -> CPU ID mapping.
@@ -332,6 +335,7 @@ netisr_default_flow2cpu(u_int flowid)
 
 	return (nws_array[flowid % nws_count]);
 }
+#endif  /* __rtems__ */
 
 /*
  * Register a new netisr handler, which requires initializing per-protocol
@@ -400,7 +404,11 @@ netisr_register(const struct netisr_handler *nhp)
 	for (i = 0; i <= mp_maxid; i++) {
 		if (CPU_ABSENT(i))
 			continue;
+#ifndef __rtems__
 		npwp = &(DPCPU_ID_PTR(i, nws))->nws_work[proto];
+#else /* __rtems__ */
+		npwp = &rtems_bsd_nws.nws_work[proto];
+#endif /* __rtems__ */
 		bzero(npwp, sizeof(*npwp));
 		npwp->nw_qlimit = np[proto].np_qlimit;
 	}
@@ -434,7 +442,11 @@ netisr_clearqdrops(const struct netisr_handler *nhp)
 	for (i = 0; i <= mp_maxid; i++) {
 		if (CPU_ABSENT(i))
 			continue;
+#ifndef __rtems__
 		npwp = &(DPCPU_ID_PTR(i, nws))->nws_work[proto];
+#else /* __rtems__ */
+		npwp = &rtems_bsd_nws.nws_work[proto];
+#endif /* __rtems__ */
 		npwp->nw_qdrops = 0;
 	}
 	NETISR_WUNLOCK();
@@ -469,7 +481,11 @@ netisr_getqdrops(const struct netisr_handler *nhp, u_int64_t *qdropp)
 	for (i = 0; i <= mp_maxid; i++) {
 		if (CPU_ABSENT(i))
 			continue;
+#ifndef __rtems__
 		npwp = &(DPCPU_ID_PTR(i, nws))->nws_work[proto];
+#else /* __rtems__ */
+		npwp = &rtems_bsd_nws.nws_work[proto];
+#endif /* __rtems__ */
 		*qdropp += npwp->nw_qdrops;
 	}
 	NETISR_RUNLOCK(&tracker);
@@ -535,7 +551,11 @@ netisr_setqlimit(const struct netisr_handler *nhp, u_int qlimit)
 	for (i = 0; i <= mp_maxid; i++) {
 		if (CPU_ABSENT(i))
 			continue;
+#ifndef __rtems__
 		npwp = &(DPCPU_ID_PTR(i, nws))->nws_work[proto];
+#else /* __rtems__ */
+		npwp = &rtems_bsd_nws.nws_work[proto];
+#endif /* __rtems__ */
 		npwp->nw_qlimit = qlimit;
 	}
 	NETISR_WUNLOCK();
@@ -601,7 +621,11 @@ netisr_unregister(const struct netisr_handler *nhp)
 	for (i = 0; i <= mp_maxid; i++) {
 		if (CPU_ABSENT(i))
 			continue;
+#ifndef __rtems__
 		npwp = &(DPCPU_ID_PTR(i, nws))->nws_work[proto];
+#else /* __rtems__ */
+		npwp = &rtems_bsd_nws.nws_work[proto];
+#endif /* __rtems__ */
 		netisr_drain_proto(npwp);
 		bzero(npwp, sizeof(*npwp));
 	}
@@ -621,6 +645,7 @@ netisr_select_cpuid(struct netisr_proto *npp, uintptr_t source,
 
 	NETISR_LOCK_ASSERT();
 
+#ifndef __rtems__
 	/*
 	 * In the event we have only one worker, shortcut and deliver to it
 	 * without further ado.
@@ -665,6 +690,10 @@ netisr_select_cpuid(struct netisr_proto *npp, uintptr_t source,
 		panic("%s: invalid policy %u for %s", __func__,
 		    npp->np_policy, npp->np_name);
 	}
+#else /* __rtems__ */
+	*cpuidp = 0;
+	return (m);
+#endif /* __rtems__ */
 }
 
 /*
@@ -829,7 +858,11 @@ netisr_queue_internal(u_int proto, struct mbuf *m, u_int cpuid)
 
 	dosignal = 0;
 	error = 0;
+#ifndef __rtems__
 	nwsp = DPCPU_ID_PTR(cpuid, nws);
+#else /* __rtems__ */
+	nwsp = &rtems_bsd_nws;
+#endif /* __rtems__ */
 	npwp = &nwsp->nws_work[proto];
 	NWS_LOCK(nwsp);
 	error = netisr_queue_workstream(nwsp, proto, npwp, m, &dosignal);
@@ -1037,7 +1070,11 @@ netisr_start_swi(u_int cpuid, struct pcpu *pc)
 
 	KASSERT(!CPU_ABSENT(cpuid), ("%s: CPU %u absent", __func__, cpuid));
 
+#ifndef __rtems__
 	nwsp = DPCPU_ID_PTR(cpuid, nws);
+#else /* __rtems__ */
+	nwsp = &rtems_bsd_nws;
+#endif /* __rtems__ */
 	mtx_init(&nwsp->nws_mtx, "netisr_mtx", NULL, MTX_DEF);
 	nwsp->nws_cpu = cpuid;
 	snprintf(swiname, sizeof(swiname), "netisr %u", cpuid);
@@ -1053,11 +1090,11 @@ netisr_start_swi(u_int cpuid, struct pcpu *pc)
 			printf("%s: cpu %u: intr_event_bind: %d", __func__,
 			    cpuid, error);
 	}
-#endif
 	NETISR_WLOCK();
 	nws_array[nws_count] = nwsp->nws_cpu;
 	nws_count++;
 	NETISR_WUNLOCK();
+#endif
 }
 
 /*
diff --git a/freebsd/sys/sys/pcpu.h b/freebsd/sys/sys/pcpu.h
index 48a3bcc..e0eb23f 100644
--- a/freebsd/sys/sys/pcpu.h
+++ b/freebsd/sys/sys/pcpu.h
@@ -38,9 +38,7 @@
 #endif
 
 #include <sys/queue.h>
-#ifndef __rtems__
 #include <sys/vmmeter.h>
-#endif
 #include <rtems/bsd/sys/resource.h>
 #include <machine/pcpu.h>
 
@@ -75,8 +73,12 @@ extern uintptr_t dpcpu_off[];
 /*
  * Accessors with a given base.
  */
+#ifndef __rtems__
 #define	_DPCPU_PTR(b, n)						\
     (__typeof(DPCPU_NAME(n))*)((b) + (uintptr_t)&DPCPU_NAME(n))
+#else /* __rtems__ */
+#define	_DPCPU_PTR(b, n) NULL
+#endif /* __rtems__ */
 #define	_DPCPU_GET(b, n)	(*_DPCPU_PTR(b, n))
 #define	_DPCPU_SET(b, n, v)	(*_DPCPU_PTR(b, n) = v)
 
diff --git a/libbsd.txt b/libbsd.txt
index 5207a88..165656d 100644
--- a/libbsd.txt
+++ b/libbsd.txt
@@ -46,6 +46,10 @@ the current Git submodule commit is this
   svn co http://svn.freebsd.org/base/releng/8.2 -r255967 freebsd-8.2
 
 == Issues and To Do
+* Per-CPU data should be enabled once the new stack is ready for SMP.
+
+* Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP.
+
 * Sebastian Huber and Joel Sherrill discussed the need for a a basic USB
   functionality test that is known to work on qemu pc.
 




More information about the vc mailing list