Timestamps with SocketCAN using recvmsg and ioctl

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
marc.andrew
Posts: 1
Joined: Wed 17. Jun 2015, 17:42

Timestamps with SocketCAN using recvmsg and ioctl

Post by marc.andrew » Wed 17. Jun 2015, 17:50

Hi,

I am currently looking into SocketCAN with a focus on timestamps.

My setup is as following:
Ubuntu 14.01LTS Laptop (Kernel 3.16.0)
SocketCAN
PCAN USB Adapter using the mainline driver

My question is: What kind of timestamp is generated when using recvmsg (HW timestamp, driver timestamp ,...)?
Is there a difference when using ioctl as I read in some internet forums?

Thanks for your help!

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Timestamps with SocketCAN using recvmsg and ioctl

Post by S.Grosjean » Thu 18. Jun 2015, 11:15

Hello!

The timestamps received from the socket layer are multiple.

You should have a look to this first:

https://www.kernel.org/doc/Documentatio ... stamping.c

The "default" timestamp tools like "candump" may display is a "network layer" timestamp, which is obtained with using SO_TIMESTAMP socket option (see https://github.com/linux-can/can-utils/ ... ump.c#L554).

Fortunately, the peak-usb driver is able to provide its own timestamps read from the PCAN-USB device, so called "hardware" timestamps. These can be obtained by using the SIOCSHWTSTAMP socket option, as described in the above Kernel timestamping.c.

To complete the answer, this "hardware" timestamp is the same that is returned by the "chardev" interface of the out-of-tree "pcan" driver (that is, by the ioctl() call you talked about).

Hope this helps,

Regards,

Stéphane
— Stéphane

Post Reply