linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 3/3] libtracefs: Add a pthread_mutex per instance
Date: Wed, 7 Apr 2021 16:21:26 -0400	[thread overview]
Message-ID: <20210407202126.1870994-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210407202126.1870994-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add a pthread_mutex per instance such that modifications being done on
specific instances do not interfere with each other. This also includes a
new "toplevel_lock" that is to be used when modifying the toplevel
instance.

Convert the filter_mutex over to the toplevel/instance locking.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs-local.h | 13 ++++++++-----
 src/tracefs-instance.c  |  5 +++++
 src/tracefs-tools.c     |  8 +++++---
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index 060de7e..6865611 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -15,13 +15,16 @@
 	do { if (!(1/!(cond))) { } } while (0)
 
 struct tracefs_instance {
-	char	*trace_dir;
-	char	*name;
-	int	flags;
-	int	ftrace_filter_fd;
-	int	ftrace_notrace_fd;
+	char			*trace_dir;
+	char			*name;
+	pthread_mutex_t		lock;
+	int			flags;
+	int			ftrace_filter_fd;
+	int			ftrace_notrace_fd;
 };
 
+extern pthread_mutex_t toplevel_lock;
+
 /* Can be overridden */
 void warning(const char *fmt, ...);
 
diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index 9f45624..599c3a7 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -15,6 +15,7 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <limits.h>
+#include <pthread.h>
 #include "tracefs.h"
 #include "tracefs-local.h"
 
@@ -43,6 +44,9 @@ static struct tracefs_instance *instance_alloc(const char *trace_dir, const char
 			goto error;
 	}
 
+	if (pthread_mutex_init(&instance->lock, NULL) < 0)
+		goto error;
+
 	instance->ftrace_filter_fd = -1;
 	instance->ftrace_notrace_fd = -1;
 
@@ -69,6 +73,7 @@ void tracefs_instance_free(struct tracefs_instance *instance)
 		return;
 	free(instance->trace_dir);
 	free(instance->name);
+	pthread_mutex_destroy(&instance->lock);
 	free(instance);
 }
 
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index b41806b..d48062c 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -19,6 +19,8 @@
 #include "tracefs.h"
 #include "tracefs-local.h"
 
+__hidden pthread_mutex_t toplevel_lock = PTHREAD_MUTEX_INITIALIZER;
+
 #define TRACE_CTRL		"tracing_on"
 #define TRACE_FILTER		"set_ftrace_filter"
 #define TRACE_NOTRACE		"set_ftrace_notrace"
@@ -27,7 +29,6 @@
 /* File descriptor for Top level set_ftrace_filter  */
 static int ftrace_filter_fd = -1;
 static int ftrace_notrace_fd = -1;
-static pthread_mutex_t filter_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static const char * const options_map[] = {
 	"unknown",
@@ -755,6 +756,7 @@ static int update_filter(const char *filter_path, int *fd,
 	bool reset = flags & TRACEFS_FL_RESET;
 	bool cont = flags & TRACEFS_FL_CONTINUE;
 	bool future = flags & TRACEFS_FL_FUTURE;
+	pthread_mutex_t *lock = instance ? &instance->lock : &toplevel_lock;
 	int open_flags;
 	int ret = 1;
 
@@ -764,7 +766,7 @@ static int update_filter(const char *filter_path, int *fd,
 		return 1;
 	}
 
-	pthread_mutex_lock(&filter_lock);
+	pthread_mutex_lock(lock);
 
 	/* RESET is only allowed if the file is not opened yet */
 	if (reset && *fd >= 0) {
@@ -839,7 +841,7 @@ static int update_filter(const char *filter_path, int *fd,
  out_free:
 	free_func_list(func_list);
  out:
-	pthread_mutex_unlock(&filter_lock);
+	pthread_mutex_unlock(lock);
 
 	return ret;
 }
-- 
2.29.2


  parent reply	other threads:[~2021-04-07 20:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 20:21 [PATCH 0/3] libtracefs: Update filtering functions Steven Rostedt
2021-04-07 20:21 ` [PATCH 1/3] libtracefs: Move most functionality into helper function for tracefs_function_filter() Steven Rostedt
2021-04-07 20:21 ` [PATCH 2/3] libtracefs: Add tracefs_function_notrace() API Steven Rostedt
2021-04-08  4:25   ` Tzvetomir Stoyanov
2021-04-08 12:53     ` Steven Rostedt
2021-04-07 20:21 ` Steven Rostedt [this message]
2021-04-07 20:30 ` [PATCH 0/3] libtracefs: Update filtering functions Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210407202126.1870994-4-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=sameeruddin.shaik8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).