Skip to contentSkip to conversation

eal affinitize low priority threads to lcore 0

PATCH In review Bruce Richardson 3 participants 7 messages Sep 11, 2014 – Sep 12, 2014 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover eal affinitize low priority threads to lcore 0

This patchset sets things up so that we can affinitize the interrupt, vfio management, and hpet timer management threads to lcore 0, so that they never interfere with data plane threads.

Bruce Richardson (3):
eal: add core id param to eal_thread_set_affinity
eal: increase scope of eal_thread_set_affinity
eal: affinitize low-priority threads to lcore 0

 lib/librte_eal/bsdapp/eal/eal_thread.c             | 12 ++++++------
 lib/librte_eal/common/include/eal_private.h        | 10 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  5 +++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |  6 ++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c           | 12 ++++++------
 lib/librte_eal/linuxapp/eal/eal_timer.c            |  5 +++++
 6 files changed, 38 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.3

A message that is not in the archive (sent off-list or not yet received): 1410445387-4849-1-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/3 eal: add core id param to eal_thread_set_affinity

the function eal_thread_set_affinity always sets the affinity of the thread to the lcore_id of the thread as given by the thread-local variable. To allow this function to be used by arbitrary threads (e.g. eal utility threads such as those for interrupts, timers, etc.), add a parameter to specify the core id to be used for the affinity.

---
 lib/librte_eal/bsdapp/eal/eal_thread.c   | 10 +++++-----
 lib/librte_eal/linuxapp/eal/eal_thread.c | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +5 -5
index ab05368..18df2a3 100644
@@ -96,7 +96,7 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 
 /* set affinity for current thread */
 static int
-eal_thread_set_affinity(void)
+eal_thread_set_affinity(unsigned lcore_id)
 {
 	int s;
 	pthread_t thread;
@@ -126,7 +126,7 @@ eal_thread_set_affinity(void)
 
 	size = CPU_ALLOC_SIZE(RTE_MAX_LCORE);
 	CPU_ZERO_S(size, cpusetp);
-	CPU_SET_S(rte_lcore_id(), size, cpusetp);
+	CPU_SET_S(lcore_id, size, cpusetp);
 
 	thread = pthread_self();
 	s = pthread_setaffinity_np(thread, size, cpusetp);
@@ -140,7 +140,7 @@ eal_thread_set_affinity(void)
 #else /* CPU_ALLOC */
 	cpuset_t cpuset;
 	CPU_ZERO( &cpuset );
-	CPU_SET( rte_lcore_id(), &cpuset );
+	CPU_SET(lcore_id, &cpuset );
 
 	thread = pthread_self();
 	s = pthread_setaffinity_np(thread, sizeof( cpuset ), &cpuset);
@@ -158,7 +158,7 @@ void eal_thread_init_master(unsigned lcore_id)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
+	if (eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 }
 
@@ -192,7 +192,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
+	if (eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 
 	/* read on our pipe to get commands */
lib/librte_eal/linuxapp/eal/eal_thread.c +5 -5
index 80a985f..9dc3f98 100644
@@ -96,7 +96,7 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 
 /* set affinity for current thread */
 static int
-eal_thread_set_affinity(void)
+eal_thread_set_affinity(unsigned lcore_id)
 {
 	int s;
 	pthread_t thread;
@@ -126,7 +126,7 @@ eal_thread_set_affinity(void)
 
 	size = CPU_ALLOC_SIZE(RTE_MAX_LCORE);
 	CPU_ZERO_S(size, cpusetp);
-	CPU_SET_S(rte_lcore_id(), size, cpusetp);
+	CPU_SET_S(lcore_id, size, cpusetp);
 
 	thread = pthread_self();
 	s = pthread_setaffinity_np(thread, size, cpusetp);
@@ -140,7 +140,7 @@ eal_thread_set_affinity(void)
 #else /* CPU_ALLOC */
 	cpu_set_t cpuset;
 	CPU_ZERO( &cpuset );
-	CPU_SET( rte_lcore_id(), &cpuset );
+	CPU_SET(lcore_id, &cpuset);
 
 	thread = pthread_self();
 	s = pthread_setaffinity_np(thread, sizeof( cpuset ), &cpuset);
@@ -158,7 +158,7 @@ void eal_thread_init_master(unsigned lcore_id)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
+	if (eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 }
 
@@ -192,7 +192,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
+	if (eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 
 	/* read on our pipe to get commands */
Signature · 1 line
1.9.3
#3 lore raw

PATCH 2/3 eal: increase scope of eal_thread_set_affinity

In reply to a message not in the archive

This patch changes eal_thread_set_affinity to the EAL-local function rte_eal_thread_set_affinity. This will allow us to use the function anywhere else in the EAL, while not having it part of the official APIs

---
 lib/librte_eal/bsdapp/eal/eal_thread.c      |  8 ++++----
 lib/librte_eal/common/include/eal_private.h | 10 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c    |  8 ++++----
 3 files changed, 18 insertions(+), 8 deletions(-)
lib/librte_eal/bsdapp/eal/eal_thread.c +4 -4
index 18df2a3..66191bb 100644
@@ -95,8 +95,8 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 }
 
 /* set affinity for current thread */
-static int
-eal_thread_set_affinity(unsigned lcore_id)
+int
+rte_eal_thread_set_affinity(unsigned lcore_id)
 {
 	int s;
 	pthread_t thread;
@@ -158,7 +158,7 @@ void eal_thread_init_master(unsigned lcore_id)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity(lcore_id) < 0)
+	if (rte_eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 }
 
@@ -192,7 +192,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity(lcore_id) < 0)
+	if (rte_eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 
 	/* read on our pipe to get commands */
lib/librte_eal/common/include/eal_private.h +10 -0
index b440ffb..0f01f81 100644
@@ -196,4 +196,14 @@ int rte_eal_intr_init(void);
  */
 int rte_eal_alarm_init(void);
 
+/**
+ * Set the affinity of the current thread to a given core
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *  0 on success, negative on error
+ */
+int rte_eal_thread_set_affinity(unsigned lcore_id);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/linuxapp/eal/eal_thread.c +4 -4
index 9dc3f98..cf5e75c 100644
@@ -95,8 +95,8 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 }
 
 /* set affinity for current thread */
-static int
-eal_thread_set_affinity(unsigned lcore_id)
+int
+rte_eal_thread_set_affinity(unsigned lcore_id)
 {
 	int s;
 	pthread_t thread;
@@ -158,7 +158,7 @@ void eal_thread_init_master(unsigned lcore_id)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity(lcore_id) < 0)
+	if (rte_eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 }
 
@@ -192,7 +192,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 	RTE_PER_LCORE(_lcore_id) = lcore_id;
 
 	/* set CPU affinity */
-	if (eal_thread_set_affinity(lcore_id) < 0)
+	if (rte_eal_thread_set_affinity(lcore_id) < 0)
 		rte_panic("cannot set affinity\n");
 
 	/* read on our pipe to get commands */
Signature · 1 line
1.9.3
#4 lore raw

PATCH 3/3 eal: affinitize low-priority threads to lcore 0

In reply to a message not in the archive

There are extra utility threads inside the linuxapp EAL, for managing things like interrupts, requests for the vfio file handle for multi-process, and hpet timer management. These are mostly sleeping, but to avoid any possibility of conflict with threads handling packets, this patch affinitizes those threads to lcore 0 explicitly.

---
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       | 5 +++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 6 ++++++
 lib/librte_eal/linuxapp/eal/eal_timer.c            | 5 +++++
 3 files changed, 16 insertions(+)
lib/librte_eal/linuxapp/eal/eal_interrupts.c +5 -0
index dc2668a..6227f2b 100644
@@ -739,6 +739,11 @@ eal_intr_thread_main(__rte_unused void *arg)
 {
 	struct epoll_event ev;
 
+	/* set our affinity to lcore 0 so we never interfere with the normal
+	 * data-plane threads. Lcore 0 is used by Linux so is subject to
+	 * interruptions anyway. */
+	rte_eal_thread_set_affinity(0);
+
 	/* host thread, never break out */
 	for (;;) {
 		/* build up the epoll fd with all descriptors we are to
lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c +6 -0
index 6588fb1..ccccbdb 100644
@@ -53,6 +53,7 @@
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
 
+#include <eal_private.h>
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
 
@@ -268,6 +269,11 @@ pci_vfio_mp_sync_thread(void __rte_unused * arg)
 {
 	int ret, fd, vfio_group_no;
 
+	/* set our affinity to lcore 0 so we never interfere with the normal
+	 * data-plane threads. Lcore 0 is used by Linux so is subject to
+	 * interruptions anyway. */
+	rte_eal_thread_set_affinity(0);
+
 	/* wait for requests on the socket */
 	for (;;) {
 		int conn_sock;
lib/librte_eal/linuxapp/eal/eal_timer.c +5 -0
index ca57916..f61e303 100644
@@ -125,6 +125,11 @@ hpet_msb_inc(__attribute__((unused)) void *arg)
 {
 	uint32_t t;
 
+	/* set our affinity to lcore 0 so we never interfere with the normal
+	 * data-plane threads. Lcore 0 is used by Linux so is subject to
+	 * interruptions anyway. */
+	rte_eal_thread_set_affinity(0);
+
 	while (1) {
 		t = (eal_hpet->counter_l >> 30);
 		if (t != (eal_hpet_msb & 3))
Signature · 1 line
1.9.3
#5 lore raw
In reply to a message not in the archive

Hi Bruce,

Quoted 5 lines

Subject: [dpdk-dev] [PATCH 0/3] eal affinitize low priority threads to lcore 0

This patchset sets things up so that we can affinitize the interrupt, vfio management, and hpet timer management threads to lcore 0, so that they never interfere with data plane threads.

I don't think it works well always.
The management threads can be floating all cpus on demand, because those threads are created before the master thread affinity is set. The kernel scheduler will take care of it. And we should isolate cpus which data plane threads are pinned to, so the management threads cannot run on those isolated cpus data plane thread run.
In some cases, the user may run data plane thread on lcore 0, but with this patchset the data plane pinned to lcore 0 always run with the management threads. That doesn't seem good.

I think this functionality should be conditional.
How about to add a parameter to specify the mask for the management threads instead of statically assignment to lcore 0?

thanks,
Hiroshi

Quoted 16 lines

Bruce Richardson (3):
eal: add core id param to eal_thread_set_affinity
eal: increase scope of eal_thread_set_affinity
eal: affinitize low-priority threads to lcore 0

 lib/librte_eal/bsdapp/eal/eal_thread.c             | 12 ++++++------
 lib/librte_eal/common/include/eal_private.h        | 10 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  5 +++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |  6 ++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c           | 12 ++++++------
 lib/librte_eal/linuxapp/eal/eal_timer.c            |  5 +++++
 6 files changed, 38 insertions(+), 12 deletions(-)

--
1.9.3

A message that is not in the archive (sent off-list or not yet received): 7F861DC0615E0C47A872E6F3C5FCDDBD011AC7A6-ZmjkEB1lVlLt6d3pZDjeaEtBU8KWyXPq@public.gmane.org

#7 lore raw
Quoted 18 lines · On Thu, 11 Sep 2014 23:47:52 +0000 Hiroshi Shimamoto…

Hi Bruce,

Quoted 5 lines

Subject: [dpdk-dev] [PATCH 0/3] eal affinitize low priority threads to lcore 0

This patchset sets things up so that we can affinitize the interrupt, vfio management, and hpet timer management threads to lcore 0, so that they never interfere with data plane threads.

I don't think it works well always.
The management threads can be floating all cpus on demand, because those threads are created before the master thread affinity is set. The kernel scheduler will take care of it. And we should isolate cpus which data plane threads are pinned to, so the management threads cannot run on those isolated cpus data plane thread run.
In some cases, the user may run data plane thread on lcore 0, but with this patchset the data plane pinned to lcore 0 always run with the management threads. That doesn't seem good.

Quoted 24 lines

I think this functionality should be conditional.
How about to add a parameter to specify the mask for the management threads instead of statically assignment to lcore 0?

thanks,
Hiroshi

Quoted 16 lines

Bruce Richardson (3):
eal: add core id param to eal_thread_set_affinity
eal: increase scope of eal_thread_set_affinity
eal: affinitize low-priority threads to lcore 0

 lib/librte_eal/bsdapp/eal/eal_thread.c             | 12 ++++++------
 lib/librte_eal/common/include/eal_private.h        | 10 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  5 +++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |  6 ++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c           | 12 ++++++------
 lib/librte_eal/linuxapp/eal/eal_timer.c            |  5 +++++
 6 files changed, 38 insertions(+), 12 deletions(-)

--
1.9.3

We just set the non-master DPDK worker threads to be real time by using pthread_set_scheduler. This works very well and makes it clear to Linux scheduler what the intention is. This also improves wakeup behavior from sleeps.

#8 lore raw
In reply to a message not in the archive
Quoted 14 lines

-----Original Message-----
From: Hiroshi Shimamoto [mailto:h-shimamoto-ehU+Cx/zZe18UrSeD/[email protected]]
Sent: Friday, September 12, 2014 12:48 AM
To: Richardson, Bruce; [email protected]
Subject: RE: [dpdk-dev] [PATCH 0/3] eal affinitize low priority threads to lcore 0

Hi Bruce,

Quoted 5 lines

Subject: [dpdk-dev] [PATCH 0/3] eal affinitize low priority threads to lcore 0

This patchset sets things up so that we can affinitize the interrupt, vfio management, and hpet timer management threads to lcore 0, so that they never interfere with data plane threads.

Quoted 6 lines

I don't think it works well always.
The management threads can be floating all cpus on demand, because those threads are created before the master thread affinity is set. The kernel scheduler will take care of it. And we should isolate cpus which data plane threads are pinned to, so the management threads cannot run on those isolated cpus data plane thread run.

Yes, this was my understanding as well of how things would work - we just had a report back of where the management threads were using the same core as the data-plane despite the core being isolated. I'll double-check to see if this really is happening and resubmit a new patch with a configurable core assignment if it is definitely needed.

/Bruce

Quoted 27 lines

In some cases, the user may run data plane thread on lcore 0, but with this patchset the data plane pinned to lcore 0 always run with the management threads. That doesn't seem good.

I think this functionality should be conditional.
How about to add a parameter to specify the mask for the management threads instead of statically assignment to lcore 0?

thanks,
Hiroshi

Quoted 16 lines

Bruce Richardson (3):
eal: add core id param to eal_thread_set_affinity
eal: increase scope of eal_thread_set_affinity
eal: affinitize low-priority threads to lcore 0

 lib/librte_eal/bsdapp/eal/eal_thread.c             | 12 ++++++------
 lib/librte_eal/common/include/eal_private.h        | 10 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  5 +++++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |  6 ++++++
 lib/librte_eal/linuxapp/eal/eal_thread.c           | 12 ++++++------
 lib/librte_eal/linuxapp/eal/eal_timer.c            |  5 +++++
 6 files changed, 38 insertions(+), 12 deletions(-)

--
1.9.3