linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: make it build against musl C library
@ 2020-11-28 19:22 Beniamin Sandu
  2020-11-30  8:13 ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 4+ messages in thread
From: Beniamin Sandu @ 2020-11-28 19:22 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Beniamin Sandu

* add some missing headers and macros
* set pthread affinity using pthread_setaffinity_np after creating the thread
instead of pthread_attr_setaffinity_np (which seems to not be implemented
in musl)

Tested using https://musl.cc/x86_64-linux-musl-native.tgz

Signed-off-by: Beniamin Sandu <beniaminsandu@gmail.com>
---
 lib/trace-cmd/include/private/trace-cmd-private.h |  1 +
 lib/trace-cmd/include/trace-cmd-local.h           |  1 +
 lib/tracefs/include/tracefs-local.h               | 12 ++++++++++++
 lib/tracefs/tracefs-events.c                      |  1 +
 tracecmd/include/trace-local.h                    |  1 +
 tracecmd/trace-tsync.c                            | 11 +++++++----
 6 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 458760e..a0dac5d 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -6,6 +6,7 @@
 #ifndef _TRACE_CMD_PRIVATE_H
 #define _TRACE_CMD_PRIVATE_H
 
+#include <sys/types.h>
 #include "traceevent/event-parse.h"
 #include "trace-cmd/trace-cmd.h"
 
diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h
index d0a7365..0cd2744 100644
--- a/lib/trace-cmd/include/trace-cmd-local.h
+++ b/lib/trace-cmd/include/trace-cmd-local.h
@@ -6,6 +6,7 @@
 #ifndef _TRACE_CMD_LOCAL_H
 #define _TRACE_CMD_LOCAL_H
 
+#include <byteswap.h>
 #include "trace-cmd-private.h"
 
 /* Can be overridden */
diff --git a/lib/tracefs/include/tracefs-local.h b/lib/tracefs/include/tracefs-local.h
index 9cc371b..bdbf89e 100644
--- a/lib/tracefs/include/tracefs-local.h
+++ b/lib/tracefs/include/tracefs-local.h
@@ -13,4 +13,16 @@ void warning(const char *fmt, ...);
 int str_read_file(const char *file, char **buffer);
 char *trace_append_file(const char *dir, const char *name);
 
+#ifndef ACCESSPERMS
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
+#endif
+
+#ifndef ALLPERMS
+#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
+#endif
+
+#ifndef DEFFILEMODE
+#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666*/
+#endif
+
 #endif /* _TRACE_FS_LOCAL_H */
diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c
index 80a25ee..a4e5215 100644
--- a/lib/tracefs/tracefs-events.c
+++ b/lib/tracefs/tracefs-events.c
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>
 
 #include "kbuffer.h"
 #include "tracefs.h"
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 28d1b4e..85c7e03 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -8,6 +8,7 @@
 
 #include <sys/types.h>
 #include <dirent.h>	/* for DIR */
+#include <limits.h>
 
 #include "trace-cmd-private.h"
 #include "event-utils.h"
diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c
index e639788..2cbe7f2 100644
--- a/tracecmd/trace-tsync.c
+++ b/tracecmd/trace-tsync.c
@@ -104,11 +104,13 @@ int tracecmd_host_tsync(struct buffer_instance *instance,
 
 	pthread_attr_init(&attrib);
 	pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
-	if (!get_first_cpu(&pin_mask, &mask_size))
-		pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
 
 	ret = pthread_create(&instance->tsync_thread, &attrib,
 			     tsync_host_thread, &instance->tsync);
+
+	if (!get_first_cpu(&pin_mask, &mask_size))
+		pthread_setaffinity_np(instance->tsync_thread, mask_size, pin_mask);
+
 	if (!ret)
 		instance->tsync_thread_running = true;
 	if (pin_mask)
@@ -243,11 +245,12 @@ unsigned int tracecmd_guest_tsync(char *tsync_protos,
 	pthread_attr_init(&attrib);
 	tsync->sync_proto = proto;
 	pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
-	if (!get_first_cpu(&pin_mask, &mask_size))
-		pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
 
 	ret = pthread_create(thr_id, &attrib, tsync_agent_thread, tsync);
 
+	if (!get_first_cpu(&pin_mask, &mask_size))
+		pthread_setaffinity_np(*thr_id, mask_size, pin_mask);
+
 	if (pin_mask)
 		CPU_FREE(pin_mask);
 	pthread_attr_destroy(&attrib);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] trace-cmd: make it build against musl C library
  2020-11-28 19:22 [PATCH] trace-cmd: make it build against musl C library Beniamin Sandu
@ 2020-11-30  8:13 ` Tzvetomir Stoyanov
  0 siblings, 0 replies; 4+ messages in thread
From: Tzvetomir Stoyanov @ 2020-11-30  8:13 UTC (permalink / raw)
  To: Beniamin Sandu; +Cc: Linux Trace Devel

On Sun, Nov 29, 2020 at 12:04 AM Beniamin Sandu <beniaminsandu@gmail.com> wrote:
>
> * add some missing headers and macros
> * set pthread affinity using pthread_setaffinity_np after creating the thread
> instead of pthread_attr_setaffinity_np (which seems to not be implemented
> in musl)
>
> Tested using https://musl.cc/x86_64-linux-musl-native.tgz
>
> Signed-off-by: Beniamin Sandu <beniaminsandu@gmail.com>

Hi Beniamin,
Thanks for testing trace-cmd with different build environments and
sending this patch.
I looked at the changes, they look good to me in general. I have two
small comments.

> ---
>  lib/trace-cmd/include/private/trace-cmd-private.h |  1 +
>  lib/trace-cmd/include/trace-cmd-local.h           |  1 +
>  lib/tracefs/include/tracefs-local.h               | 12 ++++++++++++
>  lib/tracefs/tracefs-events.c                      |  1 +
>  tracecmd/include/trace-local.h                    |  1 +
>  tracecmd/trace-tsync.c                            | 11 +++++++----
>  6 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
> index 458760e..a0dac5d 100644
> --- a/lib/trace-cmd/include/private/trace-cmd-private.h
> +++ b/lib/trace-cmd/include/private/trace-cmd-private.h
> @@ -6,6 +6,7 @@
>  #ifndef _TRACE_CMD_PRIVATE_H
>  #define _TRACE_CMD_PRIVATE_H
>
> +#include <sys/types.h>
>  #include "traceevent/event-parse.h"
>  #include "trace-cmd/trace-cmd.h"
>
> diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h
> index d0a7365..0cd2744 100644
> --- a/lib/trace-cmd/include/trace-cmd-local.h
> +++ b/lib/trace-cmd/include/trace-cmd-local.h
> @@ -6,6 +6,7 @@
>  #ifndef _TRACE_CMD_LOCAL_H
>  #define _TRACE_CMD_LOCAL_H
>
> +#include <byteswap.h>
>  #include "trace-cmd-private.h"
>
>  /* Can be overridden */
> diff --git a/lib/tracefs/include/tracefs-local.h b/lib/tracefs/include/tracefs-local.h
> index 9cc371b..bdbf89e 100644
> --- a/lib/tracefs/include/tracefs-local.h
> +++ b/lib/tracefs/include/tracefs-local.h
> @@ -13,4 +13,16 @@ void warning(const char *fmt, ...);
>  int str_read_file(const char *file, char **buffer);
>  char *trace_append_file(const char *dir, const char *name);
>
> +#ifndef ACCESSPERMS
> +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
> +#endif
> +
> +#ifndef ALLPERMS
> +#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
> +#endif
> +
> +#ifndef DEFFILEMODE
> +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666*/
> +#endif
> +
>  #endif /* _TRACE_FS_LOCAL_H */
> diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c
> index 80a25ee..a4e5215 100644
> --- a/lib/tracefs/tracefs-events.c
> +++ b/lib/tracefs/tracefs-events.c
> @@ -13,6 +13,7 @@
>  #include <errno.h>
>  #include <sys/stat.h>
>  #include <fcntl.h>
> +#include <limits.h>
>
>  #include "kbuffer.h"
>  #include "tracefs.h"
> diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
> index 28d1b4e..85c7e03 100644
> --- a/tracecmd/include/trace-local.h
> +++ b/tracecmd/include/trace-local.h
> @@ -8,6 +8,7 @@
>
>  #include <sys/types.h>
>  #include <dirent.h>    /* for DIR */
> +#include <limits.h>
>
>  #include "trace-cmd-private.h"
>  #include "event-utils.h"
> diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c
> index e639788..2cbe7f2 100644
> --- a/tracecmd/trace-tsync.c
> +++ b/tracecmd/trace-tsync.c
> @@ -104,11 +104,13 @@ int tracecmd_host_tsync(struct buffer_instance *instance,
>
>         pthread_attr_init(&attrib);
>         pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
> -       if (!get_first_cpu(&pin_mask, &mask_size))
> -               pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
>
>         ret = pthread_create(&instance->tsync_thread, &attrib,
>                              tsync_host_thread, &instance->tsync);
> +
> +       if (!get_first_cpu(&pin_mask, &mask_size))
> +               pthread_setaffinity_np(instance->tsync_thread, mask_size, pin_mask);
> +
The new affinity should be set only in case pthread_create() does not
return any error.
This new logic could be moved where the ret is checked for error.

>         if (!ret)
>                 instance->tsync_thread_running = true;
>         if (pin_mask)
> @@ -243,11 +245,12 @@ unsigned int tracecmd_guest_tsync(char *tsync_protos,
>         pthread_attr_init(&attrib);
>         tsync->sync_proto = proto;
>         pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
> -       if (!get_first_cpu(&pin_mask, &mask_size))
> -               pthread_attr_setaffinity_np(&attrib, mask_size, pin_mask);
>
>         ret = pthread_create(thr_id, &attrib, tsync_agent_thread, tsync);
>
> +       if (!get_first_cpu(&pin_mask, &mask_size))
> +               pthread_setaffinity_np(*thr_id, mask_size, pin_mask);
> +
The same here, the new affinity should not be set in case of
pthread_create() failure.

>         if (pin_mask)
>                 CPU_FREE(pin_mask);
>         pthread_attr_destroy(&attrib);
> --
> 2.25.1
>

--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] trace-cmd: make it build against musl C library
  2022-11-01 10:58 Peter Bergin
@ 2022-11-10  0:36 ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2022-11-10  0:36 UTC (permalink / raw)
  To: Peter Bergin; +Cc: linux-trace-devel

On Tue,  1 Nov 2022 11:58:03 +0100
Peter Bergin <peter@berginkonsult.se> wrote:

> Add missing header file to make it compile with musl C library.
> 
> Signed-off-by: Peter Bergin <peter@berginkonsult.se>

Applied. Thanks Peter!

-- Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] trace-cmd: make it build against musl C library
@ 2022-11-01 10:58 Peter Bergin
  2022-11-10  0:36 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Bergin @ 2022-11-01 10:58 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Peter Bergin

Add missing header file to make it compile with musl C library.

Signed-off-by: Peter Bergin <peter@berginkonsult.se>
---
 lib/trace-cmd/trace-timesync-kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/trace-cmd/trace-timesync-kvm.c b/lib/trace-cmd/trace-timesync-kvm.c
index aa1799b1..bbef8b60 100644
--- a/lib/trace-cmd/trace-timesync-kvm.c
+++ b/lib/trace-cmd/trace-timesync-kvm.c
@@ -10,6 +10,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <ctype.h>
+#include <limits.h>
 
 #include "trace-cmd.h"
 #include "trace-cmd-private.h"
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-10  0:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-28 19:22 [PATCH] trace-cmd: make it build against musl C library Beniamin Sandu
2020-11-30  8:13 ` Tzvetomir Stoyanov
2022-11-01 10:58 Peter Bergin
2022-11-10  0:36 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).