]> rtime.felk.cvut.cz Git - can-benchmark.git/commitdiff
Implement busy_poll (aka low latency) for read method
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 12 Jan 2014 22:47:34 +0000 (23:47 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 12 Jan 2014 22:47:34 +0000 (23:47 +0100)
ugw/ugw.c

index 64d00b0616d805e8008c420c12bb849306d83fc3..9458e7d22a3e83d42dfdcb3d32d68a05e9e2a889 100644 (file)
--- a/ugw/ugw.c
+++ b/ugw/ugw.c
 #include <sys/mman.h>
 #include <arpa/inet.h>
 
+#ifndef SO_BUSY_POLL
+#define SO_BUSY_POLL 46
+#endif
+
 #define FRAME_SIZE 256
 #define BLOCK_SIZE 4096
 #define BLOCK_NR 2
@@ -36,6 +40,7 @@ char *devout = "can1";
 enum { IN_READ, IN_RECVMMSG, IN_MMAP, IN_MMAPBUSY } in_method = IN_READ;
 enum { WRITE, OUT_MMAP } out_method = WRITE;
 bool quiet = false;
+int busy_poll_us = 0;
 
 enum in2out {
        STORE_ONLY,
@@ -80,6 +85,11 @@ void init_read(struct in_ctx *ctx)
 
        s = CHECK(socket(PF_CAN, SOCK_RAW, CAN_RAW));
 
+       if (busy_poll_us) {
+               CHECK(setsockopt(s, SOL_SOCKET, SO_BUSY_POLL,
+                                &busy_poll_us, sizeof(busy_poll_us)));
+       }
+
        strncpy(ifr.ifr_name, devin, sizeof(ifr.ifr_name));
        if (-1 == ioctl(s, SIOCGIFINDEX, &ifr)) {
                perror(devin);
@@ -313,8 +323,11 @@ int main(int argc, char *argv[])
 {
        int opt;
 
-       while ((opt = getopt(argc, argv, "qr:t:")) != -1) {
+       while ((opt = getopt(argc, argv, "b:qr:t:")) != -1) {
                switch (opt) {
+               case 'b':
+                       busy_poll_us = atoi(optarg);
+                       break;
                case 'q':
                        quiet = true;
                        break;