lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 24 Nov 2017 13:47:34 -0500 (EST)
From:   Mikulas Patocka <mpatocka@...hat.com>
To:     Ingo Molnar <mingo@...nel.org>
cc:     Ingo Molnar <mingo@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] schedule: use unlikely()



On Fri, 24 Nov 2017, Ingo Molnar wrote:

> * Mikulas Patocka <mpatocka@...hat.com> wrote:
> 
> > A small patch for schedule(), so that the code goes straght in the common
> > case.
> > 
> > Signed-off-by: Mikulas Patocka <mpatocka@...hat.com>
> > 
> > ---
> >  include/linux/blkdev.h |    2 +-
> >  kernel/sched/core.c    |    2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > Index: linux-2.6/include/linux/blkdev.h
> > ===================================================================
> > --- linux-2.6.orig/include/linux/blkdev.h
> > +++ linux-2.6/include/linux/blkdev.h
> > @@ -1308,7 +1308,7 @@ static inline bool blk_needs_flush_plug(
> >  {
> >  	struct blk_plug *plug = tsk->plug;
> >  
> > -	return plug &&
> > +	return unlikely(plug != NULL) &&
> >  		(!list_empty(&plug->list) ||
> >  		 !list_empty(&plug->mq_list) ||
> >  		 !list_empty(&plug->cb_list));
> 
> That's an unrelated change.

It is related, because this function gets inlined into schedule().

> > Index: linux-2.6/kernel/sched/core.c
> > ===================================================================
> > --- linux-2.6.orig/kernel/sched/core.c
> > +++ linux-2.6/kernel/sched/core.c
> > @@ -3405,7 +3405,7 @@ void __noreturn do_task_dead(void)
> >  
> >  static inline void sched_submit_work(struct task_struct *tsk)
> >  {
> > -	if (!tsk->state || tsk_is_pi_blocked(tsk))
> > +	if (!tsk->state || unlikely(tsk_is_pi_blocked(tsk)))
> >  		return;
> >  	/*
> >  	 * If we are going to sleep and we have plugged IO queued,
> 
> Do these changes actually change the generated assembly code?
> 
> Thanks,
> 
> 	Ingo

Yes. It saves two jumps because the compiler falsely assumes that 
tsk_is_pi_blocked would return true. Likewise, the compiler falsely 
assumes that tsk->plug would be true.

The static branch prediction in gcc assumes that pointers are usually not 
NULL, but in this case tsk->pi_blocked_on and tsk->plug are usually NULL.

Mikulas

Powered by blists - more mailing lists