sysprog21/simrupt

The function annotation description in the simrupt.c file seems to be wrong.

Closed this issue · 1 comments

The comment in the produce_data function mentions "skip oldest element if kfifo buffer is full".

static void produce_data(unsigned char val)
{
    /* Implement a kind of circular FIFO here (skip oldest element if kfifo
     * buffer is full).
     */
    unsigned int len = kfifo_in(&rx_fifo, &val, sizeof(val));
    if (unlikely(len < sizeof(val)) && printk_ratelimit())
        pr_warn("%s: %zu bytes dropped\n", __func__, sizeof(val) - len);

    pr_debug("simrupt: %s: in %u/%u bytes\n", __func__, len,
             kfifo_len(&rx_fifo));
}

But in fact, it seems that when the buffer is full, it will choose not to insert new data, because the implementation of kfifo_in will first confirm whether the size to be put is greater than the remaining size. If it is, the remaining size will be the main one.

[ref: https://elixir.bootlin.com/linux/latest/source/lib/kfifo.c#L113]

unsigned int __kfifo_in(struct __kfifo *fifo,
                        const void *buf, unsigned int len)
{
    unsigned int l;

    l = kfifo_unused(fifo);
    if (len > l)
        len = l;

    kfifo_copy_in(fifo, buf, len, fifo->in);
    fifo->in += len;
    return len;
}
jserv commented

Refine the subject of this issue to make it more informative. In addition, you should provide some code snippets to emphasize the case you are concerned about.