You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/03 16:24:28 UTC

[incubator-nuttx] branch master updated (707404d -> 817259e)

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

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 707404d  rx65n: Add missing parameters in printf
     new b30bf4f  syslog/default_channel: fix log confusion when multi task writing together
     new 7fa69e4  syslog/ramlog: get ramlog size by ioctl
     new 817259e  syslog/ramlog_channel: fix log confusion when multi task writing together

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/syslog/ramlog.c         | 235 +++++++++++++++++++++++++---------------
 drivers/syslog/syslog_channel.c |  34 +++++-
 include/nuttx/syslog/ramlog.h   |  13 +++
 3 files changed, 189 insertions(+), 93 deletions(-)

[incubator-nuttx] 02/03: syslog/ramlog: get ramlog size by ioctl

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7fa69e417317f2d82fc64ac8d14140d86942298d
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Mon Apr 19 21:53:25 2021 +0800

    syslog/ramlog: get ramlog size by ioctl
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/syslog/ramlog.c | 57 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 9 deletions(-)

diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c
index 7ca5358..df65b4d 100644
--- a/drivers/syslog/ramlog.c
+++ b/drivers/syslog/ramlog.c
@@ -43,6 +43,7 @@
 #include <nuttx/kmalloc.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
 #include <nuttx/syslog/ramlog.h>
 #include <nuttx/compiler.h>
 
@@ -57,16 +58,16 @@
 struct ramlog_dev_s
 {
 #ifndef CONFIG_RAMLOG_NONBLOCKING
-  volatile uint8_t  rl_nwaiters;     /* Number of threads waiting for data */
+  volatile uint8_t  rl_nwaiters; /* Number of threads waiting for data */
 #endif
-  volatile uint16_t rl_head;         /* The head index (where data is added) */
-  volatile uint16_t rl_tail;         /* The tail index (where data is removed) */
-  sem_t             rl_exclsem;      /* Enforces mutually exclusive access */
+  volatile size_t   rl_head;     /* The head index (where data is added) */
+  volatile size_t   rl_tail;     /* The tail index (where data is removed) */
+  sem_t             rl_exclsem;  /* Enforces mutually exclusive access */
 #ifndef CONFIG_RAMLOG_NONBLOCKING
-  sem_t             rl_waitsem;      /* Used to wait for data */
+  sem_t             rl_waitsem;  /* Used to wait for data */
 #endif
-  size_t            rl_bufsize;      /* Size of the RAM buffer */
-  FAR char         *rl_buffer;       /* Circular RAM buffer */
+  size_t            rl_bufsize;  /* Size of the RAM buffer */
+  FAR char         *rl_buffer;   /* Circular RAM buffer */
 
   /* The following is a list if poll structures of threads waiting for
    * driver events. The 'struct pollfd' reference for each open is also
@@ -95,6 +96,8 @@ static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer,
                            size_t buflen);
 static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer,
                             size_t buflen);
+static int     ramlog_ioctl(FAR struct file *filep, int cmd,
+                            unsigned long arg);
 static int     ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds,
                            bool setup);
 
@@ -109,7 +112,7 @@ static const struct file_operations g_ramlogfops =
   ramlog_read,  /* read */
   ramlog_write, /* write */
   NULL,         /* seek */
-  NULL,         /* ioctl */
+  ramlog_ioctl, /* ioctl */
   ramlog_poll   /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   , NULL        /* unlink */
@@ -535,10 +538,46 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer,
 }
 
 /****************************************************************************
+ * Name: ramlog_ioctl
+ ****************************************************************************/
+
+static int ramlog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct ramlog_dev_s *priv;
+  int ret;
+
+  DEBUGASSERT(inode && inode->i_private);
+  priv = (FAR struct ramlog_dev_s *)inode->i_private;
+
+  ret = nxsem_wait(&priv->rl_exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  switch (cmd)
+    {
+      case FIONREAD:
+        *(FAR int *)((uintptr_t)arg) = (priv->rl_bufsize + priv->rl_head -
+                                        priv->rl_tail) % priv->rl_bufsize;
+        break;
+      default:
+        ret = -ENOTTY;
+        break;
+    }
+
+  nxsem_post(&priv->rl_exclsem);
+
+  return ret;
+}
+
+/****************************************************************************
  * Name: ramlog_poll
  ****************************************************************************/
 
-int ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
+static int ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                       bool setup)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct ramlog_dev_s *priv;

[incubator-nuttx] 03/03: syslog/ramlog_channel: fix log confusion when multi task writing together

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 817259ec2d454a2974b39ad16dc48138dae35931
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jun 17 17:00:47 2021 +0800

    syslog/ramlog_channel: fix log confusion when multi task writing together
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/syslog/ramlog.c         | 212 ++++++++++++++++++++++------------------
 drivers/syslog/syslog_channel.c |   4 +-
 include/nuttx/syslog/ramlog.h   |  13 +++
 3 files changed, 131 insertions(+), 98 deletions(-)

diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c
index df65b4d..e183900 100644
--- a/drivers/syslog/ramlog.c
+++ b/drivers/syslog/ramlog.c
@@ -92,14 +92,14 @@ static int     ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch);
 
 /* Character driver methods */
 
-static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer,
-                           size_t buflen);
-static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer,
-                            size_t buflen);
-static int     ramlog_ioctl(FAR struct file *filep, int cmd,
-                            unsigned long arg);
-static int     ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds,
-                           bool setup);
+static ssize_t ramlog_file_read(FAR struct file *filep, FAR char *buffer,
+                                size_t buflen);
+static ssize_t ramlog_file_write(FAR struct file *filep,
+                                 FAR const char *buffer, size_t buflen);
+static int     ramlog_file_ioctl(FAR struct file *filep, int cmd,
+                                 unsigned long arg);
+static int     ramlog_file_poll(FAR struct file *filep,
+                                FAR struct pollfd *fds, bool setup);
 
 /****************************************************************************
  * Private Data
@@ -107,15 +107,15 @@ static int     ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds,
 
 static const struct file_operations g_ramlogfops =
 {
-  NULL,         /* open */
-  NULL,         /* close */
-  ramlog_read,  /* read */
-  ramlog_write, /* write */
-  NULL,         /* seek */
-  ramlog_ioctl, /* ioctl */
-  ramlog_poll   /* poll */
+  NULL,              /* open */
+  NULL,              /* close */
+  ramlog_file_read,  /* read */
+  ramlog_file_write, /* write */
+  NULL,              /* seek */
+  ramlog_file_ioctl, /* ioctl */
+  ramlog_file_poll   /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
-  , NULL        /* unlink */
+  , NULL             /* unlink */
 #endif
 };
 
@@ -287,11 +287,88 @@ again:
 }
 
 /****************************************************************************
+ * Name: ramlog_addbuf
+ ****************************************************************************/
+
+static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
+                             FAR const char *buffer, size_t len)
+{
+  int readers_waken;
+  ssize_t nwritten;
+  char ch;
+  int ret;
+
+  ret = nxsem_wait(&priv->rl_exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  for (nwritten = 0; (size_t)nwritten < len; nwritten++)
+    {
+      /* Get the next character to output */
+
+      ch = buffer[nwritten];
+
+      /* Then output the character */
+
+      ret = ramlog_addchar(priv, ch);
+      if (ret < 0)
+        {
+          /* The buffer is full and nothing was saved.  The remaining
+           * data to be written is dropped on the floor.
+           */
+
+          break;
+        }
+    }
+
+  /* Was anything written? */
+
+  if (nwritten > 0)
+    {
+      readers_waken = 0;
+
+#ifndef CONFIG_RAMLOG_NONBLOCKING
+      /* Are there threads waiting for read data? */
+
+      readers_waken = ramlog_readnotify(priv);
+#endif
+
+      /* If there are multiple readers, some of them might block despite
+       * POLLIN because first reader might read all data. Favor readers
+       * and notify poll waiters only if no reader was awaken, even if the
+       * latter may starve.
+       *
+       * This also implies we do not have to make these two notify
+       * operations a critical section.
+       */
+
+      if (readers_waken == 0)
+        {
+          /* Notify all poll/select waiters that they can read from the
+           * FIFO.
+           */
+
+          ramlog_pollnotify(priv, POLLIN);
+        }
+    }
+
+  /* We always have to return the number of bytes requested and NOT the
+   * number of bytes that were actually written.  Otherwise, callers
+   * probably retry, causing same error condition again.
+   */
+
+  nxsem_post(&priv->rl_exclsem);
+  return len;
+}
+
+/****************************************************************************
  * Name: ramlog_read
  ****************************************************************************/
 
-static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer,
-                           size_t len)
+static ssize_t ramlog_file_read(FAR struct file *filep, FAR char *buffer,
+                                size_t len)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct ramlog_dev_s *priv;
@@ -354,8 +431,8 @@ static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer,
 
           /* Otherwise, wait for something to be written to the circular
            * buffer. Increment the number of waiters so that the
-           * ramlog_write() will note that it needs to post the semaphore
-           * to wake us up.
+           * ramlog_file_write() will note that it needs to post the
+           * semaphore to wake us up.
            */
 
           sched_lock();
@@ -452,96 +529,29 @@ errout_without_sem:
 }
 
 /****************************************************************************
- * Name: ramlog_write
+ * Name: ramlog_file_write
  ****************************************************************************/
 
-static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer,
-                            size_t len)
+static ssize_t ramlog_file_write(FAR struct file *filep,
+                                 FAR const char *buffer, size_t len)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct ramlog_dev_s *priv;
-  int readers_waken;
-  ssize_t nwritten;
-  char ch;
-  int ret;
 
   /* Some sanity checking */
 
   DEBUGASSERT(inode && inode->i_private);
   priv = (FAR struct ramlog_dev_s *)inode->i_private;
 
-  /* Loop until all of the bytes have been written.  This function may be
-   * called from an interrupt handler!  Semaphores cannot be used!
-   *
-   * The write logic only needs to modify the rl_head index.  Therefore,
-   * there is a difference in the way that rl_head and rl_tail are protected:
-   * rl_tail is protected with a semaphore; rl_head is protected by disabling
-   * interrupts.
-   */
-
-  for (nwritten = 0; (size_t)nwritten < len; nwritten++)
-    {
-      /* Get the next character to output */
-
-      ch = buffer[nwritten];
-
-      /* Then output the character */
-
-      ret = ramlog_addchar(priv, ch);
-      if (ret < 0)
-        {
-          /* The buffer is full and nothing was saved.  The remaining
-           * data to be written is dropped on the floor.
-           */
-
-          break;
-        }
-    }
-
-  /* Was anything written? */
-
-  if (nwritten > 0)
-    {
-      readers_waken = 0;
-
-#ifndef CONFIG_RAMLOG_NONBLOCKING
-      /* Are there threads waiting for read data? */
-
-      readers_waken = ramlog_readnotify(priv);
-#endif
-
-      /* If there are multiple readers, some of them might block despite
-       * POLLIN because first reader might read all data. Favor readers
-       * and notify poll waiters only if no reader was awaken, even if the
-       * latter may starve.
-       *
-       * This also implies we do not have to make these two notify
-       * operations a critical section.
-       */
-
-      if (readers_waken == 0)
-        {
-          /* Notify all poll/select waiters that they can read from the
-           * FIFO.
-           */
-
-          ramlog_pollnotify(priv, POLLIN);
-        }
-    }
-
-  /* We always have to return the number of bytes requested and NOT the
-   * number of bytes that were actually written.  Otherwise, callers
-   * probably retry, causing same error condition again.
-   */
-
-  return len;
+  return ramlog_addbuf(priv, buffer, len);
 }
 
 /****************************************************************************
- * Name: ramlog_ioctl
+ * Name: ramlog_file_ioctl
  ****************************************************************************/
 
-static int ramlog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+static int ramlog_file_ioctl(FAR struct file *filep, int cmd,
+                             unsigned long arg)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct ramlog_dev_s *priv;
@@ -573,11 +583,11 @@ static int ramlog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
 }
 
 /****************************************************************************
- * Name: ramlog_poll
+ * Name: ramlog_file_poll
  ****************************************************************************/
 
-static int ramlog_poll(FAR struct file *filep, FAR struct pollfd *fds,
-                       bool setup)
+static int ramlog_file_poll(FAR struct file *filep, FAR struct pollfd *fds,
+                            bool setup)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct ramlog_dev_s *priv;
@@ -868,6 +878,14 @@ int ramlog_putc(FAR struct syslog_channel_s *channel, int ch)
 
   return ch;
 }
+
+ssize_t ramlog_write(FAR struct syslog_channel_s *channel,
+                     FAR const char *buffer, size_t buflen)
+{
+  FAR struct ramlog_dev_s *priv = &g_sysdev;
+
+  return ramlog_addbuf(priv, buffer, buflen);
+}
 #endif
 
 #endif /* CONFIG_RAMLOG */
diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c
index 2357993..c05c4ba 100644
--- a/drivers/syslog/syslog_channel.c
+++ b/drivers/syslog/syslog_channel.c
@@ -68,7 +68,9 @@ static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
 static const struct syslog_channel_ops_s g_ramlog_channel_ops =
 {
   ramlog_putc,
-  ramlog_putc
+  ramlog_putc,
+  NULL,
+  ramlog_write
 };
 
 static struct syslog_channel_s g_ramlog_channel =
diff --git a/include/nuttx/syslog/ramlog.h b/include/nuttx/syslog/ramlog.h
index 0d13010..a71f02e 100644
--- a/include/nuttx/syslog/ramlog.h
+++ b/include/nuttx/syslog/ramlog.h
@@ -140,6 +140,19 @@ void ramlog_syslog_register(void);
 int ramlog_putc(FAR struct syslog_channel_s *channel, int ch);
 #endif
 
+/****************************************************************************
+ * Name: ramlog_write
+ *
+ * Description:
+ *   This is the low-level system logging interface.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RAMLOG_SYSLOG
+ssize_t ramlog_write(FAR struct syslog_channel_s *channel,
+                     FAR const char *buffer, size_t buflen);
+#endif
+
 #undef EXTERN
 #ifdef __cplusplus
 }

[incubator-nuttx] 01/03: syslog/default_channel: fix log confusion when multi task writing together

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b30bf4ff064b3ef20f0ed131d701f4db408492cb
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jun 10 22:05:58 2021 +0800

    syslog/default_channel: fix log confusion when multi task writing together
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/syslog/syslog_channel.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c
index 2cedae2..2357993 100644
--- a/drivers/syslog/syslog_channel.c
+++ b/drivers/syslog/syslog_channel.c
@@ -56,10 +56,12 @@
 #if defined(CONFIG_SYSLOG_DEFAULT)
 static int syslog_default_putc(FAR struct syslog_channel_s *channel,
                                int ch);
+static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
+                                    FAR const char *buffer, size_t buflen);
 #endif
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
 #if defined(CONFIG_RAMLOG_SYSLOG)
@@ -91,10 +93,14 @@ static struct syslog_channel_s g_rpmsg_channel =
 #endif
 
 #if defined(CONFIG_SYSLOG_DEFAULT)
+static sem_t g_syslog_default_sem = SEM_INITIALIZER(1);
+
 static const struct syslog_channel_ops_s g_default_channel_ops =
 {
   syslog_default_putc,
-  syslog_default_putc
+  syslog_default_putc,
+  NULL,
+  syslog_default_write
 };
 
 static struct syslog_channel_s g_default_channel =
@@ -126,7 +132,7 @@ FAR struct syslog_channel_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: syslog_default_putc and syslog_default_flush
+ * Name: syslog_default_putc
  *
  * Description:
  *   If the arch supports a low-level putc function, output will be
@@ -145,6 +151,24 @@ static int syslog_default_putc(FAR struct syslog_channel_s *channel, int ch)
 
   return ch;
 }
+
+static ssize_t syslog_default_write(FAR struct syslog_channel_s *channel,
+                                    FAR const char *buffer, size_t buflen)
+{
+#if defined(CONFIG_ARCH_LOWPUTC)
+  size_t nwritten;
+
+  nxsem_wait(&g_syslog_default_sem);
+  for (nwritten = 0; nwritten < buflen; nwritten++)
+    {
+      up_putc(buffer[nwritten]);
+    }
+
+  nxsem_post(&g_syslog_default_sem);
+#endif
+
+  return OK;
+}
 #endif
 
 /****************************************************************************