Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation

From: Sergey Senozhatsky
Date: Tue Jun 18 2019 - 01:01:46 EST


Hello John,

On (06/07/19 18:29), John Ogness wrote:
[..]
> + struct prb_reserved_entry e;
> + char *s;
> +
> + s = prb_reserve(&e, &rb, 32);
> + if (s) {
> + sprintf(s, "Hello, world!");
> + prb_commit(&e);
> + }

A nit: snprintf().

sprintf() is tricky, it may write "slightly more than was
anticipated" bytes - all those string_nocheck(" disabled"),
error_string("pK-error"), etc.

[..]
> +Sample reader code::
> +
> + DECLARE_PRINTKRB_ENTRY(entry, 128);
> + DECLARE_PRINTKRB_ITER(iter, &test_rb, &entry);
> + u64 last_seq = 0;
> + int len;
> + char *s;
> +
> + prb_for_each_entry(&iter, len) {
> + if (entry.seq - last_seq != 1) {
> + printf("LOST %llu ENTRIES\n",
> + entry.seq - (last_seq + 1));
> + }
> + last_seq = entry.seq;
> +
> + s = (char *)&entry.buffer[0];
> + if (len >= 128)
> + s[128 - 1] = 0;
> + printf("data: %s\n", s);
> + }

How are we going to handle pr_cont() loops?

print_modules()
preempt_disable();
list_for_each_entry_rcu(mod, &modules, list) {
pr_cont(" %s%s", mod->name, module_flags(mod, buf));
}
preempt_enable();

-ss