ramlog: support setting threshold value of ramlog for poll waiters

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-02-28 21:39:59 +08:00 committed by Xiang Xiao
parent ed49aa1906
commit a8866132c2
2 changed files with 22 additions and 5 deletions

View File

@ -61,6 +61,12 @@ config RAMLOG_OVERWRITE
Enable overwrite of circular buffer. If RAMLOG buffer overflows, Enable overwrite of circular buffer. If RAMLOG buffer overflows,
overwrite it from the top of buffer and always keep the latest log. overwrite it from the top of buffer and always keep the latest log.
config RAMLOG_POLLTHRESHOLD
int "The threshold value of circular buffer to notify poll waiters"
default 1
---help---
When the length of circular buffer exceeds the threshold value, the poll() will
return POLLIN to all poll waiters.
endif endif
config SYSLOG_BUFFER config SYSLOG_BUFFER

View File

@ -155,6 +155,16 @@ static struct ramlog_dev_s g_sysdev =
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: ramlog_bufferused
****************************************************************************/
static size_t ramlog_bufferused(FAR struct ramlog_dev_s *priv)
{
return (priv->rl_bufsize + priv->rl_head - priv->rl_tail) %
priv->rl_bufsize;
}
/**************************************************************************** /****************************************************************************
* Name: ramlog_readnotify * Name: ramlog_readnotify
****************************************************************************/ ****************************************************************************/
@ -408,7 +418,8 @@ static ssize_t ramlog_addbuf(FAR struct ramlog_dev_s *priv,
* operations a critical section. * operations a critical section.
*/ */
if (readers_waken == 0) if (readers_waken == 0 &&
ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
{ {
/* Notify all poll/select waiters that they can read from the /* Notify all poll/select waiters that they can read from the
* FIFO. * FIFO.
@ -633,8 +644,7 @@ static int ramlog_file_ioctl(FAR struct file *filep, int cmd,
switch (cmd) switch (cmd)
{ {
case FIONREAD: case FIONREAD:
*(FAR int *)((uintptr_t)arg) = (priv->rl_bufsize + priv->rl_head - *(FAR int *)((uintptr_t)arg) = ramlog_bufferused(priv);
priv->rl_tail) % priv->rl_bufsize;
break; break;
default: default:
ret = -ENOTTY; ret = -ENOTTY;
@ -723,7 +733,7 @@ static int ramlog_file_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Check if the receive buffer is not empty. */ /* Check if the receive buffer is not empty. */
if (priv->rl_head != priv->rl_tail) if (ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
{ {
eventset |= POLLIN; eventset |= POLLIN;
} }
@ -874,7 +884,8 @@ int ramlog_putc(FAR struct syslog_channel_s *channel, int ch)
* operations a critical section. * operations a critical section.
*/ */
if (readers_waken == 0) if (readers_waken == 0 &&
ramlog_bufferused(priv) >= CONFIG_RAMLOG_POLLTHRESHOLD)
{ {
/* Notify all poll/select waiters that they can read from the FIFO */ /* Notify all poll/select waiters that they can read from the FIFO */