Andrew Geissler | 8fc454f | 2020-12-11 16:27:59 -0600 | [diff] [blame] | 1 | From b63f13d2df91ede45288653b21e0d30a6b45f2ac Mon Sep 17 00:00:00 2001 |
| 2 | From: Beniamin Sandu <beniaminsandu@gmail.com> |
| 3 | Date: Mon, 30 Nov 2020 18:24:48 +0200 |
| 4 | Subject: [PATCH] trace-cmd: make it build with musl |
| 5 | |
| 6 | Signed-off-by: Beniamin Sandu <beniaminsandu@gmail.com> |
| 7 | --- |
| 8 | include/trace-cmd/trace-cmd.h | 1 + |
| 9 | lib/trace-cmd/trace-msg.c | 1 + |
| 10 | lib/trace-cmd/trace-plugin.c | 2 ++ |
| 11 | lib/tracefs/tracefs-events.c | 1 + |
| 12 | tracecmd/trace-agent.c | 1 + |
| 13 | tracecmd/trace-setup-guest.c | 1 + |
| 14 | tracecmd/trace-tsync.c | 15 ++++++++++----- |
| 15 | 7 files changed, 17 insertions(+), 5 deletions(-) |
| 16 | |
| 17 | diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h |
| 18 | index f3c95f3..a697905 100644 |
| 19 | --- a/include/trace-cmd/trace-cmd.h |
| 20 | +++ b/include/trace-cmd/trace-cmd.h |
| 21 | @@ -6,6 +6,7 @@ |
| 22 | #ifndef _TRACE_CMD_H |
| 23 | #define _TRACE_CMD_H |
| 24 | |
| 25 | +#include <sys/types.h> |
| 26 | #include "traceevent/event-parse.h" |
| 27 | |
| 28 | #define TRACECMD_MAGIC { 23, 8, 68 } |
| 29 | diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c |
| 30 | index 4a0bfa9..fc1f2c7 100644 |
| 31 | --- a/lib/trace-cmd/trace-msg.c |
| 32 | +++ b/lib/trace-cmd/trace-msg.c |
| 33 | @@ -21,6 +21,7 @@ |
| 34 | #include <arpa/inet.h> |
| 35 | #include <sys/types.h> |
| 36 | #include <linux/types.h> |
| 37 | +#include <byteswap.h> |
| 38 | |
| 39 | #include "trace-write-local.h" |
| 40 | #include "trace-cmd-local.h" |
| 41 | diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c |
| 42 | index 92f9edf..c2ef3dc 100644 |
| 43 | --- a/lib/trace-cmd/trace-plugin.c |
| 44 | +++ b/lib/trace-cmd/trace-plugin.c |
| 45 | @@ -8,6 +8,8 @@ |
| 46 | #include <dlfcn.h> |
| 47 | #include <sys/stat.h> |
| 48 | #include <libgen.h> |
| 49 | +#include <limits.h> |
| 50 | + |
| 51 | #include "trace-cmd.h" |
| 52 | #include "trace-local.h" |
| 53 | |
| 54 | diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c |
| 55 | index 8e825f5..a8d8560 100644 |
| 56 | --- a/lib/tracefs/tracefs-events.c |
| 57 | +++ b/lib/tracefs/tracefs-events.c |
| 58 | @@ -13,6 +13,7 @@ |
| 59 | #include <errno.h> |
| 60 | #include <sys/stat.h> |
| 61 | #include <fcntl.h> |
| 62 | +#include <limits.h> |
| 63 | |
| 64 | #include "kbuffer.h" |
| 65 | #include "tracefs.h" |
| 66 | diff --git a/tracecmd/trace-agent.c b/tracecmd/trace-agent.c |
| 67 | index b581696..abfefac 100644 |
| 68 | --- a/tracecmd/trace-agent.c |
| 69 | +++ b/tracecmd/trace-agent.c |
| 70 | @@ -20,6 +20,7 @@ |
| 71 | #include <unistd.h> |
| 72 | #include <linux/vm_sockets.h> |
| 73 | #include <pthread.h> |
| 74 | +#include <limits.h> |
| 75 | |
| 76 | #include "trace-local.h" |
| 77 | #include "trace-msg.h" |
| 78 | diff --git a/tracecmd/trace-setup-guest.c b/tracecmd/trace-setup-guest.c |
| 79 | index 899848c..99595a1 100644 |
| 80 | --- a/tracecmd/trace-setup-guest.c |
| 81 | +++ b/tracecmd/trace-setup-guest.c |
| 82 | @@ -13,6 +13,7 @@ |
| 83 | #include <string.h> |
| 84 | #include <sys/stat.h> |
| 85 | #include <unistd.h> |
| 86 | +#include <limits.h> |
| 87 | |
| 88 | #include "trace-local.h" |
| 89 | #include "trace-msg.h" |
| 90 | diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c |
| 91 | index e639788..b8b5ac3 100644 |
| 92 | --- a/tracecmd/trace-tsync.c |
| 93 | +++ b/tracecmd/trace-tsync.c |
| 94 | @@ -104,13 +104,15 @@ int tracecmd_host_tsync(struct buffer_instance *instance, |
| 95 | |
| 96 | pthread_attr_init(&attrib); |
| 97 | pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE); |
| 98 | - if (!get_first_cpu(&pin_mask, &mask_size)) |
| 99 | - pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask); |
| 100 | |
| 101 | ret = pthread_create(&instance->tsync_thread, &attrib, |
| 102 | tsync_host_thread, &instance->tsync); |
| 103 | - if (!ret) |
| 104 | + if (!ret) { |
| 105 | + if (!get_first_cpu(&pin_mask, &mask_size)) |
| 106 | + pthread_setaffinity_np(instance->tsync_thread, mask_size, pin_mask); |
| 107 | instance->tsync_thread_running = true; |
| 108 | + } |
| 109 | + |
| 110 | if (pin_mask) |
| 111 | CPU_FREE(pin_mask); |
| 112 | pthread_attr_destroy(&attrib); |
| 113 | @@ -243,11 +245,14 @@ unsigned int tracecmd_guest_tsync(char *tsync_protos, |
| 114 | pthread_attr_init(&attrib); |
| 115 | tsync->sync_proto = proto; |
| 116 | pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE); |
| 117 | - if (!get_first_cpu(&pin_mask, &mask_size)) |
| 118 | - pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask); |
| 119 | |
| 120 | ret = pthread_create(thr_id, &attrib, tsync_agent_thread, tsync); |
| 121 | |
| 122 | + if (!ret) { |
| 123 | + if (!get_first_cpu(&pin_mask, &mask_size)) |
| 124 | + pthread_setaffinity_np(*thr_id, mask_size, pin_mask); |
| 125 | + } |
| 126 | + |
| 127 | if (pin_mask) |
| 128 | CPU_FREE(pin_mask); |
| 129 | pthread_attr_destroy(&attrib); |
| 130 | -- |
| 131 | 2.25.1 |
| 132 | |