diff mbox

[12/14] hrtimer: don't emulate notifier call to initialize timer base

Message ID 7eb4d1a03031b4d873ce08e8912900d7936a3ca8.1395832156.git.viresh.kumar@linaro.org
State New
Headers show

Commit Message

Viresh Kumar March 26, 2014, 11:21 a.m. UTC
In hrtimers_init() we need to call init_hrtimers_cpu() for boot CPU. For this,
currently we are emulating a call to hotplug notifier. Probably this was done
initially to get rid of code redundancy. But this sequence always called a
single routine, i.e. init_hrtimers_cpu(), and so calling that routine directly
would be better. This would get rid of emulating a notifier call, few typecasts
and the extra steps we are doing in notifier callback.

So, this patch calls init_hrtimers_cpu() directly from hrtimers_init().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 kernel/hrtimer.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Srivatsa S. Bhat March 26, 2014, 12:40 p.m. UTC | #1
On 03/26/2014 04:51 PM, Viresh Kumar wrote:
> In hrtimers_init() we need to call init_hrtimers_cpu() for boot CPU. For this,
> currently we are emulating a call to hotplug notifier. Probably this was done
> initially to get rid of code redundancy. But this sequence always called a
> single routine, i.e. init_hrtimers_cpu(), and so calling that routine directly
> would be better. This would get rid of emulating a notifier call, few typecasts
> and the extra steps we are doing in notifier callback.
> 
> So, this patch calls init_hrtimers_cpu() directly from hrtimers_init().
>

I don't think this is such a good idea. Open-coding a part of that callback
in the init routine can lead to loop-holes down the road: what if someone
changes or adds something to the CPU_UP_PREPARE switch-case, and forgets to
do the same in the init-routine?

It is more comforting to know that there is just one single place where CPU
hotplug operations are handled (hrtimer_cpu_notify). That, in turn is good
for reliability because it makes it easier to write bug-free code.

Regards,
Srivatsa S. Bhat
 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  kernel/hrtimer.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
> index f14d861..39dbdbd 100644
> --- a/kernel/hrtimer.c
> +++ b/kernel/hrtimer.c
> @@ -1756,8 +1756,7 @@ static struct notifier_block hrtimers_nb = {
> 
>  void __init hrtimers_init(void)
>  {
> -	hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
> -			  (void *)(long)smp_processor_id());
> +	init_hrtimers_cpu(smp_processor_id());
>  	register_cpu_notifier(&hrtimers_nb);
>  #ifdef CONFIG_HIGH_RES_TIMERS
>  	open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Viresh Kumar March 26, 2014, 2:17 p.m. UTC | #2
On 26 March 2014 18:10, Srivatsa S. Bhat
<srivatsa.bhat@linux.vnet.ibm.com> wrote:
> I don't think this is such a good idea. Open-coding a part of that callback
> in the init routine can lead to loop-holes down the road:

We think that we are open-coding part of that callback here because it is
implemented that way on the first design.

Rather, we should have a common routine which should do all the work
required when a CPU comes up. And any modification should be done
to that code.

> what if someone
> changes or adds something to the CPU_UP_PREPARE switch-case, and forgets to
> do the same in the init-routine?

This is not a driver which only 2-3 people use. This part is so well reviewed
by so many highly smart people that this should never happen. And if it
happens than its nothing but a review mistake.

> It is more comforting to know that there is just one single place where CPU
> hotplug operations are handled (hrtimer_cpu_notify). That, in turn is good
> for reliability because it makes it easier to write bug-free code.

And for me that single place is: init_hrtimers_cpu() :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index f14d861..39dbdbd 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -1756,8 +1756,7 @@  static struct notifier_block hrtimers_nb = {
 
 void __init hrtimers_init(void)
 {
-	hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
-			  (void *)(long)smp_processor_id());
+	init_hrtimers_cpu(smp_processor_id());
 	register_cpu_notifier(&hrtimers_nb);
 #ifdef CONFIG_HIGH_RES_TIMERS
 	open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);