This is an automated email from the ASF dual-hosted git repository.

michallenc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 23e8014dd37fcd25c74647097353ba0c68e3abaa
Author: mazhuang <[email protected]>
AuthorDate: Mon Nov 2 19:14:17 2026 +0800

    drivers/rpmsg: filter the trace by endpoint name through /proc/rpmsg
    
    Tracing every message of every endpoint fills the note buffer quickly.
    Writing a pattern to /proc/rpmsg now restricts rpmsg_trace() to the
    endpoints whose name matches it (fnmatch() syntax). All endpoints are
    traced until a pattern is written, and "*" traces all of them again:
    
      echo "rpmsg-ping" > /proc/rpmsg
      echo "*" > /proc/rpmsg
    
    Signed-off-by: mazhuang <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_procfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++--
 drivers/rpmsg/rpmsg_procfs.h |  4 ++++
 drivers/rpmsg/rpmsg_trace.c  |  7 ++++++-
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_procfs.c b/drivers/rpmsg/rpmsg_procfs.c
index f7515dc12f9..49b7f2b6bbf 100644
--- a/drivers/rpmsg/rpmsg_procfs.c
+++ b/drivers/rpmsg/rpmsg_procfs.c
@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <string.h>
 #include <debug.h>
+#include <fnmatch.h>
 
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/procfs.h>
@@ -90,6 +91,8 @@ static int     rpmsg_procfs_dup(FAR const struct file *oldp,
                                 FAR struct file *newp);
 static int     rpmsg_procfs_stat(FAR const char *relpath,
                                  FAR struct stat *buf);
+static ssize_t rpmsg_procfs_write(FAR struct file *filep,
+                                  FAR const char *buffer, size_t buflen);
 
 /****************************************************************************
  * Private Data
@@ -100,7 +103,7 @@ static const struct procfs_operations g_rpmsg_procfs_ops =
   rpmsg_procfs_open,   /* open */
   rpmsg_procfs_close,  /* close */
   rpmsg_procfs_read,   /* read */
-  NULL,                /* write */
+  rpmsg_procfs_write,  /* write */
   NULL,                /* poll */
 
   rpmsg_procfs_dup,    /* dup */
@@ -118,6 +121,10 @@ static const struct procfs_entry_s g_rpmsg_procfs_root =
   "rpmsg", &g_rpmsg_procfs_ops, PROCFS_FILE_TYPE
 };
 
+/* Endpoint name pattern rpmsg_trace() records, empty to record all */
+
+static char g_rpmsg_procfs_filter[RPMSG_PROCFS_LINELEN];
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -190,7 +197,7 @@ static int rpmsg_procfs_dup(FAR const struct file *oldp,
 static int rpmsg_procfs_stat(FAR const char *relpath, FAR struct stat *buf)
 {
   memset(buf, 0, sizeof(struct stat));
-  buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
+  buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR;
   return OK;
 }
 
@@ -255,10 +262,45 @@ static ssize_t rpmsg_procfs_read(FAR struct file *filep, 
FAR char *buffer,
   return procinfo.totalsize;
 }
 
+/****************************************************************************
+ * Name: rpmsg_procfs_write
+ ****************************************************************************/
+
+static ssize_t rpmsg_procfs_write(FAR struct file *filep,
+                                  FAR const char *buffer, size_t buflen)
+{
+  size_t len = buflen;
+
+  if (buffer == NULL || len >= RPMSG_PROCFS_LINELEN)
+    {
+      return -EINVAL;
+    }
+
+  if (len > 0 && buffer[len - 1] == '\n')
+    {
+      len--;
+    }
+
+  memcpy(g_rpmsg_procfs_filter, buffer, len);
+  g_rpmsg_procfs_filter[len] = '\0';
+
+  return buflen;
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: rpmsg_procfs_trace_allow
+ ****************************************************************************/
+
+bool rpmsg_procfs_trace_allow(FAR const char *ept_name)
+{
+  return g_rpmsg_procfs_filter[0] == '\0' ||
+         fnmatch(g_rpmsg_procfs_filter, ept_name, 0) == 0;
+}
+
 /****************************************************************************
  * Name: rpmsg_procfs_initialize
  ****************************************************************************/
diff --git a/drivers/rpmsg/rpmsg_procfs.h b/drivers/rpmsg/rpmsg_procfs.h
index d663ecd7e79..941ad339999 100644
--- a/drivers/rpmsg/rpmsg_procfs.h
+++ b/drivers/rpmsg/rpmsg_procfs.h
@@ -29,6 +29,8 @@
 
 #include <nuttx/config.h>
 
+#include <stdbool.h>
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -39,7 +41,9 @@
 
 #ifdef CONFIG_RPMSG_PROCFS
 void rpmsg_procfs_initialize(void);
+bool rpmsg_procfs_trace_allow(FAR const char *ept_name);
 #else
 #  define rpmsg_procfs_initialize()
+#  define rpmsg_procfs_trace_allow(ept_name) true
 #endif /* CONFIG_RPMSG_PROCFS */
 #endif /* __DRIVERS_RPMSG_RPMSG_PROCFS_H */
diff --git a/drivers/rpmsg/rpmsg_trace.c b/drivers/rpmsg/rpmsg_trace.c
index f5e52a9fbbf..f48bdd8eba3 100644
--- a/drivers/rpmsg/rpmsg_trace.c
+++ b/drivers/rpmsg/rpmsg_trace.c
@@ -38,6 +38,8 @@
 #include <nuttx/streams.h>
 #include <nuttx/rpmsg/rpmsg.h>
 
+#include "rpmsg_procfs.h"
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -85,7 +87,10 @@ void rpmsg_vtrace(FAR const char *name, bool bt, FAR const 
void *buf,
 {
   irqstate_t flags;
 
-  UNUSED(name);
+  if (!rpmsg_procfs_trace_allow(name))
+    {
+      return;
+    }
 
 #if CONFIG_RPMSG_TRACE_BACKTRACE > 0
   if (bt)

Reply via email to