From: Peter Xu <peterx@redhat.com>
To: linux-rt-users@vger.kernel.org
Cc: Luiz Capitulino <lcapitulino@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
peterx@redhat.com, Andrew Theurer <atheurer@redhat.com>,
John Kacur <jkacur@redhat.com>,
Clark Williams <williams@redhat.com>
Subject: [PATCH 1/2] rt-tests: cyclictest: Move ftrace helpers into rt-utils.[ch]
Date: Mon, 17 Aug 2020 17:55:04 -0400 [thread overview]
Message-ID: <20200817215505.227046-2-peterx@redhat.com> (raw)
In-Reply-To: <20200817215505.227046-1-peterx@redhat.com>
Then they can be further used by other programs too.
Two trivial things to mention.
Firstly, move trace_marker out of enable_trace_mark(). No functional change.
Secondly, remove the fileprefix setting in process_options(), because if
tracelimit is non-zero, fileprefix will be after all replaced by a further call
to get_debugfileprefix() in debugfs_prepare().
Signed-off-by: Peter Xu <peterx@redhat.com>
---
src/cyclictest/cyclictest.c | 90 +------------------------------------
src/include/rt-utils.h | 3 ++
src/lib/rt-utils.c | 82 +++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 89 deletions(-)
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index eb61be3..dd41893 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -219,8 +219,6 @@ static pthread_barrier_t align_barr;
static pthread_barrier_t globalt_barr;
static struct timespec globalt;
-static char *procfileprefix = "/proc/sys/kernel/";
-static char *fileprefix;
static char fifopath[MAX_PATH];
static char histfile[MAX_PATH];
@@ -330,89 +328,6 @@ static inline int64_t calctime(struct timespec t)
return time;
}
-static int trace_file_exists(char *name)
-{
- struct stat sbuf;
- char *tracing_prefix = get_debugfileprefix();
- char path[MAX_PATH];
- strcat(strcpy(path, tracing_prefix), name);
- return stat(path, &sbuf) ? 0 : 1;
-}
-
-#define TRACEBUFSIZ 1024
-static __thread char tracebuf[TRACEBUFSIZ];
-
-static void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
-static void tracemark(char *fmt, ...)
-{
- va_list ap;
- int len;
-
- /* bail out if we're not tracing */
- /* or if the kernel doesn't support trace_mark */
- if (tracemark_fd < 0 || trace_fd < 0)
- return;
-
- va_start(ap, fmt);
- len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap);
- va_end(ap);
-
- /* write the tracemark message */
- write(tracemark_fd, tracebuf, len);
-
- /* now stop any trace */
- write(trace_fd, "0\n", 2);
-}
-
-static void open_tracemark_fd(void)
-{
- char path[MAX_PATH];
-
- /*
- * open the tracemark file if it's not already open
- */
- if (tracemark_fd < 0) {
- sprintf(path, "%s/%s", fileprefix, "trace_marker");
- tracemark_fd = open(path, O_WRONLY);
- if (tracemark_fd < 0) {
- warn("unable to open trace_marker file: %s\n", path);
- return;
- }
- }
-
- /*
- * if we're not tracing and the tracing_on fd is not open,
- * open the tracing_on file so that we can stop the trace
- * if we hit a breaktrace threshold
- */
- if (trace_fd < 0) {
- sprintf(path, "%s/%s", fileprefix, "tracing_on");
- if ((trace_fd = open(path, O_WRONLY)) < 0)
- warn("unable to open tracing_on file: %s\n", path);
- }
-}
-
-static void debugfs_prepare(void)
-{
- if (mount_debugfs(NULL))
- fatal("could not mount debugfs");
-
- fileprefix = get_debugfileprefix();
- if (!trace_file_exists("tracing_enabled") &&
- !trace_file_exists("tracing_on"))
- warn("tracing_enabled or tracing_on not found\n"
- "debug fs not mounted");
-}
-
-static void enable_trace_mark(void)
-{
- if (!trace_marker)
- return;
-
- debugfs_prepare();
- open_tracemark_fd();
-}
-
/*
* Raise the soft priority limit up to prio, if that is less than or equal
* to the hard limit
@@ -1498,9 +1413,6 @@ static void process_options (int argc, char *argv[], int max_cpus)
"on this processor\n");
}
- if (tracelimit)
- fileprefix = procfileprefix;
-
if (clocksel < 0 || clocksel > ARRAY_SIZE(clocksources))
error = 1;
@@ -2065,7 +1977,7 @@ int main(int argc, char **argv)
/* use the /dev/cpu_dma_latency trick if it's there */
set_latency_target();
- if (tracelimit)
+ if (tracelimit && trace_marker)
enable_trace_mark();
if (check_timer())
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index 6ec2b20..51489b4 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -27,4 +27,7 @@ pid_t gettid(void);
int parse_time_string(char *val);
+void enable_trace_mark(void);
+void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+
#endif /* __RT_UTILS.H */
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 1998a32..f786588 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -24,7 +24,13 @@
#include "rt-sched.h"
#include "error.h"
+#define TRACEBUFSIZ 1024
+
static char debugfileprefix[MAX_PATH];
+static char *fileprefix;
+static int trace_fd = -1;
+static int tracemark_fd = -1;
+static __thread char tracebuf[TRACEBUFSIZ];
/*
* Finds the tracing directory in a mounted debugfs
@@ -355,3 +361,79 @@ int parse_time_string(char *val)
}
return t;
}
+
+void open_tracemark_fd(void)
+{
+ char path[MAX_PATH];
+
+ /*
+ * open the tracemark file if it's not already open
+ */
+ if (tracemark_fd < 0) {
+ sprintf(path, "%s/%s", fileprefix, "trace_marker");
+ tracemark_fd = open(path, O_WRONLY);
+ if (tracemark_fd < 0) {
+ warn("unable to open trace_marker file: %s\n", path);
+ return;
+ }
+ }
+
+ /*
+ * if we're not tracing and the tracing_on fd is not open,
+ * open the tracing_on file so that we can stop the trace
+ * if we hit a breaktrace threshold
+ */
+ if (trace_fd < 0) {
+ sprintf(path, "%s/%s", fileprefix, "tracing_on");
+ if ((trace_fd = open(path, O_WRONLY)) < 0)
+ warn("unable to open tracing_on file: %s\n", path);
+ }
+}
+
+int trace_file_exists(char *name)
+{
+ struct stat sbuf;
+ char *tracing_prefix = get_debugfileprefix();
+ char path[MAX_PATH];
+ strcat(strcpy(path, tracing_prefix), name);
+ return stat(path, &sbuf) ? 0 : 1;
+}
+
+void debugfs_prepare(void)
+{
+ if (mount_debugfs(NULL))
+ fatal("could not mount debugfs");
+
+ fileprefix = get_debugfileprefix();
+ if (!trace_file_exists("tracing_enabled") &&
+ !trace_file_exists("tracing_on"))
+ warn("tracing_enabled or tracing_on not found\n"
+ "debug fs not mounted");
+}
+
+void tracemark(char *fmt, ...)
+{
+ va_list ap;
+ int len;
+
+ /* bail out if we're not tracing */
+ /* or if the kernel doesn't support trace_mark */
+ if (tracemark_fd < 0 || trace_fd < 0)
+ return;
+
+ va_start(ap, fmt);
+ len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap);
+ va_end(ap);
+
+ /* write the tracemark message */
+ write(tracemark_fd, tracebuf, len);
+
+ /* now stop any trace */
+ write(trace_fd, "0\n", 2);
+}
+
+void enable_trace_mark(void)
+{
+ debugfs_prepare();
+ open_tracemark_fd();
+}
--
2.26.2
next prev parent reply other threads:[~2020-08-17 21:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 21:55 [PATCH 0/2] rt-tests: Port oslat in Peter Xu
2020-08-17 21:55 ` Peter Xu [this message]
2020-08-18 20:51 ` [PATCH 1/2] rt-tests: cyclictest: Move ftrace helpers into rt-utils.[ch] John Kacur
2020-08-17 21:55 ` [PATCH 2/2] rt-tests: oslat: Init commit Peter Xu
2020-08-18 20:54 ` John Kacur
2020-08-19 18:58 ` John Kacur
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=20200817215505.227046-2-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=atheurer@redhat.com \
--cc=jkacur@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=williams@redhat.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