[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20101218040738.64ab69f6@apollo.gnet>
Date: Sat, 18 Dec 2010 04:07:38 +0300
From: Alexander Gordeev <lasaine@....cs.msu.su>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org,
"Nikita V\. Youshchenko" <yoush@...msu.su>,
linuxpps@...enneenne.com, Rodolfo Giometti <giometti@...eenne.com>
Subject: Re: [PATCHv6 07/16] pps: move idr stuff to pps.c
В Fri, 17 Dec 2010 16:13:28 -0800
Andrew Morton <akpm@...ux-foundation.org> пишет:
> On Fri, 17 Dec 2010 22:54:31 +0300
> Alexander Gordeev <lasaine@....cs.msu.su> wrote:
>
> > Since now idr is only used to manage char device id's and not used in
> > kernel API anymore it should be moved to pps.c. This also makes it
> > possible to release id only at actual device freeing so nobody can
> > register a pps device with the same id while our device is not freed
> > yet.
> >
> > ...
> >
> > int pps_register_cdev(struct pps_device *pps)
> > {
> > int err;
> > dev_t devt;
> >
> > + /* Get new ID for the new PPS source */
> > + if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0)
> > + return -ENOMEM;
> > +
> > + /* Now really allocate the PPS source.
> > + * After idr_get_new() calling the new source will be freely available
> > + * into the kernel.
> > + */
> > + spin_lock_irq(&pps_idr_lock);
> > + err = idr_get_new(&pps_idr, pps, &pps->id);
> > + spin_unlock_irq(&pps_idr_lock);
> > +
> > + if (err < 0)
> > + return err;
>
> The IDR interface really sucks :(
>
> What this code should be doing is
>
> retry:
> if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0)
> return -ENOMEM;
> spin_lock_irq(&pps_idr_lock);
> err = idr_get_new(&pps_idr, pps, &pps->id);
> spin_unlock_irq(&pps_idr_lock);
> if (err < 0) {
> if (err == -EAGAIN)
> goto retry;
> return err;
> }
>
> this way it correctly handles the case where the idr_pre_get()
> succeeded in precharging the pool, but some other task cam in and stole
> your reservation.
Yeah, I see. Maybe switching from spin lock to mutex and protecting the
whole thing with it can do? Like this:
...
mutex_lock(&pps_idr_lock);
if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
mutex_unlock(&pps_idr_lock);
return -ENOMEM;
}
err = idr_get_new(&pps_idr, pps, &pps->id);
mutex_unlock(&pps_idr_lock);
if (err < 0)
return err;
...
--
Alexander
Download attachment "signature.asc" of type "application/pgp-signature" (491 bytes)
Powered by blists - more mailing lists