]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - ugw/ugw.c
Added ftrace config (commented oud)
[can-benchmark.git] / ugw / ugw.c
index bb654cf7c8c790c11334a234c7ac25530aed6289..482f4e1c143443c6ccfdce2b5f6b443808aa6046 100644 (file)
--- a/ugw/ugw.c
+++ b/ugw/ugw.c
 #include <sys/mman.h>
 #include <arpa/inet.h>
 
 #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
 #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;
 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,
 
 enum in2out {
        STORE_ONLY,
@@ -80,6 +85,11 @@ void init_read(struct in_ctx *ctx)
 
        s = CHECK(socket(PF_CAN, SOCK_RAW, CAN_RAW));
 
 
        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);
        strncpy(ifr.ifr_name, devin, sizeof(ifr.ifr_name));
        if (-1 == ioctl(s, SIOCGIFINDEX, &ifr)) {
                perror(devin);
@@ -127,6 +137,11 @@ void init_packet_rx(struct in_ctx *ctx)
 
        s = CHECK(socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)));
 
 
        s = CHECK(socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)));
 
+       if (busy_poll_us) {
+               CHECK(setsockopt(s, SOL_SOCKET, SO_BUSY_POLL,
+                                &busy_poll_us, sizeof(busy_poll_us)));
+       }
+
        int val = TPACKET_V2;
        CHECK(setsockopt(s, SOL_PACKET, PACKET_VERSION, &val, sizeof(val)));
        socklen_t len = sizeof(ctx->hdrlen);
        int val = TPACKET_V2;
        CHECK(setsockopt(s, SOL_PACKET, PACKET_VERSION, &val, sizeof(val)));
        socklen_t len = sizeof(ctx->hdrlen);
@@ -195,7 +210,6 @@ int out_packet_tx(struct out_ctx *ctx, struct can_frame *cf)
        int ret = -1;
 
        while (hdr->tp_status != TP_STATUS_AVAILABLE) {
        int ret = -1;
 
        while (hdr->tp_status != TP_STATUS_AVAILABLE) {
-               printf("TX status: %#x\n", hdr->tp_status);
                struct pollfd pfd = {.fd = ctx->s, .revents = 0,
                                     .events = POLLIN|POLLRDNORM|POLLERR };
                ret = CHECK(poll(&pfd, 1, -1));
                struct pollfd pfd = {.fd = ctx->s, .revents = 0,
                                     .events = POLLIN|POLLRDNORM|POLLERR };
                ret = CHECK(poll(&pfd, 1, -1));
@@ -210,7 +224,6 @@ int out_packet_tx(struct out_ctx *ctx, struct can_frame *cf)
 
        if (ctx->from_in == SEND){
                ret = CHECK(send(ctx->s, NULL, 0, 0));
 
        if (ctx->from_in == SEND){
                ret = CHECK(send(ctx->s, NULL, 0, 0));
-               printf("send:%d\n", ret);
                return 0;
        }
        return 0;
                return 0;
        }
        return 0;
@@ -234,7 +247,7 @@ void init_packet_tx(struct out_ctx *ctx)
        CHECK(ioctl(s, SIOCGIFINDEX, &ifr));
 
        my_addr.sll_family = AF_PACKET;
        CHECK(ioctl(s, SIOCGIFINDEX, &ifr));
 
        my_addr.sll_family = AF_PACKET;
-       my_addr.sll_protocol = htons(ETH_P_ALL);
+       my_addr.sll_protocol = htons(ETH_P_CAN);
        my_addr.sll_ifindex =  ifr.ifr_ifindex;
 
        CHECK(bind(s, (struct sockaddr *)&my_addr, sizeof(struct sockaddr_ll)));
        my_addr.sll_ifindex =  ifr.ifr_ifindex;
 
        CHECK(bind(s, (struct sockaddr *)&my_addr, sizeof(struct sockaddr_ll)));
@@ -315,8 +328,11 @@ int main(int argc, char *argv[])
 {
        int opt;
 
 {
        int opt;
 
-       while ((opt = getopt(argc, argv, "qr:t:")) != -1) {
+       while ((opt = getopt(argc, argv, "b:qr:t:")) != -1) {
                switch (opt) {
                switch (opt) {
+               case 'b':
+                       busy_poll_us = atoi(optarg);
+                       break;
                case 'q':
                        quiet = true;
                        break;
                case 'q':
                        quiet = true;
                        break;