From: Daniel Borkmann <daniel@iogearbox.net>
To: Alexei Starovoitov <ast@plumgrid.com>, davem@davemloft.net
Cc: hannes@stressinduktion.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 2/5] once: make helper generic for calling function once
Date: Wed, 07 Oct 2015 23:00:39 +0200 [thread overview]
Message-ID: <561587F7.1000604@iogearbox.net> (raw)
In-Reply-To: <56154571.7050900@plumgrid.com>
On 10/07/2015 06:16 PM, Alexei Starovoitov wrote:
> On 10/7/15 6:43 AM, Daniel Borkmann wrote:
>> From: Hannes Frederic Sowa<hannes@stressinduktion.org>
>>
>> Make the get_random_once() helper generic enough, so that functions
>> in general would only be called once, where one user of this is then
>> net_get_random_once().
>>
>> The only implementation specific call is to get_random_bytes(), all
>> the rest of this *_once() facility would be duplicated among different
>> subsystems otherwise. The new do_once() helper will be used by prandom()
>> later on, but might also be useful for other scenarios as well where a
>> one-time initialization in often-called, possibly fast-path code could
>> occur.
>>
>> Signed-off-by: Hannes Frederic Sowa<hannes@stressinduktion.org>
>> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>
>> ---
>> include/linux/once.h | 25 ++++++++++++++++++-------
>> lib/once.c | 34 +++++++++++++++++++++-------------
>> 2 files changed, 39 insertions(+), 20 deletions(-)
>
> looking at the patch 1 the once.c file name really looked out of place,
> but this patch makes it fit. Interesting helper, though
> get_random_once_kvec() and kvec are not pretty, since they take extra
> stack and being inited even when static_key is disabled.
> Instead is it possible to split do_once into two parts then
> your macro can have varags and kvec/extra_helper can be removed like:
> #define do_once(func, ...) \
> ({ \
> bool ___ret = false; \
> static bool ___done = false; \
> static struct static_key ___once_key = \
> STATIC_KEY_INIT_TRUE; \
> if (static_key_true(&___once_key)) { \
> __do_once_lock(&___done); \
> func(##__VA_ARGS__); \
> __do_once_unlock(&_done, &___once_key);\
> } \
> ___ret; \
> })
Thanks, good point, I do like it! After reworking this, the outcome of
the new DO_ONCE() is a bit different than above. I'll send out v2 very
soon to show the code result.
Thanks,
Daniel
next prev parent reply other threads:[~2015-10-07 21:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-07 13:43 [PATCH net-next 0/5] BPF/random32 updates Daniel Borkmann
2015-10-07 13:43 ` [PATCH net-next 1/5] net: move net_get_random_once to lib Daniel Borkmann
2015-10-07 13:43 ` [PATCH net-next 2/5] once: make helper generic for calling function once Daniel Borkmann
2015-10-07 16:16 ` Alexei Starovoitov
2015-10-07 21:00 ` Daniel Borkmann [this message]
2015-10-07 13:43 ` [PATCH net-next 3/5] random32: add prandom_seed_full_state helper Daniel Borkmann
2015-10-07 13:43 ` [PATCH net-next 4/5] random32: add prandom_init_once helper for own rngs Daniel Borkmann
2015-10-07 16:32 ` Alexei Starovoitov
2015-10-07 13:43 ` [PATCH net-next 5/5] bpf: split state from prandom_u32() and consolidate {c,e}BPF prngs Daniel Borkmann
2015-10-07 16:38 ` Alexei Starovoitov
2015-10-07 21:01 ` Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=561587F7.1000604@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=hannes@stressinduktion.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.