All of lore.kernel.org
 help / color / mirror / Atom feed
* Problems obtaining software TX timestamps
@ 2010-09-08 12:11 Ingo Kofler
  2010-09-08 15:12 ` Eric Dumazet
  0 siblings, 1 reply; 11+ messages in thread
From: Ingo Kofler @ 2010-09-08 12:11 UTC (permalink / raw)
  To: netdev

Dear all,

I am trying to obtain software TX timestamps for a each outgoing packet 
of an UDP socket. For that purpose I set the SO_TIMESTAMPING socket 
option to SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE. The 
setsockopt call succeeds and also a subsequent getsockopt returns the 
correct flags. However, if a send a single datagram over the socket and 
try to fetch the packet as well as its timestamp via the socket's 
MSG_ERRQUEUE I do not get any information. Rather, the select call waits 
infinitely on the error queue....

I hardly found any documentation on this timestamping mechanism except 
the text file in the kernel source code. All I've figured out is that if 
I want to have hardware TX timestamps, I'll have to make a further ioctl 
which requires root permissions to active the hardware timestamping. But 
this is not what I want... software timestamps are sufficient for me. 
Here's my code....


int main (int argc, char **argv) {

    int rv;
    int sock;

    // allocate a socket
    printf("allocating socket\n");
    sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sock==-1) return 1;

    // connect socket to IP + port passed via command line
    printf("connecting socket\n");
    struct sockaddr_in toAddr;
    memset(&toAddr, 0, sizeof(struct sockaddr_in));
    toAddr.sin_family = PF_INET;
    toAddr.sin_addr.s_addr = inet_addr(argv[1]);
    toAddr.sin_port = htons(atoi(argv[2]));
    rv = connect(sock, (struct sockaddr*) &toAddr, sizeof(struct 
sockaddr_in));
    if (rv!=0) return 1;

    // try to enable software TX timestamps
    printf("enabling (?) timestamping\n");
    int flags =  SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
    rv = setsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, &flags, 
sizeof(flags));
    if (rv!=0) return 2;

    // check if the setsockopt was successful
    socklen_t slen = sizeof(flags);
    rv = getsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, &flags, &slen);
    if (rv!=0) return 3;
    printf("getsockopt returned %d\n", flags);
   
    // send something via the socket
    char buffer[200];
    int len = sizeof(buffer);
    rv = send(sock, buffer, len, 0);
    printf("send returned %d\n", rv);

    // prepare select call to wait for packet on MSG_ERRQUEUE
    fd_set errorfs;
    FD_ZERO(&errorfs);   
    FD_SET(sock, &errorfs);
    rv = select(sock + 1, 0, 0, &errorfs, NULL);                 <<--- 
This select blocks forever...
    printf("select returned %d\n", rv);
    ...

Any suggestions what's wrong with my code?  Btw. I've tested this with 
kernel 2.6.31 and 2.6.33...

Thanks and best regards,
Ingo

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

end of thread, other threads:[~2010-09-09 18:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-08 12:11 Problems obtaining software TX timestamps Ingo Kofler
2010-09-08 15:12 ` Eric Dumazet
2010-09-08 21:21   ` Ingo Kofler
2010-09-08 21:24     ` David Miller
2010-09-09  6:35     ` Richard Cochran
2010-09-09  8:26       ` Ingo Kofler
2010-09-09 13:57         ` Richard Cochran
2010-09-09 14:02           ` Eric Dumazet
2010-09-09 14:31             ` Loke, Chetan
2010-09-09 17:32             ` Richard Cochran
2010-09-09 18:58               ` Eric Dumazet

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.