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 15/16] pps: add parallel port PPS client
Date: Sat, 18 Dec 2010 03:50:54 +0300	[thread overview]
Message-ID: <20101218035054.2aaac64b@apollo.gnet> (raw)
In-Reply-To: <20101217161756.664b8d8b.akpm@linux-foundation.org>

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

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

> On Fri, 17 Dec 2010 22:54:39 +0300
> Alexander Gordeev <lasaine@lvk.cs.msu.su> wrote:
> 
> > Add parallel port PPS client. It uses a standard method for capturing
> > timestamps for assert edge transitions: getting a timestamp soon after
> > an interrupt has happened. This is not a very precise source of time
> > information due to interrupt handling delays. However, timestamps for
> > clear edge transitions are much more precise because the interrupt
> > handler continuously polls hardware port until the transition is done.
> > Hardware port operations require only about 1us so the maximum error
> > should not exceed this value. This was my primary goal when developing
> > this client.
> > Clear edge capture could be disabled using clear_wait parameter.
> > 
> > ...
> >
> > +/* parport interrupt handler */
> > +static void parport_irq(void *handle)
> > +{
> > +	struct pps_event_time ts_assert, ts_clear;
> > +	struct pps_client_pp *dev = handle;
> > +	struct parport *port = dev->pardev->port;
> > +	unsigned int i;
> > +	unsigned long flags;
> > +
> > +	/* first of all we get the time stamp... */
> > +	pps_get_ts(&ts_assert);
> > +
> > +	if (dev->cw == 0)
> > +		/* clear edge capture disabled */
> > +		goto out_assert;
> > +
> > +	/* try capture the clear edge */
> > +	local_irq_save(flags);
> > +	/* check the signal (no signal means the pulse is lost this time) */
> > +	if (!signal_is_set(port)) {
> > +		local_irq_restore(flags);
> > +		dev_err(dev->pps->dev, "lost the signal\n");
> > +		goto out_assert;
> > +	}
> > +
> > +	/* poll the port until the signal is unset */
> > +	for (i = dev->cw; i; i--)
> > +		if (!signal_is_set(port)) {
> > +			pps_get_ts(&ts_clear);
> > +			local_irq_restore(flags);
> > +			dev->cw_err = 0;
> > +			goto out_both;
> > +		}
> > +	local_irq_restore(flags);
> 
> Why is this function paying around with local_irq_save()?  It's unusual
> and looks buggy because local_irq_save() doesn't stop other CPUs from
> taking an interrupt and coming in and playing with the "protected" data.

The idea is to prevent other interrupts on the same processor to
introduce uncontrolled time lags here. Reading from IO port is known to
take approximately 1us while other interrupt handlers can probably take
much more. So I poll the port with locally disabled interrupts to
ensure that the maximum lag here is 1us. All my experiments show that
it is in fact very precise this way given that input signal is precise.

> I have a feeling I asked this before, but you didn't add a comment
> explaining it, so I went and asked it again!  Cause, effect.

No, you didn't ask this before, I think.

> > +static void parport_attach(struct parport *port)
> > +{
> > +	struct pps_client_pp *device;
> > +	struct pps_source_info info = {
> > +		.name		= KBUILD_MODNAME,
> > +		.path		= "",
> > +		.mode		= PPS_CAPTUREBOTH | \
> > +				  PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
> > +				  PPS_ECHOASSERT | PPS_ECHOCLEAR | \
> > +				  PPS_CANWAIT | PPS_TSFMT_TSPEC,
> > +		.echo		= pps_echo,
> > +		.owner		= THIS_MODULE,
> > +		.dev		= NULL
> > +	};
> > +
> > +	device = kzalloc(sizeof(struct pps_client_pp), GFP_KERNEL);
> > +	if (!device) {
> > +		pr_err("memory allocation failed, not attaching\n");
> > +		return;
> 
> And the void-returning parport_driver.attach() still sucks.

Hmm. Do you want me to rewrite the parport subsystem? There are lots of
problems in it now:
 * not part of LDM
 * controlled through /proc
 * detach is called for every port, not only the on being attached to
 * ...

Sure, I think it should be rewritten quite a bit but I cannot do that
right now, sorry.

> > +	}
> > +
> > +	device->pardev = parport_register_device(port, KBUILD_MODNAME,
> > +			NULL, NULL, parport_irq, 0, device);
> > +	if (!device->pardev) {
> > +		pr_err("couldn't register with %s\n", port->name);
> > +		goto err_free;
> > +	}
> > +
> > +	if (parport_claim_or_block(device->pardev) < 0) {
> > +		pr_err("couldn't claim %s\n", port->name);
> > +		goto err_unregister_dev;
> > +	}
> > +
> > +	device->pps = pps_register_source(&info,
> > +			PPS_CAPTUREBOTH | PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
> > +	if (device->pps == NULL) {
> > +		pr_err("couldn't register PPS source\n");
> > +		goto err_release_dev;
> > +	}
> > +
> > +	device->cw = clear_wait;
> > +
> > +	port->ops->enable_irq(port);
> > +
> > +	pr_info("attached to %s\n", port->name);
> > +
> > +	return;
> > +
> > +err_release_dev:
> > +	parport_release(device->pardev);
> > +err_unregister_dev:
> > +	parport_unregister_device(device->pardev);
> > +err_free:
> > +	kfree(device);
> > +}
> > +
> 


-- 
  Alexander

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

  reply	other threads:[~2010-12-18  0:51 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
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 [this message]
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=20101218035054.2aaac64b@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