FreeBSD Bugzilla – Attachment 201394 Details for
Bug 207261
netmap: Doesn't do TX sync with kqueue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Example netmap program using kqueue to read or write from a netmap port.
netmap_kqueue.c (text/plain), 2.51 KB, created by
Vincenzo Maffione
on 2019-01-25 14:58:55 UTC
(
hide
)
Description:
Example netmap program using kqueue to read or write from a netmap port.
Filename:
MIME Type:
Creator:
Vincenzo Maffione
Created:
2019-01-25 14:58:55 UTC
Size:
2.51 KB
patch
obsolete
>#include <stdio.h> >#include <assert.h> > >#include <sys/types.h> >#include <sys/event.h> >#include <sys/time.h> >#include <unistd.h> > >#ifndef NETMAP_WITH_LIBS >#define NETMAP_WITH_LIBS >#endif >#include <net/netmap_user.h> > >static int >kq_add(int kq, int fd, int read) >{ > struct kevent changes[1]; > int filter = read ? EVFILT_READ : EVFILT_WRITE; > int ret; > > EV_SET(&changes[0], fd, filter, EV_ADD, 0, 0, NULL); > ret = kevent(kq, changes, 1, NULL, 0, NULL); > assert(ret != -1); > > return (ret); >} > >static void >kq_wait(int kq) >{ > struct kevent events[1]; > int ret; > > ret = kevent(kq, NULL, 0, events, 1, NULL); > assert(ret != -1); >} > >static void >usage(void) >{ > printf("netmap kqueue test program\n" > " [-h (help)]\n" > " [-i PORT_NAME]\n" > " [-r (read mode)\n" > " [-w (write mode)\n" > " [-T WRITE_INTERVAL_MSECS\n]"); > exit(EXIT_SUCCESS); >} > >int main(int argc, char **argv) >{ > struct netmap_ring *ring; > const char *portname = "vale1:1"; > struct nm_desc *d; > int T = 1000; > int read = 1; > int n = 0; > int kq; > int ch; > > while ((ch = getopt(argc, argv, "hi:rwT:")) != -1) { > switch (ch) { > default: > printf("bad option %c %s\n", ch, optarg); > /* fallthrough */ > case 'h': > usage(); > break; > case 'i': /* interface */ > portname = optarg; > break; > case 'r': > read = 1; > break; > case 'w': > read = 0; > break; > case 'T': > T = atoi(optarg); > if (T < 0 || T > 10000) { > printf("T out of bounds %d\n", T); > exit(EXIT_FAILURE); > } > break; > } > } > > T *= 1000; /* convert to usecs */ > > d = nm_open(portname, NULL, 0, 0); > assert(d != NULL); > if (read) { > ring = NETMAP_RXRING(d->nifp, 0); > } else { > ring = NETMAP_TXRING(d->nifp, 0); > } > printf("init: head %u tail %u\n", ring->head, ring->tail); > > kq = kqueue(); > assert(kq != -1); > > kq_add(kq, d->fd, read); > > while (1) { > unsigned int head; > > kq_wait(kq); > > head = ring->head; > while (head != ring->tail) { > struct netmap_slot *slot = ring->slot + head; > char *buf = NETMAP_BUF(ring, slot->buf_idx); > > if (read) { > printf("%d: recv len %u\n", n, slot->len); > } else { > slot->len = 80; > slot->flags = 0; > > memset(buf, 0xf, 6); > memset(buf + 6, 0, 6); > buf[12] = 0x08; > buf[13] = 0x00; > memset(buf + 14, 'k', slot->len); > printf("%d: sent %d\n", n, slot->len); > usleep(T); > } > head = nm_ring_next(ring, head); > n++; > } > ring->head = ring->cur = head; > } > > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 207261
: 201394