[PATCH 1/1] sched.h: silent false ATOMIC_SLEEP warning from cond_resched

From: Hariom Panthi
Date: Wed Oct 09 2024 - 23:28:32 EST


In case of (CONFIG_PREEMPTION && !CONFIG_PREEMPT_DYNAMIC),
cond_reched() is not sleeping.

Thus remove __might_resched in that cases.

Co-developed-by: Maninder Singh <maninder1.s@xxxxxxxxxxx>
Signed-off-by: Maninder Singh <maninder1.s@xxxxxxxxxxx>
Signed-off-by: Hariom Panthi <hariom1.p@xxxxxxxxxxx>
---
include/linux/sched.h | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index c6009faf8da5..a748ea8a435c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2067,6 +2067,7 @@ static inline int _cond_resched(void)

#endif /* PREEMPT_DYNAMIC && CONFIG_HAVE_PREEMPT_DYNAMIC_CALL */

+#define __might_resched_possible __might_resched
#else /* CONFIG_PREEMPTION && !CONFIG_PREEMPT_DYNAMIC */

static inline int _cond_resched(void)
@@ -2075,11 +2076,13 @@ static inline int _cond_resched(void)
return 0;
}

+static inline void __might_resched_possible(const char *file, int line, unsigned int offsets) {}
+
#endif /* !CONFIG_PREEMPTION || CONFIG_PREEMPT_DYNAMIC */

-#define cond_resched() ({ \
- __might_resched(__FILE__, __LINE__, 0); \
- _cond_resched(); \
+#define cond_resched() ({ \
+ __might_resched_possible(__FILE__, __LINE__, 0); \
+ _cond_resched(); \
})

extern int __cond_resched_lock(spinlock_t *lock);
@@ -2105,19 +2108,19 @@ extern int __cond_resched_rwlock_write(rwlock_t *lock);
(PREEMPT_LOCK_OFFSET + (1U << MIGHT_RESCHED_RCU_SHIFT))
#endif

-#define cond_resched_lock(lock) ({ \
- __might_resched(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
- __cond_resched_lock(lock); \
+#define cond_resched_lock(lock) ({ \
+ __might_resched_possible(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
+ __cond_resched_lock(lock); \
})

-#define cond_resched_rwlock_read(lock) ({ \
- __might_resched(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
- __cond_resched_rwlock_read(lock); \
+#define cond_resched_rwlock_read(lock) ({ \
+ __might_resched_possible(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
+ __cond_resched_rwlock_read(lock); \
})

-#define cond_resched_rwlock_write(lock) ({ \
- __might_resched(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
- __cond_resched_rwlock_write(lock); \
+#define cond_resched_rwlock_write(lock) ({ \
+ __might_resched_possible(__FILE__, __LINE__, PREEMPT_LOCK_RESCHED_OFFSETS); \
+ __cond_resched_rwlock_write(lock); \
})

static __always_inline bool need_resched(void)
--
2.25.1