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  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 10 Dec 2019 15:46:21 +0530
From:   Srikar Dronamraju <srikar@...ux.vnet.ibm.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Dave Chinner <david@...morbit.com>, Phil Auld <pauld@...hat.com>,
        Ming Lei <ming.lei@...hat.com>, linux-block@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, linux-xfs@...r.kernel.org,
        linux-kernel@...r.kernel.org, Jeff Moyer <jmoyer@...hat.com>,
        Dave Chinner <dchinner@...hat.com>,
        Eric Sandeen <sandeen@...hat.com>,
        Christoph Hellwig <hch@....de>, Jens Axboe <axboe@...nel.dk>,
        Ingo Molnar <mingo@...hat.com>, Tejun Heo <tj@...nel.org>,
        Vincent Guittot <vincent.guittot@...aro.org>
Subject: Re: [PATCH v2] sched/core: Preempt current task in favour of bound
 kthread

* Peter Zijlstra <peterz@...radead.org> [2019-12-10 10:26:01]:

> On Tue, Dec 10, 2019 at 11:13:30AM +0530, Srikar Dronamraju wrote:
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 44123b4d14e8..82126cbf62cd 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -2664,7 +2664,12 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> >   */
> >  int wake_up_process(struct task_struct *p)
> >  {
> > -	return try_to_wake_up(p, TASK_NORMAL, 0);
> > +	int wake_flags = 0;
> > +
> > +	if (is_per_cpu_kthread(p))
> > +		wake_flags = WF_KTHREAD;
> > +
> > +	return try_to_wake_up(p, TASK_NORMAL, wake_flags);
> >  }
> >  EXPORT_SYMBOL(wake_up_process);
> 
> Why wake_up_process() and not try_to_wake_up() ? This way
> wake_up_state(.state = TASK_NORMAL() is no longer the same as
> wake_up_process(), and that's weird!
> 

Thanks Vincent and Peter for your review comments.

I was trying to be more conservative. But I don't see any reason why we
can't do the same at try_to_wake_up. And I mostly thought the kthreads were
using wake_up_process.

So I shall move the check to try_to_wake_up then.

> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 69a81a5709ff..36486f71e59f 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -6660,6 +6660,27 @@ static void set_skip_buddy(struct sched_entity *se)
> >  		cfs_rq_of(se)->skip = se;
> >  }
> >  
> > +static int kthread_wakeup_preempt(struct rq *rq, struct task_struct *p, int wake_flags)
> > +{
> > +	struct task_struct *curr = rq->curr;
> > +	struct cfs_rq *cfs_rq = task_cfs_rq(curr);
> > +
> > +	if (!(wake_flags & WF_KTHREAD))
> > +		return 0;
> > +
> > +	if (p->nr_cpus_allowed != 1 || curr->nr_cpus_allowed == 1)
> > +		return 0;
> 
> Per the above, WF_KTHREAD already implies p->nr_cpus_allowed == 1.

Yes, this is redundant.

> 
> > +	if (cfs_rq->nr_running > 2)
> > +		return 0;
> > +
> > +	/*
> > +	 * Don't preempt, if the waking kthread is more CPU intensive than
> > +	 * the current thread.
> > +	 */
> > +	return p->nvcsw * curr->nivcsw >= p->nivcsw * curr->nvcsw;
> 
> Both these conditions seem somewhat arbitrary. The number of context
> switch does not correspond to CPU usage _at_all_.
> 
> vtime OTOH does reflect exactly that, if it runs a lot, it will be ahead
> in the tree.
> 

Right, my rational was to not allow a runaway kthread to preempt and take
control.


-- 
Thanks and Regards
Srikar Dronamraju

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ