Skip to content

Commit 7464c07

Browse files
FlyGoattsbogend
authored andcommitted
MIPS: csrc-r4k: Don't register as sched_clock if unfit
When we have more than one CPU in system, counter synchronisation overhead can lead to a scenario that sched_clock goes backward when being read from different CPUs. This is accommodated by CONFIG_HAVE_UNSTABLE_SCHED_CLOCK, but it's unavailable on 32bit kernel. We don't want to risk sched_clock correctness, so if we have multiple CPU in system and CONFIG_HAVE_UNSTABLE_SCHED_CLOCK is not set, we just don't use counter as sched_clock source. Signed-off-by: Jiaxun Yang <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 426fa8e commit 7464c07

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

arch/mips/kernel/csrc-r4k.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ static bool rdhwr_count_usable(void)
6868
return false;
6969
}
7070

71+
static inline __init bool count_can_be_sched_clock(void)
72+
{
73+
if (IS_ENABLED(CONFIG_CPU_FREQ))
74+
return false;
75+
76+
if (num_possible_cpus() > 1 &&
77+
!IS_ENABLED(CONFIG_HAVE_UNSTABLE_SCHED_CLOCK))
78+
return false;
79+
80+
return true;
81+
}
82+
7183
#ifdef CONFIG_CPU_FREQ
7284

7385
static bool __read_mostly r4k_clock_unstable;
@@ -125,9 +137,8 @@ int __init init_r4k_clocksource(void)
125137

126138
clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
127139

128-
#ifndef CONFIG_CPU_FREQ
129-
sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency);
130-
#endif
140+
if (count_can_be_sched_clock())
141+
sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency);
131142

132143
return 0;
133144
}

0 commit comments

Comments
 (0)