Re: [PATCH v3 1/2] timer: make deferrable cpu unbound timers really not bound to a cpu

From: psodagud
Date: Wed May 13 2020 - 16:55:37 EST


On 2020-05-13 13:28, Thomas Gleixner wrote:
psodagud@xxxxxxxxxxxxxx writes:
On 2020-05-06 06:28, Thomas Gleixner wrote:
#ifdef CONFIG_SMP
+struct timer_base timer_base_deferrable;
unsigned int sysctl_timer_migration = 1;

DEFINE_STATIC_KEY_FALSE(timers_migration_enabled);
@@ -841,8 +842,14 @@ static inline struct timer_base
*get_timer_cpu_base(u32 tflags, u32 cpu)
* If the timer is deferrable and NO_HZ_COMMON is set then we need
* to use the deferrable base.
*/
- if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE))
- base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
+ if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE))
{
+#ifdef CONFIG_SMP
+ base = &timer_base_deferrable;
+#endif

There are definitely smarter ways of solving this than sprinkling
#ifdef's around the code.

I am able to understand all other comments and I will address all those
comments in the next patch set.
It is not clear to me how to avoid #ifdef's in this case. Could you
please share an example here?

The answer is further down already:

Thanks Tglx for quick response.

I think, you are referring stub functions. Yes. I can reduce some of the #ifdefs with stub functions as you mentioned and not all the cases right?
I have introduced two variables timer_base_deferrable and deferrable_pending and I can put stub function where ever is possible. But it may not be appropriate to have stub function for all the references of these variables right? Correct me if my understanding is wrong.

-Thanks, Prasad


Stub functions exist to avoid this unreadable #ifdef garbage.