summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/rng-tools/rng-tools/0002-Allow-for-use-of-either-pthread-affinity-set-methods.patch
blob: f7470d04bff3a69891ac56004d62510ba3337471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From e4909f329245db52415102e96fc7c99ca1445d05 Mon Sep 17 00:00:00 2001
From: Neil Horman <nhorman@gmail.com>
Date: Thu, 15 Jul 2021 08:48:10 -0400
Subject: [PATCH] Allow for use of either pthread affinity set methods

musl has support for pthread_setaffinity_np, but not
pthread_attr_setaffinity_np.  so check for hte existence of either
function in configure, and use the appropriate one.

Upstream-Status: Backport
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
---
 rngd_jitter.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/rngd_jitter.c b/rngd_jitter.c
index ea29436..5c7e09e 100644
--- a/rngd_jitter.c
+++ b/rngd_jitter.c
@@ -67,12 +67,25 @@ static int rngd_notime_start(void *ctx,
 	for(i=i-1;i>=0;i--) {
 		CPU_SET(i,cpus);
 	}
-	pthread_attr_setaffinity_np(&thread_ctx->notime_pthread_attr, cpusize, cpus);
 
+        /*
+	 * Note that only one of:
+	 * HAVE_PTHREAD_ATTR_SETAFFINITY
+	 * and
+	 * HAVE_PTHREAD_SETAFFINITY
+	 * Will ever be set, as per the configure.ac logic
+	 */
+#ifdef HAVE_PTHREAD_ATTR_SETAFFINITY
+	pthread_attr_setaffinity_np(&thread_ctx->notime_pthread_attr, cpusize, cpus);
+#endif
 	ret = -pthread_create(&thread_ctx->notime_thread_id,
 				&thread_ctx->notime_pthread_attr,
 				start_routine, arg);
 
+#ifdef HAVE_PTHREAD_SETAFFINITY
+	pthread_setaffinity_np(&thread_ctx->notime_thread_id, cpusize, cpus);
+#endif
+
 	CPU_FREE(cpus);
 	return ret;
 }