[PATCH v2 1/2] net: Add network task affinity config
Daniel Cederman
cederman at gaisler.com
Thu Nov 13 10:21:01 UTC 2014
From: Daniel Hellstrom <daniel at gaisler.com>
This patch adds a default network tasks CPU affinity configuration
option. The network drivers have the option to create their own
daemon tasks with a custom CPU affinity set, or rely on the
default set.
---
cpukit/libnetworking/rtems/rtems_bsdnet.h | 9 ++++++
cpukit/libnetworking/rtems/rtems_bsdnet_internal.h | 12 ++++++++
cpukit/libnetworking/rtems/rtems_glue.c | 34 ++++++++++++++++++++++
3 files changed, 55 insertions(+)
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet.h b/cpukit/libnetworking/rtems/rtems_bsdnet.h
index 9dd44fe..3953efa 100644
--- a/cpukit/libnetworking/rtems/rtems_bsdnet.h
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet.h
@@ -11,6 +11,7 @@ extern "C" {
#endif
#include <rtems.h>
+#include <sys/cpuset.h>
/*
* If this file is included from inside the Network Stack proper or
@@ -181,6 +182,14 @@ struct rtems_bsdnet_config {
*/
unsigned long tcp_tx_buf_size;
unsigned long tcp_rx_buf_size;
+
+ /*
+ * Default Network Tasks CPU Affinity
+ */
+#ifdef RTEMS_SMP
+ cpu_set_t *network_task_cpuset;
+ size_t network_task_cpuset_size;
+#endif
};
/*
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
index 865b644..5be781b 100644
--- a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
@@ -157,6 +157,18 @@ rtems_id rtems_bsdnet_newproc (
void *arg
);
+#ifdef RTEMS_SMP
+/* As rtems_bsdnet_newproc() but with ability to set CPU affinity too */
+rtems_id rtems_bsdnet_newproc_affinity (
+ char *name,
+ int stacksize,
+ void (*entry)(void *),
+ void *arg,
+ const cpu_set_t *set,
+ const size_t setsize
+);
+#endif
+
rtems_status_code rtems_bsdnet_event_receive (
rtems_event_set event_in,
rtems_option option_set,
diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
index 8ed17d1..21e4a96 100644
--- a/cpukit/libnetworking/rtems/rtems_glue.c
+++ b/cpukit/libnetworking/rtems/rtems_glue.c
@@ -56,6 +56,10 @@ Semaphore_Control *the_networkSemaphore;
#endif
static rtems_id networkDaemonTid;
static uint32_t networkDaemonPriority;
+#ifdef RTEMS_SMP
+static cpu_set_t *networkDaemonCpuset = 0;
+static size_t networkDaemonCpusetSize = 0;
+#endif
static void networkDaemon (void *task_argument);
/*
@@ -281,6 +285,14 @@ rtems_bsdnet_initialize (void)
networkDaemonPriority = rtems_bsdnet_config.network_task_priority;
/*
+ * Default network task CPU affinity
+ */
+#ifdef RTEMS_SMP
+ networkDaemonCpuset = rtems_bsdnet_config.network_task_cpuset;
+ networkDaemonCpusetSize = rtems_bsdnet_config.network_task_cpuset_size;
+#endif
+
+ /*
* Set the memory allocation limits
*/
if (rtems_bsdnet_config.mbuf_bytecount)
@@ -660,11 +672,25 @@ taskEntry (rtems_task_argument arg)
rtems_panic ("Network task returned!\n");
}
+
/*
* Start a network task
*/
+#ifdef RTEMS_SMP
+rtems_id
+rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg)
+{
+ return rtems_bsdnet_newproc_affinity( name, stacksize, entry, arg,
+ networkDaemonCpuset, networkDaemonCpusetSize );
+}
+
+rtems_id
+rtems_bsdnet_newproc_affinity (char *name, int stacksize, void(*entry)(void *),
+ void *arg, const cpu_set_t *set, const size_t setsize)
+#else
rtems_id
rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg)
+#endif
{
struct newtask *t;
char nm[4];
@@ -681,6 +707,14 @@ rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg
if (sc != RTEMS_SUCCESSFUL)
rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc));
+#ifdef RTEMS_SMP
+ /*
+ * Use the default affinity or use the user-provided CPU set
+ */
+ if ( set != 0 )
+ rtems_task_set_affinity( tid, setsize, set );
+#endif
+
/*
* Set up task arguments
*/
--
2.1.3
More information about the devel
mailing list