From: Cruz Zhao <CruzZhao@linux.alibaba.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
bristot@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] sched/core: Introduce nr_running percpu for each cookie
Date: Tue, 28 Jun 2022 15:57:24 +0800 [thread overview]
Message-ID: <1656403045-100840-3-git-send-email-CruzZhao@linux.alibaba.com> (raw)
In-Reply-To: <1656403045-100840-1-git-send-email-CruzZhao@linux.alibaba.com>
Introduce a percpu count to struct sched_core_cookie, which indicates how
many tasks with this cookie in the runqueue of this cpu.
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
---
kernel/sched/core.c | 7 +++++++
kernel/sched/core_sched.c | 16 ++++++++--------
kernel/sched/sched.h | 9 +++++++++
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 263d764..9f71042 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -235,21 +235,28 @@ static inline int rb_sched_core_cmp(const void *key, const struct rb_node *node)
void sched_core_enqueue(struct rq *rq, struct task_struct *p)
{
+ struct sched_core_cookie *ck = (struct sched_core_cookie *)p->core_cookie;
+
rq->core->core_task_seq++;
if (!p->core_cookie)
return;
rb_add(&p->core_node, &rq->core_tree, rb_sched_core_less);
+
+ *per_cpu_ptr(ck->nr_running, rq->cpu) += 1;
}
void sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags)
{
+ struct sched_core_cookie *ck = (struct sched_core_cookie *)p->core_cookie;
+
rq->core->core_task_seq++;
if (sched_core_enqueued(p)) {
rb_erase(&p->core_node, &rq->core_tree);
RB_CLEAR_NODE(&p->core_node);
+ *per_cpu_ptr(ck->nr_running, rq->cpu) -= 1;
}
/*
diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index ba2466c..65ab9fcb 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -1,20 +1,19 @@
// SPDX-License-Identifier: GPL-2.0-only
-/*
- * A simple wrapper around refcount. An allocated sched_core_cookie's
- * address is used to compute the cookie of the task.
- */
-struct sched_core_cookie {
- refcount_t refcnt;
-};
-
static unsigned long sched_core_alloc_cookie(void)
{
struct sched_core_cookie *ck = kmalloc(sizeof(*ck), GFP_KERNEL);
+ int cpu;
+
if (!ck)
return 0;
refcount_set(&ck->refcnt, 1);
+
+ ck->nr_running = alloc_percpu(unsigned int);
+ for_each_possible_cpu(cpu)
+ *per_cpu_ptr(ck->nr_running, cpu) = 0;
+
sched_core_get();
return (unsigned long)ck;
@@ -25,6 +24,7 @@ static void sched_core_put_cookie(unsigned long cookie)
struct sched_core_cookie *ptr = (void *)cookie;
if (ptr && refcount_dec_and_test(&ptr->refcnt)) {
+ free_percpu(ptr->nr_running);
kfree(ptr);
sched_core_put();
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 5b14b6b..d852c67 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1186,6 +1186,15 @@ static inline raw_spinlock_t *__rq_lockp(struct rq *rq)
bool cfs_prio_less(struct task_struct *a, struct task_struct *b, bool fi);
/*
+ * A simple wrapper around refcount. An allocated sched_core_cookie's
+ * address is used to compute the cookie of the task.
+ */
+struct sched_core_cookie {
+ refcount_t refcnt;
+ unsigned int __percpu *nr_running;
+};
+
+/*
* Helpers to check if the CPU's core cookie matches with the task's cookie
* when core scheduling is enabled.
* A special case is that the task's cookie always matches with CPU's core
--
1.8.3.1
next prev parent reply other threads:[~2022-06-28 7:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 7:57 [PATCH 0/3] sched/core: Optimize load balance of core scheduling Cruz Zhao
2022-06-28 7:57 ` [PATCH 1/3] sched/core: Fix the bug that task won't enqueue into core tree when update cookie Cruz Zhao
2022-07-03 14:19 ` cruzzhao
2022-07-04 8:53 ` Peter Zijlstra
2022-07-14 11:37 ` Peter Zijlstra
2022-07-15 5:08 ` cruzzhao
2022-07-21 8:44 ` [tip: sched/core] " tip-bot2 for Cruz Zhao
2022-06-28 7:57 ` Cruz Zhao [this message]
2022-07-04 8:56 ` [PATCH 2/3] sched/core: Introduce nr_running percpu for each cookie Peter Zijlstra
2022-07-04 9:45 ` Peter Zijlstra
2022-07-06 7:45 ` cruzzhao
2022-06-28 7:57 ` [PATCH 3/3] sched/core: Make tasks with the same cookie pairs on SMT siblings Cruz Zhao
2022-07-04 9:43 ` Peter Zijlstra
2022-07-06 8:03 ` cruzzhao
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=1656403045-100840-3-git-send-email-CruzZhao@linux.alibaba.com \
--to=cruzzhao@linux.alibaba.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--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