summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>2019-04-04 21:47:41 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-04-05 17:32:50 +0100
commit9c01b82269104bd37be4ac459af2604e00468e11 (patch)
tree818572ac46efccbede5e40a46ba3e90022bcc7bc /meta
parent8e9a0fe61f0ccdad8d88ecf8f46ae90c0c73da97 (diff)
downloadpoky-9c01b82269104bd37be4ac459af2604e00468e11.tar.gz
lttng-ust: backport musl workaround
musl implementation for _SC_NPROCESSORS_CONF is a bit fishy. [1] https://www.openwall.com/lists/musl/2019/03/15/5 Anyway, we implemented a fallback. This patch should be gone by next recipe update. (From OE-Core rev: 5feddda9ac7ea72eac3d5a83251fa023b67aebce) Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-kernel/lttng/lttng-ust/0001-compat-work-around-broken-_SC_NPROCESSORS_CONF-on-MU.patch109
-rw-r--r--meta/recipes-kernel/lttng/lttng-ust_2.10.3.bb2
2 files changed, 111 insertions, 0 deletions
diff --git a/meta/recipes-kernel/lttng/lttng-ust/0001-compat-work-around-broken-_SC_NPROCESSORS_CONF-on-MU.patch b/meta/recipes-kernel/lttng/lttng-ust/0001-compat-work-around-broken-_SC_NPROCESSORS_CONF-on-MU.patch
new file mode 100644
index 0000000000..5c4bd36726
--- /dev/null
+++ b/meta/recipes-kernel/lttng/lttng-ust/0001-compat-work-around-broken-_SC_NPROCESSORS_CONF-on-MU.patch
@@ -0,0 +1,109 @@
1From 5de7c318804a7b1edce8562d4891b4c74aac0677 Mon Sep 17 00:00:00 2001
2From: Michael Jeanson <mjeanson@efficios.com>
3Date: Wed, 20 Mar 2019 11:07:35 -0400
4Subject: [PATCH] compat: work around broken _SC_NPROCESSORS_CONF on MUSL libc
5
6On MUSL libc the _SC_NPROCESSORS_CONF sysconf will report the number of
7CPUs allocated to the task based on the affinity mask instead of the
8total number of CPUs configured on the system.
9
10Upstream-Status: Accepted [1] [5de7c318804a7b1edce8562d4891b4c74aac0677]
11[1] https://lists.lttng.org/pipermail/lttng-dev/2019-March/028616.html
12
13Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
14Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15---
16 libringbuffer/smp.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
17 1 file changed, 66 insertions(+)
18
19diff --git a/libringbuffer/smp.c b/libringbuffer/smp.c
20index 9e7114be..656a75da 100644
21--- a/libringbuffer/smp.c
22+++ b/libringbuffer/smp.c
23@@ -2,6 +2,7 @@
24 * libringbuffer/smp.c
25 *
26 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
27+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
28 *
29 * This library is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU Lesser General Public
31@@ -26,6 +27,7 @@
32
33 int __num_possible_cpus;
34
35+#if (defined(__GLIBC__) || defined( __UCLIBC__))
36 void _get_num_possible_cpus(void)
37 {
38 int result;
39@@ -43,3 +45,67 @@ void _get_num_possible_cpus(void)
40 return;
41 __num_possible_cpus = result;
42 }
43+
44+#else
45+
46+/*
47+ * The MUSL libc implementation of the _SC_NPROCESSORS_CONF sysconf does not
48+ * return the number of configured CPUs in the system but relies on the cpu
49+ * affinity mask of the current task.
50+ *
51+ * So instead we use a strategy similar to GLIBC's, counting the cpu
52+ * directories in "/sys/devices/system/cpu" and fallback on the value from
53+ * sysconf if it fails.
54+ */
55+
56+#include <dirent.h>
57+#include <limits.h>
58+#include <stdlib.h>
59+#include <string.h>
60+#include <sys/types.h>
61+
62+#define __max(a,b) ((a)>(b)?(a):(b))
63+
64+void _get_num_possible_cpus(void)
65+{
66+ int result, count = 0;
67+ DIR *cpudir;
68+ struct dirent *entry;
69+
70+ cpudir = opendir("/sys/devices/system/cpu");
71+ if (cpudir == NULL)
72+ goto end;
73+
74+ /*
75+ * Count the number of directories named "cpu" followed by and
76+ * integer. This is the same strategy as glibc uses.
77+ */
78+ while ((entry = readdir(cpudir))) {
79+ if (entry->d_type == DT_DIR &&
80+ strncmp(entry->d_name, "cpu", 3) == 0) {
81+
82+ char *endptr;
83+ unsigned long cpu_num;
84+
85+ cpu_num = strtoul(entry->d_name + 3, &endptr, 10);
86+ if ((cpu_num < ULONG_MAX) && (endptr != entry->d_name + 3)
87+ && (*endptr == '\0')) {
88+ count++;
89+ }
90+ }
91+ }
92+
93+end:
94+ /*
95+ * Get the sysconf value as a fallback. Keep the highest number.
96+ */
97+ result = __max(sysconf(_SC_NPROCESSORS_CONF), count);
98+
99+ /*
100+ * If both methods failed, don't store the value.
101+ */
102+ if (result < 1)
103+ return;
104+ __num_possible_cpus = result;
105+}
106+#endif
107--
1082.17.1
109
diff --git a/meta/recipes-kernel/lttng/lttng-ust_2.10.3.bb b/meta/recipes-kernel/lttng/lttng-ust_2.10.3.bb
index c0f408eeec..d546104129 100644
--- a/meta/recipes-kernel/lttng/lttng-ust_2.10.3.bb
+++ b/meta/recipes-kernel/lttng/lttng-ust_2.10.3.bb
@@ -27,7 +27,9 @@ PE = "2"
27 27
28SRC_URI = "https://lttng.org/files/lttng-ust/lttng-ust-${PV}.tar.bz2 \ 28SRC_URI = "https://lttng.org/files/lttng-ust/lttng-ust-${PV}.tar.bz2 \
29 file://lttng-ust-doc-examples-disable.patch \ 29 file://lttng-ust-doc-examples-disable.patch \
30 file://0001-compat-work-around-broken-_SC_NPROCESSORS_CONF-on-MU.patch \
30 " 31 "
32
31SRC_URI[md5sum] = "ffcfa8c1ba9a52f002d240e936e9afa2" 33SRC_URI[md5sum] = "ffcfa8c1ba9a52f002d240e936e9afa2"
32SRC_URI[sha256sum] = "9e8420f90d5f963f7aa32bc6d44adc1e491136f687c69ffb7a3075d33b40852b" 34SRC_URI[sha256sum] = "9e8420f90d5f963f7aa32bc6d44adc1e491136f687c69ffb7a3075d33b40852b"
33 35