Skip to content

Commit 63678ee

Browse files
committed
s390/preempt: disable __preempt_count_add() optimization for PROFILE_ALL_BRANCHES
gcc 12 does not (always) optimize away code that should only be generated if parameters are constant and within in a certain range. This depends on various obscure kernel config options, however in particular PROFILE_ALL_BRANCHES can trigger this compile error: In function ‘__atomic_add_const’, inlined from ‘__preempt_count_add.part.0’ at ./arch/s390/include/asm/preempt.h:50:3: ./arch/s390/include/asm/atomic_ops.h:80:9: error: impossible constraint in ‘asm’ 80 | asm volatile( \ | ^~~ Workaround this by simply disabling the optimization for PROFILE_ALL_BRANCHES, since the kernel will be so slow, that this optimization won't matter at all. Reported-by: Thomas Richter <[email protected]> Reviewed-by: Sven Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 5ace65e commit 63678ee

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

arch/s390/include/asm/preempt.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ static inline bool test_preempt_need_resched(void)
4646

4747
static inline void __preempt_count_add(int val)
4848
{
49-
if (__builtin_constant_p(val) && (val >= -128) && (val <= 127))
50-
__atomic_add_const(val, &S390_lowcore.preempt_count);
51-
else
52-
__atomic_add(val, &S390_lowcore.preempt_count);
49+
/*
50+
* With some obscure config options and CONFIG_PROFILE_ALL_BRANCHES
51+
* enabled, gcc 12 fails to handle __builtin_constant_p().
52+
*/
53+
if (!IS_ENABLED(CONFIG_PROFILE_ALL_BRANCHES)) {
54+
if (__builtin_constant_p(val) && (val >= -128) && (val <= 127)) {
55+
__atomic_add_const(val, &S390_lowcore.preempt_count);
56+
return;
57+
}
58+
}
59+
__atomic_add(val, &S390_lowcore.preempt_count);
5360
}
5461

5562
static inline void __preempt_count_sub(int val)

0 commit comments

Comments
 (0)