lkml.org 
[lkml]   [2011]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Locking in the clk API, part 2: clk_prepare/clk_unprepare
Date
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



\
 
 \ /
  Last update: 2011-02-01 15:43    [W:0.073 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site