Skip to content

Commit 8657a68

Browse files
committed
sched: Define sched_clock_irqtime as static key
JIRA: https://issues.redhat.com/browse/RHEL-78821 commit 8722903 Author: Yafang Shao <laoar.shao@gmail.com> Date: Fri Jan 3 10:24:06 2025 +0800 sched: Define sched_clock_irqtime as static key 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> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Michal Koutný <mkoutny@suse.com> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lore.kernel.org/r/20250103022409.2544-2-laoar.shao@gmail.com Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 62c982d commit 8657a68

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

kernel/sched/cputime.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
77

8+
DEFINE_STATIC_KEY_FALSE(sched_clock_irqtime);
9+
810
/*
911
* There are no locks covering percpu hardirq/softirq time.
1012
* They are only modified in vtime_account, on corresponding CPU
@@ -18,16 +20,14 @@
1820
*/
1921
DEFINE_PER_CPU(struct irqtime, cpu_irqtime);
2022

21-
static int sched_clock_irqtime;
22-
2323
void enable_sched_clock_irqtime(void)
2424
{
25-
sched_clock_irqtime = 1;
25+
static_branch_enable(&sched_clock_irqtime);
2626
}
2727

2828
void disable_sched_clock_irqtime(void)
2929
{
30-
sched_clock_irqtime = 0;
30+
static_branch_disable(&sched_clock_irqtime);
3131
}
3232

3333
static void irqtime_account_delta(struct irqtime *irqtime, u64 delta,
@@ -53,7 +53,7 @@ void irqtime_account_irq(struct task_struct *curr, unsigned int offset)
5353
s64 delta;
5454
int cpu;
5555

56-
if (!sched_clock_irqtime)
56+
if (!irqtime_enabled())
5757
return;
5858

5959
cpu = smp_processor_id();
@@ -86,8 +86,6 @@ static u64 irqtime_tick_accounted(u64 maxtime)
8686

8787
#else /* CONFIG_IRQ_TIME_ACCOUNTING */
8888

89-
#define sched_clock_irqtime (0)
90-
9189
static u64 irqtime_tick_accounted(u64 dummy)
9290
{
9391
return 0;
@@ -487,7 +485,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
487485
if (vtime_accounting_enabled_this_cpu())
488486
return;
489487

490-
if (sched_clock_irqtime) {
488+
if (irqtime_enabled()) {
491489
irqtime_account_process_tick(p, user_tick, 1);
492490
return;
493491
}
@@ -516,7 +514,7 @@ void account_idle_ticks(unsigned long ticks)
516514
{
517515
u64 cputime, steal;
518516

519-
if (sched_clock_irqtime) {
517+
if (irqtime_enabled()) {
520518
irqtime_account_idle_ticks(ticks);
521519
return;
522520
}

kernel/sched/sched.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,12 @@ struct irqtime {
30293029
};
30303030

30313031
DECLARE_PER_CPU(struct irqtime, cpu_irqtime);
3032+
DECLARE_STATIC_KEY_FALSE(sched_clock_irqtime);
3033+
3034+
static inline int irqtime_enabled(void)
3035+
{
3036+
return static_branch_likely(&sched_clock_irqtime);
3037+
}
30323038

30333039
/*
30343040
* Returns the irqtime minus the softirq time computed by ksoftirqd.
@@ -3049,6 +3055,13 @@ static inline u64 irq_time_read(int cpu)
30493055
return total;
30503056
}
30513057

3058+
#else
3059+
3060+
static inline int irqtime_enabled(void)
3061+
{
3062+
return 0;
3063+
}
3064+
30523065
#endif /* CONFIG_IRQ_TIME_ACCOUNTING */
30533066

30543067
#ifdef CONFIG_CPU_FREQ

0 commit comments

Comments
 (0)