public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rodolfo Giometti <giometti@enneenne.com>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Chris Friesen <cfriesen@nortel.com>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: LinuxPPS & spinlocks
Date: Sun, 29 Jul 2007 11:17:10 +0200	[thread overview]
Message-ID: <20070729091709.GY9840@enneenne.com> (raw)
In-Reply-To: <a781481a0707271347w53dd9755j87e7762cfe953777@mail.gmail.com>

On Sat, Jul 28, 2007 at 02:17:24AM +0530, Satyam Sharma wrote:
> 
> I only glanced through the code, so could be wrong, but I noticed that
> the only global / shared data you have in there is a global "pps_source"
> array of pps_s structs. That's accessed / modified from the various
> syscalls introduced in the API exported to userspace, as well as the
> register/unregister/pps_event API exported to in-kernel client subsystems,
> yes? So it looks like you need to introduce proper locking for it, simply
> type-qualifying it as "volatile" is not enough.
> 
> However, I think you've introduced two locks for it. The syscalls (that
> run in process context, obviously) seem to use a pps_mutex and
> pps_event() seems to be using the pps_lock spinlock (because that
> gets executed from interrupt context) -- and from the looks of it, the
> register/unregister functions are using /both/ the mutex and spinlock (!)

This is right.

> This isn't quite right, (in fact there's nothing to protect pps_event from
> racing against a syscall), so you should use *only* the spinlock for
> synchronization -- the spin_lock_irqsave/restore() variants, in fact.

We can't use the spin_lock_irqsave/restore() variants since PPS
sources cannot manage IRQ enable/disable. For instance, the serial
source doesn't manage IRQs directly but just uses it to record PPS
events. The serial driver manages the IRQ enable/disable, not the PPS
source which only uses the IRQ handler to records events.

About using both mutex and spinlock I did it since (I think) I should
protect syscalls from each others and from pps_register/unregister(),
and pps_event() against pps_register/unregister().

> [ Also, have you considered making pps_source a list and not an array?
> It'll help you lose a whole lot of MAX_SOURCES, pps_is_allocated, etc
> kind of gymnastics in there, and you _can_ return a pointer to the
> corresponding pps source struct from the register() function to the in-kernel
> users, so that way you get to retain the O(1) access to the corresponding
> source when a client calls into pps_event(), similar to how you're using the
> array index presently. ]
> 
> I also noticed code like (from pps_event):
> 
> +	/* Try to grab the lock, if not we prefere loose the event... */
> +	if (!spin_trylock(&pps_lock))
> +		return;
> 
> which looks worrisome and unnecessary. That spinlock looks to be of
> fine enough granularity to me, do you think there'd be any contention
> on it? I /think/ you can simply make that a spin_lock().

This is due the fact I cannot manage IRQ enable/disable.

> Overall the code looks simple / straightforward enough to me (except for
> the parport / uart stuff that I have no clue about), and I'll also read up on
> the relevant RFC for this and would hopefully try and give you a more
> meaningful review over the weekend.

Thanks a lot for your help!

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti@enneenne.com
Linux Device Driver                             giometti@gnudd.com
Embedded Systems                     		giometti@linux.it
UNIX programming                     phone:     +39 349 2432127

  parent reply	other threads:[~2007-07-29  9:15 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-17 18:05 [PATCH] LinuxPPS - definitive version Rodolfo Giometti
2007-07-23 13:35 ` David Woodhouse
2007-07-23 16:04   ` Rodolfo Giometti
2007-07-23 19:28   ` Andrew Morton
2007-07-23 19:48     ` David Woodhouse
2007-07-24  8:00   ` Rodolfo Giometti
2007-07-24 13:49     ` David Woodhouse
2007-07-24 14:20       ` Rodolfo Giometti
2007-07-24 14:46         ` David Woodhouse
2007-07-24 14:52         ` David Woodhouse
2007-07-24 16:01           ` Rodolfo Giometti
2007-07-27 18:44           ` LinuxPPS & spinlocks Rodolfo Giometti
2007-07-27 19:08             ` Chris Friesen
2007-07-27 19:28               ` Rodolfo Giometti
2007-07-27 19:40                 ` Chris Friesen
2007-07-27 19:45                   ` Rodolfo Giometti
2007-07-27 20:47                     ` Satyam Sharma
2007-07-27 23:41                       ` Satyam Sharma
2007-07-29  9:50                         ` Rodolfo Giometti
2007-07-30  5:03                           ` Satyam Sharma
2007-07-30  8:51                             ` Rodolfo Giometti
2007-07-30  9:20                               ` Satyam Sharma
2007-08-01 22:14                                 ` Christopher Hoover
2007-08-01 23:03                                   ` Satyam Sharma
2007-07-29  9:57                         ` Rodolfo Giometti
2007-07-29 10:00                         ` Rodolfo Giometti
2007-07-30  5:09                           ` Satyam Sharma
2007-07-30  8:53                             ` Rodolfo Giometti
2007-07-30  9:31                               ` Satyam Sharma
2007-07-29  9:17                       ` Rodolfo Giometti [this message]
2007-07-30  4:19                         ` Satyam Sharma
2007-07-30  8:32                           ` Rodolfo Giometti
2007-07-30  9:07                             ` Satyam Sharma
2007-07-30 14:55                               ` Rodolfo Giometti
2007-07-30 22:01                                 ` Satyam Sharma
2007-07-31  8:20                                   ` Rodolfo Giometti
2007-07-31 18:49                                     ` Satyam Sharma
2007-07-31 19:44                                       ` Rodolfo Giometti
2007-07-31 21:15                                         ` Satyam Sharma
2007-07-24 14:31       ` [PATCH] LinuxPPS - definitive version Rodolfo Giometti
2007-07-24 14:45         ` David Woodhouse
2007-07-24 16:09           ` Rodolfo Giometti
2007-07-26 19:52         ` Roman Zippel

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=20070729091709.GY9840@enneenne.com \
    --to=giometti@enneenne.com \
    --cc=akpm@linux-foundation.org \
    --cc=cfriesen@nortel.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=satyam.sharma@gmail.com \
    /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