linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
To: Richard Cochran <richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Alan Cox <alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>,
	Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
	Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>,
	David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>,
	John Stultz <johnstul-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
	Krzysztof Halasa <khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org>,
	Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Rodolfo Giometti <giometti-k2GhghHVRtY@public.gmane.org>
Subject: Re: [PATCH V7 4/8] posix clocks: hook dynamic clocks into system calls
Date: Fri, 17 Dec 2010 11:03:46 +0100 (CET)	[thread overview]
Message-ID: <alpine.LFD.2.00.1012171010160.12146@localhost6.localdomain6> (raw)
In-Reply-To: <20101217070450.GB2982-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>

On Fri, 17 Dec 2010, Richard Cochran wrote:
> On Fri, Dec 17, 2010 at 12:20:44AM +0100, Thomas Gleixner wrote:
> > > +static inline bool clock_is_static(const clockid_t id)
> > > +{
> > > +	if (0 == (id & ~CLOCKFD_MASK))
> > > +		return true;
> > > +	if (CLOCKFD == (id & CLOCKFD_MASK))
> > > +		return false;
> > 
> > Please use the usual kernel notation.
>
> Sorry, what do you mean?

  if (!id & ~CLOCKFD_MASK)
  if ((id & CLOCKFD_MASK) == CLOCKFD)

Not a real problem. I just always stumble over that coding style.

> The code in the patch set is modeled after a USB driver, namely
> drivers/usb/class/usbtmc.c. Alan Cox had brought up the example of a
> PTP Hardware Clock appearing as a USB device. So the device might
> suddenly disappear, and the zombie field is supposed to cover the case
> where the hardware no longer exists, but the file pointer is still
> valid.

Hmm ok, so you use clk->mutex to prevent the underlying device from
going away while you call a function and clk->zombie indicates that
it's gone and clk just kept around for an open file descriptor. Now it
makes sense, but that wants a big fat comment in the code. :)

Doesn't the same problem exist for the file operations of patch 3? I
think you want the very same protection there unless you want to do
the same magic in your USB driver as well.

So you could do the following:

static int get_fd_clk(struct posix_clock_descr *cd, struct file *fp)
{
	cd->fp = fp;
	cd->clk = fp->private_data;
	mutex_lock(&cd->clk->mutex);
	if (!cd->clk->zombie)
		return 0;
	mutex_unlock(&cd->clk->mutex);
	return -ENODEV;
}

static void put_fd_clk(struct posix_clock_descr *cd)
{
	mutex_unlock(&cd->clk->mutex);
}

static int get_posix_clock(const clockid_t id, struct posix_clock_descr *cd)
{
	struct file *fp = fget(CLOCKID_TO_FD(id));
	int ret;

	if (!fp || fp->f_op->open != posix_clock_open || !fp->private_data)
	   	return -ENODEV;
	ret = get_fd_clk(cd, fp);
	if (ret)
		fput(fp);
	return ret;
}

static void put_posix_clock(struct posix_clock_descr *cd)
{
	put_fd_clk(cd);
	fput(cd->fp);
}

So your fops would call get_fd_clk() and put_fd_clk() and the pc_timer
ones get_posix_clock() and put_posix_clock() or whatever sensible
function names you come up with.

Thoughts ?

> I would summarize the discussion like this:
> 
> Alan Cox was strongly in favor of using a regular file descriptor as
> the reference to the dynamic clock.
> 
> John Stultz thought it wouldn't be too bad to cycle though a number of
> static ids, being careful not to every assign the same static id (in
> series) to two different clocks.
> 
> I implemented Alan's idea, since it seemed like maintaining the
> mapping between clocks and static ids would be extra work, but without
> any real benefit.

Yes, he's right. Was too tired to think about the clock ids assingment
when devices are removed and plugged. The fd mapping makes that all go
away.

Thanks,

	tglx

  parent reply	other threads:[~2010-12-17 10:03 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-16 15:41 [PATCH V7 0/8] ptp: IEEE 1588 hardware clock support Richard Cochran
     [not found] ` <cover.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-12-16 15:41   ` [PATCH V7 1/8] ntp: add ADJ_SETOFFSET mode bit Richard Cochran
     [not found]     ` <880d82bb8120f73973db27e0c48e949014b1a106.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-12-16 17:48       ` Thomas Gleixner
2010-12-17 20:16       ` Kuwahara,T.
     [not found]         ` <AANLkTi=yGoFwYt4p_LeHtAQyYgmURspO-p57UdL0sUEZ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-21  7:56           ` Richard Cochran
     [not found]             ` <20101221075612.GA13626-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-12-21 20:57               ` Kuwahara,T.
     [not found]                 ` <AANLkTimJd5pScKTiDxuYd-h+NevYbCusyvUAqmUDXe8h-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-21 22:25                   ` john stultz
2010-12-22  7:13                     ` Richard Cochran
2010-12-22 20:27                     ` Kuwahara,T.
     [not found]                       ` <AANLkTimmTzH8+fSYmbajqZ+hU5Ps-UZaTp_1TYzjHB6P-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-23  0:00                         ` john stultz
2010-12-23  6:13                         ` Richard Cochran
2010-12-25 20:38                           ` Kuwahara,T.
2010-12-26 14:14                             ` Richard Cochran
2010-12-21 19:37         ` john stultz
2010-12-21 21:13           ` Kuwahara,T.
     [not found]             ` <AANLkTikHV-qN73Zvvvxn76vtFFKG_VNTQhF3qpqTnOrE-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-21 21:59               ` john stultz
2010-12-22  7:11                 ` Richard Cochran
2010-12-22  9:58                 ` Alexander Gordeev
2010-12-16 15:42   ` [PATCH V7 2/8] posix clocks: introduce a syscall for clock tuning Richard Cochran
     [not found]     ` <a93ce18c2987f7e102bc2ff5b12130211c222ea7.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-12-16 15:51       ` Arnd Bergmann
2010-12-16 17:55       ` Thomas Gleixner
2010-12-16 15:43   ` [PATCH V7 4/8] posix clocks: hook dynamic clocks into system calls Richard Cochran
     [not found]     ` <6241238a1df55033e50b151ec9d35ba957e43d53.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-12-16 23:20       ` Thomas Gleixner
2010-12-17  7:04         ` Richard Cochran
     [not found]           ` <20101217070450.GB2982-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-12-17 10:03             ` Thomas Gleixner [this message]
2010-12-21  8:00               ` Richard Cochran
2010-12-22  8:21               ` Richard Cochran
2010-12-16 15:44   ` [PATCH V7 5/8] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2010-12-16 15:57     ` Arnd Bergmann
2010-12-16 16:08     ` Rodolfo Giometti
2010-12-16 15:44   ` [PATCH V7 7/8] ptp: Added a clock driver for the IXP46x Richard Cochran
     [not found]     ` <d2e0a5ac5eb51e9e4c7fcc94723b67c72c2f57c1.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2011-01-02  8:45       ` Pavel Machek
     [not found]         ` <20110102084505.GA3980-+ZI9xUNit7I@public.gmane.org>
2011-01-02  9:12           ` Richard Cochran
     [not found]             ` <20110102091233.GA2847-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2011-01-02  9:20               ` Pavel Machek
2011-01-03 17:07                 ` Richard Cochran
     [not found]                   ` <20110103170732.GA3700-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2011-01-06 20:04                     ` Pavel Machek
2011-01-02  9:19           ` Richard Cochran
2010-12-16 15:43 ` [PATCH V7 3/8] posix clocks: introduce dynamic clocks Richard Cochran
     [not found]   ` <8debe4d48d9a6484b7fbd35d8888524155fed977.1292512461.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-12-16 16:16     ` Arnd Bergmann
2010-12-16 20:56   ` Thomas Gleixner
2010-12-17  6:29     ` Richard Cochran
2010-12-16 15:44 ` [PATCH V7 6/8] ptp: Added a clock that uses the eTSEC found on the MPC85xx Richard Cochran
2010-12-16 15:45 ` [PATCH V7 8/8] ptp: Added a clock driver for the National Semiconductor PHYTER Richard Cochran

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=alpine.LFD.2.00.1012171010160.12146@localhost6.localdomain6 \
    --to=tglx-hfztesqfncyowbw4kg4ksq@public.gmane.org \
    --cc=alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=giometti-k2GhghHVRtY@public.gmane.org \
    --cc=johnstul-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    --cc=khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).