public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Gordeev <lasaine@lvk.cs.msu.su>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	"Nikita V\. Youshchenko" <yoush@cs.msu.su>,
	linuxpps@ml.enneenne.com,
	Rodolfo Giometti <giometti@enneenne.com>
Subject: Re: [PATCHv6 07/16] pps: move idr stuff to pps.c
Date: Sat, 18 Dec 2010 04:07:38 +0300	[thread overview]
Message-ID: <20101218040738.64ab69f6@apollo.gnet> (raw)
In-Reply-To: <20101217161328.457ac8e6.akpm@linux-foundation.org>

[-- Attachment #1: Type: text/plain, Size: 1990 bytes --]

В Fri, 17 Dec 2010 16:13:28 -0800
Andrew Morton <akpm@linux-foundation.org> пишет:

> On Fri, 17 Dec 2010 22:54:31 +0300
> Alexander Gordeev <lasaine@lvk.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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  reply	other threads:[~2010-12-18  1:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-17 19:54 [PATCHv6 00/16] pps: several fixes and improvements Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 01/16] pps: trivial fixes Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 02/16] pps: declare variables where they are used in switch Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 03/16] pps: fix race in PPS_FETCH handler Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 04/16] pps: unify timestamp gathering Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 05/16] pps: access pps device by direct pointer Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 06/16] pps: convert printk/pr_* to dev_* Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 07/16] pps: move idr stuff to pps.c Alexander Gordeev
2010-12-18  0:13   ` Andrew Morton
2010-12-18  1:07     ` Alexander Gordeev [this message]
2010-12-18  1:18       ` Andrew Morton
2010-12-17 19:54 ` [PATCHv6 08/16] pps: do not disable interrupts for idr operations Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 09/16] pps: use BUG_ON for kernel API safety checks Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 10/16] pps: simplify conditions a bit Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 11/16] pps: timestamp is always passed to dcd_change() Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 12/16] ntp: add hardpps implementation Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 13/16] pps: capture MONOTONIC_RAW timestamps as well Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 14/16] pps: add kernel consumer support Alexander Gordeev
2010-12-17 19:54 ` [PATCHv6 15/16] pps: add parallel port PPS client Alexander Gordeev
2010-12-18  0:17   ` Andrew Morton
2010-12-18  0:50     ` Alexander Gordeev
2010-12-18  1:13       ` Andrew Morton
2010-12-17 19:54 ` [PATCHv6 16/16] pps: add parallel port PPS signal generator Alexander Gordeev
2010-12-18  0:18   ` Andrew Morton
2010-12-18  0:52     ` Alexander Gordeev
2010-12-18  0:19 ` [PATCHv6 00/16] pps: several fixes and improvements Andrew Morton
2010-12-18  1:00   ` Alexander Gordeev
2010-12-18  1:14     ` Andrew Morton
2010-12-20 11:54 ` [PATCHv7 00/16] changed some patches Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 08/16] pps: make idr lock a mutex and protect idr_pre_get Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 12/16] ntp: add hardpps implementation Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 13/16] pps: capture MONOTONIC_RAW timestamps as well Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 14/16] pps: add kernel consumer support Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 15/16] pps: add parallel port PPS client Alexander Gordeev
2010-12-20 11:54   ` [PATCHv7 16/16] pps: add parallel port PPS signal generator Alexander Gordeev
2010-12-24  0:35     ` Andrew Morton
2010-12-24  1:37       ` Alexander Gordeev

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=20101218040738.64ab69f6@apollo.gnet \
    --to=lasaine@lvk.cs.msu.su \
    --cc=akpm@linux-foundation.org \
    --cc=giometti@enneenne.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxpps@ml.enneenne.com \
    --cc=yoush@cs.msu.su \
    /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