- Activated the number of cores configuration parameter for mTCP applications
---> When applications such as epserver, epwget and lighttpd are run with a a value '-N' that is less than the number of cores currently online in the system, then mTCP application will dynamically adjust the number of NIC queues to '-N' and spawn respective mTCP threads. ---> The 'num_cores' can also be adjusted via mtcp.conf file (see sample_mtcp.conf) for details. Please note that in case num_cores is `activated', the value of '-N' passed through command-line arguments is given lower precedence. ---> '-N' logic for apache-benchmark has not been adjusted yet. This will be updated soon.master
parent
d887ff401a
commit
c101fbc46f
|
@ -540,7 +540,7 @@ main(int argc, char **argv)
|
|||
int fd;
|
||||
int ret;
|
||||
uint64_t total_read;
|
||||
|
||||
struct mtcp_conf mcfg;
|
||||
int cores[MAX_CPUS];
|
||||
int i;
|
||||
|
||||
|
@ -569,6 +569,14 @@ main(int argc, char **argv)
|
|||
"number of CPUS: %d\n", num_cores);
|
||||
return FALSE;
|
||||
}
|
||||
/**
|
||||
* it is important that core limit is set
|
||||
* before mtcp_init() is called. You can
|
||||
* not set core_limit after mtcp_init()
|
||||
*/
|
||||
mtcp_getconf(&mcfg);
|
||||
mcfg.num_cores = core_limit;
|
||||
mtcp_setconf(&mcfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -630,6 +638,7 @@ main(int argc, char **argv)
|
|||
TRACE_ERROR("Failed to initialize mtcp\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* register signal handler to mtcp */
|
||||
mtcp_register_signal(SIGINT, SignalHandler);
|
||||
|
||||
|
|
|
@ -5,6 +5,15 @@
|
|||
#io = psio
|
||||
io = dpdk
|
||||
|
||||
# No. of cores setting (enabling this option will override
|
||||
# the `cpu' config for those applications that accept
|
||||
# num_cores as command line arguments)
|
||||
#
|
||||
# e.g. in case ./epserver is executed with `-N 4', the
|
||||
# mtcp core will still invoke 8 mTCP threads if the
|
||||
# following line is uncommented.
|
||||
#num_cores = 8
|
||||
|
||||
# Number of memory channels per processor socket (dpdk-only)
|
||||
num_mem_ch = 4
|
||||
|
||||
|
@ -17,7 +26,8 @@ num_mem_ch = 4
|
|||
#port = xge0 xge1
|
||||
#port = xge1
|
||||
#------ DPDK ports -------#
|
||||
port = dpdk0 dpdk1
|
||||
port = dpdk0
|
||||
#port = dpdk0 dpdk1
|
||||
#port = dpdk0:0
|
||||
#port = dpdk0:1
|
||||
|
||||
|
@ -47,9 +57,9 @@ tcp_timewait = 0
|
|||
#stat_print = xge0
|
||||
#stat_print = xge1
|
||||
#------ DPDK ports -------#
|
||||
#stat_print = dpdk0
|
||||
stat_print = dpdk0
|
||||
#stat_print = dpdk0:0
|
||||
#stat_print = dpdk0:1
|
||||
stat_print = dpdk1
|
||||
#stat_print = dpdk1
|
||||
|
||||
#######################################################
|
|
@ -735,6 +735,14 @@ main(int argc, char **argv)
|
|||
"number of CPUS: %d\n", num_cores);
|
||||
return FALSE;
|
||||
}
|
||||
/**
|
||||
* it is important that core limit is set
|
||||
* before mtcp_init() is called. You can
|
||||
* not set core_limit after mtcp_init()
|
||||
*/
|
||||
mtcp_getconf(&mcfg);
|
||||
mcfg.num_cores = core_limit;
|
||||
mtcp_setconf(&mcfg);
|
||||
} else if (strcmp(argv[i], "-c") == 0) {
|
||||
total_concurrency = atoi(argv[i + 1]);
|
||||
|
||||
|
|
|
@ -5,6 +5,15 @@
|
|||
#io = psio
|
||||
io = dpdk
|
||||
|
||||
# No. of cores setting (enabling this option will override
|
||||
# the `cpu' config for those applications that accept
|
||||
# num_cores as command line arguments)
|
||||
#
|
||||
# e.g. in case ./epwget is executed with `-N 4', the
|
||||
# mtcp core will still invoke 8 mTCP threads if the
|
||||
# following line is uncommented.
|
||||
#num_cores = 8
|
||||
|
||||
# Number of memory channels per processor socket (dpdk-only)
|
||||
num_mem_ch = 4
|
||||
|
||||
|
|
|
@ -1585,6 +1585,14 @@ main(int argc, char **argv) {
|
|||
init_server_states(&srv_states, cpus, srv, conf_file);
|
||||
|
||||
#ifdef USE_MTCP
|
||||
/**
|
||||
* it is important that core limit is set
|
||||
* before mtcp_init() is called. You can
|
||||
* not set core_limit after mtcp_init()
|
||||
*/
|
||||
mtcp_getconf(&mcfg);
|
||||
mcfg.num_cores = cpus;
|
||||
mtcp_setconf(&mcfg);
|
||||
/* initialize the mtcp context */
|
||||
if (mtcp_init("mtcp.conf")) {
|
||||
fprintf(stderr, "Failed to initialize mtcp\n");
|
||||
|
|
|
@ -5,6 +5,15 @@
|
|||
#io = psio
|
||||
io = dpdk
|
||||
|
||||
# No. of cores setting (enabling this option will override
|
||||
# the `cpu' config for those applications that accept
|
||||
# num_cores as command line arguments)
|
||||
#
|
||||
# e.g. in case ./epserver is executed with `-N 4', the
|
||||
# mtcp core will still invoke 8 mTCP threads if the
|
||||
# following line is uncommented.
|
||||
#num_cores = 8
|
||||
|
||||
# Enable multi-process support (currently under development)
|
||||
#multiprocess = 0 master
|
||||
#multiprocess = 1
|
||||
|
|
|
@ -623,6 +623,7 @@ ac_subst_vars='LTLIBOBJS
|
|||
LIBOBJS
|
||||
PSLIBPATH
|
||||
DPDKLIBPATH
|
||||
NETMAP
|
||||
PSIO
|
||||
DPDK
|
||||
EGREP
|
||||
|
@ -677,6 +678,7 @@ ac_subst_files=''
|
|||
ac_user_opts='
|
||||
enable_option_checking
|
||||
with_stuff
|
||||
enable_netmap
|
||||
'
|
||||
ac_precious_vars='build_alias
|
||||
host_alias
|
||||
|
@ -1292,6 +1294,12 @@ if test -n "$ac_init_help"; then
|
|||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
Optional Features:
|
||||
--disable-option-checking ignore unrecognized --enable/--with options
|
||||
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
|
||||
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
|
||||
--enable-netmap Enable netmap module (UNDER DEVELOPMENT)
|
||||
|
||||
Optional Packages:
|
||||
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
|
||||
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
|
||||
|
@ -3199,6 +3207,9 @@ DPDK=0
|
|||
# Reset PSIO to 0
|
||||
PSIO=0
|
||||
|
||||
# Reset NETMAP to 0
|
||||
NETMAP=0
|
||||
|
||||
|
||||
# Check dpdk-1.8.0 path (lib & inc)
|
||||
|
||||
|
@ -3230,9 +3241,22 @@ then
|
|||
|
||||
fi
|
||||
|
||||
if test "$with_psio_lib" == "" && test "$with_dpdk_lib" == ""
|
||||
# Check whether --enable-netmap was given.
|
||||
if test "${enable_netmap+set}" = set; then :
|
||||
enableval=$enable_netmap;
|
||||
fi
|
||||
|
||||
|
||||
if test "x$enable_netmap" = "xyes"; then :
|
||||
|
||||
NETMAP=1
|
||||
|
||||
|
||||
fi
|
||||
|
||||
if test "$with_psio_lib" == "" && test "$with_dpdk_lib" == "" && test "x$enable_netmap" = "xno"
|
||||
then
|
||||
as_fn_error $? "Packet I/O library is missing. Please set either dpdk or psio as your I/O lib." "$LINENO" 5
|
||||
as_fn_error $? "Packet I/O library is missing. Please set either dpdk or psio or netmap as your I/O lib." "$LINENO" 5
|
||||
fi
|
||||
|
||||
ac_config_files="$ac_config_files mtcp/src/Makefile"
|
||||
|
|
14
configure.ac
14
configure.ac
|
@ -15,6 +15,8 @@ AC_CHECK_HEADER(numa.h,,,)
|
|||
AC_SUBST(DPDK, 0)
|
||||
# Reset PSIO to 0
|
||||
AC_SUBST(PSIO, 0)
|
||||
# Reset NETMAP to 0
|
||||
AC_SUBST(NETMAP, 0)
|
||||
|
||||
# Check dpdk-1.8.0 path (lib & inc)
|
||||
AC_ARG_WITH(stuff, [ --with-dpdk-lib path to the dpdk-1.8.0 install root])
|
||||
|
@ -32,9 +34,17 @@ then
|
|||
AC_SUBST(PSIO, 1)
|
||||
fi
|
||||
|
||||
if test "$with_psio_lib" == "" && test "$with_dpdk_lib" == ""
|
||||
dnl Example of default-disabled feature
|
||||
AC_ARG_ENABLE([netmap],
|
||||
AS_HELP_STRING([--enable-netmap], [Enable netmap module (UNDER DEVELOPMENT)]))
|
||||
|
||||
AS_IF([test "x$enable_netmap" = "xyes"], [
|
||||
AC_SUBST(NETMAP, 1)
|
||||
])
|
||||
|
||||
if test "$with_psio_lib" == "" && test "$with_dpdk_lib" == "" && test "x$enable_netmap" = "xno"
|
||||
then
|
||||
AC_MSG_ERROR([Packet I/O library is missing. Please set either dpdk or psio as your I/O lib.])
|
||||
AC_MSG_ERROR([Packet I/O library is missing. Please set either dpdk or psio or netmap as your I/O lib.])
|
||||
fi
|
||||
|
||||
AC_OUTPUT(mtcp/src/Makefile)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
### TARGET ###
|
||||
PS=@PSIO@
|
||||
DPDK=@DPDK@
|
||||
NETMAP=@NETMAP@
|
||||
MTCP_LIB_DIR=../lib
|
||||
MTCP_LIB=libmtcp.a
|
||||
MTCP_HDR_DIR=../include
|
||||
|
@ -35,6 +36,12 @@ else
|
|||
INC += -DDISABLE_PSIO
|
||||
endif
|
||||
|
||||
ifeq ($(NETMAP),1)
|
||||
# do nothing
|
||||
else
|
||||
INC += -DDISABLE_NETMAP
|
||||
endif
|
||||
|
||||
# PacketShader LIBRARY and HEADER
|
||||
PS_DIR=../../io_engine
|
||||
INC += -I$(PS_DIR)/include
|
||||
|
@ -61,7 +68,7 @@ SRCS = core.c tcp_stream.c config.c api.c eventpoll.c socket.c pipe.c \
|
|||
tcp_util.c eth_in.c ip_in.c tcp_in.c eth_out.c ip_out.c tcp_out.c \
|
||||
arp.c timer.c cpu.c rss.c addr_pool.c fhash.c memory_mgt.c logger.c debug.c \
|
||||
tcp_rb_frag_queue.c tcp_ring_buffer.c tcp_send_buffer.c tcp_sb_queue.c tcp_stream_queue.c \
|
||||
psio_module.c io_module.c dpdk_module.c icmp.c
|
||||
psio_module.c io_module.c dpdk_module.c netmap_module.c icmp.c
|
||||
|
||||
OBJS = $(patsubst %.c,%.o,$(SRCS))
|
||||
DEPS = $(patsubst %.c,.%.d,$(SRCS))
|
||||
|
|
|
@ -483,6 +483,7 @@ ParseConfiguration(char *line)
|
|||
"# physical CPU cores.\n");
|
||||
return -1;
|
||||
}
|
||||
num_cpus = CONFIG.num_cores;
|
||||
} else if (strcmp(p, "max_concurrency") == 0) {
|
||||
CONFIG.max_concurrency = atoi(q);
|
||||
if (CONFIG.max_concurrency < 0) {
|
||||
|
|
|
@ -1327,18 +1327,24 @@ mtcp_setconf(const struct mtcp_conf *conf)
|
|||
if (!conf)
|
||||
return -1;
|
||||
|
||||
CONFIG.num_cores = conf->num_cores;
|
||||
CONFIG.max_concurrency = conf->max_concurrency;
|
||||
if (conf->num_cores <= 0)
|
||||
CONFIG.num_cores = conf->num_cores;
|
||||
if (conf->max_concurrency <= 0)
|
||||
CONFIG.max_concurrency = conf->max_concurrency;
|
||||
if (conf->max_num_buffers <= 0)
|
||||
CONFIG.max_num_buffers = conf->max_num_buffers;
|
||||
if (conf->rcvbuf_size <= 0)
|
||||
CONFIG.rcvbuf_size = conf->rcvbuf_size;
|
||||
if (conf->sndbuf_size <= 0)
|
||||
CONFIG.sndbuf_size = conf->sndbuf_size;
|
||||
|
||||
CONFIG.max_num_buffers = conf->max_num_buffers;
|
||||
CONFIG.rcvbuf_size = conf->rcvbuf_size;
|
||||
CONFIG.sndbuf_size = conf->sndbuf_size;
|
||||
|
||||
CONFIG.tcp_timewait = conf->tcp_timewait;
|
||||
CONFIG.tcp_timeout = conf->tcp_timeout;
|
||||
if (conf->tcp_timewait <= 0)
|
||||
CONFIG.tcp_timewait = conf->tcp_timewait;
|
||||
if (conf->tcp_timeout <= 0)
|
||||
CONFIG.tcp_timeout = conf->tcp_timeout;
|
||||
|
||||
TRACE_CONFIG("Configuration updated by mtcp_setconf().\n");
|
||||
PrintConfiguration();
|
||||
//PrintConfiguration();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1354,7 +1360,9 @@ mtcp_init(char *config_file)
|
|||
}
|
||||
|
||||
/* getting cpu and NIC */
|
||||
num_cpus = GetNumCPUs();
|
||||
/* set to max cpus only if user has not arbitrarily set it to lower # */
|
||||
num_cpus = (CONFIG.num_cores == 0) ? GetNumCPUs() : CONFIG.num_cores;
|
||||
|
||||
assert(num_cpus >= 1);
|
||||
|
||||
if (num_cpus > MAX_CPUS) {
|
||||
|
|
|
@ -0,0 +1,638 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $FreeBSD: head/sys/net/netmap.h 251139 2013-05-30 14:07:14Z luigi $
|
||||
*
|
||||
* Definitions of constants and the structures used by the netmap
|
||||
* framework, for the part visible to both kernel and userspace.
|
||||
* Detailed info on netmap is available with "man netmap" or at
|
||||
*
|
||||
* http://info.iet.unipi.it/~luigi/netmap/
|
||||
*
|
||||
* This API is also used to communicate with the VALE software switch
|
||||
*/
|
||||
|
||||
#ifndef _NET_NETMAP_H_
|
||||
#define _NET_NETMAP_H_
|
||||
|
||||
#define NETMAP_API 11 /* current API version */
|
||||
|
||||
#define NETMAP_MIN_API 11 /* min and max versions accepted */
|
||||
#define NETMAP_MAX_API 15
|
||||
/*
|
||||
* Some fields should be cache-aligned to reduce contention.
|
||||
* The alignment is architecture and OS dependent, but rather than
|
||||
* digging into OS headers to find the exact value we use an estimate
|
||||
* that should cover most architectures.
|
||||
*/
|
||||
#define NM_CACHE_ALIGN 128
|
||||
|
||||
/*
|
||||
* --- Netmap data structures ---
|
||||
*
|
||||
* The userspace data structures used by netmap are shown below.
|
||||
* They are allocated by the kernel and mmap()ed by userspace threads.
|
||||
* Pointers are implemented as memory offsets or indexes,
|
||||
* so that they can be easily dereferenced in kernel and userspace.
|
||||
|
||||
KERNEL (opaque, obviously)
|
||||
|
||||
====================================================================
|
||||
|
|
||||
USERSPACE | struct netmap_ring
|
||||
+---->+---------------+
|
||||
/ | head,cur,tail |
|
||||
struct netmap_if (nifp, 1 per fd) / | buf_ofs |
|
||||
+---------------+ / | other fields |
|
||||
| ni_tx_rings | / +===============+
|
||||
| ni_rx_rings | / | buf_idx, len | slot[0]
|
||||
| | / | flags, ptr |
|
||||
| | / +---------------+
|
||||
+===============+ / | buf_idx, len | slot[1]
|
||||
| txring_ofs[0] | (rel.to nifp)--' | flags, ptr |
|
||||
| txring_ofs[1] | +---------------+
|
||||
(tx+1 entries) (num_slots entries)
|
||||
| txring_ofs[t] | | buf_idx, len | slot[n-1]
|
||||
+---------------+ | flags, ptr |
|
||||
| rxring_ofs[0] | +---------------+
|
||||
| rxring_ofs[1] |
|
||||
(rx+1 entries)
|
||||
| rxring_ofs[r] |
|
||||
+---------------+
|
||||
|
||||
* For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to
|
||||
* a file descriptor, the mmap()ed region contains a (logically readonly)
|
||||
* struct netmap_if pointing to struct netmap_ring's.
|
||||
*
|
||||
* There is one netmap_ring per physical NIC ring, plus one tx/rx ring
|
||||
* pair attached to the host stack (this pair is unused for non-NIC ports).
|
||||
*
|
||||
* All physical/host stack ports share the same memory region,
|
||||
* so that zero-copy can be implemented between them.
|
||||
* VALE switch ports instead have separate memory regions.
|
||||
*
|
||||
* The netmap_ring is the userspace-visible replica of the NIC ring.
|
||||
* Each slot has the index of a buffer (MTU-sized and residing in the
|
||||
* mmapped region), its length and some flags. An extra 64-bit pointer
|
||||
* is provided for user-supplied buffers in the tx path.
|
||||
*
|
||||
* In user space, the buffer address is computed as
|
||||
* (char *)ring + buf_ofs + index * NETMAP_BUF_SIZE
|
||||
*
|
||||
* Added in NETMAP_API 11:
|
||||
*
|
||||
* + NIOCREGIF can request the allocation of extra spare buffers from
|
||||
* the same memory pool. The desired number of buffers must be in
|
||||
* nr_arg3. The ioctl may return fewer buffers, depending on memory
|
||||
* availability. nr_arg3 will return the actual value, and, once
|
||||
* mapped, nifp->ni_bufs_head will be the index of the first buffer.
|
||||
*
|
||||
* The buffers are linked to each other using the first uint32_t
|
||||
* as the index. On close, ni_bufs_head must point to the list of
|
||||
* buffers to be released.
|
||||
*
|
||||
* + NIOCREGIF can request space for extra rings (and buffers)
|
||||
* allocated in the same memory space. The number of extra rings
|
||||
* is in nr_arg1, and is advisory. This is a no-op on NICs where
|
||||
* the size of the memory space is fixed.
|
||||
*
|
||||
* + NIOCREGIF can attach to PIPE rings sharing the same memory
|
||||
* space with a parent device. The ifname indicates the parent device,
|
||||
* which must already exist. Flags in nr_flags indicate if we want to
|
||||
* bind the master or slave side, the index (from nr_ringid)
|
||||
* is just a cookie and does not need to be sequential.
|
||||
*
|
||||
* + NIOCREGIF can also attach to 'monitor' rings that replicate
|
||||
* the content of specific rings, also from the same memory space.
|
||||
*
|
||||
* Extra flags in nr_flags support the above functions.
|
||||
* Application libraries may use the following naming scheme:
|
||||
* netmap:foo all NIC ring pairs
|
||||
* netmap:foo^ only host ring pair
|
||||
* netmap:foo+ all NIC ring + host ring pairs
|
||||
* netmap:foo-k the k-th NIC ring pair
|
||||
* netmap:foo{k PIPE ring pair k, master side
|
||||
* netmap:foo}k PIPE ring pair k, slave side
|
||||
*/
|
||||
|
||||
/*
|
||||
* struct netmap_slot is a buffer descriptor
|
||||
*/
|
||||
struct netmap_slot {
|
||||
uint32_t buf_idx; /* buffer index */
|
||||
uint16_t len; /* length for this slot */
|
||||
uint16_t flags; /* buf changed, etc. */
|
||||
uint64_t ptr; /* pointer for indirect buffers */
|
||||
};
|
||||
|
||||
/*
|
||||
* The following flags control how the slot is used
|
||||
*/
|
||||
|
||||
#define NS_BUF_CHANGED 0x0001 /* buf_idx changed */
|
||||
/*
|
||||
* must be set whenever buf_idx is changed (as it might be
|
||||
* necessary to recompute the physical address and mapping)
|
||||
*
|
||||
* It is also set by the kernel whenever the buf_idx is
|
||||
* changed internally (e.g., by pipes). Applications may
|
||||
* use this information to know when they can reuse the
|
||||
* contents of previously prepared buffers.
|
||||
*/
|
||||
|
||||
#define NS_REPORT 0x0002 /* ask the hardware to report results */
|
||||
/*
|
||||
* Request notification when slot is used by the hardware.
|
||||
* Normally transmit completions are handled lazily and
|
||||
* may be unreported. This flag lets us know when a slot
|
||||
* has been sent (e.g. to terminate the sender).
|
||||
*/
|
||||
|
||||
#define NS_FORWARD 0x0004 /* pass packet 'forward' */
|
||||
/*
|
||||
* (Only for physical ports, rx rings with NR_FORWARD set).
|
||||
* Slot released to the kernel (i.e. before ring->head) with
|
||||
* this flag set are passed to the peer ring (host/NIC),
|
||||
* thus restoring the host-NIC connection for these slots.
|
||||
* This supports efficient traffic monitoring or firewalling.
|
||||
*/
|
||||
|
||||
#define NS_NO_LEARN 0x0008 /* disable bridge learning */
|
||||
/*
|
||||
* On a VALE switch, do not 'learn' the source port for
|
||||
* this buffer.
|
||||
*/
|
||||
|
||||
#define NS_INDIRECT 0x0010 /* userspace buffer */
|
||||
/*
|
||||
* (VALE tx rings only) data is in a userspace buffer,
|
||||
* whose address is in the 'ptr' field in the slot.
|
||||
*/
|
||||
|
||||
#define NS_MOREFRAG 0x0020 /* packet has more fragments */
|
||||
/*
|
||||
* (VALE ports only)
|
||||
* Set on all but the last slot of a multi-segment packet.
|
||||
* The 'len' field refers to the individual fragment.
|
||||
*/
|
||||
|
||||
#define NS_PORT_SHIFT 8
|
||||
#define NS_PORT_MASK (0xff << NS_PORT_SHIFT)
|
||||
/*
|
||||
* The high 8 bits of the flag, if not zero, indicate the
|
||||
* destination port for the VALE switch, overriding
|
||||
* the lookup table.
|
||||
*/
|
||||
|
||||
#define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff)
|
||||
/*
|
||||
* (VALE rx rings only) the high 8 bits
|
||||
* are the number of fragments.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* struct netmap_ring
|
||||
*
|
||||
* Netmap representation of a TX or RX ring (also known as "queue").
|
||||
* This is a queue implemented as a fixed-size circular array.
|
||||
* At the software level the important fields are: head, cur, tail.
|
||||
*
|
||||
* In TX rings:
|
||||
*
|
||||
* head first slot available for transmission.
|
||||
* cur wakeup point. select() and poll() will unblock
|
||||
* when 'tail' moves past 'cur'
|
||||
* tail (readonly) first slot reserved to the kernel
|
||||
*
|
||||
* [head .. tail-1] can be used for new packets to send;
|
||||
* 'head' and 'cur' must be incremented as slots are filled
|
||||
* with new packets to be sent;
|
||||
* 'cur' can be moved further ahead if we need more space
|
||||
* for new transmissions. XXX todo (2014-03-12)
|
||||
*
|
||||
* In RX rings:
|
||||
*
|
||||
* head first valid received packet
|
||||
* cur wakeup point. select() and poll() will unblock
|
||||
* when 'tail' moves past 'cur'
|
||||
* tail (readonly) first slot reserved to the kernel
|
||||
*
|
||||
* [head .. tail-1] contain received packets;
|
||||
* 'head' and 'cur' must be incremented as slots are consumed
|
||||
* and can be returned to the kernel;
|
||||
* 'cur' can be moved further ahead if we want to wait for
|
||||
* new packets without returning the previous ones.
|
||||
*
|
||||
* DATA OWNERSHIP/LOCKING:
|
||||
* The netmap_ring, and all slots and buffers in the range
|
||||
* [head .. tail-1] are owned by the user program;
|
||||
* the kernel only accesses them during a netmap system call
|
||||
* and in the user thread context.
|
||||
*
|
||||
* Other slots and buffers are reserved for use by the kernel
|
||||
*/
|
||||
struct netmap_ring {
|
||||
/*
|
||||
* buf_ofs is meant to be used through macros.
|
||||
* It contains the offset of the buffer region from this
|
||||
* descriptor.
|
||||
*/
|
||||
const int64_t buf_ofs;
|
||||
const uint32_t num_slots; /* number of slots in the ring. */
|
||||
const uint32_t nr_buf_size;
|
||||
const uint16_t ringid;
|
||||
const uint16_t dir; /* 0: tx, 1: rx */
|
||||
|
||||
uint32_t head; /* (u) first user slot */
|
||||
uint32_t cur; /* (u) wakeup point */
|
||||
uint32_t tail; /* (k) first kernel slot */
|
||||
|
||||
uint32_t flags;
|
||||
|
||||
struct timeval ts; /* (k) time of last *sync() */
|
||||
|
||||
/* opaque room for a mutex or similar object */
|
||||
#if !defined(_WIN32) || defined(__CYGWIN__)
|
||||
uint8_t __attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128];
|
||||
#else
|
||||
uint8_t __declspec(align(NM_CACHE_ALIGN)) sem[128];
|
||||
#endif
|
||||
|
||||
/* the slots follow. This struct has variable size */
|
||||
struct netmap_slot slot[0]; /* array of slots. */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* RING FLAGS
|
||||
*/
|
||||
#define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */
|
||||
/*
|
||||
* updates the 'ts' field on each netmap syscall. This saves
|
||||
* saves a separate gettimeofday(), and is not much worse than
|
||||
* software timestamps generated in the interrupt handler.
|
||||
*/
|
||||
|
||||
#define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */
|
||||
/*
|
||||
* Enables the NS_FORWARD slot flag for the ring.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Netmap representation of an interface and its queue(s).
|
||||
* This is initialized by the kernel when binding a file
|
||||
* descriptor to a port, and should be considered as readonly
|
||||
* by user programs. The kernel never uses it.
|
||||
*
|
||||
* There is one netmap_if for each file descriptor on which we want
|
||||
* to select/poll.
|
||||
* select/poll operates on one or all pairs depending on the value of
|
||||
* nmr_queueid passed on the ioctl.
|
||||
*/
|
||||
struct netmap_if {
|
||||
char ni_name[IFNAMSIZ]; /* name of the interface. */
|
||||
const uint32_t ni_version; /* API version, currently unused */
|
||||
const uint32_t ni_flags; /* properties */
|
||||
#define NI_PRIV_MEM 0x1 /* private memory region */
|
||||
|
||||
/*
|
||||
* The number of packet rings available in netmap mode.
|
||||
* Physical NICs can have different numbers of tx and rx rings.
|
||||
* Physical NICs also have a 'host' ring pair.
|
||||
* Additionally, clients can request additional ring pairs to
|
||||
* be used for internal communication.
|
||||
*/
|
||||
const uint32_t ni_tx_rings; /* number of HW tx rings */
|
||||
const uint32_t ni_rx_rings; /* number of HW rx rings */
|
||||
|
||||
uint32_t ni_bufs_head; /* head index for extra bufs */
|
||||
uint32_t ni_spare1[5];
|
||||
/*
|
||||
* The following array contains the offset of each netmap ring
|
||||
* from this structure, in the following order:
|
||||
* NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings;
|
||||
* NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings.
|
||||
*
|
||||
* The area is filled up by the kernel on NIOCREGIF,
|
||||
* and then only read by userspace code.
|
||||
*/
|
||||
const ssize_t ring_ofs[0];
|
||||
};
|
||||
|
||||
|
||||
#ifndef NIOCREGIF
|
||||
/*
|
||||
* ioctl names and related fields
|
||||
*
|
||||
* NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
|
||||
* whose identity is set in NIOCREGIF through nr_ringid.
|
||||
* These are non blocking and take no argument.
|
||||
*
|
||||
* NIOCGINFO takes a struct ifreq, the interface name is the input,
|
||||
* the outputs are number of queues and number of descriptor
|
||||
* for each queue (useful to set number of threads etc.).
|
||||
* The info returned is only advisory and may change before
|
||||
* the interface is bound to a file descriptor.
|
||||
*
|
||||
* NIOCREGIF takes an interface name within a struct nmre,
|
||||
* and activates netmap mode on the interface (if possible).
|
||||
*
|
||||
* The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we
|
||||
* can pass it down to other NIC-related ioctls.
|
||||
*
|
||||
* The actual argument (struct nmreq) has a number of options to request
|
||||
* different functions.
|
||||
* The following are used in NIOCREGIF when nr_cmd == 0:
|
||||
*
|
||||
* nr_name (in)
|
||||
* The name of the port (em0, valeXXX:YYY, etc.)
|
||||
* limited to IFNAMSIZ for backward compatibility.
|
||||
*
|
||||
* nr_version (in/out)
|
||||
* Must match NETMAP_API as used in the kernel, error otherwise.
|
||||
* Always returns the desired value on output.
|
||||
*
|
||||
* nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out)
|
||||
* On input, non-zero values may be used to reconfigure the port
|
||||
* according to the requested values, but this is not guaranteed.
|
||||
* On output the actual values in use are reported.
|
||||
*
|
||||
* nr_ringid (in)
|
||||
* Indicates how rings should be bound to the file descriptors.
|
||||
* If nr_flags != 0, then the low bits (in NETMAP_RING_MASK)
|
||||
* are used to indicate the ring number, and nr_flags specifies
|
||||
* the actual rings to bind. NETMAP_NO_TX_POLL is unaffected.
|
||||
*
|
||||
* NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED:
|
||||
* If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control
|
||||
* the binding as follows:
|
||||
* 0 (default) binds all physical rings
|
||||
* NETMAP_HW_RING | ring number binds a single ring pair
|
||||
* NETMAP_SW_RING binds only the host tx/rx rings
|
||||
*
|
||||
* NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push
|
||||
* packets on tx rings only if POLLOUT is set.
|
||||
* The default is to push any pending packet.
|
||||
*
|
||||
* NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release
|
||||
* packets on rx rings also when POLLIN is NOT set.
|
||||
* The default is to touch the rx ring only with POLLIN.
|
||||
* Note that this is the opposite of TX because it
|
||||
* reflects the common usage.
|
||||
*
|
||||
* NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead.
|
||||
* NETMAP_PRIV_MEM is set on return for ports that do not use
|
||||
* the global memory allocator.
|
||||
* This information is not significant and applications
|
||||
* should look at the region id in nr_arg2
|
||||
*
|
||||
* nr_flags is the recommended mode to indicate which rings should
|
||||
* be bound to a file descriptor. Values are NR_REG_*
|
||||
*
|
||||
* nr_arg1 (in) The number of extra rings to be reserved.
|
||||
* Especially when allocating a VALE port the system only
|
||||
* allocates the amount of memory needed for the port.
|
||||
* If more shared memory rings are desired (e.g. for pipes),
|
||||
* the first invocation for the same basename/allocator
|
||||
* should specify a suitable number. Memory cannot be
|
||||
* extended after the first allocation without closing
|
||||
* all ports on the same region.
|
||||
*
|
||||
* nr_arg2 (in/out) The identity of the memory region used.
|
||||
* On input, 0 means the system decides autonomously,
|
||||
* other values may try to select a specific region.
|
||||
* On return the actual value is reported.
|
||||
* Region '1' is the global allocator, normally shared
|
||||
* by all interfaces. Other values are private regions.
|
||||
* If two ports the same region zero-copy is possible.
|
||||
*
|
||||
* nr_arg3 (in/out) number of extra buffers to be allocated.
|
||||
*
|
||||
*
|
||||
*
|
||||
* nr_cmd (in) if non-zero indicates a special command:
|
||||
* NETMAP_BDG_ATTACH and nr_name = vale*:ifname
|
||||
* attaches the NIC to the switch; nr_ringid specifies
|
||||
* which rings to use. Used by vale-ctl -a ...
|
||||
* nr_arg1 = NETMAP_BDG_HOST also attaches the host port
|
||||
* as in vale-ctl -h ...
|
||||
*
|
||||
* NETMAP_BDG_DETACH and nr_name = vale*:ifname
|
||||
* disconnects a previously attached NIC.
|
||||
* Used by vale-ctl -d ...
|
||||
*
|
||||
* NETMAP_BDG_LIST
|
||||
* list the configuration of VALE switches.
|
||||
*
|
||||
* NETMAP_BDG_VNET_HDR
|
||||
* Set the virtio-net header length used by the client
|
||||
* of a VALE switch port.
|
||||
*
|
||||
* NETMAP_BDG_NEWIF
|
||||
* create a persistent VALE port with name nr_name.
|
||||
* Used by vale-ctl -n ...
|
||||
*
|
||||
* NETMAP_BDG_DELIF
|
||||
* delete a persistent VALE port. Used by vale-ctl -d ...
|
||||
*
|
||||
* nr_arg1, nr_arg2, nr_arg3 (in/out) command specific
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* struct nmreq overlays a struct ifreq (just the name)
|
||||
*/
|
||||
struct nmreq {
|
||||
char nr_name[IFNAMSIZ];
|
||||
uint32_t nr_version; /* API version */
|
||||
uint32_t nr_offset; /* nifp offset in the shared region */
|
||||
uint32_t nr_memsize; /* size of the shared region */
|
||||
uint32_t nr_tx_slots; /* slots in tx rings */
|
||||
uint32_t nr_rx_slots; /* slots in rx rings */
|
||||
uint16_t nr_tx_rings; /* number of tx rings */
|
||||
uint16_t nr_rx_rings; /* number of rx rings */
|
||||
|
||||
uint16_t nr_ringid; /* ring(s) we care about */
|
||||
#define NETMAP_HW_RING 0x4000 /* single NIC ring pair */
|
||||
#define NETMAP_SW_RING 0x2000 /* only host ring pair */
|
||||
|
||||
#define NETMAP_RING_MASK 0x0fff /* the ring number */
|
||||
|
||||
#define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */
|
||||
|
||||
#define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */
|
||||
|
||||
uint16_t nr_cmd;
|
||||
#define NETMAP_BDG_ATTACH 1 /* attach the NIC */
|
||||
#define NETMAP_BDG_DETACH 2 /* detach the NIC */
|
||||
#define NETMAP_BDG_REGOPS 3 /* register bridge callbacks */
|
||||
#define NETMAP_BDG_LIST 4 /* get bridge's info */
|
||||
#define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */
|
||||
#define NETMAP_BDG_OFFSET NETMAP_BDG_VNET_HDR /* deprecated alias */
|
||||
#define NETMAP_BDG_NEWIF 6 /* create a virtual port */
|
||||
#define NETMAP_BDG_DELIF 7 /* destroy a virtual port */
|
||||
#define NETMAP_PT_HOST_CREATE 8 /* create ptnetmap kthreads */
|
||||
#define NETMAP_PT_HOST_DELETE 9 /* delete ptnetmap kthreads */
|
||||
uint16_t nr_arg1; /* reserve extra rings in NIOCREGIF */
|
||||
#define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */
|
||||
|
||||
uint16_t nr_arg2;
|
||||
uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */
|
||||
uint32_t nr_flags;
|
||||
/* various modes, extends nr_ringid */
|
||||
uint32_t spare2[1];
|
||||
};
|
||||
|
||||
#define NR_REG_MASK 0xf /* values for nr_flags */
|
||||
enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */
|
||||
NR_REG_ALL_NIC = 1,
|
||||
NR_REG_SW = 2,
|
||||
NR_REG_NIC_SW = 3,
|
||||
NR_REG_ONE_NIC = 4,
|
||||
NR_REG_PIPE_MASTER = 5,
|
||||
NR_REG_PIPE_SLAVE = 6,
|
||||
};
|
||||
/* monitor uses the NR_REG to select the rings to monitor */
|
||||
#define NR_MONITOR_TX 0x100
|
||||
#define NR_MONITOR_RX 0x200
|
||||
#define NR_ZCOPY_MON 0x400
|
||||
/* request exclusive access to the selected rings */
|
||||
#define NR_EXCLUSIVE 0x800
|
||||
/* request ptnetmap host support */
|
||||
#define NR_PASSTHROUGH_HOST NR_PTNETMAP_HOST /* deprecated */
|
||||
#define NR_PTNETMAP_HOST 0x1000
|
||||
|
||||
|
||||
/*
|
||||
* Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined
|
||||
* in ws2def.h but not sure if they are in the form we need.
|
||||
* XXX so we redefine them
|
||||
* in a convenient way to use for DeviceIoControl signatures
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#undef _IO // ws2def.h
|
||||
#define _WIN_NM_IOCTL_TYPE 40000
|
||||
#define _IO(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
|
||||
METHOD_BUFFERED, FILE_ANY_ACCESS )
|
||||
#define _IO_direct(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
|
||||
METHOD_OUT_DIRECT, FILE_ANY_ACCESS )
|
||||
|
||||
#define _IOWR(_c, _n, _s) _IO(_c, _n)
|
||||
|
||||
/* We havesome internal sysctl in addition to the externally visible ones */
|
||||
#define NETMAP_MMAP _IO_direct('i', 160) // note METHOD_OUT_DIRECT
|
||||
#define NETMAP_POLL _IO('i', 162)
|
||||
|
||||
/* and also two setsockopt for sysctl emulation */
|
||||
#define NETMAP_SETSOCKOPT _IO('i', 140)
|
||||
#define NETMAP_GETSOCKOPT _IO('i', 141)
|
||||
|
||||
|
||||
//These linknames are for the Netmap Core Driver
|
||||
#define NETMAP_NT_DEVICE_NAME L"\\Device\\NETMAP"
|
||||
#define NETMAP_DOS_DEVICE_NAME L"\\DosDevices\\netmap"
|
||||
|
||||
//Definition of a structure used to pass a virtual address within an IOCTL
|
||||
typedef struct _MEMORY_ENTRY {
|
||||
PVOID pUsermodeVirtualAddress;
|
||||
} MEMORY_ENTRY, *PMEMORY_ENTRY;
|
||||
|
||||
typedef struct _POLL_REQUEST_DATA {
|
||||
int events;
|
||||
int timeout;
|
||||
int revents;
|
||||
} POLL_REQUEST_DATA;
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/*
|
||||
* FreeBSD uses the size value embedded in the _IOWR to determine
|
||||
* how much to copy in/out. So we need it to match the actual
|
||||
* data structure we pass. We put some spares in the structure
|
||||
* to ease compatibility with other versions
|
||||
*/
|
||||
#define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */
|
||||
#define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */
|
||||
#define NIOCTXSYNC _IO('i', 148) /* sync tx queues */
|
||||
#define NIOCRXSYNC _IO('i', 149) /* sync rx queues */
|
||||
#define NIOCCONFIG _IOWR('i',150, struct nm_ifreq) /* for ext. modules */
|
||||
#endif /* !NIOCREGIF */
|
||||
|
||||
|
||||
/*
|
||||
* Helper functions for kernel and userspace
|
||||
*/
|
||||
|
||||
/*
|
||||
* check if space is available in the ring.
|
||||
*/
|
||||
static inline int
|
||||
nm_ring_empty(struct netmap_ring *ring)
|
||||
{
|
||||
return (ring->cur == ring->tail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Opaque structure that is passed to an external kernel
|
||||
* module via ioctl(fd, NIOCCONFIG, req) for a user-owned
|
||||
* bridge port (at this point ephemeral VALE interface).
|
||||
*/
|
||||
#define NM_IFRDATA_LEN 256
|
||||
struct nm_ifreq {
|
||||
char nifr_name[IFNAMSIZ];
|
||||
char data[NM_IFRDATA_LEN];
|
||||
};
|
||||
|
||||
/*
|
||||
* netmap kernel thread configuration
|
||||
*/
|
||||
/* bhyve/vmm.ko MSIX paramenters for IOCTL */
|
||||
struct ptn_vmm_ioctl_msix {
|
||||
uint64_t msg;
|
||||
uint64_t addr;
|
||||
};
|
||||
|
||||
/* IOCTL parameters */
|
||||
struct nm_kth_ioctl {
|
||||
u_long com;
|
||||
/* TODO: use union */
|
||||
union {
|
||||
struct ptn_vmm_ioctl_msix msix;
|
||||
} data;
|
||||
};
|
||||
/* event configuration */
|
||||
struct nm_kth_event_cfg {
|
||||
uint64_t ioeventfd; /* eventfd in linux, tsleep() parameter in FreeBSD */
|
||||
uint64_t irqfd; /* eventfd in linux, ioctl fd in FreeBSD */
|
||||
struct nm_kth_ioctl ioctl; /* ioctl parameter to send irq (only used in bhyve/FreeBSD) */
|
||||
};
|
||||
#endif /* _NET_NETMAP_H_ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,272 @@
|
|||
/* for io_module_func def'ns */
|
||||
#include "io_module.h"
|
||||
#ifndef DISABLE_NETMAP
|
||||
/* for mtcp related def'ns */
|
||||
#include "mtcp.h"
|
||||
/* for errno */
|
||||
#include <errno.h>
|
||||
/* for logging */
|
||||
#include "debug.h"
|
||||
/* for num_devices_* */
|
||||
#include "config.h"
|
||||
/* for netmap definitions */
|
||||
#define NETMAP_WITH_LIBS
|
||||
#include "netmap_user.h"
|
||||
/* for poll */
|
||||
#include <sys/poll.h>
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define MAX_PKT_BURST 64
|
||||
#define ETHERNET_FRAME_SIZE 1514
|
||||
#define MAX_IFNAMELEN (IF_NAMESIZE + 10)
|
||||
|
||||
struct netmap_private_context {
|
||||
struct nm_desc *local_nmd[MAX_DEVICES];
|
||||
int fd[MAX_DEVICES];
|
||||
char *recv_pktbuf[MAX_DEVICES][MAX_PKT_BURST];
|
||||
unsigned int recv_pkt_cnt[MAX_DEVICES];
|
||||
unsigned int recv_pkt_len[MAX_DEVICES][MAX_PKT_BURST];
|
||||
char send_pktbuf[MAX_DEVICES][MAX_PKT_BURST][ETHERNET_FRAME_SIZE];
|
||||
unsigned int send_pkt_cnt[MAX_DEVICES];
|
||||
} __attribute__((aligned(__WORDSIZE)));
|
||||
|
||||
struct netmap_global {
|
||||
struct nm_desc *nmd;
|
||||
int main_fd;
|
||||
};
|
||||
struct netmap_global ng[MAX_DEVICES];
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
netmap_init_handle(struct mtcp_thread_context *ctxt)
|
||||
{
|
||||
struct netmap_private_context *npc;
|
||||
char nifname[MAX_IFNAMELEN];
|
||||
int j;
|
||||
|
||||
/* create and initialize private I/O module context */
|
||||
ctxt->io_private_context = calloc(1, sizeof(struct netmap_private_context));
|
||||
if (ctxt->io_private_context == NULL) {
|
||||
TRACE_ERROR("Failed to initialize ctxt->io_private_context: "
|
||||
"Can't allocate memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
|
||||
/* set wmbufs correctly */
|
||||
for (j = 0; j < num_devices_attached; j++) {
|
||||
if (if_indextoname(devices_attached[j], nifname) == NULL) {
|
||||
TRACE_ERROR("Failed to initialize interface %s\n",
|
||||
nifname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sprintf(nifname, "netmap:%s", nifname);
|
||||
struct nm_desc nmd = *ng[j].nmd;
|
||||
uint64_t nmd_flags = 0;
|
||||
nmd.self = &nmd;
|
||||
|
||||
if (ctxt->cpu > 0) {
|
||||
/*
|
||||
* the first thread uses the fd opened by the main thread,
|
||||
* the other threads re-open /dev/netmap
|
||||
*/
|
||||
nmd.req.nr_flags = ng[j].nmd->req.nr_flags & ~NR_REG_MASK;
|
||||
nmd.req.nr_flags |= NR_REG_ONE_NIC;
|
||||
nmd.req.nr_ringid = ctxt->cpu;
|
||||
|
||||
npc->local_nmd[j] = nm_open(nifname, NULL, nmd_flags |
|
||||
NM_OPEN_IFNAME | NM_OPEN_NO_MMAP,
|
||||
&nmd);
|
||||
if (npc->local_nmd[j] == NULL) {
|
||||
TRACE_ERROR("Unable to open %s: %s\n",
|
||||
nifname, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
npc->local_nmd[j] = ng[j].nmd;
|
||||
}
|
||||
npc->fd[j] = ng[j].nmd->fd;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int
|
||||
netmap_link_devices(struct mtcp_thread_context *ctxt)
|
||||
{
|
||||
/* linking takes place during mtcp_init() */
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
netmap_release_pkt(struct mtcp_thread_context *ctxt, int ifidx, unsigned char *pkt_data, int len)
|
||||
{
|
||||
/*
|
||||
* do nothing over here - memory reclamation
|
||||
* will take place in dpdk_recv_pkts
|
||||
*/
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int
|
||||
netmap_send_pkts(struct mtcp_thread_context *ctxt, int nif)
|
||||
{
|
||||
int i;
|
||||
struct netmap_private_context *npc;
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
|
||||
for (i = 0; i < npc->send_pkt_cnt[nif]; i++) {
|
||||
//local_nmd
|
||||
}
|
||||
|
||||
npc->send_pkt_cnt[nif] = 0;
|
||||
return 0;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint8_t *
|
||||
netmap_get_wptr(struct mtcp_thread_context *ctxt, int nif, uint16_t pktsize)
|
||||
{
|
||||
struct netmap_private_context *npc;
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
|
||||
|
||||
return (uint8_t *)npc->send_pktbuf[nif][npc->send_pkt_cnt[nif]++];
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int32_t
|
||||
netmap_recv_pkts(struct mtcp_thread_context *ctxt, int ifidx)
|
||||
{
|
||||
struct netmap_private_context *npc;
|
||||
struct netmap_if *nifp;
|
||||
int i, count = 0;
|
||||
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
for (i = npc->local_nmd[ifidx]->first_rx_ring; i <= npc->local_nmd[ifidx]->last_rx_ring; i++) {
|
||||
int m, cur, count;
|
||||
struct netmap_ring *rxring;
|
||||
|
||||
nifp = npc->local_nmd[ifidx]->nifp;
|
||||
rxring = NETMAP_RXRING(nifp, i);
|
||||
if (nm_ring_empty(rxring))
|
||||
continue;
|
||||
cur = rxring->cur;
|
||||
count = nm_ring_space(rxring);
|
||||
if (count > MAX_PKT_BURST)
|
||||
count = MAX_PKT_BURST;
|
||||
/* receive packets */
|
||||
for (m = 0; m < count; m++) {
|
||||
struct netmap_slot *slot = &rxring->slot[cur];
|
||||
npc->recv_pktbuf[ifidx][npc->recv_pkt_cnt[ifidx]] = NETMAP_BUF(rxring, slot->buf_idx);
|
||||
npc->recv_pkt_len[ifidx][npc->recv_pkt_cnt[ifidx]] = slot->len;
|
||||
cur = nm_ring_next(rxring, cur);
|
||||
npc->recv_pkt_cnt[ifidx]++;
|
||||
}
|
||||
rxring->head = rxring->cur = cur;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint8_t *
|
||||
netmap_get_rptr(struct mtcp_thread_context *ctxt, int ifidx, int index, uint16_t *len)
|
||||
{
|
||||
struct netmap_private_context *npc;
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
|
||||
*len = npc->recv_pkt_len[ifidx][index];
|
||||
return (unsigned char *)npc->recv_pktbuf[ifidx][index];
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int32_t
|
||||
netmap_select(struct mtcp_thread_context *ctxt)
|
||||
{
|
||||
struct netmap_private_context *npc;
|
||||
|
||||
npc = (struct netmap_private_context *)ctxt->io_private_context;
|
||||
struct pollfd pfd = { .fd = npc->fd[0], .events = POLLIN };
|
||||
|
||||
if (poll(&pfd, 1, 1 * 1000) <= 0) {
|
||||
TRACE_ERROR("Poll failed! (cpu: %d, err: %d)\n",
|
||||
ctxt->cpu, errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pfd.revents & POLLERR) {
|
||||
TRACE_ERROR("Poll failed! (cpu: %d\n, err: %d)\n",
|
||||
ctxt->cpu, errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
netmap_destroy_handle(struct mtcp_thread_context *ctxt)
|
||||
{
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void
|
||||
netmap_load_module(void)
|
||||
{
|
||||
char nifname[MAX_IFNAMELEN];
|
||||
struct nmreq base_nmd;
|
||||
int j;
|
||||
|
||||
memset(&base_nmd, 0, sizeof(base_nmd));
|
||||
|
||||
for (j = 0; j < num_devices_attached; j++) {
|
||||
if (if_indextoname(devices_attached[j], nifname) == NULL) {
|
||||
TRACE_ERROR("Failed to initialize interface %s\n",
|
||||
nifname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sprintf(nifname, "netmap:%s", nifname);
|
||||
ng[j].nmd = nm_open(nifname, &base_nmd, 0, NULL);
|
||||
if (ng[j].nmd == NULL) {
|
||||
TRACE_ERROR("Failed to call nm_open for iface %s on g_nmd\n",
|
||||
nifname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct nm_desc saved_desc = *(ng[j].nmd);
|
||||
saved_desc.self = &saved_desc;
|
||||
saved_desc.mem = NULL;
|
||||
nm_close(ng[j].nmd);
|
||||
saved_desc.req.nr_flags &= ~NR_REG_MASK;
|
||||
saved_desc.req.nr_flags |= NR_REG_ONE_NIC;
|
||||
saved_desc.req.nr_ringid = 0;
|
||||
ng[j].nmd = nm_open(nifname, &base_nmd, NM_OPEN_IFNAME, &saved_desc);
|
||||
if (ng[j].nmd == NULL) {
|
||||
TRACE_ERROR("Unable to open %s: %s", nifname, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ng[j].main_fd = ng[j].nmd->fd;
|
||||
TRACE_LOG("mapped %dKB at %p", g_nmd[j].req.nr_memsize>>10,
|
||||
ng[j].nmd->mem);
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
io_module_func netmap_module_func = {
|
||||
.load_module = netmap_load_module,
|
||||
.init_handle = netmap_init_handle,
|
||||
.link_devices = netmap_link_devices,
|
||||
.release_pkt = netmap_release_pkt,
|
||||
.send_pkts = netmap_send_pkts,
|
||||
.get_wptr = netmap_get_wptr,
|
||||
.recv_pkts = netmap_recv_pkts,
|
||||
.get_rptr = netmap_get_rptr,
|
||||
.select = netmap_select,
|
||||
.destroy_handle = netmap_destroy_handle
|
||||
};
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#else
|
||||
io_module_func netmap_module_func = {
|
||||
.load_module = NULL,
|
||||
.init_handle = NULL,
|
||||
.link_devices = NULL,
|
||||
.release_pkt = NULL,
|
||||
.send_pkts = NULL,
|
||||
.get_wptr = NULL,
|
||||
.recv_pkts = NULL,
|
||||
.get_rptr = NULL,
|
||||
.select = NULL,
|
||||
.destroy_handle = NULL
|
||||
};
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#endif /* !DISABLE_NETMAP */
|
Loading…
Reference in New Issue