80b419eb82825ccb0b86fc9f7e582245fbdaa654
[openwrt/openwrt.git] / package / devel / trace-cmd / patches / 100-musl.patch
1 From 1a000636c1828eecdcec5360a51623ef4ffbff04 Mon Sep 17 00:00:00 2001
2 From: Beniamin Sandu <beniaminsandu@gmail.com>
3 Date: Mon, 30 Nov 2020 14:27:55 +0200
4 Subject: trace-cmd: make it build against musl C library
5
6 * add some missing headers and macros
7 * set pthread affinity using pthread_setaffinity_np after creating the thread
8 instead of pthread_attr_setaffinity_np (which seems to not be implemented
9 in musl)
10
11 Tested using https://musl.cc/x86_64-linux-musl-native.tgz
12
13 Link: https://lore.kernel.org/linux-trace-devel/20201130122755.31000-1-beniaminsandu@gmail.com
14
15 Reviewed-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
16 Signed-off-by: Beniamin Sandu <beniaminsandu@gmail.com>
17 [ Fixed a whitespace issue ]
18 Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
19 ---
20 include/trace-cmd/trace-cmd.h | 1 +
21 lib/trace-cmd/include/trace-cmd-local.h | 1 +
22 lib/tracefs/tracefs-events.c | 1 +
23 tracecmd/include/trace-local.h | 1 +
24 tracecmd/trace-tsync.c | 16 +++++++++++-----
25 5 files changed, 20 insertions(+), 5 deletions(-)
26
27 --- a/include/trace-cmd/trace-cmd.h
28 +++ b/include/trace-cmd/trace-cmd.h
29 @@ -6,6 +6,7 @@
30 #ifndef _TRACE_CMD_H
31 #define _TRACE_CMD_H
32
33 +#include <pthread.h>
34 #include "traceevent/event-parse.h"
35
36 #define TRACECMD_MAGIC { 23, 8, 68 }
37 --- a/lib/trace-cmd/include/trace-cmd-local.h
38 +++ b/lib/trace-cmd/include/trace-cmd-local.h
39 @@ -26,5 +26,6 @@ void warning(const char *fmt, ...);
40 #endif
41 #endif
42
43 +#include <byteswap.h>
44
45 #endif /* _TRACE_CMD_LOCAL_H */
46 --- a/lib/tracefs/tracefs-events.c
47 +++ b/lib/tracefs/tracefs-events.c
48 @@ -13,6 +13,7 @@
49 #include <errno.h>
50 #include <sys/stat.h>
51 #include <fcntl.h>
52 +#include <limits.h>
53
54 #include "kbuffer.h"
55 #include "tracefs.h"
56 --- a/tracecmd/include/trace-local.h
57 +++ b/tracecmd/include/trace-local.h
58 @@ -8,6 +8,7 @@
59
60 #include <sys/types.h>
61 #include <dirent.h> /* for DIR */
62 +#include <limits.h>
63
64 #include "trace-cmd.h"
65 #include "event-utils.h"
66 --- a/tracecmd/trace-tsync.c
67 +++ b/tracecmd/trace-tsync.c
68 @@ -104,13 +104,16 @@ int tracecmd_host_tsync(struct buffer_in
69
70 pthread_attr_init(&attrib);
71 pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
72 - if (!get_first_cpu(&pin_mask, &mask_size))
73 - pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
74
75 ret = pthread_create(&instance->tsync_thread, &attrib,
76 tsync_host_thread, &instance->tsync);
77 - if (!ret)
78 +
79 + if (!ret) {
80 + if (!get_first_cpu(&pin_mask, &mask_size))
81 + pthread_setaffinity_np(instance->tsync_thread, mask_size, pin_mask);
82 instance->tsync_thread_running = true;
83 + }
84 +
85 if (pin_mask)
86 CPU_FREE(pin_mask);
87 pthread_attr_destroy(&attrib);
88 @@ -243,11 +246,14 @@ unsigned int tracecmd_guest_tsync(char *
89 pthread_attr_init(&attrib);
90 tsync->sync_proto = proto;
91 pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
92 - if (!get_first_cpu(&pin_mask, &mask_size))
93 - pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
94
95 ret = pthread_create(thr_id, &attrib, tsync_agent_thread, tsync);
96
97 + if (!ret) {
98 + if (!get_first_cpu(&pin_mask, &mask_size))
99 + pthread_setaffinity_np(*thr_id, mask_size, pin_mask);
100 + }
101 +
102 if (pin_mask)
103 CPU_FREE(pin_mask);
104 pthread_attr_destroy(&attrib);