mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xunlei Pang <xlpang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Juri Lelli <juri.lelli@arm.com>, Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Xunlei Pang <xlpang@redhat.com>
Subject: [PATCH v2 2/2] rtmutex: Kill pi_waiters_leftmost from task_struct
Date: Wed,  6 Apr 2016 20:59:16 +0800	[thread overview]
Message-ID: <1459947556-12332-2-git-send-email-xlpang@redhat.com> (raw)
In-Reply-To: <1459947556-12332-1-git-send-email-xlpang@redhat.com>

Current code use pi_waiters_leftmost to record the leftmost waiter,
but actually it can be get directly from task_struct::pi_waiters
using rb_first(). The performance penalty introduced by rb_first()
should be fine, because normally there aren't that many rtmutexes
chained together for one task.

We don't remove rt_mutex:pi_waiters_leftmost, as it is quite possible
for many tasks sharing one rtmutex.

Thus, hereby remove pi_waiters_leftmost from task_struct.

Signed-off-by: Xunlei Pang <xlpang@redhat.com>
---
 include/linux/init_task.h       |  1 -
 include/linux/sched.h           |  1 -
 kernel/fork.c                   |  1 -
 kernel/locking/rtmutex.c        | 13 ++-----------
 kernel/locking/rtmutex_common.h |  2 +-
 5 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index de834f3..a967dbf 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -162,7 +162,6 @@ extern struct task_group root_task_group;
 #ifdef CONFIG_RT_MUTEXES
 # define INIT_RT_MUTEXES(tsk)						\
 	.pi_waiters = RB_ROOT,						\
-	.pi_waiters_leftmost = NULL,					\
 	.pi_top_task = NULL,
 #else
 # define INIT_RT_MUTEXES(tsk)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index b4d9347..6477e22 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1620,7 +1620,6 @@ struct task_struct {
 #ifdef CONFIG_RT_MUTEXES
 	/* PI waiters blocked on a rt_mutex held by this task */
 	struct rb_root pi_waiters;
-	struct rb_node *pi_waiters_leftmost;
 	struct task_struct *pi_top_task;
 	/* Deadlock detection and priority inheritance handling */
 	struct rt_mutex_waiter *pi_blocked_on;
diff --git a/kernel/fork.c b/kernel/fork.c
index 3ad84c9..fc6e5d8 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1207,7 +1207,6 @@ static void rt_mutex_init_task(struct task_struct *p)
 	raw_spin_lock_init(&p->pi_lock);
 #ifdef CONFIG_RT_MUTEXES
 	p->pi_waiters = RB_ROOT;
-	p->pi_waiters_leftmost = NULL;
 	p->pi_blocked_on = NULL;
 	p->pi_top_task = NULL;
 #endif
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 6c3a806..b8e9300 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -223,22 +223,16 @@ 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)) {
+		if (rt_mutex_waiter_less(waiter, entry))
 			link = &parent->rb_left;
-		} else {
+		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);
 }
@@ -249,9 +243,6 @@ 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);
 }
diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
index 93b0924..ccfa34a 100644
--- a/kernel/locking/rtmutex_common.h
+++ b/kernel/locking/rtmutex_common.h
@@ -63,7 +63,7 @@ static inline int task_has_pi_waiters(struct task_struct *p)
 static inline struct rt_mutex_waiter *
 task_top_pi_waiter(struct task_struct *p)
 {
-	return rb_entry(p->pi_waiters_leftmost, struct rt_mutex_waiter,
+	return rb_entry(rb_first(&p->pi_waiters), struct rt_mutex_waiter,
 			pi_tree_entry);
 }
 
-- 
1.8.3.1

  reply	other threads:[~2016-04-06 12:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-06 12:59 [PATCH v2 1/2] sched/rtmutex/deadline: Fix a PI crash for deadline tasks Xunlei Pang
2016-04-06 12:59 ` Xunlei Pang [this message]
2016-04-06 18:15   ` [PATCH v2 2/2] rtmutex: Kill pi_waiters_leftmost from task_struct Peter Zijlstra
2016-04-06 18:14 ` [PATCH v2 1/2] sched/rtmutex/deadline: Fix a PI crash for deadline tasks Peter Zijlstra
2016-04-08  8:04   ` Xunlei Pang
2016-04-08  8:31     ` Peter Zijlstra

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=1459947556-12332-2-git-send-email-xlpang@redhat.com \
    --to=xlpang@redhat.com \
    --cc=juri.lelli@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome