Re: [PATCH] vsprintf: Fix memory barriers of ptr_key to have_filed_random_ptr_key

From: Steven Rostedt
Date: Tue May 15 2018 - 18:41:26 EST


On Tue, 15 May 2018 15:31:37 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> > we could always do this:
>
> Ugh. I think I prefer the barriers.

But the ugliness is only at boot up, where the early printing is
important. The benefit of this is here:

@@ -1709,7 +1717,7 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec)
unsigned long hashval;
const int default_width = 2 * sizeof(ptr);

- if (unlikely(!have_filled_random_ptr_key)) {
+ if (static_branch_unlikely(&not_filled_random_ptr_key)) {
spec.field_width = default_width;
/* string length must be less than default_width */
return string(buf, end, "(ptrval)", spec);

Because not only do we not add any barriers, this code basically
becomes a nop once the ptr_key is filled, and this should have a small
speed up in execution (although I have not done any benchmarks).

-- Steve