X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/blobdiff_plain/05644389a630a808331c9c57d61ce02230bb235b..052fa871a1c16da85562fba8b256287b404d7bab:/ugw/ugw.c diff --git a/ugw/ugw.c b/ugw/ugw.c index 0e653d3..e2c04ef 100644 --- a/ugw/ugw.c +++ b/ugw/ugw.c @@ -22,12 +22,13 @@ #include #include #include +#include #ifndef SO_BUSY_POLL #define SO_BUSY_POLL 46 #endif -#define FRAME_SIZE 256 +#define FRAME_SIZE 128 #define BLOCK_SIZE 4096 #define BLOCK_NR 2 #define FRAME_NR (BLOCK_NR*(BLOCK_SIZE/FRAME_SIZE)) @@ -71,6 +72,18 @@ struct out_ctx { int (*out_fn)(struct out_ctx *ctx, struct can_frame *cf); }; +struct stats { + int store; + int send; +} stats; + +void sigint(int v) +{ + printf("store:%d\nsend:%d\ntotal:%d\n", + stats.store, stats.send, stats.store + stats.send); + exit(0); +} + enum in2out in_read(struct in_ctx *ctx, struct can_frame *cf) { int ret = read(ctx->s, cf, sizeof(*cf)); @@ -131,7 +144,6 @@ enum in2out in_packet_rx(struct in_ctx *ctx, struct can_frame *cf) //struct sockaddr_ll *addr = (void*)hdr + TPACKET_ALIGN(ctx->hdrlen); (void)ret; struct can_frame *cf_mmap = (void*)hdr + hdr->tp_mac; - //printf("ret:%d st:%#08x m:%d RX in frame %2d, CAN ID %#3x\n", ret, hdr->tp_status, hdr->tp_mac, ctx->current, cf_mmap->can_id); *cf = *cf_mmap; hdr->tp_status = 0; ctx->current = (ctx->current + 1) % FRAME_NR; @@ -221,18 +233,14 @@ void init_write(struct out_ctx *ctx) int out_packet_tx(struct out_ctx *ctx, struct can_frame *cf) { volatile struct tpacket2_hdr *hdr = ctx->ptr + ctx->current*FRAME_SIZE; - int ret = -1; if (ctx->from_in == NOP) return 0; - while (hdr->tp_status != TP_STATUS_AVAILABLE) { - struct pollfd pfd = {.fd = ctx->s, .revents = 0, - .events = POLLIN|POLLRDNORM|POLLERR }; - ret = CHECK(poll(&pfd, 1, -1)); + CHECK(send(ctx->s, NULL, 0, 0)); } - (void)ret; + //struct sockaddr_ll *addr = (void*)hdr + TPACKET_HDRLEN - sizeof(struct sockaddr_ll); struct can_frame *cf_mmap = (void*)hdr + TPACKET_HDRLEN - sizeof(struct sockaddr_ll); *cf_mmap = *cf; @@ -241,7 +249,7 @@ int out_packet_tx(struct out_ctx *ctx, struct can_frame *cf) ctx->current = (ctx->current + 1) % FRAME_NR; if (ctx->from_in == SEND){ - ret = CHECK(send(ctx->s, NULL, 0, 0)); + CHECK(send(ctx->s, NULL, 0, 0)); return 0; } return 0; @@ -396,6 +404,7 @@ int main(int argc, char *argv[]) if (optind+1 < argc) devout = argv[optind+1]; + signal(SIGINT, sigint); gw(); return 0;