From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: walken@google.com, dave@stgolabs.net, mingo@kernel.org,
tglx@linutronix.de, oleg@redhat.com, irogers@google.com,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
peterz@infradead.org
Subject: [RFC][PATCH 3/7] rbtree, sched/deadline: Use rb_add_cached()
Date: Wed, 29 Apr 2020 17:33:01 +0200 [thread overview]
Message-ID: <20200429153549.128224664@infradead.org> (raw)
In-Reply-To: 20200429153258.563269446@infradead.org
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/sched/deadline.c | 75 +++++++++++++++---------------------------------
1 file changed, 24 insertions(+), 51 deletions(-)
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -440,58 +440,38 @@ static void dec_dl_migration(struct sche
update_dl_migration(dl_rq);
}
+#define __node_2_pdl(node) \
+ rb_entry((node), struct task_struct, pushable_dl_tasks)
+
+static inline bool __pushable_less(struct rb_node *a, const struct rb_node *b)
+{
+ return dl_entity_preempt(&__node_2_pdl(a)->dl, &__node_2_pdl(b)->dl);
+}
+
/*
* The list of pushable -deadline task is not a plist, like in
* sched_rt.c, it is an rb-tree with tasks ordered by deadline.
*/
static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
{
- struct dl_rq *dl_rq = &rq->dl;
- struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_root.rb_node;
- struct rb_node *parent = NULL;
- struct task_struct *entry;
- bool leftmost = true;
-
BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks));
- while (*link) {
- parent = *link;
- entry = rb_entry(parent, struct task_struct,
- pushable_dl_tasks);
- if (dl_entity_preempt(&p->dl, &entry->dl))
- link = &parent->rb_left;
- else {
- link = &parent->rb_right;
- leftmost = false;
- }
- }
-
- if (leftmost)
- dl_rq->earliest_dl.next = p->dl.deadline;
-
- rb_link_node(&p->pushable_dl_tasks, parent, link);
- rb_insert_color_cached(&p->pushable_dl_tasks,
- &dl_rq->pushable_dl_tasks_root, leftmost);
+ if (rb_add_cached(&rq->dl.pushable_dl_tasks_root, &p->pushable_dl_tasks,
+ __pushable_less))
+ rq->dl.earliest_dl.next = p->dl.deadline;
}
static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
{
struct dl_rq *dl_rq = &rq->dl;
+ struct rb_root_cached *root = &dl_rq->pushable_dl_tasks_root;
if (RB_EMPTY_NODE(&p->pushable_dl_tasks))
return;
- if (dl_rq->pushable_dl_tasks_root.rb_leftmost == &p->pushable_dl_tasks) {
- struct rb_node *next_node;
+ if (rb_erase_cached(&p->pushable_dl_tasks, root))
+ dl_rq->earliest_dl.next = __node_2_pdl(rb_first_cached(root))->dl.deadline;
- next_node = rb_next(&p->pushable_dl_tasks);
- if (next_node) {
- dl_rq->earliest_dl.next = rb_entry(next_node,
- struct task_struct, pushable_dl_tasks)->dl.deadline;
- }
- }
-
- rb_erase_cached(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
RB_CLEAR_NODE(&p->pushable_dl_tasks);
}
@@ -1401,29 +1381,21 @@ void dec_dl_tasks(struct sched_dl_entity
dec_dl_migration(dl_se, dl_rq);
}
+#define __node_2_dle(node) \
+ rb_entry((node), struct sched_dl_entity, rb_node)
+
+static inline bool __dl_less(struct rb_node *a, const struct rb_node *b)
+{
+ return dl_time_before(__node_2_dle(a)->deadline, __node_2_dle(b)->deadline);
+}
+
static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
{
struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
- struct rb_node **link = &dl_rq->root.rb_root.rb_node;
- struct rb_node *parent = NULL;
- struct sched_dl_entity *entry;
- int leftmost = 1;
BUG_ON(!RB_EMPTY_NODE(&dl_se->rb_node));
- while (*link) {
- parent = *link;
- entry = rb_entry(parent, struct sched_dl_entity, rb_node);
- if (dl_time_before(dl_se->deadline, entry->deadline))
- link = &parent->rb_left;
- else {
- link = &parent->rb_right;
- leftmost = 0;
- }
- }
-
- rb_link_node(&dl_se->rb_node, parent, link);
- rb_insert_color_cached(&dl_se->rb_node, &dl_rq->root, leftmost);
+ rb_add_cached(&dl_rq->root, &dl_se->rb_node, __dl_less);
inc_dl_tasks(dl_se, dl_rq);
}
@@ -1436,6 +1408,7 @@ static void __dequeue_dl_entity(struct s
return;
rb_erase_cached(&dl_se->rb_node, &dl_rq->root);
+
RB_CLEAR_NODE(&dl_se->rb_node);
dec_dl_tasks(dl_se, dl_rq);
next prev parent reply other threads:[~2020-04-29 15:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 15:32 [RFC][PATCH 0/7] Generic RB-tree helpers Peter Zijlstra
2020-04-29 15:32 ` [RFC][PATCH 1/7] rbtree: Add generic add and find helpers Peter Zijlstra
2020-04-30 1:04 ` Michel Lespinasse
2020-04-30 8:46 ` Peter Zijlstra
2020-04-30 9:26 ` Peter Zijlstra
2020-04-30 7:28 ` Juri Lelli
2020-04-30 7:51 ` Michel Lespinasse
2020-04-30 8:07 ` Juri Lelli
2020-04-30 8:27 ` Peter Zijlstra
2020-04-29 15:33 ` [RFC][PATCH 2/7] rbtree, sched/fair: Use rb_add_cached() Peter Zijlstra
2020-04-29 15:33 ` Peter Zijlstra [this message]
2020-04-29 15:33 ` [RFC][PATCH 4/7] rbtree, perf: Use new rbtree helpers Peter Zijlstra
2020-04-29 15:33 ` [RFC][PATCH 5/7] rbtree, uprobes: Use " Peter Zijlstra
2020-04-29 15:33 ` [RFC][PATCH 6/7] rbtree, rtmutex: Use rb_add_cached() Peter Zijlstra
2020-04-29 15:33 ` [RFC][PATCH 7/7] rbtree, timerqueue: " 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=20200429153549.128224664@infradead.org \
--to=peterz@infradead.org \
--cc=dave@stgolabs.net \
--cc=irogers@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=walken@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;
as well as URLs for NNTP newsgroup(s).