Deployment with dpdk and spdk should limit the core of non-pmd
threads. When starting ovs with ovs-ctl or systemd, the process will
inherit the affinity of its parent process. Even if we manuanlly
set the affinity, restarting after crash will lose the setting.

Prepend taskset in ovs-ctl when start daemon, so it will set the
affinity each time starting the ovs.

Signed-off-by: Wan Junjie <[email protected]>
---
 Documentation/ref/ovs-ctl.8.rst | 5 +++++
 utilities/ovs-ctl.in            | 8 ++++++--
 utilities/ovs-lib.in            | 6 ++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Documentation/ref/ovs-ctl.8.rst b/Documentation/ref/ovs-ctl.8.rst
index 9f077a122..603e9ca1e 100644
--- a/Documentation/ref/ovs-ctl.8.rst
+++ b/Documentation/ref/ovs-ctl.8.rst
@@ -199,6 +199,11 @@ The following options are less important:
   Sets the ``nice(1)`` level used for each daemon.  All of them
   default to ``-10``.
 
+* ``--ovsdb-server-affinity=<corelist>`` or
+  ``--ovs-vswitchd-affinity=<corelist>``
+
+  Sets the ``taskset(1)`` affinity for each daemon process.
+
 * ``--ovsdb-server-wrapper=<wrapper>`` or
   ``--ovs-vswitchd-wrapper=<wrapper>``
 
diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
index 0b2820c36..3f033a98e 100644
--- a/utilities/ovs-ctl.in
+++ b/utilities/ovs-ctl.in
@@ -157,7 +157,7 @@ do_start_ovsdb () {
         [ "$OVSDB_SERVER_OPTIONS" != "" ] && set "$@" $OVSDB_SERVER_OPTIONS
 
         start_daemon "$OVSDB_SERVER_PRIORITY" "$OVSDB_SERVER_WRAPPER" \
-            "$OVSDB_SERVER_UMASK" "$@" || return 1
+            "$OVSDB_SERVER_UMASK" "$OVSDB_SERVER_AFFINITY" "$@" || return 1
 
         # Initialize database settings.
         ovs_vsctl -- init -- set Open_vSwitch . db-version="$schemaver" \
@@ -227,7 +227,7 @@ do_start_forwarding () {
         [ "$OVS_VSWITCHD_OPTIONS" != "" ] &&set "$@" $OVS_VSWITCHD_OPTIONS
 
         start_daemon "$OVS_VSWITCHD_PRIORITY" "$OVS_VSWITCHD_WRAPPER" \
-            "$OVS_VSWITCHD_UMASK" "$@" || return 1
+            "$OVS_VSWITCHD_UMASK" "$OVS_VSWITCHD_AFFINITY" "$@" || return 1
     fi
 }
 
@@ -344,6 +344,8 @@ set_defaults () {
     OVS_VSWITCHD=yes
     OVSDB_SERVER_PRIORITY=-10
     OVS_VSWITCHD_PRIORITY=-10
+    OVSDB_SERVER_AFFINITY=
+    OVS_VSWITCHD_AFFINITY=
     OVSDB_SERVER_WRAPPER=
     OVS_VSWITCHD_WRAPPER=
     OVSDB_SERVER_OPTIONS=
@@ -436,8 +438,10 @@ Less important options for "start", "restart" and 
"force-reload-kmod":
   --dump-hugepages               include hugepages in core dumps
   --no-mlockall                  do not lock all of ovs-vswitchd into memory
   --ovsdb-server-priority=NICE   set ovsdb-server's niceness (default: 
$OVSDB_SERVER_PRIORITY)
+  --ovsdb-server-affinity=CORE   set ovsdb-server's affinity (default: 
$OVSDB_SERVER_AFFINITY)
   --ovsdb-server-options=OPTIONS additional options for ovsdb-server (example: 
'-vconsole:dbg -vfile:dbg')
   --ovs-vswitchd-priority=NICE   set ovs-vswitchd's niceness (default: 
$OVS_VSWITCHD_PRIORITY)
+  --ovs-vswitchd-affinity=CORE   set ovs-vswitchd's affinity (default: 
$OVS_VSWITCHD_AFFINITY)
   --ovs-vswitchd-options=OPTIONS additional options for ovs-vswitchd (example: 
'-vconsole:dbg -vfile:dbg')
   --no-full-hostname             set short hostname instead of full hostname
   --no-record-hostname           do not attempt to determine/record system
diff --git a/utilities/ovs-lib.in b/utilities/ovs-lib.in
index 7812a94ee..f48d62376 100644
--- a/utilities/ovs-lib.in
+++ b/utilities/ovs-lib.in
@@ -168,6 +168,7 @@ start_daemon () {
     priority=$1 && shift
     wrapper=$1 && shift
     umask=$1 && shift
+    affinity=$1 && shift
     daemon=$1
     strace=""
 
@@ -223,6 +224,11 @@ start_daemon () {
         set nice -n "$priority" "$@"
     fi
 
+    # affinity
+    if test X"$affinity" != X; then
+        set taskset -c "$affinity" "$@"
+    fi
+
     # Set requested umask if any and turn previous value back.
     if [ -n "$umask" ]; then
         previuos_umask_value=$(umask)
-- 
2.39.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to