From: Steven Rostedt <rostedt@goodmis.org>
To: Juri Lelli <juri.lelli@gmail.com>
Cc: peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com,
oleg@redhat.com, fweisbec@gmail.com, darren@dvhart.com,
johan.eker@ericsson.com, p.faure@akatech.ch,
linux-kernel@vger.kernel.org, claudio@evidence.eu.com,
michael@amarulasolutions.com, fchecconi@gmail.com,
tommaso.cucinotta@sssup.it, nicola.manica@disi.unitn.it,
luca.abeni@unitn.it, dhaval.giani@gmail.com, hgu1972@gmail.com,
paulmck@linux.vnet.ibm.com, raistlin@linux.it,
insop.song@gmail.com, liming.wang@windriver.com,
jkacur@redhat.com, harald.gustafsson@ericsson.com,
vincent.guittot@linaro.org, bruce.ashfield@windriver.com
Subject: Re: [PATCH 09/14] rtmutex: turn the plist into an rb-tree.
Date: Wed, 20 Nov 2013 22:07:57 -0500 [thread overview]
Message-ID: <20131120220757.2e9cad94@gandalf.local.home> (raw)
In-Reply-To: <1383831828-15501-10-git-send-email-juri.lelli@gmail.com>
On Thu, 7 Nov 2013 14:43:43 +0100
Juri Lelli <juri.lelli@gmail.com> wrote:
> From: Peter Zijlstra <peterz@infradead.org>
>
> Turn the pi-chains from plist to rb-tree, in the rt_mutex code,
> and provide a proper comparison function for -deadline and
> -priority tasks.
>
> This is done mainly because:
> - classical prio field of the plist is just an int, which might
> not be enough for representing a deadline;
> - manipulating such a list would become O(nr_deadline_tasks),
> which might be to much, as the number of -deadline task increases.
>
> Therefore, an rb-tree is used, and tasks are queued in it according
> to the following logic:
> - among two -priority (i.e., SCHED_BATCH/OTHER/RR/FIFO) tasks, the
> one with the higher (lower, actually!) prio wins;
> - among a -priority and a -deadline task, the latter always wins;
> - among two -deadline tasks, the one with the earliest deadline
> wins.
>
> Queueing and dequeueing functions are changed accordingly, for both
> the list of a task's pi-waiters and the list of tasks blocked on
> a pi-lock.
It will be interesting to see if this affects performance of the -rt
patch, as the pi lists are stressed much more.
Although this looks like it will remove that nasty hack in the -rt
patch where the locks have to call "init_lists()" because plists are
something not initialized easily on static variables.
> diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
> index 0dd6aec..4ea7eaa 100644
> --- a/kernel/rtmutex.c
> +++ b/kernel/rtmutex.c
> @@ -91,10 +91,104 @@ static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
> }
> #endif
>
> +static inline int
> +rt_mutex_waiter_less(struct rt_mutex_waiter *left,
> + struct rt_mutex_waiter *right)
> +{
> + if (left->task->prio < right->task->prio)
> + return 1;
> +
> + /*
> + * If both tasks are dl_task(), we check their deadlines.
> + */
> + if (dl_prio(left->task->prio) && dl_prio(right->task->prio))
> + return (left->task->dl.deadline < right->task->dl.deadline);
Hmm, actually you only need to check the left task if it has a
dl_prio() or not. If it has a dl_prio, then the only way it could have
not returned with a 1 from the first compare is if the right task also
has a dl_prio().
> +
> + return 0;
> +}
> +
> +static void
> +rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
> +{
> + struct rb_node **link = &lock->waiters.rb_node;
> + struct rb_node *parent = NULL;
> + struct rt_mutex_waiter *entry;
> + int leftmost = 1;
> +
> + while (*link) {
> + parent = *link;
> + entry = rb_entry(parent, struct rt_mutex_waiter, tree_entry);
> + if (rt_mutex_waiter_less(waiter, entry)) {
> + link = &parent->rb_left;
> + } else {
> + link = &parent->rb_right;
> + leftmost = 0;
> + }
> + }
> +
> + if (leftmost)
> + lock->waiters_leftmost = &waiter->tree_entry;
> +
> + rb_link_node(&waiter->tree_entry, parent, link);
> + rb_insert_color(&waiter->tree_entry, &lock->waiters);
> +}
> +
> +static void
> +rt_mutex_dequeue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
> +{
> + if (RB_EMPTY_NODE(&waiter->tree_entry))
> + return;
> +
> + if (lock->waiters_leftmost == &waiter->tree_entry)
> + lock->waiters_leftmost = rb_next(&waiter->tree_entry);
> +
> + rb_erase(&waiter->tree_entry, &lock->waiters);
> + RB_CLEAR_NODE(&waiter->tree_entry);
> +}
> +
> +static void
> +rt_mutex_enqueue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
> +{
> + struct rb_node **link = &task->pi_waiters.rb_node;
> + struct rb_node *parent = NULL;
> + struct rt_mutex_waiter *entry;
> + int leftmost = 1;
> +
> + while (*link) {
> + parent = *link;
> + entry = rb_entry(parent, struct rt_mutex_waiter, pi_tree_entry);
> + if (rt_mutex_waiter_less(waiter, entry)) {
> + link = &parent->rb_left;
> + } else {
> + link = &parent->rb_right;
> + leftmost = 0;
> + }
> + }
> +
> + if (leftmost)
> + task->pi_waiters_leftmost = &waiter->pi_tree_entry;
> +
> + rb_link_node(&waiter->pi_tree_entry, parent, link);
> + rb_insert_color(&waiter->pi_tree_entry, &task->pi_waiters);
> +}
> +
> +static void
> +rt_mutex_dequeue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
> +{
> + if (RB_EMPTY_NODE(&waiter->pi_tree_entry))
> + return;
> +
> + if (task->pi_waiters_leftmost == &waiter->pi_tree_entry)
> + task->pi_waiters_leftmost = rb_next(&waiter->pi_tree_entry);
> +
> + rb_erase(&waiter->pi_tree_entry, &task->pi_waiters);
> + RB_CLEAR_NODE(&waiter->pi_tree_entry);
> +}
> +
> /*
> - * Calculate task priority from the waiter list priority
> + * Calculate task priority from the waiter tree priority
> *
> - * Return task->normal_prio when the waiter list is empty or when
> + * Return task->normal_prio when the waiter tree is empty or when
> * the waiter is not allowed to do priority boosting
> */
> int rt_mutex_getprio(struct task_struct *task)
> @@ -102,7 +196,7 @@ int rt_mutex_getprio(struct task_struct *task)
> if (likely(!task_has_pi_waiters(task)))
> return task->normal_prio;
>
> - return min(task_top_pi_waiter(task)->pi_list_entry.prio,
> + return min(task_top_pi_waiter(task)->task->prio,
> task->normal_prio);
> }
>
> @@ -233,7 +327,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
> * When deadlock detection is off then we check, if further
> * priority adjustment is necessary.
> */
> - if (!detect_deadlock && waiter->list_entry.prio == task->prio)
> + if (!detect_deadlock && waiter->task->prio == task->prio)
This will always be true, as waiter->task == task.
> goto out_unlock_pi;
>
> lock = waiter->lock;
> @@ -254,9 +348,9 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
> top_waiter = rt_mutex_top_waiter(lock);
>
> /* Requeue the waiter */
> - plist_del(&waiter->list_entry, &lock->wait_list);
> - waiter->list_entry.prio = task->prio;
> - plist_add(&waiter->list_entry, &lock->wait_list);
> + rt_mutex_dequeue(lock, waiter);
> + waiter->task->prio = task->prio;
This is rather pointless, as waiter->task == task.
We need to add a prio to the rt_mutex_waiter structure, because we need
a way to know if the prio changed or not. There's a reason we used the
list_entry.prio and not the task prio.
Then you could substitute all the waiter->task->prio with just
waiter->prio and that should also work.
-- Steve
> + rt_mutex_enqueue(lock, waiter);
>
> /* Release the task */
> raw_spin_unlock_irqrestore(&task->pi_lock, flags);
next prev parent reply other threads:[~2013-11-21 3:08 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-07 13:43 [PATCH 00/14] sched: SCHED_DEADLINE v9 Juri Lelli
2013-11-07 13:43 ` [PATCH 01/14] sched: add sched_class->task_dead Juri Lelli
2013-11-12 4:17 ` Paul Turner
2013-11-12 17:19 ` Steven Rostedt
2013-11-12 17:53 ` Juri Lelli
2013-11-27 14:10 ` [tip:sched/core] sched: Add sched_class->task_dead() method tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 02/14] sched: add extended scheduling interface Juri Lelli
2013-11-12 17:23 ` Steven Rostedt
2013-11-13 8:43 ` Juri Lelli
2013-11-12 17:32 ` Steven Rostedt
2013-11-13 9:07 ` Juri Lelli
2013-11-27 13:23 ` [PATCH 02/14] sched: add extended scheduling interface. (new ABI) Ingo Molnar
2013-11-27 13:30 ` Peter Zijlstra
2013-11-27 14:01 ` Ingo Molnar
2013-11-27 14:13 ` Peter Zijlstra
2013-11-27 14:17 ` Ingo Molnar
2013-11-28 11:14 ` Juri Lelli
2013-11-28 11:28 ` Peter Zijlstra
2013-11-30 14:06 ` Ingo Molnar
2013-12-03 16:13 ` Juri Lelli
2013-12-03 16:41 ` Steven Rostedt
2013-12-03 17:04 ` Juri Lelli
2014-01-13 15:53 ` [tip:sched/core] sched: Add new scheduler syscalls to support an extended scheduling parameters ABI tip-bot for Dario Faggioli
2014-01-15 16:22 ` [RFC][PATCH] sched: Move SCHED_RESET_ON_FORK into attr::sched_flags Peter Zijlstra
2014-01-16 13:40 ` [tip:sched/core] sched: Move SCHED_RESET_ON_FORK into attr:: sched_flags tip-bot for Peter Zijlstra
2014-01-17 17:29 ` [tip:sched/core] sched: Add new scheduler syscalls to support an extended scheduling parameters ABI Stephen Warren
2014-01-17 18:04 ` Stephen Warren
2013-11-07 13:43 ` [PATCH 03/14] sched: SCHED_DEADLINE structures & implementation Juri Lelli
2013-11-13 2:31 ` Steven Rostedt
2013-11-13 9:54 ` Juri Lelli
2013-11-20 20:23 ` Steven Rostedt
2013-11-21 14:15 ` Juri Lelli
2014-01-13 15:53 ` [tip:sched/core] sched/deadline: Add " tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 04/14] sched: SCHED_DEADLINE SMP-related data structures & logic Juri Lelli
2013-11-20 18:51 ` Steven Rostedt
2013-11-21 14:13 ` Juri Lelli
2013-11-21 14:41 ` Steven Rostedt
2013-11-21 16:08 ` Paul E. McKenney
2013-11-21 16:16 ` Juri Lelli
2013-11-21 16:26 ` Paul E. McKenney
2013-11-21 16:47 ` Steven Rostedt
2013-11-21 19:38 ` Paul E. McKenney
2014-01-13 15:53 ` [tip:sched/core] sched/deadline: Add " tip-bot for Juri Lelli
2013-11-07 13:43 ` [PATCH 05/14] sched: SCHED_DEADLINE avg_update accounting Juri Lelli
2014-01-13 15:53 ` [tip:sched/core] sched/deadline: Add " tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 06/14] sched: add period support for -deadline tasks Juri Lelli
2014-01-13 15:53 ` [tip:sched/core] sched/deadline: Add period support for SCHED_DEADLINE tasks tip-bot for Harald Gustafsson
2013-11-07 13:43 ` [PATCH 07/14] sched: add schedstats for -deadline tasks Juri Lelli
2013-11-07 13:43 ` [PATCH 08/14] sched: add latency tracing " Juri Lelli
2013-11-20 21:33 ` Steven Rostedt
2013-11-27 13:43 ` Juri Lelli
2013-11-27 14:16 ` Steven Rostedt
2013-11-27 14:19 ` Juri Lelli
2013-11-27 14:26 ` Peter Zijlstra
2013-11-27 14:34 ` Ingo Molnar
2013-11-27 14:58 ` Peter Zijlstra
2013-11-27 15:35 ` Ingo Molnar
2013-11-27 15:40 ` Peter Zijlstra
2013-11-27 15:46 ` Ingo Molnar
2013-11-27 15:54 ` Peter Zijlstra
2013-11-27 15:56 ` Steven Rostedt
2013-11-27 16:01 ` Peter Zijlstra
2013-11-27 16:02 ` Steven Rostedt
2013-11-27 16:13 ` Ingo Molnar
2013-11-27 16:33 ` Steven Rostedt
2013-11-27 16:24 ` Oleg Nesterov
2013-11-27 15:42 ` Ingo Molnar
2013-11-27 15:00 ` Steven Rostedt
2014-01-13 15:54 ` [tip:sched/core] sched/deadline: Add latency tracing for SCHED_DEADLINE tasks tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 09/14] rtmutex: turn the plist into an rb-tree Juri Lelli
2013-11-21 3:07 ` Steven Rostedt [this message]
2013-11-21 17:52 ` [PATCH] rtmutex: Fix compare of waiter prio and task prio Steven Rostedt
2013-11-22 10:37 ` Juri Lelli
2014-01-13 15:54 ` [tip:sched/core] rtmutex: Turn the plist into an rb-tree tip-bot for Peter Zijlstra
2013-11-07 13:43 ` [PATCH 10/14] sched: drafted deadline inheritance logic Juri Lelli
2014-01-13 15:54 ` [tip:sched/core] sched/deadline: Add SCHED_DEADLINE " tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 11/14] sched: add bandwidth management for sched_dl Juri Lelli
2014-01-13 15:54 ` [tip:sched/core] sched/deadline: Add bandwidth management for SCHED_DEADLINE tasks tip-bot for Dario Faggioli
2013-11-07 13:43 ` [PATCH 12/14] sched: make dl_bw a sub-quota of rt_bw Juri Lelli
2013-11-07 13:43 ` [PATCH 13/14] sched: speed up -dl pushes with a push-heap Juri Lelli
2014-01-13 15:54 ` [tip:sched/core] sched/deadline: speed up SCHED_DEADLINE " tip-bot for Juri Lelli
-- strict thread matches above, loose matches on Subject: below --
2013-10-14 10:43 [PATCH 00/14] sched: SCHED_DEADLINE v8 Juri Lelli
2013-10-14 10:43 ` [PATCH 09/14] rtmutex: turn the plist into an rb-tree Juri Lelli
2013-02-11 18:50 [PATCH 00/14] sched: SCHED_DEADLINE v7 Juri Lelli
2013-02-11 18:50 ` [PATCH 09/14] rtmutex: turn the plist into an rb-tree Juri Lelli
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=20131120220757.2e9cad94@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bruce.ashfield@windriver.com \
--cc=claudio@evidence.eu.com \
--cc=darren@dvhart.com \
--cc=dhaval.giani@gmail.com \
--cc=fchecconi@gmail.com \
--cc=fweisbec@gmail.com \
--cc=harald.gustafsson@ericsson.com \
--cc=hgu1972@gmail.com \
--cc=insop.song@gmail.com \
--cc=jkacur@redhat.com \
--cc=johan.eker@ericsson.com \
--cc=juri.lelli@gmail.com \
--cc=liming.wang@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.abeni@unitn.it \
--cc=michael@amarulasolutions.com \
--cc=mingo@redhat.com \
--cc=nicola.manica@disi.unitn.it \
--cc=oleg@redhat.com \
--cc=p.faure@akatech.ch \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=raistlin@linux.it \
--cc=tglx@linutronix.de \
--cc=tommaso.cucinotta@sssup.it \
--cc=vincent.guittot@linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).