On Thu 2020-09-24 15:17:46, Sergey Senozhatsky wrote: > On (20/09/22 17:44), John Ogness wrote: > > +/* > > + * The sprint buffers are used with interrupts disabled, so each CPU > > + * only requires 2 buffers: for non-NMI and NMI contexts. Recursive > > + * printk() calls are handled by the safe buffers. > > + */ > > +#define SPRINT_CTX_DEPTH 2 > > + > > +/* Static sprint buffers for early boot (only 1 CPU). */ > > +static DECLARE_BITMAP(sprint_static_textbuf_map, SPRINT_CTX_DEPTH); > > +static char sprint_static_textbuf[SPRINT_CTX_DEPTH * LOG_LINE_MAX]; > > + > > +/* Dynamically allocated sprint buffers. */ > > +static unsigned int sprint_dynamic_textbuf_count; > > +static unsigned long *sprint_dynamic_textbuf_map; > > +static char *sprint_dynamic_textbuf; > > Just a question: > > Can dynamic_textbuf be a PER_CPU array of five textbuf[1024] buffers > (for normal printk, nmi, hard irq, soft irq and one extra buffer for > recursive printk calls)?
That would be my preferred fallback when the approach with vsprintf(NULL, ) is not acceptable for some reasons. But I still think that calling vsprintf(NULL, ) is the most trivial and good enough solution. IMHO, the solution with per-CPU buffers is not that trivial, for example: What if recursive printk() is interrupted by NMI and it causes yet another recursion? Is one level of recursion enough? Best Regards, Petr