All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Borislav Petkov <bp@suse.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Christoph Hellwig <hch@lst.de>,
	kan.liang@intel.com, Peter Zijlstra <peterz@infradead.org>,
	Rik van Riel <riel@surriel.com>, Will Deacon <will@kernel.org>
Subject: Re: [PATCH 1/9] sched/core: add is_kthread() helper
Date: Mon, 19 Aug 2019 10:52:13 +0200	[thread overview]
Message-ID: <20190819085213.GA15409@gmail.com> (raw)
In-Reply-To: <20190814113232.GE17931@lakrids.cambridge.arm.com>


* Mark Rutland <mark.rutland@arm.com> wrote:

> On Wed, Aug 14, 2019 at 01:26:43PM +0200, Geert Uytterhoeven wrote:
> > Hi Mark,
> > 
> > On Wed, Aug 14, 2019 at 12:43 PM Mark Rutland <mark.rutland@arm.com> wrote:
> > > Code checking whether a task is a kthread isn't very consistent. Some
> > > code correctly tests task->flags & PF_THREAD, while other code checks
> > > task->mm (which can be true for a kthread which calls use_mm()).
> > >
> > > So that we can clean this up and keep the code easy to follow, let's add
> > > an obvious helper function to test whether a task is a kthread.
> > > Subsequent patches will use this as part of cleaning up and correcting
> > > open-coded tests.
> > >
> > > At the same time, let's fix up the kerneldoc for is_idle_task() for
> > > consistency with the new helper, using true/false rather than 0/1, given
> > > the functions return bool.
> > >
> > > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > 
> > Thanks for your patch!
> > 
> > > --- a/include/linux/sched.h
> > > +++ b/include/linux/sched.h
> > > @@ -1621,13 +1621,24 @@ extern struct task_struct *idle_task(int cpu);
> > >   * is_idle_task - is the specified task an idle task?
> > >   * @p: the task in question.
> > >   *
> > > - * Return: 1 if @p is an idle task. 0 otherwise.
> > > + * Return: true if @p is an idle task, false otherwise.
> > >   */
> > >  static inline bool is_idle_task(const struct task_struct *p)
> > >  {
> > >         return !!(p->flags & PF_IDLE);
> > >  }
> > >
> > > +/**
> > > + * is_kthread - is the specified task a kthread
> > > + * @p: the task in question.
> > > + *
> > > + * Return: true if @p is a kthread, false otherwise.
> > > + */
> > > +static inline bool is_kthread(const struct task_struct *p)
> > > +{
> > > +       return !!(p->flags & PF_KTHREAD);
> > 
> > The !! is not really needed.
> > Probably you followed is_idle_task() above (where it's also not needed).
> 
> Indeed! I'm aware of the implicit bool conversion, but kept that for
> consistency.
> 
> Peter, Ingo, do you have a preference?

So the !! pattern is useful where the return value is an integer (i.e. 
there's a risk of non-bool use) - but the return value is an explicit 
bool here, so !! is IMO an entirely superfluous obfuscation.

Should probably be fixed for is_idle_task() as well?

Thanks,

	Ingo

  reply	other threads:[~2019-08-19  8:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14 10:41 [PATCH 0/9] kthread detection cleanup Mark Rutland
2019-08-14 10:41 ` [PATCH 1/9] sched/core: add is_kthread() helper Mark Rutland
2019-08-14 11:26   ` Geert Uytterhoeven
2019-08-14 11:32     ` Mark Rutland
2019-08-19  8:52       ` Ingo Molnar [this message]
2019-08-21 11:21         ` Peter Zijlstra
2019-08-14 10:41 ` [PATCH 2/9] sched: treewide: use is_kthread() Mark Rutland
2019-08-14 11:27   ` Geert Uytterhoeven
2019-08-14 12:39   ` Sebastian Andrzej Siewior
2019-08-14 13:35     ` Mark Rutland
2019-08-14 13:37   ` Valentin Schneider
2019-08-14 10:41 ` [PATCH 3/9] kmemleak: correctly check for kthreads Mark Rutland
2019-08-14 16:39   ` Catalin Marinas
2019-08-14 10:41 ` [PATCH 4/9] arm/perf: " Mark Rutland
2019-08-14 10:41 ` [PATCH 5/9] arm64: correctly check for ktrheads Mark Rutland
2019-08-14 16:40   ` Catalin Marinas
2019-08-14 10:41 ` [PATCH 6/9] sparc/perf: correctly check for kthreads Mark Rutland
2019-08-14 16:26   ` David Miller
2019-08-14 10:41 ` [PATCH 7/9] x86/lbr: " Mark Rutland
2019-08-14 10:41 ` [PATCH 8/9] x86/fpu: " Mark Rutland
2019-08-14 13:07   ` Sebastian Andrzej Siewior
2019-08-14 13:39     ` Mark Rutland
2019-08-14 14:55       ` Sebastian Andrzej Siewior
2019-08-14 10:41 ` [PATCH 9/9] samples/kretprobe: " Mark Rutland
2019-08-14 13:43 ` [PATCH 0/9] kthread detection cleanup Valentin Schneider

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=20190819085213.GA15409@gmail.com \
    --to=mingo@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=bp@suse.de \
    --cc=catalin.marinas@arm.com \
    --cc=davem@davemloft.net \
    --cc=geert@linux-m68k.org \
    --cc=hch@lst.de \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=will@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.