summaryrefslogtreecommitdiff
blob: 48a7a297afc1aaab019103395c8ce3ef0fddd107 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
From 4daa685588ee3848fc98fd9c6328b76f136ee876 Mon Sep 17 00:00:00 2001
From: Kurt Kanzenbach <kurt@kmk-computers.de>
Date: Wed, 1 Apr 2020 20:15:24 +0200
Subject: [PATCH] all: Fix musl build

There are a few problems:

 * pi stress:  pthread_attr_setaffinity_np() is not supported
 * cyclictest: SIGEV_THREAD_ID is not supported
 * hackbench:  Fix include
 * all:        Fix sched_* calls

With these changes applied, the rt-tests seem to run fine.

Signed-off-by: Kurt Kanzenbach <kurt@kmk-computers.de>
---
 Makefile                              |  5 --
 src/backfire/sendme.c                 |  1 +
 src/cyclictest/cyclictest.c           | 68 ++++-----------------------
 src/hackbench/hackbench.c             |  4 +-
 src/include/musl.h                    | 28 +++++++++++
 src/lib/rt-utils.c                    |  1 +
 src/pi_tests/classic_pi.c             |  2 +
 src/pi_tests/tst-mutexpi10.c          |  2 +
 src/pmqtest/pmqtest.c                 |  1 +
 src/ptsematest/ptsematest.c           |  1 +
 src/rt-migrate-test/rt-migrate-test.c |  1 +
 src/sched_deadline/cyclicdeadline.c   |  2 +
 12 files changed, 50 insertions(+), 66 deletions(-)
 create mode 100644 src/include/musl.h

diff --git a/Makefile b/Makefile
index 05fc5eda71fa..9340f28f2c32 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,6 @@ OBJDIR = bld
 sources = cyclictest.c \
 	  hackbench.c \
 	  pip_stress.c \
-	  pi_stress.c \
 	  pmqtest.c \
 	  ptsematest.c \
 	  rt-migrate-test.c \
@@ -35,7 +34,6 @@ LDFLAGS ?=
 PYLIB  ?= $(shell python3 -c 'import distutils.sysconfig;  print (distutils.sysconfig.get_python_lib())')
 
 MANPAGES = src/cyclictest/cyclictest.8 \
-	   src/pi_tests/pi_stress.8 \
 	   src/ptsematest/ptsematest.8 \
 	   src/rt-migrate-test/rt-migrate-test.8 \
 	   src/sigwaittest/sigwaittest.8 \
@@ -125,9 +123,6 @@ deadline_test: $(OBJDIR)/deadline_test.o $(OBJDIR)/librttest.a
 signaltest: $(OBJDIR)/signaltest.o $(OBJDIR)/librttest.a
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(RTTESTLIB)
 
-pi_stress: $(OBJDIR)/pi_stress.o $(OBJDIR)/librttest.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(RTTESTLIB)
-
 hwlatdetect:  src/hwlatdetect/hwlatdetect.py
 	chmod +x src/hwlatdetect/hwlatdetect.py
 	ln -s src/hwlatdetect/hwlatdetect.py hwlatdetect
diff --git a/src/backfire/sendme.c b/src/backfire/sendme.c
index c1854d9660cb..ecec5c201bef 100644
--- a/src/backfire/sendme.c
+++ b/src/backfire/sendme.c
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
+#include "musl.h"
 
 #include <utmpx.h>
 #include <sys/types.h>
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index c5f1fd46567a..8204e57cbbac 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -36,6 +36,7 @@
 #include "rt_numa.h"
 
 #include "rt-utils.h"
+#include "musl.h"
 
 #include <bionic.h>
 
@@ -628,12 +629,8 @@ static void *timerthread(void *param)
 {
 	struct thread_param *par = param;
 	struct sched_param schedp;
-	struct sigevent sigev;
 	sigset_t sigset;
-	timer_t timer;
 	struct timespec now, next, interval, stop;
-	struct itimerval itimer;
-	struct itimerspec tspec;
 	struct thread_stat *stat = par->stats;
 	int stopped = 0;
 	cpu_set_t mask;
@@ -664,14 +661,6 @@ static void *timerthread(void *param)
 	sigaddset(&sigset, par->signal);
 	sigprocmask(SIG_BLOCK, &sigset, NULL);
 
-	if (par->mode == MODE_CYCLIC) {
-		sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL;
-		sigev.sigev_signo = par->signal;
-		sigev.sigev_notify_thread_id = stat->tid;
-		timer_create(par->clock, &sigev, &timer);
-		tspec.it_interval = interval;
-	}
-
 	memset(&schedp, 0, sizeof(schedp));
 	schedp.sched_priority = par->prio;
 	if (setscheduler(0, par->policy, &schedp))
@@ -726,20 +715,6 @@ static void *timerthread(void *param)
 		stop = now;
 		stop.tv_sec += duration;
 	}
-	if (par->mode == MODE_CYCLIC) {
-		if (par->timermode == TIMER_ABSTIME)
-			tspec.it_value = next;
-		else
-			tspec.it_value = interval;
-		timer_settime(timer, par->timermode, &tspec, NULL);
-	}
-
-	if (par->mode == MODE_SYS_ITIMER) {
-		itimer.it_interval.tv_sec = interval.tv_sec;
-		itimer.it_interval.tv_usec = interval.tv_nsec / 1000;
-		itimer.it_value = itimer.it_interval;
-		setitimer(ITIMER_REAL, &itimer, NULL);
-	}
 
 	stat->threadstarted++;
 
@@ -747,16 +722,10 @@ static void *timerthread(void *param)
 
 		uint64_t diff;
 		unsigned long diff_smi = 0;
-		int sigs, ret;
+		int ret;
 
 		/* Wait for next period */
 		switch (par->mode) {
-		case MODE_CYCLIC:
-		case MODE_SYS_ITIMER:
-			if (sigwait(&sigset, &sigs) < 0)
-				goto out;
-			break;
-
 		case MODE_CLOCK_NANOSLEEP:
 			if (par->timermode == TIMER_ABSTIME) {
 				ret = clock_nanosleep(par->clock, TIMER_ABSTIME,
@@ -878,11 +847,6 @@ static void *timerthread(void *param)
 
 		next.tv_sec += interval.tv_sec;
 		next.tv_nsec += interval.tv_nsec;
-		if (par->mode == MODE_CYCLIC) {
-			int overrun_count = timer_getoverrun(timer);
-			next.tv_sec += overrun_count * interval.tv_sec;
-			next.tv_nsec += overrun_count * interval.tv_nsec;
-		}
 		tsnorm(&next);
 
 		while (tsgreater(&now, &next)) {
@@ -907,17 +871,6 @@ out:
 		pthread_mutex_unlock(&refresh_on_max_lock);
 	}
 
-	if (par->mode == MODE_CYCLIC)
-		timer_delete(timer);
-
-	if (par->mode == MODE_SYS_ITIMER) {
-		itimer.it_value.tv_sec = 0;
-		itimer.it_value.tv_usec = 0;
-		itimer.it_interval.tv_sec = 0;
-		itimer.it_interval.tv_usec = 0;
-		setitimer(ITIMER_REAL, &itimer, NULL);
-	}
-
 	/* close msr file */
 	if (smi)
 		close(par->msr_fd);
@@ -1417,7 +1370,8 @@ static void process_options (int argc, char *argv[], int max_cpus)
 		case OPT_VERBOSE: verbose = 1; break;
 		case 'x':
 		case OPT_POSIX_TIMERS:
-			use_nanosleep = MODE_CYCLIC; break;
+			fatal("--posix_timers is not available on your libc\n");
+			break;
 		case '?':
 		case OPT_HELP:
 			display_help(0); break;
@@ -1450,13 +1404,6 @@ static void process_options (int argc, char *argv[], int max_cpus)
 		}
 	}
 
-	if ((use_system == MODE_SYS_OFFSET) && (use_nanosleep == MODE_CYCLIC)) {
-		warn("The system option requires clock_nanosleep\n");
-		warn("and is not compatible with posix_timers\n");
-		warn("Using clock_nanosleep\n");
-		use_nanosleep = MODE_CLOCK_NANOSLEEP;
-	}
-
 	/* if smp wasn't requested, test for numa automatically */
 	if (!smp) {
 #ifdef NUMA
@@ -2157,7 +2104,6 @@ int main(int argc, char **argv)
 
 	}
 
-
 	mode = use_nanosleep + use_system;
 
 	sigemptyset(&sigset);
@@ -2207,16 +2153,18 @@ int main(int argc, char **argv)
 			void *stack;
 			void *currstk;
 			size_t stksize;
+			int err;
 
 			/* find the memory node associated with the cpu i */
 			node = rt_numa_numa_node_of_cpu(cpu);
 
 			/* get the stack size set for for this thread */
-			if (pthread_attr_getstack(&attr, &currstk, &stksize))
+			err = pthread_attr_getstack(&attr, &currstk, &stksize);
+			if (err != EINVAL)
 				fatal("failed to get stack size for thread %d\n", i);
 
 			/* if the stack size is zero, set a default */
-			if (stksize == 0)
+			if (err == EINVAL || stksize == 0)
 				stksize = PTHREAD_STACK_MIN * 2;
 
 			/*  allocate memory for a stack on appropriate node */
diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c
index 5a883d341f2e..9f1e4db736a7 100644
--- a/src/hackbench/hackbench.c
+++ b/src/hackbench/hackbench.c
@@ -24,13 +24,15 @@
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/time.h>
-#include <sys/poll.h>
+#include <poll.h>
 #include <limits.h>
 #include <getopt.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <sched.h>
 
+#include "musl.h"
+
 static unsigned int datasize = 100;
 static unsigned int loops = 100;
 static unsigned int num_groups = 10;
diff --git a/src/include/musl.h b/src/include/musl.h
new file mode 100644
index 000000000000..ea5075e768c8
--- /dev/null
+++ b/src/include/musl.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2020 Kurt Kanzenbach <kurt@kmk-computers.de>
+ * Time-stamp: <2020-04-04 10:54:01 kurt>
+ */
+
+#ifndef _MUSL_H_
+#define _MUSL_H_
+
+#include <unistd.h>
+#include <sys/syscall.h>
+
+/*
+ * Musl someshow defines sched_* to ENOSYS which is not correct ...
+ * See commit 1e21e78bf7a5 ("add support for thread scheduling (POSIX TPS option)")
+ *
+ * Workaround: define them to syscall(...)
+ */
+
+#define sched_getparam(pid, param)		\
+	syscall(SYS_sched_getparam, pid, param)
+#define sched_setparam(pid, param)		\
+	syscall(SYS_sched_setparam, pid, param)
+#define sched_getscheduler(pid)			\
+	syscall(SYS_sched_getscheduler, pid)
+#define sched_setscheduler(pid, policy, param)			\
+	syscall(SYS_sched_setscheduler, pid, policy, param)
+
+#endif /* _MUSL_H_ */
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 1998a327d036..f7adda9c5987 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -23,6 +23,7 @@
 #include "rt-utils.h"
 #include "rt-sched.h"
 #include "error.h"
+#include "musl.h"
 
 static char debugfileprefix[MAX_PATH];
 
diff --git a/src/pi_tests/classic_pi.c b/src/pi_tests/classic_pi.c
index 64af8890276f..bb088d3973b2 100644
--- a/src/pi_tests/classic_pi.c
+++ b/src/pi_tests/classic_pi.c
@@ -34,6 +34,8 @@
 #include <signal.h>
 #include <getopt.h>
 
+#include "musl.h"
+
 /* test timeout */
 #define TIMEOUT 2
 
diff --git a/src/pi_tests/tst-mutexpi10.c b/src/pi_tests/tst-mutexpi10.c
index 97a345edd26e..1028d344edff 100644
--- a/src/pi_tests/tst-mutexpi10.c
+++ b/src/pi_tests/tst-mutexpi10.c
@@ -35,6 +35,8 @@
 #include <string.h>
 #include <signal.h>
 
+#include "musl.h"
+
 /* test timeout */
 #define TIMEOUT 2
 
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index 3ce29252b9a2..1a57841cb7e8 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -24,6 +24,7 @@
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
 #include "error.h"
+#include "musl.h"
 
 #include <pthread.h>
 
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index 485c991ec173..c000e083615f 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -22,6 +22,7 @@
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
 #include "error.h"
+#include "musl.h"
 
 #include <pthread.h>
 
diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
index 4863238edeb4..9f1aba159dc7 100644
--- a/src/rt-migrate-test/rt-migrate-test.c
+++ b/src/rt-migrate-test/rt-migrate-test.c
@@ -25,6 +25,7 @@
 #include <sched.h>
 #include <pthread.h>
 #include "rt-utils.h"
+#include "musl.h"
 
 int nr_tasks;
 int lfd;
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index a08e28e73c42..675a0ea1a162 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -32,6 +32,8 @@
 #include <rt-utils.h>
 #include <rt-sched.h>
 
+#include "musl.h"
+
 #define _STR(x) #x
 #define STR(x) _STR(x)
 #ifndef MAXPATH
-- 
2.24.1