From: Ingo Molnar <mingo@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] timer: Allocate per-cpu tvec_base's statically
Date: Tue, 31 Mar 2015 09:45:53 +0200 [thread overview]
Message-ID: <20150331074553.GA11603@gmail.com> (raw)
In-Reply-To: <a5dc32177588796245879ef6b2cf8fcd72e54d8a.1427691098.git.viresh.kumar@linaro.org>
* Viresh Kumar <viresh.kumar@linaro.org> wrote:
> From: Peter Zijlstra <peterz@infradead.org>
>
> Memory for tvec_base is allocated separately for boot CPU (statically) and
> non-boot CPUs (dynamically).
>
> The reason is because __TIMER_INITIALIZER() needs to set ->base to a valid
> pointer (because we've made NULL special, hint: lock_timer_base()) and we cannot
> get a compile time pointer to per-cpu entries because we don't know where we'll
> map the section, even for the boot cpu.
>
> This can be simplified a bit by statically allocating per-cpu memory. The only
> disadvantage is that memory for one of the structures will stay unused, i.e. for
> the boot CPU, which uses boot_tvec_bases.
>
> This will also guarantee that tvec_base is cacheline aligned. Even though
> tvec_base has ____cacheline_aligned stuck on, kzalloc_node() does not actually
> respect that (but guarantees a minimum u64 alignment).
>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> kernel/time/timer.c | 36 ++++++++----------------------------
> 1 file changed, 8 insertions(+), 28 deletions(-)
>
> diff --git a/kernel/time/timer.c b/kernel/time/timer.c
> index 2d3f5c504939..6e8220ec8a62 100644
> --- a/kernel/time/timer.c
> +++ b/kernel/time/timer.c
> @@ -93,6 +93,7 @@ struct tvec_base {
> struct tvec_base boot_tvec_bases;
> EXPORT_SYMBOL(boot_tvec_bases);
> static DEFINE_PER_CPU(struct tvec_base *, tvec_bases) = &boot_tvec_bases;
> +static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
>
> /* Functions below help us manage 'deferrable' flag */
> static inline unsigned int tbase_get_deferrable(struct tvec_base *base)
> @@ -1534,46 +1535,25 @@ EXPORT_SYMBOL(schedule_timeout_uninterruptible);
>
> static int init_timers_cpu(int cpu)
> {
> - int j;
> - struct tvec_base *base;
> + struct tvec_base *base = per_cpu(tvec_bases, cpu);
> static char tvec_base_done[NR_CPUS];
> + int j;
>
> if (!tvec_base_done[cpu]) {
> static char boot_done;
>
> + if (!boot_done) {
> + boot_done = 1; /* skip the boot cpu */
So it would be a lot more descriptive to name this flag
'boot_cpu_skipped'?
> } else {
> + base = per_cpu_ptr(&__tvec_bases, cpu);
> + per_cpu(tvec_bases, cpu) = base;
> }
> +
> spin_lock_init(&base->lock);
> tvec_base_done[cpu] = 1;
> base->cpu = cpu;
> }
Also, I'd put a description about the PER_CPU background into comments
as well, because it's not obvious at first sight at all what the whole
(boot_tvec_bases, tvec_bases, __tvec_bases) dance does.
Thanks,
Ingo
next prev parent reply other threads:[~2015-03-31 7:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-30 5:17 [PATCH 0/3] timers: Allocate per-cpu tvec_base's statically Viresh Kumar
2015-03-30 5:17 ` [PATCH 1/3] timer: " Viresh Kumar
2015-03-31 7:45 ` Ingo Molnar [this message]
2015-03-31 11:32 ` Viresh Kumar
2015-03-30 5:17 ` [PATCH 2/3] timer: Limit the scope of __tvec_bases to init_timers_cpu() Viresh Kumar
2015-03-30 5:17 ` [PATCH 3/3] timer: Don't initialize tvec_base on hotplug Viresh Kumar
2015-03-30 8:18 ` [PATCH 0/3] timers: Allocate per-cpu tvec_base's statically Peter Zijlstra
2015-03-30 9:55 ` Viresh Kumar
2015-03-30 10:27 ` Peter Zijlstra
2015-03-30 10:33 ` Viresh Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150331074553.GA11603@gmail.com \
--to=mingo@kernel.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox