2020-05-02 18:31:47

by Prasad Sodagudi

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

From: Joonwoo Park <[email protected]>

When a deferrable work (INIT_DEFERRABLE_WORK, etc.) is queued via
queue_delayed_work() it's probably intended to run the work item on any
CPU that isn't idle. However, we queue the work to run at a later time
by starting a deferrable timer that binds to whatever CPU the work is
queued on which is same with queue_delayed_work_on(smp_processor_id())
effectively.

As a result WORK_CPU_UNBOUND work items aren't really cpu unbound now.
In fact this is perfectly fine with UP kernel and also won't affect much a
system without dyntick with SMP kernel too as every cpus run timers
periodically. But on SMP systems with dyntick current implementation leads
deferrable timers not very scalable because the timer's base which has
queued the deferrable timer won't wake up till next non-deferrable timer
expires even though there are possible other non idle cpus are running
which are able to run expired deferrable timers.

The deferrable work is a good example of the current implementation's
victim like below.

INIT_DEFERRABLE_WORK(&dwork, fn);
CPU 0 CPU 1
queue_delayed_work(wq, &dwork, HZ);
queue_delayed_work_on(WORK_CPU_UNBOUND);
...
__mod_timer() -> queues timer to the
current cpu's timer
base.
...
tick_nohz_idle_enter() -> cpu enters idle.
A second later
cpu 0 is now in idle. cpu 1 exits idle or wasn't in idle so
now it's in active but won't
cpu 0 won't wake up till next handle cpu unbound deferrable timer
non-deferrable timer expires. as it's in cpu 0's timer base.

To make all cpu unbound deferrable timers are scalable, introduce a common
timer base which is only for cpu unbound deferrable timers to make those
are indeed cpu unbound so that can be scheduled by any of non idle cpus.
This common timer fixes scalability issue of delayed work and all other cpu
unbound deferrable timer using implementations.

Signed-off-by: Joonwoo Park <[email protected]>
Signed-off-by: Prasad Sodagudi <[email protected]>
---
kernel/time/timer.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index a5221ab..1bf9b49 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -220,6 +220,7 @@ static void timer_update_keys(struct work_struct *work);
static DECLARE_WORK(timer_update_work, timer_update_keys);

#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
+ if (tflags & TIMER_PINNED)
+ base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
+ }
+
return base;
}

@@ -854,8 +861,14 @@ static inline struct timer_base *get_timer_this_cpu_base(u32 tflags)
* 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 = this_cpu_ptr(&timer_bases[BASE_DEF]);
+ if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) {
+#ifdef CONFIG_SMP
+ base = &timer_base_deferrable;
+#endif
+ if (tflags & TIMER_PINNED)
+ base = this_cpu_ptr(&timer_bases[BASE_DEF]);
+ }
+
return base;
}

@@ -1785,8 +1798,14 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h)
struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);

__run_timers(base);
- if (IS_ENABLED(CONFIG_NO_HZ_COMMON))
+ if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
__run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
+#ifdef CONFIG_SMP
+ if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
+ tick_do_timer_cpu == smp_processor_id())
+ __run_timers(&timer_base_deferrable);
+#endif
+ }
}

/*
@@ -2025,6 +2044,16 @@ static void __init init_timer_cpu(int cpu)
}
}

+#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
+static void __init init_timer_deferrable_global(void)
+{
+ timer_base_deferrable.cpu = nr_cpu_ids;
+ raw_spin_lock_init(&timer_base_deferrable.lock);
+ timer_base_deferrable.clk = jiffies;
+ timer_base_init_expiry_lock(&timer_base_deferrable);
+}
+#endif
+
static void __init init_timer_cpus(void)
{
int cpu;
@@ -2036,6 +2065,9 @@ static void __init init_timer_cpus(void)
void __init init_timers(void)
{
init_timer_cpus();
+#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
+ init_timer_deferrable_global();
+#endif
open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
}

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2020-05-04 18:14:41

by kernel test robot

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

Hi Prasad,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/timers/core]
[also build test ERROR on tip/auto-latest tip/timers/nohz v5.7-rc4 next-20200501]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Prasad-Sodagudi/timer-make-deferrable-cpu-unbound-timers-really-not-bound-to-a-cpu/20200503-025049
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 4479730e9263befbb9ce9563a09563db2acb8f7c
config: riscv-nommu_virt_defconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=riscv

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>

All errors (new ones prefixed by >>):

kernel/time/timer.c: In function 'get_timer_cpu_base':
>> kernel/time/timer.c:847:11: error: 'timer_base_deferrable' undeclared (first use in this function)
847 | base = &timer_base_deferrable;
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/timer.c:847:11: note: each undeclared identifier is reported only once for each function it appears in
kernel/time/timer.c: In function 'get_timer_this_cpu_base':
kernel/time/timer.c:866:11: error: 'timer_base_deferrable' undeclared (first use in this function)
866 | base = &timer_base_deferrable;
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/timer.c: In function 'run_timer_softirq':
kernel/time/timer.c:1805:18: error: 'timer_base_deferrable' undeclared (first use in this function)
1805 | __run_timers(&timer_base_deferrable);
| ^~~~~~~~~~~~~~~~~~~~~

vim +/timer_base_deferrable +847 kernel/time/timer.c

836
837 static inline struct timer_base *get_timer_cpu_base(u32 tflags, u32 cpu)
838 {
839 struct timer_base *base = per_cpu_ptr(&timer_bases[BASE_STD], cpu);
840
841 /*
842 * If the timer is deferrable and NO_HZ_COMMON is set then we need
843 * to use the deferrable base.
844 */
845 if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) {
846 #ifdef CONFIG_SMP
> 847 base = &timer_base_deferrable;
848 #endif
849 if (tflags & TIMER_PINNED)
850 base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
851 }
852
853 return base;
854 }
855

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (2.89 kB)
.config.gz (6.63 kB)
Download all attachments

2020-05-05 00:11:02

by kernel test robot

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

Hi Prasad,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/timers/core]
[also build test ERROR on tip/auto-latest tip/timers/nohz v5.7-rc4 next-20200504]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Prasad-Sodagudi/timer-make-deferrable-cpu-unbound-timers-really-not-bound-to-a-cpu/20200503-025049
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 4479730e9263befbb9ce9563a09563db2acb8f7c
config: ia64-randconfig-a001-20200505 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>

All errors (new ones prefixed by >>):

kernel/time/timer.c: In function 'get_timer_cpu_base':
kernel/time/timer.c:847:11: error: 'timer_base_deferrable' undeclared (first use in this function)
847 | base = &timer_base_deferrable;
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/timer.c:847:11: note: each undeclared identifier is reported only once for each function it appears in
kernel/time/timer.c: In function 'get_timer_this_cpu_base':
kernel/time/timer.c:866:11: error: 'timer_base_deferrable' undeclared (first use in this function)
866 | base = &timer_base_deferrable;
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/timer.c: In function 'run_timer_softirq':
>> kernel/time/timer.c:1803:7: error: 'tick_do_timer_cpu' undeclared (first use in this function); did you mean 'tick_dep_clear_cpu'?
1803 | if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
| ^~~~~~~~~~~~~~~~~
| tick_dep_clear_cpu
>> kernel/time/timer.c:1803:28: error: 'TICK_DO_TIMER_NONE' undeclared (first use in this function)
1803 | if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
| ^~~~~~~~~~~~~~~~~~
kernel/time/timer.c:1805:18: error: 'timer_base_deferrable' undeclared (first use in this function)
1805 | __run_timers(&timer_base_deferrable);
| ^~~~~~~~~~~~~~~~~~~~~

vim +1803 kernel/time/timer.c

1791
1792 /*
1793 * This function runs timers and the timer-tq in bottom half context.
1794 */
1795 static __latent_entropy void run_timer_softirq(struct softirq_action *h)
1796 {
1797 struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
1798
1799 __run_timers(base);
1800 if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
1801 __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
1802 #ifdef CONFIG_SMP
> 1803 if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
1804 tick_do_timer_cpu == smp_processor_id())
1805 __run_timers(&timer_base_deferrable);
1806 #endif
1807 }
1808 }
1809

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.35 kB)
.config.gz (30.28 kB)
Download all attachments

2020-05-06 19:06:45

by Thomas Gleixner

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

Prasad Sodagudi <[email protected]> writes:
> To make all cpu unbound deferrable timers are scalable, introduce a common
> timer base which is only for cpu unbound deferrable timers to make those
> are indeed cpu unbound so that can be scheduled by any of non idle cpus.
> This common timer fixes scalability issue of delayed work and all other cpu
> unbound deferrable timer using implementations.

Scalability? That's really the wrong term here. A global timer base is
the opposite and you really want to explain why this is not creating a
scalability problem on large systems.

> #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.

> + if (tflags & TIMER_PINNED)
> + base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
> + }
> +
> return base;
> }
> @@ -1785,8 +1798,14 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h)
> struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
>
> __run_timers(base);
> - if (IS_ENABLED(CONFIG_NO_HZ_COMMON))
> + if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
> __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
> +#ifdef CONFIG_SMP
> + if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
> + tick_do_timer_cpu == smp_processor_id())
> + __run_timers(&timer_base_deferrable);
> +#endif

Again, this can be solved in readable ways. Just slapping #ifdefs all
over the place is sloppy and lazy.

Aside of that accessing the tick internals here open coded is just a
layering violation.

> + }
> }
>
> /*
> @@ -2025,6 +2044,16 @@ static void __init init_timer_cpu(int cpu)
> }
> }
>
> +#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
> +static void __init init_timer_deferrable_global(void)
> +{
> + timer_base_deferrable.cpu = nr_cpu_ids;

This was obviously never tested with CONFIG_DEBUG_PER_CPU_MAPS=y as this
will simply result in out of bounds accesses.

> static void __init init_timer_cpus(void)
> {
> int cpu;
> @@ -2036,6 +2065,9 @@ static void __init init_timer_cpus(void)
> void __init init_timers(void)
> {
> init_timer_cpus();
> +#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
> + init_timer_deferrable_global();
> +#endif

Stub functions exist to avoid this unreadable #ifdef garbage.

Thanks,

tglx

2020-05-13 19:59:10

by Prasad Sodagudi

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

Hi Tglx,

On 2020-05-06 06:28, Thomas Gleixner wrote:
> Prasad Sodagudi <[email protected]> writes:
>> To make all cpu unbound deferrable timers are scalable, introduce a
>> common
>> timer base which is only for cpu unbound deferrable timers to make
>> those
>> are indeed cpu unbound so that can be scheduled by any of non idle
>> cpus.
>> This common timer fixes scalability issue of delayed work and all
>> other cpu
>> unbound deferrable timer using implementations.
>
> Scalability? That's really the wrong term here. A global timer base is
> the opposite and you really want to explain why this is not creating a
> scalability problem on large systems.
>
>> #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?


>
>> + if (tflags & TIMER_PINNED)
>> + base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
>> + }
>> +
>> return base;
>> }
>> @@ -1785,8 +1798,14 @@ static __latent_entropy void
>> run_timer_softirq(struct softirq_action *h)
>> struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
>>
>> __run_timers(base);
>> - if (IS_ENABLED(CONFIG_NO_HZ_COMMON))
>> + if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) {
>> __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
>> +#ifdef CONFIG_SMP
>> + if (tick_do_timer_cpu == TICK_DO_TIMER_NONE ||
>> + tick_do_timer_cpu == smp_processor_id())
>> + __run_timers(&timer_base_deferrable);
>> +#endif
>
> Again, this can be solved in readable ways. Just slapping #ifdefs all
> over the place is sloppy and lazy.
Sorry. I will try to address this. It is not clear to me how to avoid
#ifdefs in this case too.
Please provide me more information.

>
> Aside of that accessing the tick internals here open coded is just a
> layering violation.
I will fix this and avoid using referring to tick internals here.

>
>> + }
>> }
>>
>> /*
>> @@ -2025,6 +2044,16 @@ static void __init init_timer_cpu(int cpu)
>> }
>> }
>>
>> +#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
>> +static void __init init_timer_deferrable_global(void)
>> +{
>> + timer_base_deferrable.cpu = nr_cpu_ids;
>
> This was obviously never tested with CONFIG_DEBUG_PER_CPU_MAPS=y as
> this
> will simply result in out of bounds accesses.

Sure. I will test this CONFIG_DEBUG_PER_CPU_MAPS=y enabled before
pushing the next patch set.
>
>> static void __init init_timer_cpus(void)
>> {
>> int cpu;
>> @@ -2036,6 +2065,9 @@ static void __init init_timer_cpus(void)
>> void __init init_timers(void)
>> {
>> init_timer_cpus();
>> +#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
>> + init_timer_deferrable_global();
>> +#endif
>
> Stub functions exist to avoid this unreadable #ifdef garbage.
Got it. I will fix this in the next patch set.

>
> Thanks,
>
> tglx

2020-05-13 20:57:12

by Prasad Sodagudi

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

On 2020-05-13 13:28, Thomas Gleixner wrote:
> [email protected] 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.

2020-05-13 20:58:15

by Thomas Gleixner

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

[email protected] 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:

>> Stub functions exist to avoid this unreadable #ifdef garbage.

2020-05-13 21:36:24

by Thomas Gleixner

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

Prasad,

[email protected] writes:
> On 2020-05-13 13:28, Thomas Gleixner wrote:
>> [email protected] writes:
>>> 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:
>
> 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.

Is this a quiz or are you expecting me to make your homework?

Thanks,

Thomas