All of lore.kernel.org
 help / color / mirror / Atom feed
* Accessing monotonic clock from modules
@ 2005-06-02  6:36 Mikael Starvik
  2005-06-02  7:29 ` Arjan van de Ven
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Mikael Starvik @ 2005-06-02  6:36 UTC (permalink / raw)
  To: linux-kernel

We would like to get the posix monotonic clock from a loadable module.
Would a patch to make do_posix_clock_monotonic_gettime exported ok or
should we do it in some other way?

/Mikael

Here is such a patch (against 2.6.11):

Index: posix-timers.c
===================================================================
RCS file: /usr/local/cvs/linux/os/linux-2.6/kernel/posix-timers.c,v
retrieving revision 1.1.1.13
diff -u -r1.1.1.13 posix-timers.c
--- posix-timers.c	3 Mar 2005 08:53:02 -0000	1.1.1.13
+++ posix-timers.c	2 Jun 2005 06:35:30 -0000
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/time.h>
+#include <linux/module.h>
 
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
@@ -191,6 +192,8 @@
 int do_posix_clock_monotonic_gettime(struct timespec *tp);
 static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags);
 
+EXPORT_SYMBOL(do_posix_clock_monotonic_gettime);
+
 static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
 {
 	spin_unlock_irqrestore(&timr->it_lock, flags);


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  6:36 Accessing monotonic clock from modules Mikael Starvik
@ 2005-06-02  7:29 ` Arjan van de Ven
  2005-06-02  7:30 ` Arjan van de Ven
  2005-06-03  0:14 ` Gerald Britton
  2 siblings, 0 replies; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02  7:29 UTC (permalink / raw)
  To: Mikael Starvik; +Cc: linux-kernel

On Thu, 2005-06-02 at 08:36 +0200, Mikael Starvik wrote:
> We would like to get the posix monotonic clock from a loadable module.
> Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> should we do it in some other way?

how about making this a _GPL export?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  6:36 Accessing monotonic clock from modules Mikael Starvik
  2005-06-02  7:29 ` Arjan van de Ven
@ 2005-06-02  7:30 ` Arjan van de Ven
  2005-06-02  7:40   ` Robert Love
  2005-06-03  0:14 ` Gerald Britton
  2 siblings, 1 reply; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02  7:30 UTC (permalink / raw)
  To: Mikael Starvik; +Cc: linux-kernel

On Thu, 2005-06-02 at 08:36 +0200, Mikael Starvik wrote:
> We would like to get the posix monotonic clock from a loadable module.
> Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> should we do it in some other way?
> 
> /Mikael

also... when are you going to get this module merged?
(exporting things without the module going into kernel.org shouldn't be
done imo... it makes it harder to change internals and causes overhead
for all kernel users)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  7:30 ` Arjan van de Ven
@ 2005-06-02  7:40   ` Robert Love
  2005-06-02  7:48     ` Arjan van de Ven
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Love @ 2005-06-02  7:40 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Mikael Starvik, linux-kernel

On Thu, 2005-06-02 at 09:30 +0200, Arjan van de Ven wrote:
> On Thu, 2005-06-02 at 08:36 +0200, Mikael Starvik wrote:
> > We would like to get the posix monotonic clock from a loadable module.
> > Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> > should we do it in some other way?
> > 
> > /Mikael
> 
> also... when are you going to get this module merged?
> (exporting things without the module going into kernel.org shouldn't be
> done imo... it makes it harder to change internals and causes overhead
> for all kernel users)

And if we are going to make it an official interface, does it have to be
called "do_posix_clock_monotonic_gettime" ?  Perhaps a more
export-friendly name?

	Robert Love



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  7:40   ` Robert Love
@ 2005-06-02  7:48     ` Arjan van de Ven
  2005-06-02  7:52       ` Robert Love
  0 siblings, 1 reply; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02  7:48 UTC (permalink / raw)
  To: Robert Love; +Cc: Mikael Starvik, linux-kernel

On Thu, 2005-06-02 at 03:40 -0400, Robert Love wrote:
> On Thu, 2005-06-02 at 09:30 +0200, Arjan van de Ven wrote:
> > On Thu, 2005-06-02 at 08:36 +0200, Mikael Starvik wrote:
> > > We would like to get the posix monotonic clock from a loadable module.
> > > Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> > > should we do it in some other way?
> > > 
> > > /Mikael
> > 
> > also... when are you going to get this module merged?
> > (exporting things without the module going into kernel.org shouldn't be
> > done imo... it makes it harder to change internals and causes overhead
> > for all kernel users)
> 
> And if we are going to make it an official interface, does it have to be
> called "do_posix_clock_monotonic_gettime" ?  Perhaps a more
> export-friendly name?

agreed.

well maybe it doesn't have such a name since it isn't intended as such
interface....



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  7:48     ` Arjan van de Ven
@ 2005-06-02  7:52       ` Robert Love
  2005-06-02  7:56         ` Arjan van de Ven
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Love @ 2005-06-02  7:52 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Mikael Starvik, linux-kernel

On Thu, 2005-06-02 at 09:48 +0200, Arjan van de Ven wrote:

> agreed.
> 
> well maybe it doesn't have such a name since it isn't intended as such
> interface....

That was the root of my concern; if the interface is more of a "do"
function, maybe we need something cleaner as the officially exported
interface?  With, of course, a better name. ;-)

I do thing that this is useful, though--at GUADEC I talked with some
folks who really want to get at a good clock source, the same from both
the kernel and user-space.

	Robert Love



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  7:52       ` Robert Love
@ 2005-06-02  7:56         ` Arjan van de Ven
  2005-06-02 13:46           ` Chris Friesen
  0 siblings, 1 reply; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02  7:56 UTC (permalink / raw)
  To: Robert Love; +Cc: Mikael Starvik, linux-kernel


> I do thing that this is useful, though--at GUADEC I talked with some
> folks who really want to get at a good clock source, the same from both
> the kernel and user-space.

I'd love to see one (but preferably 2 or 3) users of this so that we can
figure out what a good interface would look like...



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  7:56         ` Arjan van de Ven
@ 2005-06-02 13:46           ` Chris Friesen
  2005-06-02 13:48             ` Arjan van de Ven
  0 siblings, 1 reply; 16+ messages in thread
From: Chris Friesen @ 2005-06-02 13:46 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Robert Love, Mikael Starvik, linux-kernel

Arjan van de Ven wrote:
>>I do thing that this is useful, though--at GUADEC I talked with some
>>folks who really want to get at a good clock source, the same from both
>>the kernel and user-space.
> 
> 
> I'd love to see one (but preferably 2 or 3) users of this so that we can
> figure out what a good interface would look like...

For ourselves we implemented an clock interface for a limited subset of 
architectures that provides a fast timestamp in kernel and userspace.

Basically it has one call to return a 64-bit timestamp, and another call 
to tell you how fast the clock is ticking.

If it can, it uses things like the x86 cycle counter or the ppc 
timebase.  If there is no arch support, it falls back to clock_gettime.

Chris

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02 13:46           ` Chris Friesen
@ 2005-06-02 13:48             ` Arjan van de Ven
  2005-06-02 14:21               ` Chris Friesen
  0 siblings, 1 reply; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02 13:48 UTC (permalink / raw)
  To: Chris Friesen; +Cc: Robert Love, Mikael Starvik, linux-kernel

On Thu, 2005-06-02 at 07:46 -0600, Chris Friesen wrote:
> Arjan van de Ven wrote:
> >>I do thing that this is useful, though--at GUADEC I talked with some
> >>folks who really want to get at a good clock source, the same from both
> >>the kernel and user-space.
> > 
> > 
> > I'd love to see one (but preferably 2 or 3) users of this so that we can
> > figure out what a good interface would look like...
> 
> For ourselves we implemented an clock interface for a limited subset of 
> architectures that provides a fast timestamp in kernel and userspace.
> 
> Basically it has one call to return a 64-bit timestamp, and another call 
> to tell you how fast the clock is ticking.

hmm this is tricky if cpufreq actually varies cpu speeds... you would
need to not cache the "how fast it ticks" for too long.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02 13:48             ` Arjan van de Ven
@ 2005-06-02 14:21               ` Chris Friesen
  2005-06-04  3:27                 ` Lee Revell
  2005-06-04 21:48                 ` Lee Revell
  0 siblings, 2 replies; 16+ messages in thread
From: Chris Friesen @ 2005-06-02 14:21 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Robert Love, Mikael Starvik, linux-kernel

Arjan van de Ven wrote:
> On Thu, 2005-06-02 at 07:46 -0600, Chris Friesen wrote:

>>For ourselves we implemented an clock interface for a limited subset of 
>>architectures that provides a fast timestamp in kernel and userspace.
>>
>>Basically it has one call to return a 64-bit timestamp, and another call 
>>to tell you how fast the clock is ticking.
> 
> 
> hmm this is tricky if cpufreq actually varies cpu speeds... you would
> need to not cache the "how fast it ticks" for too long.

Luckily we didn't need to deal with that.

In order to use the fast versions with varying frequency you'd need some 
kind of notification to all users when the frequency changes.

Alternately, on architectures where clock_gettime doesn't require the 
overhead of a syscall, you could just use that.

Chris

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02  6:36 Accessing monotonic clock from modules Mikael Starvik
  2005-06-02  7:29 ` Arjan van de Ven
  2005-06-02  7:30 ` Arjan van de Ven
@ 2005-06-03  0:14 ` Gerald Britton
  2 siblings, 0 replies; 16+ messages in thread
From: Gerald Britton @ 2005-06-03  0:14 UTC (permalink / raw)
  To: Mikael Starvik; +Cc: linux-kernel

On Thu, Jun 02, 2005 at 08:36:48AM +0200, Mikael Starvik wrote:
> We would like to get the posix monotonic clock from a loadable module.
> Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> should we do it in some other way?

A possible use of a clean api would be in the packet rx timestamping code
where one is interested in accurate inter-packet timing, but the only way of
timestamping currently uses do_gettimeofday, so is fragile across time
time changes.

				-- Gerald

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02 14:21               ` Chris Friesen
@ 2005-06-04  3:27                 ` Lee Revell
  2005-06-04 21:48                 ` Lee Revell
  1 sibling, 0 replies; 16+ messages in thread
From: Lee Revell @ 2005-06-04  3:27 UTC (permalink / raw)
  To: Chris Friesen, Arjan van de Ven; +Cc: Robert Love, Mikael Starvik, linux-kernel

> Arjan van de Ven wrote:
>> On Thu, 2005-06-02 at 07:46 -0600, Chris Friesen wrote:
>
>>>For ourselves we implemented an clock interface for a limited subset of 
>>>architectures that provides a fast timestamp in kernel and userspace.
>>>
>>>Basically it has one call to return a 64-bit timestamp, and another call 
>>>to tell you how fast the clock is ticking.
>>
>>
>> hmm this is tricky if cpufreq actually varies cpu speeds... you would
>> need to not cache the "how fast it ticks" for too long.
>
> Luckily we didn't need to deal with that.
>
> In order to use the fast versions with varying frequency you'd need some 
> kind of notification to all users when the frequency changes.
>
> Alternately, on architectures where clock_gettime doesn't require the 
> overhead of a syscall, you could just use that.

JACK also implements a fast high-res timer for each supported arch.  We
can't use gettimeofday as it's about 50x slower than rdtsc (tested it just 
now).

I suggested using the kernel events mechanism to notify userspace when
the CPU speed changes a few months ago, for this exact reason.

Lee


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Accessing monotonic clock from modules
  2005-06-02 14:21               ` Chris Friesen
  2005-06-04  3:27                 ` Lee Revell
@ 2005-06-04 21:48                 ` Lee Revell
  1 sibling, 0 replies; 16+ messages in thread
From: Lee Revell @ 2005-06-04 21:48 UTC (permalink / raw)
  To: Chris Friesen; +Cc: Arjan van de Ven, Robert Love, Mikael Starvik, linux-kernel

On Thu, 2005-06-02 at 08:21 -0600, Chris Friesen wrote:
> Arjan van de Ven wrote:
> > On Thu, 2005-06-02 at 07:46 -0600, Chris Friesen wrote:
> 
> >>For ourselves we implemented an clock interface for a limited subset of 
> >>architectures that provides a fast timestamp in kernel and userspace.
> >>
> >>Basically it has one call to return a 64-bit timestamp, and another call 
> >>to tell you how fast the clock is ticking.
> > 
> > 
> > hmm this is tricky if cpufreq actually varies cpu speeds... you would
> > need to not cache the "how fast it ticks" for too long.
> 
> Luckily we didn't need to deal with that.
> 
> In order to use the fast versions with varying frequency you'd need some 
> kind of notification to all users when the frequency changes.
> 
> Alternately, on architectures where clock_gettime doesn't require the 
> overhead of a syscall, you could just use that.

JACK does this too.  Much of the code was just copied from the 2.4
kernel headers.

http://cvs.sourceforge.net/viewcvs.py/jackit/jack/config/cpu/

We have to do this because gettimeofday() is ~50 times slower than rdtsc
on x86.

In lieu of making gettimeofday() faster, the kernel events layer could
be used to notify userspace when the CPU speed changes.

Lee


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: Accessing monotonic clock from modules
       [not found] <BFECAF9E178F144FAEF2BF4CE739C66802FA3913@exmail1.se.axis.com>
@ 2005-06-02 12:40 ` Mikael Starvik
  0 siblings, 0 replies; 16+ messages in thread
From: Mikael Starvik @ 2005-06-02 12:40 UTC (permalink / raw)
  To: 'Arjan van de Ven', Mikael Starvik; +Cc: linux-kernel

>For your own kernel it'd be trivial to add that simple export patch
>local...

Certainly, already done that. My original mail was more about checking 
that there wasn't a better way in this particular case and sugest an 
export because others may need it as well.

I'll just keep it in the local repository and let others decide whether
to export or not.

/Mikael


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: Accessing monotonic clock from modules
  2005-06-02 10:57 ` Mikael Starvik
@ 2005-06-02 11:15   ` Arjan van de Ven
  0 siblings, 0 replies; 16+ messages in thread
From: Arjan van de Ven @ 2005-06-02 11:15 UTC (permalink / raw)
  To: Mikael Starvik; +Cc: linux-kernel

On Thu, 2005-06-02 at 12:57 +0200, Mikael Starvik wrote:
> >how about making this a _GPL export?
> 
> Yes
> 
> >also... when are you going to get this module merged?
> 
> Do we really want modules for all kind of exotic hardware only used by one
> company in the kernel tree? In this case we are the only user of this module
> since we make the HW ourself and doesn't resell it. So it's my headache if
> any API or similar is changed.

in which case.... why bloat all linux' users kernel binary with it
(exports cost about 100 bytes each or so) while you're the only user?
For your own kernel it'd be trivial to add that simple export patch
local...



^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: Accessing monotonic clock from modules
       [not found] <BFECAF9E178F144FAEF2BF4CE739C66802FA37AC@exmail1.se.axis.com>
@ 2005-06-02 10:57 ` Mikael Starvik
  2005-06-02 11:15   ` Arjan van de Ven
  0 siblings, 1 reply; 16+ messages in thread
From: Mikael Starvik @ 2005-06-02 10:57 UTC (permalink / raw)
  To: 'Arjan van de Ven', Mikael Starvik; +Cc: linux-kernel

>how about making this a _GPL export?

Yes

>also... when are you going to get this module merged?

Do we really want modules for all kind of exotic hardware only used by one
company in the kernel tree? In this case we are the only user of this module
since we make the HW ourself and doesn't resell it. So it's my headache if
any API or similar is changed.

>And if we are going to make it an official interface, does it have to be
>called "do_posix_clock_monotonic_gettime" ?  Perhaps a more
>export-friendly name?

Sure. Any suggestions welcome. 

/Mikael

-----Original Message-----
From: Arjan van de Ven [mailto:arjan@infradead.org] 
Sent: Thursday, June 02, 2005 9:30 AM
To: Mikael Starvik
Cc: linux-kernel@vger.kernel.org
Subject: Re: Accessing monotonic clock from modules


On Thu, 2005-06-02 at 08:36 +0200, Mikael Starvik wrote:
> We would like to get the posix monotonic clock from a loadable module.
> Would a patch to make do_posix_clock_monotonic_gettime exported ok or
> should we do it in some other way?
> 
> /Mikael

also... when are you going to get this module merged?
(exporting things without the module going into kernel.org shouldn't be
done imo... it makes it harder to change internals and causes overhead
for all kernel users)


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-06-04 21:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-02  6:36 Accessing monotonic clock from modules Mikael Starvik
2005-06-02  7:29 ` Arjan van de Ven
2005-06-02  7:30 ` Arjan van de Ven
2005-06-02  7:40   ` Robert Love
2005-06-02  7:48     ` Arjan van de Ven
2005-06-02  7:52       ` Robert Love
2005-06-02  7:56         ` Arjan van de Ven
2005-06-02 13:46           ` Chris Friesen
2005-06-02 13:48             ` Arjan van de Ven
2005-06-02 14:21               ` Chris Friesen
2005-06-04  3:27                 ` Lee Revell
2005-06-04 21:48                 ` Lee Revell
2005-06-03  0:14 ` Gerald Britton
     [not found] <BFECAF9E178F144FAEF2BF4CE739C66802FA37AC@exmail1.se.axis.com>
2005-06-02 10:57 ` Mikael Starvik
2005-06-02 11:15   ` Arjan van de Ven
     [not found] <BFECAF9E178F144FAEF2BF4CE739C66802FA3913@exmail1.se.axis.com>
2005-06-02 12:40 ` Mikael Starvik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.