All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Kofler <ikofler@edu.uni-klu.ac.at>
To: netdev@vger.kernel.org
Subject: Problems obtaining software TX timestamps
Date: Wed, 08 Sep 2010 14:11:54 +0200	[thread overview]
Message-ID: <4C877D8A.6040002@edu.uni-klu.ac.at> (raw)

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

             reply	other threads:[~2010-09-08 12:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-08 12:11 Ingo Kofler [this message]
2010-09-08 15:12 ` Problems obtaining software TX timestamps 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C877D8A.6040002@edu.uni-klu.ac.at \
    --to=ikofler@edu.uni-klu.ac.at \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.