public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* printing current system time from kernel space
@ 2008-09-22  5:18 George Nychis
  2008-09-22  7:07 ` Sitsofe Wheeler
  2008-09-22 20:28 ` john stultz
  0 siblings, 2 replies; 6+ messages in thread
From: George Nychis @ 2008-09-22  5:18 UTC (permalink / raw)
  To: linux-kernel

Hi all,

Please CC me on any responses.

I am looking to measure the latency of USB data between kernel space and 
user space.  The user space driver uses a URB to get data from the 
device to the kernel and finally to user space.

To measure this latency, I was thinking of printing the current system 
time when a read occurs/succeeds in drivers/usb/core/devio.c at the 
function usbdev_read(), and then again in user space when the URB 
succeeds in reading.  Then, I could subtract the two times to get the 
latency.

I spent some time googling, but could not find out how or if it is 
possible to read the current system time in kernel space.  I could 
insert a printk() somewhere in usbdev_read() then.

If it is not possible to read the current system time, is there some 
other shared clock between kernel and user space that I could use for this?

Thank you!
George

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

* Re: printing current system time from kernel space
  2008-09-22  5:18 printing current system time from kernel space George Nychis
@ 2008-09-22  7:07 ` Sitsofe Wheeler
  2008-09-22 15:11   ` George Nychis
  2008-09-22 20:28 ` john stultz
  1 sibling, 1 reply; 6+ messages in thread
From: Sitsofe Wheeler @ 2008-09-22  7:07 UTC (permalink / raw)
  To: George Nychis; +Cc: linux-kernel

George Nychis wrote:
> I spent some time googling, but could not find out how or if it is 
> possible to read the current system time in kernel space.  I could 
> insert a printk() somewhere in usbdev_read() then.

If that's what you want to do could you not turn on timestamps on printk 
(CONFIG_PRINTK_TIME in the kernel hacking menu)?

-- 
Sitsofe | http://sucs.org/~sits/

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

* Re: printing current system time from kernel space
  2008-09-22  7:07 ` Sitsofe Wheeler
@ 2008-09-22 15:11   ` George Nychis
  0 siblings, 0 replies; 6+ messages in thread
From: George Nychis @ 2008-09-22 15:11 UTC (permalink / raw)
  To: Sitsofe Wheeler; +Cc: linux-kernel



Sitsofe Wheeler wrote:
> George Nychis wrote:
>> I spent some time googling, but could not find out how or if it is 
>> possible to read the current system time in kernel space.  I could 
>> insert a printk() somewhere in usbdev_read() then.
> 
> If that's what you want to do could you not turn on timestamps on printk 
> (CONFIG_PRINTK_TIME in the kernel hacking menu)?
> 

Thanks for the response!

You might be misunderstanding my goal.  I need a common clock between 
kernel and user space, so that I can say:

Event1 happened at time X in the kernel
Event2 happened at time X+Y in user space
The time between Event1 and Event2 was Y-X

So, turning off timestamps does not help anything here :)

What might be useful is if user space can read the current timestamp 
value that printk uses, that way I can just do a printk in the kernel 
and then read the value and print in user space.

Is this possible?

Thanks!
George

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

* Re: printing current system time from kernel space
  2008-09-22  5:18 printing current system time from kernel space George Nychis
  2008-09-22  7:07 ` Sitsofe Wheeler
@ 2008-09-22 20:28 ` john stultz
  2008-09-22 20:30   ` john stultz
  1 sibling, 1 reply; 6+ messages in thread
From: john stultz @ 2008-09-22 20:28 UTC (permalink / raw)
  To: George Nychis; +Cc: linux-kernel

On Sun, Sep 21, 2008 at 10:18 PM, George Nychis <gnychis@cmu.edu> wrote:
> I am looking to measure the latency of USB data between kernel space and
> user space.  The user space driver uses a URB to get data from the device to
> the kernel and finally to user space.
>
> To measure this latency, I was thinking of printing the current system time
> when a read occurs/succeeds in drivers/usb/core/devio.c at the function
> usbdev_read(), and then again in user space when the URB succeeds in
> reading.  Then, I could subtract the two times to get the latency.
>
> I spent some time googling, but could not find out how or if it is possible
> to read the current system time in kernel space.  I could insert a printk()
> somewhere in usbdev_read() then.
>
> If it is not possible to read the current system time, is there some other
> shared clock between kernel and user space that I could use for this?

Kernel: getnstimeofday()
Userland: clock_gettime(CLOCK_MONOTONIC, ...)

Those two should give you the same data. So printing timespecs from
kernel space that come from getnstimeofday() and comparing it to
userland clock_gettime(CLOCK_MONOTONIC,...) hopefully will give you
what you want.

Let me know if I misunderstood.

thanks
-john

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

* Re: printing current system time from kernel space
  2008-09-22 20:28 ` john stultz
@ 2008-09-22 20:30   ` john stultz
  2008-09-22 20:33     ` George Nychis
  0 siblings, 1 reply; 6+ messages in thread
From: john stultz @ 2008-09-22 20:30 UTC (permalink / raw)
  To: George Nychis; +Cc: linux-kernel

On Mon, Sep 22, 2008 at 1:28 PM, john stultz <johnstul@us.ibm.com> wrote:
> On Sun, Sep 21, 2008 at 10:18 PM, George Nychis <gnychis@cmu.edu> wrote:
>> I am looking to measure the latency of USB data between kernel space and
>> user space.  The user space driver uses a URB to get data from the device to
>> the kernel and finally to user space.
>>
>> To measure this latency, I was thinking of printing the current system time
>> when a read occurs/succeeds in drivers/usb/core/devio.c at the function
>> usbdev_read(), and then again in user space when the URB succeeds in
>> reading.  Then, I could subtract the two times to get the latency.
>>
>> I spent some time googling, but could not find out how or if it is possible
>> to read the current system time in kernel space.  I could insert a printk()
>> somewhere in usbdev_read() then.
>>
>> If it is not possible to read the current system time, is there some other
>> shared clock between kernel and user space that I could use for this?
>
> Kernel: getnstimeofday()
> Userland: clock_gettime(CLOCK_MONOTONIC, ...)
>
> Those two should give you the same data. So printing timespecs from
> kernel space that come from getnstimeofday() and comparing it to
> userland clock_gettime(CLOCK_MONOTONIC,...) hopefully will give you
> what you want.

Gah! Typed too fast. The above is wrong. You want to use
clock_gettime(CLOCK_REALTIME,...)  not CLOCK_MONOTONIC with
getnstimeofday().

Sorry for the confusion.
-john

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

* Re: printing current system time from kernel space
  2008-09-22 20:30   ` john stultz
@ 2008-09-22 20:33     ` George Nychis
  0 siblings, 0 replies; 6+ messages in thread
From: George Nychis @ 2008-09-22 20:33 UTC (permalink / raw)
  To: john stultz; +Cc: linux-kernel



john stultz wrote:
> On Mon, Sep 22, 2008 at 1:28 PM, john stultz <johnstul@us.ibm.com> wrote:
>> On Sun, Sep 21, 2008 at 10:18 PM, George Nychis <gnychis@cmu.edu> wrote:
>>> I am looking to measure the latency of USB data between kernel space and
>>> user space.  The user space driver uses a URB to get data from the device to
>>> the kernel and finally to user space.
>>>
>>> To measure this latency, I was thinking of printing the current system time
>>> when a read occurs/succeeds in drivers/usb/core/devio.c at the function
>>> usbdev_read(), and then again in user space when the URB succeeds in
>>> reading.  Then, I could subtract the two times to get the latency.
>>>
>>> I spent some time googling, but could not find out how or if it is possible
>>> to read the current system time in kernel space.  I could insert a printk()
>>> somewhere in usbdev_read() then.
>>>
>>> If it is not possible to read the current system time, is there some other
>>> shared clock between kernel and user space that I could use for this?
>> Kernel: getnstimeofday()
>> Userland: clock_gettime(CLOCK_MONOTONIC, ...)
>>
>> Those two should give you the same data. So printing timespecs from
>> kernel space that come from getnstimeofday() and comparing it to
>> userland clock_gettime(CLOCK_MONOTONIC,...) hopefully will give you
>> what you want.
> 
> Gah! Typed too fast. The above is wrong. You want to use
> clock_gettime(CLOCK_REALTIME,...)  not CLOCK_MONOTONIC with
> getnstimeofday().
> 
> Sorry for the confusion.
> -john
> 

Thanks John!

This is exactly what I am looking for.

- George

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

end of thread, other threads:[~2008-09-22 20:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-22  5:18 printing current system time from kernel space George Nychis
2008-09-22  7:07 ` Sitsofe Wheeler
2008-09-22 15:11   ` George Nychis
2008-09-22 20:28 ` john stultz
2008-09-22 20:30   ` john stultz
2008-09-22 20:33     ` George Nychis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox