This commit is contained in:
logwang 2017-06-14 15:38:42 +08:00
commit 3132126c98
14 changed files with 13617 additions and 188 deletions

View File

@ -0,0 +1 @@
4.0.3-0-ge9192eacf8935e29fc62fddc2701f7942b1cc02c

9702
app/redis-3.2.8/deps/jemalloc/configure vendored Executable file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,8 @@ LIBS+= -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto -pthread
TARGET="helloworld"
all:
cc -O -gdwarf-2 -g -I../lib -o ${TARGET} main.c ${LIBS}
cc -O -gdwarf-2 -I../lib -o ${TARGET} main.c ${LIBS}
cc -O -gdwarf-2 -I../lib -o ${TARGET}_epoll main_epoll.c ${LIBS}
.PHONY: clean
clean:

View File

@ -129,7 +129,6 @@ FF_SRCS+= \
ff_subr_prf.c \
ff_vfs_ops.c \
ff_veth.c \
ff_epoll.c \
ff_route.c
FF_HOST_SRCS+= \
@ -139,6 +138,7 @@ FF_HOST_SRCS+= \
ff_dpdk_if.c \
ff_dpdk_kni.c \
ff_dpdk_pcap.c \
ff_epoll.c \
ff_init.c
ifdef FF_IPSEC

View File

@ -102,6 +102,9 @@ int ff_poll(struct pollfd fds[], nfds_t nfds, int timeout);
int ff_kqueue(void);
int ff_kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout);
int ff_kevent_do_each(int kq, const struct kevent *changelist, int nchanges,
void *eventlist, int nevents, const struct timespec *timeout,
void (*do_each)(void **, struct kevent *));
/* route api begin */
enum FF_ROUTE_CTL {

View File

@ -29,10 +29,7 @@ ff_shutdown
ff_sysctl
ff_kqueue
ff_kevent
ff_epoll_create
ff_epoll_ctl
ff_epoll_wait
ff_epoll_close
ff_kevent_do_each
ff_veth_attach
ff_veth_detach
ff_veth_process_packet
@ -43,3 +40,4 @@ ff_mbuf_copydata
ff_mbuf_tx_offload
ff_route_ctl
ff_rtioctl

View File

@ -89,6 +89,9 @@
#define BITS_PER_HEX 4
#define KNI_MBUF_MAX 2048
#define KNI_QUEUE_SIZE 2048
static int enable_kni;
static int kni_accept;
@ -411,7 +414,10 @@ init_mem_pool(void)
(nb_rx_queue*RX_QUEUE_SIZE +
nb_ports*nb_lcores*MAX_PKT_BURST +
nb_ports*nb_tx_queue*TX_QUEUE_SIZE +
nb_lcores*MEMPOOL_CACHE_SIZE),
nb_lcores*MEMPOOL_CACHE_SIZE +
nb_ports*KNI_MBUF_MAX +
nb_ports*KNI_QUEUE_SIZE +
nb_lcores*nb_ports*ARP_RING_SIZE),
(unsigned)8192);
unsigned socketid = 0;
@ -591,7 +597,7 @@ init_kni(void)
int i, ret;
for (i = 0; i < nb_ports; i++) {
uint8_t port_id = ff_global_cfg.dpdk.port_cfgs[i].port_id;
ff_kni_alloc(port_id, socket_id, mbuf_pool);
ff_kni_alloc(port_id, socket_id, mbuf_pool, KNI_QUEUE_SIZE);
}
return 0;

View File

@ -40,8 +40,6 @@
#include "ff_dpdk_kni.h"
#include "ff_config.h"
#define KNI_QUEUE_SIZE 8192
/* Callback for request of changing MTU */
/* Total octets in ethernet header */
#define KNI_ENET_HEADER_SIZE 14
@ -330,7 +328,7 @@ ff_kni_init(uint16_t nb_ports, const char *tcp_ports, const char *udp_ports)
void
ff_kni_alloc(uint8_t port_id, unsigned socket_id,
struct rte_mempool *mbuf_pool)
struct rte_mempool *mbuf_pool, unsigned ring_queue_size)
{
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
struct rte_kni_conf conf;
@ -381,7 +379,7 @@ ff_kni_alloc(uint8_t port_id, unsigned socket_id,
snprintf((char*)ring_name, RTE_KNI_NAMESIZE, "kni_ring_%u", port_id);
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
kni_rp[port_id] = rte_ring_create(ring_name, KNI_QUEUE_SIZE,
kni_rp[port_id] = rte_ring_create(ring_name, ring_queue_size,
socket_id, RING_F_SC_DEQ);
if (rte_ring_lookup(ring_name) != kni_rp[port_id])

View File

@ -41,7 +41,7 @@ void ff_kni_init(uint16_t nb_ports, const char *tcp_ports,
const char *udp_ports);
void ff_kni_alloc(uint8_t port_id, unsigned socket_id,
struct rte_mempool *mbuf_pool);
struct rte_mempool *mbuf_pool, unsigned ring_queue_size);
void ff_kni_process(uint8_t port_id, uint16_t queue_id,
struct rte_mbuf **pkts_burst, unsigned count);

View File

@ -1,127 +1,103 @@
#include <sys/param.h>
#include <sys/limits.h>
#include <sys/uio.h>
#include <sys/proc.h>
#include <sys/syscallsubr.h>
#include <sys/module.h>
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/socketvar.h>
#include <sys/event.h>
#include <sys/kernel.h>
#include <sys/refcount.h>
#include <sys/sysctl.h>
#include <sys/pcpu.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <sys/event.h>
#include <sys/file.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sched.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ttycom.h>
#include <sys/filio.h>
#include <sys/sysproto.h>
#include <sys/fcntl.h>
#include <machine/stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include "ff_api.h"
#include "ff_epoll.h"
#include "ff_errno.h"
#include "ff_host_interface.h"
int
ff_epoll_create(int size __attribute__((__unused__)))
{
return ff_kqueue();
return ff_kqueue();
}
int
ff_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
{
if (!event && op != EPOLL_CTL_DEL) {
ff_os_errno(ff_EINVAL);
return -1;
}
struct kevent kev[3];
struct kevent kev[3];
if (op == EPOLL_CTL_ADD){
EV_SET(&kev[0], fd, EVFILT_READ,
EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE,
EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD,
event->events & EPOLLRDHUP ? 1 : 0, 0, NULL);
} else if (op == EPOLL_CTL_DEL) {
EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL);
} else if (op == EPOLL_CTL_MOD) {
EV_SET(&kev[0], fd, EVFILT_READ,
event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE,
event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, 0,
NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL);
} else {
ff_os_errno(ff_EINVAL);
return -1;
}
if (!event && op != EPOLL_CTL_DEL) {
errno = EINVAL;
return -1;
}
return ff_kevent(epfd, kev, 3, NULL, 0, NULL);
if (op == EPOLL_CTL_ADD){
EV_SET(&kev[0], fd, EVFILT_READ,
EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE,
EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD,
event->events & EPOLLRDHUP ? 1 : 0, 0, NULL);
} else if (op == EPOLL_CTL_DEL) {
EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL);
} else if (op == EPOLL_CTL_MOD) {
EV_SET(&kev[0], fd, EVFILT_READ,
event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE,
event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
EV_SET(&kev[2], fd, EVFILT_USER, 0,
NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL);
} else {
errno = EINVAL;
return -1;
}
return ff_kevent(epfd, kev, 3, NULL, 0, NULL);
}
static void
ff_event_to_epoll(void **ev, struct kevent *kev)
{
unsigned int event_one = 0;
struct epoll_event **ppev = (struct epoll_event **)ev;
if (kev->filter & EVFILT_READ) {
event_one |= EPOLLIN;
}
if (kev->filter & EVFILT_WRITE) {
event_one |= EPOLLOUT;
}
if (kev->flags & EV_ERROR) {
event_one |= EPOLLERR;
}
if (kev->flags & EV_EOF) {
event_one |= EPOLLIN;
}
(*ppev)->events = event_one;
(*ppev)->data.fd = kev->ident;
(*ppev)++;
}
int
ff_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
{
if (!events || maxevents < 1) {
ff_os_errno(ff_EINVAL);
return -1;
}
int i, ret;
if (!events || maxevents < 1) {
errno = EINVAL;
return -1;
}
struct kevent *evlist = malloc(sizeof(struct kevent)*maxevents, M_DEVBUF, M_ZERO|M_NOWAIT);
if(NULL == evlist){
ff_os_errno(ff_EINVAL);
return -1;
}
memset(evlist, 0, sizeof(struct kevent)*maxevents);
int ret = ff_kevent(epfd, NULL, 0, evlist, maxevents, NULL);
if (ret == -1) {
free(evlist, M_DEVBUF);
return ret;
}
unsigned int event_one = 0;
for (int i = 0; i < ret; ++i) {
event_one = 0;
if (evlist[i].filter & EVFILT_READ) {
event_one |= EPOLLIN;
}
if (evlist[i].filter & EVFILT_WRITE) {
event_one |= EPOLLOUT;
}
if (evlist[i].flags & EV_ERROR) {
event_one |= EPOLLERR;
}
if (evlist[i].flags & EV_EOF) {
event_one |= EPOLLIN;
}
events[i].events = event_one;
events[i].data.fd = evlist[i].ident;
}
free(evlist, M_DEVBUF);
return ret;
}
int
ff_epoll_close(int epfd)
{
return ff_close(epfd);
return ff_kevent_do_each(epfd, NULL, 0, events, maxevents, NULL, ff_event_to_epoll);
}

View File

@ -1,73 +1,11 @@
#ifndef _FF_EPOLL_H
#define _FF_EPOLL_H
//#include <sys/stdint.h>
//#include <sys/queue.h>
#include <sys/epoll.h>
#ifndef _KERNEL
#include <stdint.h>
#else
#include <sys/stdint.h>
#include <sys/types.h>
#endif
enum EPOLL_EVENTS
{
EPOLLIN = 0x001,
#define EPOLLIN EPOLLIN
EPOLLPRI = 0x002,
#define EPOLLPRI EPOLLPRI
EPOLLOUT = 0x004,
#define EPOLLOUT EPOLLOUT
EPOLLRDNORM = 0x040,
#define EPOLLRDNORM EPOLLRDNORM
EPOLLRDBAND = 0x080,
#define EPOLLRDBAND EPOLLRDBAND
EPOLLWRNORM = 0x100,
#define EPOLLWRNORM EPOLLWRNORM
EPOLLWRBAND = 0x200,
#define EPOLLWRBAND EPOLLWRBAND
EPOLLMSG = 0x400,
#define EPOLLMSG EPOLLMSG
EPOLLERR = 0x008,
#define EPOLLERR EPOLLERR
EPOLLHUP = 0x010,
#define EPOLLHUP EPOLLHUP
EPOLLRDHUP = 0x2000,
#define EPOLLRDHUP EPOLLRDHUP
EPOLLWAKEUP = 1u << 29,
#define EPOLLWAKEUP EPOLLWAKEUP
EPOLLONESHOT = 1u << 30,
#define EPOLLONESHOT EPOLLONESHOT
EPOLLET = 1u << 31
#define EPOLLET EPOLLET
};
/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
#define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */
#define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */
#define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */
typedef union epoll_data
{
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
struct epoll_event
{
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
};
/*warpper epoll api.*/
int ff_epoll_create(int size);
int ff_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
int ff_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
int ff_epoll_close(int epfd);
#endif

View File

@ -937,20 +937,30 @@ struct sys_kevent_args {
int fd;
const struct kevent *changelist;
int nchanges;
struct kevent *eventlist;
void *eventlist;
int nevents;
const struct timespec *timeout;
void (*do_each)(void **, struct kevent *);
};
static int
kevent_copyout(void *arg, struct kevent *kevp, int count)
{
int i;
struct kevent *ke;
struct sys_kevent_args *uap;
uap = (struct sys_kevent_args *)arg;
bcopy(kevp, uap->eventlist, count * sizeof *kevp);
uap->eventlist += count;
if (!uap->do_each) {
bcopy(kevp, uap->eventlist, count * sizeof *kevp);
uap->eventlist = (void *)((struct kevent *)(uap->eventlist) + count);
} else {
for (ke = kevp, i = 0; i < count; i++, ke++) {
uap->do_each(&(uap->eventlist), ke);
}
}
return (0);
}
@ -972,21 +982,25 @@ kevent_copyin(void *arg, struct kevent *kevp, int count)
}
int
ff_kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout)
ff_kevent_do_each(int kq, const struct kevent *changelist, int nchanges,
void *eventlist, int nevents, const struct timespec *timeout,
void (*do_each)(void **, struct kevent *))
{
int rc;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 0;
struct sys_kevent_args ska = {
kq,
changelist,
nchanges,
eventlist,
nevents,
&ts
&ts,
do_each
};
struct kevent_copyops k_ops = {
&ska,
kevent_copyout,
@ -1004,6 +1018,13 @@ kern_fail:
return (-1);
}
int
ff_kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout)
{
return ff_kevent_do_each(kq, changelist, nchanges, eventlist, nevents, timeout, NULL);
}
int
ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag,
struct linux_sockaddr *dst, struct linux_sockaddr *gw,
@ -1075,4 +1096,3 @@ kern_fail:
ff_os_errno(rc);
return (-1);
}