From: Yafang Shao <laoar.shao@gmail.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,
vschneid@redhat.com
Cc: linux-kernel@vger.kernel.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH 2/3] sched: Define sched_clock_irqtime as static key
Date: Mon, 23 Sep 2024 17:00:27 +0800 [thread overview]
Message-ID: <20240923090028.16368-3-laoar.shao@gmail.com> (raw)
In-Reply-To: <20240923090028.16368-1-laoar.shao@gmail.com>
Since CPU time accounting is a performance-critical path, let's define
sched_clock_irqtime as a static key to minimize potential overhead.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
kernel/sched/cputime.c | 16 +++++++---------
kernel/sched/sched.h | 1 +
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 4586db5cf3a8..de9a36e0fe04 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -7,6 +7,8 @@
#include <asm/cputime.h>
#endif
+DEFINE_STATIC_KEY_FALSE(sched_clock_irqtime);
+
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
/*
@@ -22,16 +24,14 @@
*/
DEFINE_PER_CPU(struct irqtime, cpu_irqtime);
-static int sched_clock_irqtime;
-
void enable_sched_clock_irqtime(void)
{
- sched_clock_irqtime = 1;
+ static_branch_enable(&sched_clock_irqtime);
}
void disable_sched_clock_irqtime(void)
{
- sched_clock_irqtime = 0;
+ static_branch_disable(&sched_clock_irqtime);
}
static void irqtime_account_delta(struct task_struct *curr,
@@ -61,7 +61,7 @@ void irqtime_account_irq(struct task_struct *curr, unsigned int offset)
s64 delta;
int cpu;
- if (!sched_clock_irqtime)
+ if (!static_branch_likely(&sched_clock_irqtime))
return;
cpu = smp_processor_id();
@@ -94,8 +94,6 @@ static u64 irqtime_tick_accounted(u64 maxtime)
#else /* CONFIG_IRQ_TIME_ACCOUNTING */
-#define sched_clock_irqtime (0)
-
static u64 irqtime_tick_accounted(u64 dummy)
{
return 0;
@@ -482,7 +480,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
if (vtime_accounting_enabled_this_cpu())
return;
- if (sched_clock_irqtime) {
+ if (static_branch_likely(&sched_clock_irqtime)) {
irqtime_account_process_tick(p, user_tick, 1);
return;
}
@@ -511,7 +509,7 @@ void account_idle_ticks(unsigned long ticks)
{
u64 cputime, steal;
- if (sched_clock_irqtime) {
+ if (static_branch_likely(&sched_clock_irqtime)) {
irqtime_account_idle_ticks(ticks);
return;
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 8063db62b027..db7d541eebff 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3174,6 +3174,7 @@ struct irqtime {
};
DECLARE_PER_CPU(struct irqtime, cpu_irqtime);
+DECLARE_STATIC_KEY_FALSE(sched_clock_irqtime);
/*
* Returns the irqtime minus the softirq time computed by ksoftirqd.
--
2.43.5
next prev parent reply other threads:[~2024-09-23 9:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 9:00 [PATCH 0/3] sched: Fix irq accounting for CONFIG_IRQ_TIME_ACCOUNTING Yafang Shao
2024-09-23 9:00 ` [PATCH 1/3] sched: Fix cgroup " Yafang Shao
2024-09-26 6:13 ` kernel test robot
2024-09-27 8:46 ` Yafang Shao
2024-09-23 9:00 ` Yafang Shao [this message]
2024-09-23 9:00 ` [PATCH 3/3] sched: Don't account irq time if sched_clock_irqtime is disabled Yafang Shao
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=20240923090028.16368-3-laoar.shao@gmail.com \
--to=laoar.shao@gmail.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 \
--cc=vschneid@redhat.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®