From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Vincent Donnefort <vdonnefort@google.com>,
"Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 6/7] libtracefs: Add tracefs_mapped_is_supported() API
Date: Tue, 9 Jan 2024 21:51:50 -0500 [thread overview]
Message-ID: <20240110030116.81837-7-rostedt@goodmis.org> (raw)
In-Reply-To: <20240110030116.81837-1-rostedt@goodmis.org>
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Add tracefs_mapped_is_supported() which returns true if tracefs mapping is
supported and false if it is not or an error occurred.
This is useful so that an application can decide to do things differently if
mapping is supported or not.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Documentation/libtracefs-cpu-map.txt | 9 ++++++++-
Documentation/libtracefs.txt | 1 +
include/tracefs.h | 1 +
src/tracefs-record.c | 19 +++++++++++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/Documentation/libtracefs-cpu-map.txt b/Documentation/libtracefs-cpu-map.txt
index ed62c96f83a1..d961123b55a8 100644
--- a/Documentation/libtracefs-cpu-map.txt
+++ b/Documentation/libtracefs-cpu-map.txt
@@ -3,7 +3,7 @@ libtracefs(3)
NAME
----
-tracefs_cpu_open_mapped, tracefs_cpu_is_mapped, tracefs_cpu_map, tracefs_cpu_unmap - Memory mapping of the ring buffer
+tracefs_cpu_open_mapped, tracefs_cpu_is_mapped, tracefs_mapped_is_supported, tracefs_cpu_map, tracefs_cpu_unmap - Memory mapping of the ring buffer
SYNOPSIS
--------
@@ -12,6 +12,7 @@ SYNOPSIS
*#include <tracefs.h>*
bool *tracefs_cpu_is_mapped*(struct tracefs_cpu pass:[*]tcpu);
+bool *tracefs_mapped_is_supported*(void);
int *tracefs_cpu_map*(struct tracefs_cpu pass:[*]tcpu);
void *tracefs_cpu_unmap*(struct tracefs_cpu pass:[*]tcpu);
struct tracefs_cpu pass:[*]*tracefs_cpu_open_mapped*(struct tracefs_instance pass:[*]instance,
@@ -45,6 +46,9 @@ its ring buffer memory mapped and false otherwise. This does not return whether
not that the kernel supports memory mapping, but that can usually be determined
by calling *tracefs_cpu_map()*.
+The *tracefs_mapped_is_supported()* returns true if the ring buffer can be
+memory mapped.
+
The *tracefs_cpu_map()* function will attempt to map the ring buffer associated
to _tcpu_ if it is not already mapped.
@@ -62,6 +66,9 @@ RETURN VALUE
*tracefs_cpu_is_mapped()* returns true if the given _tcpu_ has its ring buffer
memory mapped or false otherwise.
+*tracefs_mapped_is_supported()* returns true if the tracing ring buffer can be
+memory mapped or false if it cannot be or an error occurred.
+
*tracefs_cpu_map()* returns 0 on success and -1 on error in mapping. If 0 is
returned then *tracefs_cpu_is_mapped()* will return true afterward, or false
if the mapping failed.
diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt
index 9c3cc3ea3c06..860e2be7d96a 100644
--- a/Documentation/libtracefs.txt
+++ b/Documentation/libtracefs.txt
@@ -148,6 +148,7 @@ Trace stream:
Memory mapping the ring buffer:
bool *tracefs_cpu_is_mapped*(struct tracefs_cpu pass:[*]tcpu);
+ bool *tracefs_mapped_is_supported*(void);
int *tracefs_cpu_map*(struct tracefs_cpu pass:[*]tcpu);
void *tracefs_cpu_unmap*(struct tracefs_cpu pass:[*]tcpu);
struct tracefs_cpu pass:[*]*tracefs_cpu_open_mapped*(struct tracefs_instance pass:[*]instance,
diff --git a/include/tracefs.h b/include/tracefs.h
index 8569171247b7..b6e0f6b3c851 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -695,6 +695,7 @@ int tracefs_snapshot_free(struct tracefs_instance *instance);
/* Memory mapping of ring buffer */
bool tracefs_cpu_is_mapped(struct tracefs_cpu *tcpu);
+bool tracefs_mapped_is_supported(void);
int tracefs_cpu_map(struct tracefs_cpu *tcpu);
void tracefs_cpu_unmap(struct tracefs_cpu *tcpu);
struct tracefs_cpu *tracefs_cpu_open_mapped(struct tracefs_instance *instance,
diff --git a/src/tracefs-record.c b/src/tracefs-record.c
index 59260da0e32c..932e8b44775b 100644
--- a/src/tracefs-record.c
+++ b/src/tracefs-record.c
@@ -317,6 +317,25 @@ bool tracefs_cpu_is_mapped(struct tracefs_cpu *tcpu)
return tcpu->mapping != NULL;
}
+/**
+ * tracefs_mapped_is_supported - find out if memory mapping is supported
+ *
+ * Return true if the ring buffer can be memory mapped, or false on
+ * error or it cannot be.
+ */
+bool tracefs_mapped_is_supported(void)
+{
+ struct tracefs_cpu *tcpu;
+ bool ret;
+
+ tcpu = tracefs_cpu_open_mapped(NULL, 0, false);
+ if (!tcpu)
+ return false;
+ ret = tracefs_cpu_is_mapped(tcpu);
+ tracefs_cpu_close(tcpu);
+ return ret;
+}
+
int tracefs_cpu_map(struct tracefs_cpu *tcpu)
{
if (tcpu->mapping)
--
2.43.0
next prev parent reply other threads:[~2024-01-10 3:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-10 2:51 [PATCH 0/7] libtracefs: More fixes for memory mapping ring buffer API Steven Rostedt
2024-01-10 2:51 ` [PATCH 1/7] libtracefs: Have mapping work with the other tracefs_cpu* functions Steven Rostedt
2024-01-10 2:51 ` [PATCH 2/7] libtracefs: Have tracefs_mmap_read() include subbuf meta data Steven Rostedt
2024-01-10 2:51 ` [PATCH 3/7] libtracefs: Have nonblock tracefs_cpu reads set errno EAGAIN Steven Rostedt
2024-01-10 2:51 ` [PATCH 4/7] libtracefs: Fix tracefs_mmap() kbuf usage Steven Rostedt
2024-01-10 2:51 ` [PATCH 5/7] libtracefs: Call mmap ioctl if a refresh happens Steven Rostedt
2024-01-10 2:51 ` Steven Rostedt [this message]
2024-01-10 2:51 ` [PATCH 7/7] libtracefs utest: Add tests to use mapping if supported 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=20240110030116.81837-7-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=vdonnefort@google.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).