mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	jasonbaron0@gmail.com, luto@amacapital.net, tglx@linutronix.de,
	will.deacon@arm.com, liuj97@gmail.com, rabin@rab.in,
	ralf@linux-mips.org, ddaney@caviumnetworks.com,
	benh@kernel.crashing.org, michael@ellerman.id.au,
	heiko.carstens@de.ibm.com, davem@davemloft.net
Subject: Re: [PATCH -v2 6/8] jump_label: Add a new static_key interface
Date: Tue, 4 Aug 2015 16:33:44 +0200	[thread overview]
Message-ID: <20150804143344.GA5689@nazgul.tnic> (raw)
In-Reply-To: <20150804080645.0f29617d@gandalf.local.home>

On Tue, Aug 04, 2015 at 08:06:45AM -0400, Steven Rostedt wrote:
> I just don't like the inconsistency of the initialization and the
> setting.
> 
> Either have:
> 
>  DEFINE_STATIC_KEY_TRUE()
>  DEFINE_STATIC_KEY_FALSE()
> 
> and
> 
>  static_branch_set_true()
>  static_branch_set_false()
> 
> 
> or have:
> 
>  DEFINE_STATIC_KEY_ENABLED()
>  DEFINE_STATIC_KEY_DISABLED()
> 
> and
> 
>  static_branch_enable()
>  static_branch_disable()
> 
> 
> But having the DEFINE_STATIC_KEY_TRUE() and static_branch_enable() is
> confusing, as enable does not mean "make true"!
> 
> This may seem as bike shedding, but terminology *is* important, and
> being inconsistent just makes it more probable to have bugs.

I absolutely agree but I read "enable" as enable the branch, so no
confusion there. Now, it's a whole another question where we branch to.
And that can be confusing.

Now, let's get back to our example:

+static DEFINE_STATIC_KEY_FALSE(__use_tsc);

We don't use the TSC by default. And that's correct, we need to
calibrate it first.

After calibration:

+       static_branch_enable(&__use_tsc);

Now here we can get confused: we enable the branch but where we branch
to? The key name helps here but it is still not quite 100% clear. I'd
prefer to have:

	static_enable(&__use_tsc);

which basically says, we can use the TSC from now on. No branch, no key,
no nada. It looks like a boolean variable of sorts which says, use the
TSC from now on.

Which equally speaks for your other version:

	static_set_true(&__use_tsc);

Now this looks pretty understandable to me.


Then, the usage site looks like this:

+       if (static_likely(&__use_tsc)) {
+               u64 tsc_now = rdtsc();
+
+               /* return the value in ns */
+               return cycles_2_ns(tsc_now);
+       }

which basically says two things:

* if the static key is enabled, i.e. the boolean var is set to true.

and

* this is a likely key, i.e., the code in brackets should come first in
the layout and the code we branch to comes later.

Hell, we can drop that "key" or "branch" from the whole API for all I
know. "static_" is enough for me to say what the thing is. But that's
just me - I like short names - no poems in code and sh*t.

Thoughts, comments?

So yeah, I absolutely see the problematic here and also the need for
more bikeshedding. And this time, that bikeshedding is important.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

  reply	other threads:[~2015-08-04 14:33 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 13:20 [PATCH -v2 0/8] jump_label: Another (better) " Peter Zijlstra
2015-07-28 13:20 ` [PATCH -v2 1/8] jump_label: Rename JUMP_LABEL_{EN,DIS}ABLE Peter Zijlstra
2015-07-28 13:20 ` [PATCH -v2 2/8] jump_label: Rename JUMP_LABEL_TYPE_* Peter Zijlstra
2015-07-29 12:58   ` Borislav Petkov
2015-07-28 13:20 ` [PATCH -v2 3/8] jump_label: Add jump_entry_key() helper Peter Zijlstra
2015-07-28 13:20 ` [PATCH -v2 4/8] jump_label: Add static_key_{en,dis}able() helpers Peter Zijlstra
2015-07-28 13:21 ` [PATCH -v2 5/8] jump_label: Rework update logic Peter Zijlstra
2015-07-28 13:21 ` [PATCH -v2 6/8] jump_label: Add a new static_key interface Peter Zijlstra
2015-07-28 17:00   ` Rabin Vincent
2015-07-28 17:20     ` Peter Zijlstra
2015-07-29  6:43   ` Heiko Carstens
2015-07-29  7:19   ` Vlastimil Babka
2015-07-29  8:49     ` Peter Zijlstra
2015-08-03 19:03       ` Steven Rostedt
2015-08-03 19:18         ` Peter Zijlstra
2015-08-03 19:28           ` Steven Rostedt
2015-08-03 20:00             ` Peter Zijlstra
2015-08-03 21:57               ` Steven Rostedt
2015-08-04  3:37                 ` Borislav Petkov
2015-08-04  4:07                   ` Andy Lutomirski
2015-08-04  4:21                     ` Borislav Petkov
2015-08-04 12:06                   ` Steven Rostedt
2015-08-04 14:33                     ` Borislav Petkov [this message]
2015-08-04 14:41                       ` Steven Rostedt
2015-08-04 14:51                       ` Andy Lutomirski
2015-07-30 12:18   ` Michael Ellerman
2015-08-04  6:50   ` yalin wang
2015-08-04  9:15     ` Peter Zijlstra
2015-07-28 13:21 ` [PATCH -v2 7/8] jump_label: Add selftest Peter Zijlstra
2015-07-28 21:46   ` Jason Baron
2015-07-29  8:53     ` Peter Zijlstra
2015-07-28 13:21 ` [PATCH -v2 8/8] x86, tsc: Employ static_branch_likely() Peter Zijlstra
2015-07-29 14:07   ` Borislav Petkov
2015-07-29  6:46 ` [PATCH -v2 0/8] jump_label: Another (better) static_key interface Heiko Carstens
2015-07-29  8:58   ` Peter Zijlstra
2015-08-03 17:03   ` [tip:locking/core] s390/uaccess, locking/static_keys: employ static_branch_likely() tip-bot for Heiko Carstens

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=20150804143344.GA5689@nazgul.tnic \
    --to=bp@alien8.de \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=ddaney@caviumnetworks.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=jasonbaron0@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=luto@amacapital.net \
    --cc=michael@ellerman.id.au \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rabin@rab.in \
    --cc=ralf@linux-mips.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=will.deacon@arm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®