linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Menon, Nishanth" <nm@ti.com>
To: Kevin Hilman <khilman@ti.com>
Cc: linux-omap <linux-omap@vger.kernel.org>
Subject: Re: [PM-WIP_CPUFREQ][PATCH V3 6/8] OMAP2+: cpufreq: fix freq_table leak
Date: Wed, 25 May 2011 17:47:32 -0700	[thread overview]
Message-ID: <BANLkTimp35KXz6WFbMWgAMdy=szYYES4mg@mail.gmail.com> (raw)
In-Reply-To: <877h9ejoy1.fsf@ti.com>

On Wed, May 25, 2011 at 17:16, Kevin Hilman <khilman@ti.com> wrote:
>
> Nishanth Menon <nm@ti.com> writes:
>
> > Since we have multiple CPUs, the cpuinit call for CPU1 causes
> > freq_table of CPU0 to be overwritten. Instead, we maintain
> > a counter to keep track of cpus who use the cpufreq table
> > allocate it once(one freq table for all CPUs) and free them
> > once the last user is done with it. We also need to protect
> > freq_table and this new counter from updates from multiple
> > contexts to be on a safe side.
>
> Not sure I understand the need for all the locking here.  Once allocated
> and filled, the freq_table isn't changing.  Also, all the functions are
> only reading the freq_table, not changing it.    So what is it you're
> trying to protect against?

We just have one freq_table for both cpu0 and cpu1. We have common
data structure(freq_table and users) which is modifiable in two
APIs(init/exit) and a set of reads. What if there is a read path while
free occurs - I may be mistaken, but my understanding is that the
datastructure used in my code should be secured in my code and I
cannot depend on higher layer(cpufreq/governors) to ensure that.

>
> > Signed-off-by: Nishanth Menon <nm@ti.com>
> > ---
> >  arch/arm/mach-omap2/omap2plus-cpufreq.c |   62 +++++++++++++++++++++++++++----
> >  1 files changed, 54 insertions(+), 8 deletions(-)
> >
> > diff --git a/arch/arm/mach-omap2/omap2plus-cpufreq.c b/arch/arm/mach-omap2/omap2plus-cpufreq.c
> > index 3ff3302..f026ac4 100644
> > --- a/arch/arm/mach-omap2/omap2plus-cpufreq.c
> > +++ b/arch/arm/mach-omap2/omap2plus-cpufreq.c

[..]
> > @@ -156,22 +173,48 @@ skip_lpj:
> >
> >  static int freq_table_alloc(void)
> >  {
> > -     if (use_opp)
> > -             return opp_init_cpufreq_table(mpu_dev, &freq_table);
> > +     int ret = 0;
> >
> > -     clk_init_cpufreq_table(&freq_table);
> > -     if (!freq_table)
> > -             return -ENOMEM;
> > +     mutex_lock(&freq_table_lock);
> >
> > -     return 0;
> > +     freq_table_users++;
> > +     /* Did we allocate previously? */
> > +     if (freq_table_users - 1)
> > +             goto out;
>
> Rather than the ' - 1', this can just be
>
>     if (freq_table_users++)
>                goto out;
ok

>
> or better, you probably don't need this check protected by the mutex,
> so this could just return directly, and then take the mutex_lock() after
> this point.
The mutex lock was to protect both the freq_table and the count as
they protect the same resource - freq_table

>
> However, if you get rid of the mutex (and I think you should), you could
> use an atomic variable here
yes, we can use just atomic to protect alloc Vs free - but we cannot
protect read Vs free


Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-05-26  0:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-25 23:38 [PM-WIP_CPUFREQ][PATCH 0/6 V3] Cleanups for cpufreq Nishanth Menon
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 1/8] OMAP2+: cpufreq: move clk name decision to init Nishanth Menon
2011-05-26 17:33   ` Kevin Hilman
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 2/8] OMAP2+: cpufreq: deny initialization if no mpudev Nishanth Menon
2011-05-26 17:34   ` Kevin Hilman
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 3/8] OMAP2+: cpufreq: use opp/clk_*cpufreq_table based on silicon Nishanth Menon
2011-05-26 17:38   ` Kevin Hilman
2011-05-26 18:35     ` Menon, Nishanth
2011-05-26 18:39       ` Menon, Nishanth
2011-05-26 20:25         ` Kevin Hilman
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 4/8] OMAP2+: cpufreq: dont support !freq_table Nishanth Menon
2011-05-26  0:51   ` Todd Poynor
2011-05-26  0:53     ` Menon, Nishanth
     [not found]     ` <SNT104-W336E0DDFB034FA635C328BBA770@phx.gbl>
2011-05-26  1:03       ` Menon, Nishanth
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 5/8] OMAP2+: cpufreq: fix invalid cpufreq table with central alloc/free Nishanth Menon
2011-05-26  1:09   ` Todd Poynor
2011-05-26  1:21     ` Menon, Nishanth
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 6/8] OMAP2+: cpufreq: fix freq_table leak Nishanth Menon
2011-05-26  0:16   ` Kevin Hilman
2011-05-26  0:47     ` Menon, Nishanth [this message]
2011-05-26 17:11       ` Kevin Hilman
2011-05-26 18:34         ` Menon, Nishanth
2011-05-26  1:25   ` Todd Poynor
2011-05-26  1:36     ` Menon, Nishanth
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 7/8] OMAP2+: cpufreq: put clk if cpu_init failed Nishanth Menon
2011-05-25 23:38 ` [PM-WIP_CPUFREQ][PATCH V3 8/8] OMAP: cpufreq: minor file header updates Nishanth Menon
2011-05-26  0:18   ` Kevin Hilman
2011-05-26  0:48     ` Menon, Nishanth
2011-05-26 18:15   ` Kevin Hilman
2011-05-26 18:10 ` [PM-WIP_CPUFREQ][PATCH 0/6 V3] Cleanups for cpufreq Kevin Hilman
2011-05-26 18:36   ` Menon, Nishanth
2011-05-27  5:06   ` Santosh Shilimkar
2011-05-27  6:07     ` Menon, Nishanth
2011-05-27  6:26       ` Santosh Shilimkar
2011-05-27 15:33         ` Turquette, Mike
2011-05-27 23:27           ` Kevin Hilman
2011-05-29 17:25             ` Menon, Nishanth

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='BANLkTimp35KXz6WFbMWgAMdy=szYYES4mg@mail.gmail.com' \
    --to=nm@ti.com \
    --cc=khilman@ti.com \
    --cc=linux-omap@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).