[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <201102012240.38100.jeremy.kerr@canonical.com>
Date: Tue, 1 Feb 2011 22:40:37 +0800
From: Jeremy Kerr <jeremy.kerr@...onical.com>
To: "Uwe Kleine-König"
<u.kleine-koenig@...gutronix.de>
Cc: "Russell King - ARM Linux" <linux@....linux.org.uk>,
Dima Zavin <dmitriyz@...gle.com>,
Saravana Kannan <skannan@...eaurora.org>,
Lorenzo Pieralisi <Lorenzo.Pieralisi@....com>,
linux-sh@...r.kernel.org,
Ben Herrenschmidt <benh@...nel.crashing.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
linux-kernel@...r.kernel.org, Paul Mundt <lethal@...ux-sh.org>,
Ben Dooks <ben-linux@...ff.org>,
Vincent Guittot <vincent.guittot@...aro.org>,
linux-arm-kernel@...ts.infradead.org,
Nicolas Pitre <nicolas.pitre@...aro.org>
Subject: Re: Locking in the clk API, part 2: clk_prepare/clk_unprepare
Hi Uwe,
Thanks for the feedback, I'm not sure I like the more complex approach though:
> Right, but I thought it a bit further than you did. Like the following:
>
> int clk_prepare(struct clk *clk)
> {
> int ret = 0, first;
> unsigned long flags;
>
> spin_lock_irqsave(&clk->enable_lock, flags);
> if (clk->flags & CLK_BUSY) {
> /*
> * this must not happen, please serialize calls to
> * clk_prepare/clk_enable
> */
> ret = -EBUSY;
> goto out_unlock;
Why is this an error? Two separate drivers may be clk_prepare()-ing at the
same time, which should be acceptable. Both calls should block until the
prepare is complete.
> }
> first = clk->prepare_count++ == 0;
> if (first)
> clk->flags |= CLK_BUSY;
> spin_unlock_irqrestore(&clk->enable_lock, flags);
>
> if (!first)
> return 0;
>
> if (clk->ops->prepare) {
> might_sleep();
> ret = clk->ops->prepare(clk);
> }
>
> spin_lock_irqsave(&clk->enable_lock, flags);
> clk->flags &= ~CLK_BUSY;
> if (ret)
> clk->prepare_count--;
> out_unlock:
> spin_unlock_irqrestore(&clk->enable_lock, flags);
>
> return ret;
> }
Cheers,
Jeremy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists