opt code.

This commit is contained in:
fengbojiang 2023-04-23 10:51:56 +08:00
parent cf587718c2
commit dd7dc378ef
6 changed files with 48 additions and 21 deletions

View File

@ -74,7 +74,7 @@ fstack: ${FSTACK_OBJS}
#libff_syscall.a: ${FF_SYSCALL_OBJS}
libff_syscall.so: ${FF_SYSCALL_OBJS}
#ar -rcs $@ $^ ${FF_SYSCALL_LIBS}
${CC} -fPIC -shared -o $@ $^ ${FF_SYSCALL_LIBS}
${CC} -fPIC -shared -o $@ $^ ${FF_SYSCALL_LIBS} ${DPDK_LIBS}
${FSTACK_OBJS}: %.o: %.c
${CC} -c $(CFLAGS) ${PROF} $<

View File

@ -5,6 +5,7 @@
#include <sys/resource.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <rte_malloc.h>
#include <rte_memcpy.h>
@ -17,6 +18,9 @@
#include "ff_linux_syscall.h"
#include "ff_adapter.h"
/* Just for so, no used */
struct ff_config ff_global_cfg;
#define NS_PER_SECOND 1000000000
#ifndef likely
@ -238,6 +242,8 @@ ff_hook_socket(int domain, int type, int protocol)
ret = convert_fstack_fd(ret);
}
DEBUG_LOG("ff_hook_socket return fd:%d\n", ret);
RETURN();
}
@ -484,6 +490,8 @@ ff_hook_setsockopt(int fd, int level, int optname,
int
ff_hook_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
{
DEBUG_LOG("ff_hook_accept, fd:%d, addr:%p, len:%p\n", fd, addr, addrlen);
if ((addr == NULL && addrlen != NULL) ||
(addr != NULL && addrlen == NULL)) {
errno = EINVAL;
@ -1263,7 +1271,7 @@ int
ff_hook_epoll_create(int fdsize)
{
DEBUG_LOG("ff_hook_epoll_create, fdsize:%d\n", fdsize);
if (inited == 0 || ((fdsize & SOCK_KERNEL) && !(fdsize & SOCK_FSTACK)) || (fdsize >= 1 && fdsize <= 16)) {
if (inited == 0 || ((fdsize & SOCK_KERNEL) && !(fdsize & SOCK_FSTACK))/* || (fdsize >= 1 && fdsize <= 16)*/) {
fdsize &= ~SOCK_KERNEL;
return ff_linux_epoll_create(fdsize);
}
@ -1278,6 +1286,8 @@ ff_hook_epoll_create(int fdsize)
ret = convert_fstack_fd(ret);
}
DEBUG_LOG("ff_hook_epoll_create return fd:%d\n", ret);
RETURN();
}
@ -1442,6 +1452,7 @@ ff_hook_epoll_wait(int epfd, struct epoll_event *events,
pid_t
ff_hook_fork(void)
{
DEBUG_LOG("ff_hook_fork\n");
return ff_linux_fork();
}
@ -1655,6 +1666,7 @@ thread_destructor(void *sc)
#ifdef FF_THREAD_SOCKET
DEBUG_LOG("pthread self tid:%lu, detach sc:%p\n", pthread_self(), sc);
ff_detach_so_context(sc);
sc = NULL;
#endif
if (shutdown_args) {
@ -1692,6 +1704,18 @@ thread_destructor(void *sc)
}
}
void __attribute__((destructor))
ff_adapter_exit()
{
pthread_key_delete(key);
#ifndef FF_THREAD_SOCKET
ERR_LOG("pthread self tid:%lu, detach sc:%p\n", pthread_self(), sc);
ff_detach_so_context(sc);
sc = NULL;
#endif
}
int
ff_adapter_init()
//int __attribute__((constructor))
@ -1711,6 +1735,9 @@ ff_adapter_init()
pthread_key_create(&key, thread_destructor);
DEBUG_LOG("pthread key:%d\n", key);
//atexit(ff_adapter_exit);
//on_exit(ff_adapter_exit, NULL);
/*
* get ulimit -n to distinguish fd between kernel and F-Stack
*/
@ -1836,22 +1863,11 @@ ff_adapter_init()
return 0;
}
void __attribute__((destructor))
ff_adapter_exit()
{
pthread_key_delete(key);
#ifndef FF_THREAD_SOCKET
ERR_LOG("pthread self tid:%lu, detach sc:%p\n", pthread_self(), sc);
ff_detach_so_context(sc);
#endif
}
void
alarm_event_sem()
{
#ifndef FF_THREAD_SOCKET
DEBUG_LOG("check whether need to alarm sem sc:%p, status:%d, ops:%d\n",
DEBUG_LOG("check whether need to alarm sem sc:%p, status:%d, ops:%d, need_alarm_sem:%d\n",
sc, sc->status, sc->ops, need_alarm_sem);
rte_spinlock_lock(&sc->lock);
if (need_alarm_sem == 1) {
@ -1861,7 +1877,7 @@ alarm_event_sem()
}
rte_spinlock_unlock(&sc->lock);
DEBUG_LOG("finish alarm sem sc:%p, status:%d, ops:%d\n",
DEBUG_LOG("finish alarm sem sc:%p, status:%d, ops:%d, need_alarm_sem:%d\n",
sc, sc->status, sc->ops, need_alarm_sem);
#endif
}

View File

@ -7,6 +7,6 @@
extern int kqueue(void);
extern int kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents, const struct timespec *timeout);
struct kevent *eventlist, int nevents, const struct timespec *timeout);
#endif

View File

@ -124,6 +124,7 @@ int ff_linux_setsockopt(int s, int level, int optname,
int ff_linux_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
DEBUG_LOG("ff_linux_accept, fd:%d, addr:%p, len:%p\n", s, addr, addrlen);
SYSCALL(accept, (s, addr, addrlen));
}
@ -151,11 +152,13 @@ ssize_t ff_linux_send(int s, const void *buf, size_t len, int flags)
ssize_t ff_linux_read(int s, void *buf, size_t len)
{
DEBUG_LOG("ff_linux_read, fd:%d, buf:%p, len:%lu\n", s, buf, len);
SYSCALL(read, (s, buf, len));
}
ssize_t ff_linux_write(int s, const void *buf, size_t len)
{
DEBUG_LOG("ff_linux_write, fd:%d, buf:%p, len:%lu\n", s, buf, len);
SYSCALL(write, (s, buf, len));
}
@ -194,6 +197,7 @@ ssize_t ff_linux_recvmsg(int s, struct msghdr *msg, int flags)
int ff_linux_close(int s)
{
DEBUG_LOG("ff_linux_close, fd:%d\n", s);
SYSCALL(close, (s));
}
@ -231,6 +235,7 @@ ff_linux_epoll_wait(int epfd, struct epoll_event *events,
pid_t
ff_linux_fork(void)
{
DEBUG_LOG("ff_linux_fork\n");
SYSCALL(fork, ());
}

View File

@ -450,7 +450,7 @@ ff_handle_socket_ops(struct ff_so_context *sc)
sc->error = errno;
if (sc->ops == FF_SO_EPOLL_WAIT || sc->ops == FF_SO_KEVENT) {
DEBUG_LOG("ff_event_loop_nb:%d/%d, ff_next_event_flag:%d\n",
DEBUG_LOG("ff_event_loop_nb:%d, ff_next_event_flag:%d\n",
ff_event_loop_nb, ff_next_event_flag);
if (ff_event_loop_nb > 0) {
ff_next_event_flag = 1;
@ -481,6 +481,7 @@ void
ff_handle_each_context()
{
uint16_t i, nb_handled, tmp;
static uint64_t loop_count = 0;
ff_event_loop_nb = 0;
@ -495,9 +496,11 @@ ff_handle_each_context()
for (i = 0; i < ff_so_zone->count; i++) {
struct ff_so_context *sc = &ff_so_zone->sc[i];
DEBUG_LOG("so:%p, so->count:%d,%p, sc:%p, sc->inuse:%d,%p, i:%d, nb:%d, all_nb:%d\n",
ff_so_zone, ff_so_zone->count, &ff_so_zone->count,
sc, ff_so_zone->inuse[i], &ff_so_zone->inuse[i], i, nb_handled, tmp);
if ((loop_count & 1048575) == 0) {
DEBUG_LOG("so:%p, so->count:%d,%p, sc:%p, sc->inuse:%d,%p, i:%d, nb:%d, all_nb:%d\n",
ff_so_zone, ff_so_zone->count, &ff_so_zone->count,
sc, ff_so_zone->inuse[i], &ff_so_zone->inuse[i], i, nb_handled, tmp);
}
if (ff_so_zone->inuse[i] == 0) {
continue;
@ -523,5 +526,7 @@ ff_handle_each_context()
}
rte_spinlock_unlock(&ff_so_zone->lock);
loop_count++;
}

View File

@ -19,7 +19,8 @@
#endif
#define ERR_LOG(fmt, ...) do { \
printf("file:%s, line:%u, fun:%s, "fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
printf("file:%s, line:%u, fun:%s, thread self tid:%ld, "fmt, \
__FILE__, __LINE__, __func__, pthread_self(), ##__VA_ARGS__); \
} while (0)
#ifdef NDEBUG