Re: [PATCH v3 11/19] sched/core: Make migrate disable and CPU hotplug cooperative

From: Peter Zijlstra
Date: Fri Oct 16 2020 - 05:35:27 EST


On Fri, Oct 16, 2020 at 11:43:17AM +0800, zhout wrote:
> On Thu, Oct 15, 2020 at 01:05:43PM +0200, Peter Zijlstra wrote:
> > From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> >
>
> [ ... ]
>
> > +static inline bool rq_has_pinned_tasks(struct rq *rq)
> > +{
> > + return rq->nr_pinned;
> > +}
> > +
>
> Even I do not understand well enough, the return type of the
> above function is bool and rq->nr_pinned is unsigned int.
> Write this way:
>
> static inline bool rq_has_pinned_tasks(struct rq *rq)
> {
> return !!rq->nr_pinned;
> }

The C compiler does this for us. C has a lot of implicit type
conversions.

It is the same mechanism at work when we write:

if (rq->nr_pinned)

We know that works and we don't have to write:

if (!!rq->nr_pinned)

(although we may, but it is pointless).