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
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
11 Tested using https://musl.cc/x86_64-linux-musl-native.tgz
13 Link: https://lore.kernel.org/linux-trace-devel/20201130122755.31000-1-beniaminsandu@gmail.com
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>
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(-)
27 --- a/include/trace-cmd/trace-cmd.h
28 +++ b/include/trace-cmd/trace-cmd.h
34 #include "traceevent/event-parse.h"
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, ...);
43 +#include <byteswap.h>
45 #endif /* _TRACE_CMD_LOCAL_H */
46 --- a/lib/tracefs/tracefs-events.c
47 +++ b/lib/tracefs/tracefs-events.c
56 --- a/tracecmd/include/trace-local.h
57 +++ b/tracecmd/include/trace-local.h
60 #include <sys/types.h>
61 #include <dirent.h> /* for DIR */
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
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);
75 ret = pthread_create(&instance->tsync_thread, &attrib,
76 tsync_host_thread, &instance->tsync);
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;
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);
95 ret = pthread_create(thr_id, &attrib, tsync_agent_thread, tsync);
98 + if (!get_first_cpu(&pin_mask, &mask_size))
99 + pthread_setaffinity_np(*thr_id, mask_size, pin_mask);
104 pthread_attr_destroy(&attrib);