From f4465774126add54f42746a86fbdbe1b55e70847 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 2 Jun 2016 06:41:50 +0200 Subject: [PATCH] netmap: implement 'threads: auto' Add until function for retrieving RSS RX count from netmap. Use the RSS count to create the threads. --- src/runmode-netmap.c | 2 +- src/source-netmap.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/source-netmap.h | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/runmode-netmap.c b/src/runmode-netmap.c index 5d76e417d2..f154e7cf15 100644 --- a/src/runmode-netmap.c +++ b/src/runmode-netmap.c @@ -180,7 +180,7 @@ static void *ParseNetmapConfig(const char *iface_name) aconf->threads = 1; } else { if (strcmp(threadsstr, "auto") == 0) { - aconf->threads = GetIfaceRSSQueuesNum(aconf->iface); + aconf->threads = NetmapGetRSSCount(aconf->iface); } else { aconf->threads = (uint8_t)atoi(threadsstr); } diff --git a/src/source-netmap.c b/src/source-netmap.c index fdb4c707e7..fff2b26e27 100644 --- a/src/source-netmap.c +++ b/src/source-netmap.c @@ -277,6 +277,46 @@ static int NetmapSetIfaceFlags(int fd, const char *ifname, int flags) return 0; } +/** \brief get RSS RX-queue count + * \retval rx_rings RSS RX queue count or 1 on error + */ +int NetmapGetRSSCount(const char *ifname) +{ + struct nmreq nm_req; + int rx_rings = 1; + + SCMutexLock(&netmap_devlist_lock); + + /* open netmap */ + int fd = open("/dev/netmap", O_RDWR); + if (fd == -1) { + SCLogError(SC_ERR_NETMAP_CREATE, + "Couldn't open netmap device, error %s", + strerror(errno)); + goto error_open; + } + + /* query netmap info */ + memset(&nm_req, 0, sizeof(nm_req)); + strlcpy(nm_req.nr_name, ifname, sizeof(nm_req.nr_name)); + nm_req.nr_version = NETMAP_API; + + if (ioctl(fd, NIOCGINFO, &nm_req) != 0) { + SCLogError(SC_ERR_NETMAP_CREATE, + "Couldn't query netmap for %s, error %s", + ifname, strerror(errno)); + goto error_fd; + }; + + rx_rings = nm_req.nr_rx_rings; + +error_fd: + close(fd); +error_open: + SCMutexUnlock(&netmap_devlist_lock); + return rx_rings; +} + /** * \brief Open interface in netmap mode. * \param ifname Interface name. diff --git a/src/source-netmap.h b/src/source-netmap.h index c52b505079..c6f7b6c23f 100644 --- a/src/source-netmap.h +++ b/src/source-netmap.h @@ -67,6 +67,8 @@ typedef struct NetmapPacketVars_ void *ntv; } NetmapPacketVars; +int NetmapGetRSSCount(const char *ifname); + void TmModuleReceiveNetmapRegister (void); void TmModuleDecodeNetmapRegister (void);