This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6866bc9ec2984d78fec3b7f32b681dd78e5f2ea4 Author: xuxingliang <[email protected]> AuthorDate: Fri Jan 16 10:55:29 2026 +0800 drivers/syslog: add O_DIRECT mode support for direct up_nputs output When /dev/log is opened with O_DIRECT flag, writes bypass the syslog stream and call up_nputs() directly for lower-latency console output. This is useful for performance-critical logging scenarios where the overhead of syslog stream processing is undesirable. The write handler checks O_DIRECT in the open flags of the file: - O_DIRECT set: call up_nputs() directly (with CONFIG_ARCH_LOWPUTC) - O_DIRECT not set: use lib_syslograwstream (existing behavior) Backward compatibility is maintained - default behavior unchanged when O_DIRECT is not used. Signed-off-by: xuxingliang <[email protected]> --- drivers/syslog/syslog_chardev.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/syslog/syslog_chardev.c b/drivers/syslog/syslog_chardev.c index 977a7917726..1cdacd75619 100644 --- a/drivers/syslog/syslog_chardev.c +++ b/drivers/syslog/syslog_chardev.c @@ -33,11 +33,18 @@ #include <errno.h> #include <syslog.h> +#include <fcntl.h> + +#include <nuttx/arch.h> #include <nuttx/fs/fs.h> #include <nuttx/syslog/syslog.h> #include "syslog.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #ifdef CONFIG_SYSLOG_CHARDEV /**************************************************************************** @@ -78,11 +85,22 @@ static const struct file_operations g_syslog_fops = static ssize_t syslog_chardev_write(FAR struct file *filep, FAR const char *buffer, size_t len) { - struct lib_syslograwstream_s stream; + /* Check if opened with O_DIRECT - bypass syslog stream */ + +#ifdef CONFIG_ARCH_LOWPUTC + if (filep->f_oflags & O_DIRECT) + { + up_nputs(buffer, len); + } + else /* Default path: use syslog stream */ +#endif + { + struct lib_syslograwstream_s stream; - lib_syslograwstream_open(&stream); - lib_stream_puts(&stream.common, buffer, len); - lib_syslograwstream_close(&stream); + lib_syslograwstream_open(&stream); + lib_stream_puts(&stream.common, buffer, len); + lib_syslograwstream_close(&stream); + } return len; }
