mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Shrikanth Hegde <sshegde@linux.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, ankur.a.arora@oracle.com, efault@gmx.de,
	tglx@linutronix.de, mingo@kernel.org
Subject: Re: [PATCH 2/5] sched: Add Lazy preemption model
Date: Fri, 25 Oct 2024 15:19:30 +0200	[thread overview]
Message-ID: <20241025131930.cVOckvQQ@linutronix.de> (raw)
In-Reply-To: <e334aff9-248c-4a00-98e1-7bcb7cdd5e90@linux.ibm.com>

On 2024-10-22 22:14:41 [+0530], Shrikanth Hegde wrote:
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -1251,7 +1251,7 @@ static void update_curr(struct cfs_rq *c
> >   		return;
> >   	if (resched || did_preempt_short(cfs_rq, curr)) {
> 
> 
> 
> If there is a long running task, only after it is not eligible, LAZY would be set and
> subsequent tick would upgrade it to NR. If one sets sysctl_sched_base_slice to a large
> value (max 4seconds), LAZY would set thereafter(max 4 seconds) if there in no wakeup in
> that CPU.
> 
> If i set sysctl_sched_base_slice=300ms, spawn 2 stress-ng on one CPU, then LAZY bit is
> set usually after 300ms of sched_switch if there are no wakeups. Subsequent tick NR is set.
> Initially I was thinking, if there is a long running process, then LAZY would be set after
> one tick and on subsequent tick NR would set. I was wrong. It might take a long time for LAZY
> to be set, and On subsequent tick NR would be set.
> 
> That would be expected behavior since one setting sysctl_sched_base_slice know what to expect?

I guess so. Once the slice is up then the NEED_RESCHED bit is replaced
with the LAZY bit. That means a return-to-userland (from a syscall) or
the following tick will lead to a scheduling event.

> > -		resched_curr(rq);
> > +		resched_curr_lazy(rq);
> >   		clear_buddies(cfs_rq, curr);
> >   	}
> >   }
> > @@ -5677,7 +5677,7 @@ entity_tick(struct cfs_rq *cfs_rq, struc
> >   	 * validating it and just reschedule.
> >   	 */
> >   	if (queued) {
> 
> What's this queued used for? hrtick seems to set it. I haven't understood how it works.

from 20241009074631.GH17263@noisy.programming.kicks-ass.net:
| hrtick is disabled by default (because expensive) and so it doesn't
| matter much, but it's purpose is to increase accuracy and hence I left
| it untouched for now.

This setups a hrtimer for the (remaining) time slice and invokes the
task_tick from there (instead of the regular tick).

> > -		resched_curr(rq_of(cfs_rq));
> > +		resched_curr_lazy(rq_of(cfs_rq));
> >   		return;
> >   	}
> >   	/*
> > @@ -8832,7 +8832,7 @@ static void check_preempt_wakeup_fair(st
> >   	return;
> >   preempt:
> > -	resched_curr(rq);
> 
> Is it better to call resched_curr here? When the code arrives here, it wants to
> run pse as soon as possible right?

But wouldn't then every try_to_wakeup()/ wake_up() result in immediate
preemption? Letting it run and waiting to give up on its own, having the
preemption on return to userland results usually in better performance.
At least this is what I observed while playing with this.

> > +	resched_curr_lazy(rq);
> >   }
> >   static struct task_struct *pick_task_fair(struct rq *rq)

Sebastian

  reply	other threads:[~2024-10-25 13:19 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07  7:46 [PATCH 0/5] sched: Lazy preemption muck Peter Zijlstra
2024-10-07  7:46 ` [PATCH 1/5] sched: Add TIF_NEED_RESCHED_LAZY infrastructure Peter Zijlstra
2024-10-09 12:18   ` Sebastian Andrzej Siewior
2024-10-09 13:01     ` Peter Zijlstra
2024-11-06 10:48   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2024-10-07  7:46 ` [PATCH 2/5] sched: Add Lazy preemption model Peter Zijlstra
2024-10-08  5:43   ` Ankur Arora
2024-10-08 14:48     ` Peter Zijlstra
2024-10-09  8:50   ` Sebastian Andrzej Siewior
2024-10-09  9:14     ` Peter Zijlstra
2024-10-09  9:19       ` Sebastian Andrzej Siewior
2024-10-15 14:37   ` Shrikanth Hegde
2024-10-25 10:42     ` Sebastian Andrzej Siewior
2024-10-22 16:44   ` Shrikanth Hegde
2024-10-25 13:19     ` Sebastian Andrzej Siewior [this message]
2024-10-29 18:57       ` Shrikanth Hegde
2024-11-06 10:48   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2024-10-07  7:46 ` [PATCH 3/5] sched: Enable PREEMPT_DYNAMIC for PREEMPT_RT Peter Zijlstra
2024-10-08 13:24   ` Sebastian Andrzej Siewior
2024-10-08 14:40     ` Peter Zijlstra
2024-10-10  6:52   ` Christoph Hellwig
2024-10-10  7:50     ` Peter Zijlstra
2024-11-06 10:48   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2024-10-07  7:46 ` [PATCH 4/5] sched, x86: Enable Lazy preemption Peter Zijlstra
2024-11-06 10:48   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2024-10-07  7:46 ` [PATCH 5/5] sched: Add laziest preempt model Peter Zijlstra
2024-10-08  5:59   ` Ankur Arora
2024-10-08 14:23   ` Thomas Gleixner
2024-10-08 14:40     ` Peter Zijlstra
2024-10-08 15:07   ` Sebastian Andrzej Siewior
2024-10-07  8:33 ` [PATCH 0/5] sched: Lazy preemption muck Sebastian Andrzej Siewior
2024-10-08  4:58 ` Mike Galbraith
2024-10-08 15:32 ` Sebastian Andrzej Siewior
2024-10-09  4:40   ` Ankur Arora
2024-10-09  6:20     ` Sebastian Andrzej Siewior
2024-10-09  7:23       ` Ankur Arora
2024-10-09  8:02       ` Peter Zijlstra
2024-10-09  8:45         ` Sebastian Andrzej Siewior
2024-10-09 14:01         ` Steven Rostedt
2024-10-09 20:13           ` Thomas Gleixner
2024-10-09 20:43             ` Steven Rostedt
2024-10-09 21:06               ` Thomas Gleixner
2024-10-09 21:19                 ` Steven Rostedt
2024-10-09 23:16                   ` Thomas Gleixner
2024-10-09 23:29                     ` Steven Rostedt
2024-10-10  1:20                       ` Thomas Gleixner
2024-10-10 10:23                 ` David Laight
2024-10-13 19:02                   ` Thomas Gleixner
2024-10-14  8:21                     ` David Laight
2024-10-10  3:12               ` Tianchen Ding
2024-10-10  7:47                 ` Thomas Gleixner
2024-10-09  7:30   ` Ankur Arora
2024-10-09  7:46   ` Peter Zijlstra
2024-10-09 11:07 ` Sebastian Andrzej Siewior
2024-10-17 12:36 ` Mike Galbraith
2024-11-07 17:21   ` Thomas Meyer
2024-11-08  0:59     ` Mike Galbraith

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=20241025131930.cVOckvQQ@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=ankur.a.arora@oracle.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=efault@gmx.de \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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®