[lkml]   [2018]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [RFC][PATCHv2 2/4] printk: move printk_safe macros to printk header
On Tue, Oct 16, 2018 at 02:54:15PM +0200, Peter Zijlstra wrote:
> printk will determine the current context:
> task, softirq, hardirq or NMI
> and pick the corresponding per-cpu line buffer and do the vsnprintf()

We need 4, but we don't need to do the exact context determination for
this. We can keep a simple counter:

#define MAX_IDX 4 /* task, sirq, hirq, nmi */
#define MAX_LEN 1020 /* sizeof(struct line_buffer) < 4k */

struct line_buffers {
int idx;
char line[MAX_IDX][MAX_LEN];

static DEFINE_PER_CPU(struct line_buffers, lbs);

static char *get_linebuf(void)
struct line_buffers *lbp = this_cpu_ptr(&lbs);
int idx;

idx = lbp->idx++;
return lbp->linx[idx];

static void put_linbuf(void)

> thing. Then we have the actual line length and content. With the length
> we reserve the bytes from the global buffer, we memcpy into the buffer
> and commit.

 \ /
  Last update: 2018-10-16 16:22    [W:0.092 / U:21.244 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site