Skip to contentSkip to conversation

printing current system time from kernel space

DISCUSSION George Nychis 3 participants 6 messages Sep 22, 2008

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 1 line · George Nychis

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)?

Signature · 1 line
Sitsofe | http://sucs.org/~sits/
#2 lore raw
Quoted 5 lines · Sitsofe Wheeler
Quoted 1 line · George Nychis

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

#3 lore raw
In reply to George Nychis
Quoted 9 lines · George Nychis

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.

Quoted 6 lines

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

#4 lore raw
Quoted 17 lines · john stultz
Quoted 9 lines · George Nychis

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.

Quoted 6 lines

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?

Quoted 7 lines

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

#5 lore raw
Quoted 25 lines · john stultz
Quoted 16 lines · john stultz
Quoted 9 lines · George Nychis

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.

Quoted 6 lines

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?

Quoted 7 lines

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.

Quoted 7 lines

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