mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qais Yousef <qyousef@layalina.io>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Joel Fernandes <joel@joelfernandes.org>,
	John Stultz <jstultz@google.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	linux-kernel@vger.kernel.org, Yabin Cui <yabinc@google.com>
Subject: Re: [PATCH] sched/pi: Reweight fair_policy() tasks when inheriting prio
Date: Thu, 4 Apr 2024 23:05:00 +0100	[thread overview]
Message-ID: <20240404220500.dmfl2krll37znbi5@airbuntu> (raw)
In-Reply-To: <CAKfTPtDB8D6bouxJN9q8gXqG+BQYcsrJYEodDWtOB2kQwPH53A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2864 bytes --]

On 04/03/24 15:11, Vincent Guittot wrote:
> On Wed, 3 Apr 2024 at 02:59, Qais Yousef <qyousef@layalina.io> wrote:
> >
> > For fair tasks inheriting the priority (nice) without reweighting is
> > a NOP as the task's share won't change.
> 
> AFAICT, there is no nice priority inheritance with rt_mutex; All nice

Hmm from what I see there is

> tasks are sorted with the same "default prio" in the rb waiter tree.
> This means that the rt top waiter is not the cfs with highest prio but
> the 1st cfs waiting for the mutex.

This is about the order on which tasks contending for the lock more than the
effective priority the task holding the lock should run at though, no?

> 
> >
> > This is visible when running with PTHREAD_PRIO_INHERIT where fair tasks
> > with low priority values are susceptible to starvation leading to PI
> > like impact on lock contention.
> >
> > The logic in rt_mutex will reset these low priority fair tasks into nice
> > 0, but without the additional reweight operation to actually update the
> > weights, it doesn't have the desired impact of boosting them to allow
> > them to run sooner/longer to release the lock.
> >
> > Apply the reweight for fair_policy() tasks to achieve the desired boost
> > for those low nice values tasks. Note that boost here means resetting
> > their nice to 0; as this is what the current logic does for fair tasks.
> 
> But you can at the opposite decrease the cfs prio of a task
> and even worse with the comment :
> /* XXX used to be waiter->prio, not waiter->task->prio */
> 
> we use the prio of the top cfs waiter (ie the one waiting for the
> lock) not the default 0 so it can be anything in the range [-20:19]
> 
> Then, a task with low prio (i.e. nice > 0) can get a prio boost even
> if this task and the waiter are low priority tasks

I don't see this effect. The only change I am doing here
is that when we set the prio that we are supposed to be inheriting, instead of
simply changing prio, I also ensure we reweight so that we run at the inherited
nice value. I am not changing how the waiter logic works.

Here's my test app FWIW

	https://github.com/qais-yousef/pi_test

When I run

	pi_test --lp-nice 0 --lp-nice 10

the lp thread runs at 0 still

If I do

	pi_test --lp-nice 10 --lp-nice 5

low priority thread runs at 5

What combination are you worried about? I can give it a try. I use
sched-analyzer-pp [1] to see the division of runnable/running or you can
monitor them on top

	#!/bin/bash
	set -eux

	sudo sched-analyzer &

	./pi_test --lp-nice ${1:-10} --hp-nice ${2:-0} --affine-cpu ${3:-0} &

	sleep 10

	pkill -SIGKILL pi_test

	sudo pkill -SIGINT sched-analyzer

	sched-analyzer-pp --sched-states pi_test sched-analyzer.perfetto-trace

Picutres of output is attached for before and after

	pi_test --lp-nice 10 --hp-nice 0

[1] https://github.com/qais-yousef/sched-analyzer

[-- Attachment #2: pi_test_no_reweight.png --]
[-- Type: image/png, Size: 1674775 bytes --]

[-- Attachment #3: pi_test_fixed.png --]
[-- Type: image/png, Size: 1662364 bytes --]

  parent reply	other threads:[~2024-04-04 22:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  0:59 Qais Yousef
2024-04-03 13:11 ` Vincent Guittot
2024-04-03 13:42   ` Steven Rostedt
2024-04-03 13:54     ` Vincent Guittot
2024-04-04 22:18     ` Qais Yousef
2024-04-04 22:05   ` Qais Yousef [this message]
2024-04-05 12:15     ` Vincent Guittot
2024-04-05 17:16       ` Qais Yousef
2024-04-07 12:27         ` Qais Yousef
2024-04-08  7:16           ` Vincent Guittot
2024-04-08 19:51             ` John Stultz
2024-04-09  6:19               ` Qais Yousef
2024-04-09 12:35                 ` Vincent Guittot
2024-04-10  6:59                   ` Qais Yousef
2024-04-10  9:13                     ` Vincent Guittot
2024-04-10 15:47                       ` Qais Yousef
2024-05-14 16:07                         ` Qais Yousef
2024-04-10 17:30                     ` John Stultz
2024-04-10 18:15                       ` Qais Yousef
2024-04-08  7:14         ` Vincent Guittot

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=20240404220500.dmfl2krll37znbi5@airbuntu \
    --to=qyousef@layalina.io \
    --cc=bristot@redhat.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joel@joelfernandes.org \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=yabinc@google.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®