Skip to content

Commit

Permalink
ovs-numa: Allow leading 0x on pmd-cpu-mask.
Browse files Browse the repository at this point in the history
pmd-cpu-mask is interpreted as a hex bit mask. So it should be written
with a leading 0x to indicate this. But if this is done, while the value
is interpreted correctly and the PMDs pinned as expected, a confusing
warning message is also issued.

This patch allows but does not require a leading 0x or 0X to be used
without a warning. Existing functionality is not affected. Relevant DPDK
docs also updated.

Signed-off-by: Billy O'Mahony <[email protected]>
Tested-by: Kevin Traynor <[email protected]>
Signed-off-by: Daniele Di Proietto <[email protected]>
  • Loading branch information
billyom authored and ddiproietto committed Dec 2, 2016
1 parent 884e0df commit 3fa215b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
13 changes: 7 additions & 6 deletions INSTALL.DPDK-ADVANCED.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ core shared by two logical cores, run::
where ``N`` is the logical core number.

In this example, it would show that cores ``1`` and ``21`` share the same
physical core., thus, the ``pmd-cpu-mask`` can be used to enable these two pmd
threads running on these two logical cores (one physical core) is::
physical core. As cores are counted from 0, the ``pmd-cpu-mask`` can be used
to enable these two pmd threads running on these two logical cores (one
physical core) is::

$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=100002
$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x200002

Isolate Cores
~~~~~~~~~~~~~
Expand Down Expand Up @@ -239,7 +240,7 @@ affinitized accordingly.
By setting a bit in the mask, a pmd thread is created and pinned to the
corresponding CPU core. e.g. to run a pmd thread on core 2::

$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=4
$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x4

.. note::
pmd thread on a NUMA node is only created if there is at least one DPDK
Expand Down Expand Up @@ -269,7 +270,7 @@ is done automatically.
A set bit in the mask means a pmd thread is created and pinned to the
corresponding CPU core. For example, to run pmd threads on core 1 and 2::

$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=6
$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x6

When using dpdk and dpdkvhostuser ports in a bi-directional VM loopback as
shown below, spreading the workload over 2 or 4 pmd threads shows significant
Expand Down Expand Up @@ -436,7 +437,7 @@ guide`_ to create and initialize the database, start ovs-vswitchd and add
of rx queues at vhost-user interface gets automatically configured after
virtio device connection and doesn't need manual configuration::

$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=c
$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0xC
$ ovs-vsctl set Interface dpdk0 options:n_rxq=2
$ ovs-vsctl set Interface dpdk1 options:n_rxq=2

Expand Down
6 changes: 3 additions & 3 deletions INSTALL.DPDK.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ NUMA node 0, run::

Similarly, if you wish to better scale the workloads across cores, then
multiple pmd threads can be created and pinned to CPU cores by explicity
specifying ``pmd-cpu-mask``. For example, to spawn two pmd threads and pin
them to cores 1,2, run::
specifying ``pmd-cpu-mask``. Cores are numbered from 0, so to spawn two pmd
threads and pin them to cores 1,2, run::

$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=6
$ ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x6

For details on using ivshmem with DPDK, refer to `the advanced installation
guide <INSTALL.DPDK-ADVANCED.rst>`__.
Expand Down
11 changes: 9 additions & 2 deletions lib/ovs-numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ ovs_numa_set_cpu_mask(const char *cmask)
{
int core_id = 0;
int i;
int end_idx;

if (!found_numa_and_core) {
return;
Expand All @@ -551,7 +552,13 @@ ovs_numa_set_cpu_mask(const char *cmask)
return;
}

for (i = strlen(cmask) - 1; i >= 0; i--) {
/* Ignore leading 0x. */
end_idx = 0;
if (!strncmp(cmask, "0x", 2) || !strncmp(cmask, "0X", 2)) {
end_idx = 2;
}

for (i = strlen(cmask) - 1; i >= end_idx; i--) {
char hex = toupper((unsigned char)cmask[i]);
int bin, j;

Expand All @@ -575,7 +582,7 @@ ovs_numa_set_cpu_mask(const char *cmask)
if (core_id >= hmap_count(&all_cpu_cores)) {
return;
}
}
}
}

/* For unspecified cores, sets 'available' to false. */
Expand Down
6 changes: 3 additions & 3 deletions tests/pmd.at
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pmd thread numa_id <cleared> core_id <cleared>:
])

TMP=$(cat ovs-vswitchd.log | wc -l | tr -d [[:blank:]])
AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=3])
AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x3])
CHECK_PMD_THREADS_CREATED([2], [], [+$TMP])

AT_CHECK([ovs-appctl dpif-netdev/pmd-rxq-show | sed SED_NUMA_CORE_PATTERN], [0], [dnl
Expand All @@ -136,7 +136,7 @@ pmd thread numa_id <cleared> core_id <cleared>:
])

TMP=$(cat ovs-vswitchd.log | wc -l | tr -d [[:blank:]])
AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=1])
AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x1])
CHECK_PMD_THREADS_CREATED([1], [], [+$TMP])

AT_CHECK([ovs-appctl dpif-netdev/pmd-rxq-show | sed SED_NUMA_CORE_PATTERN], [0], [dnl
Expand Down Expand Up @@ -471,7 +471,7 @@ AT_CHECK([ovs-appctl vlog/set dpif:dbg dpif_netdev:dbg])

AT_CHECK([ovs-ofctl add-flow br0 actions=controller])

AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=1fe])
AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0x1fe])

AT_CHECK([ovs-vsctl add-port br0 p1 -- set Interface p1 type=dummy-pmd ofport_request=1 options:n_rxq=4 other_config:pmd-rxq-affinity="0:3,1:7,2:2,3:8"])

Expand Down

0 comments on commit 3fa215b

Please sign in to comment.