wip
This commit is contained in:
parent
16ea43895a
commit
955b0dfe73
6
Makefile
6
Makefile
|
@ -94,14 +94,14 @@ libruntime.a: $(runtime_obj)
|
|||
|
||||
iokerneld: $(iokernel_obj) libbase.a libnet.a base/base.ld
|
||||
$(LD) $(LDFLAGS) -o $@ $(iokernel_obj) libbase.a libnet.a $(DPDK_LIBS) \
|
||||
-lpthread -lnuma -ldl
|
||||
-lpthread -ldl -lexecinfo
|
||||
|
||||
iokerneld-noht: $(iokernel_noht_obj) libbase.a libnet.a base/base.ld
|
||||
$(LD) $(LDFLAGS) -o $@ $(iokernel_noht_obj) libbase.a libnet.a $(DPDK_LIBS) \
|
||||
-lpthread -lnuma -ldl
|
||||
-lpthread -ldl -lexecinfo
|
||||
|
||||
$(test_targets): $(test_obj) libbase.a libruntime.a libnet.a base/base.ld
|
||||
$(LD) $(LDFLAGS) -o $@ $@.o libruntime.a libnet.a libbase.a -lpthread
|
||||
$(LD) $(LDFLAGS) -o $@ $@.o libruntime.a libnet.a libbase.a -lpthread -lexecinfo
|
||||
|
||||
# general build rules for all targets
|
||||
src = $(base_src) $(net_src) $(runtime_src) $(iokernel_src) $(test_src)
|
||||
|
|
|
@ -37,11 +37,7 @@ struct shm_thread_data {
|
|||
|
||||
static pid_t gettid(void)
|
||||
{
|
||||
#ifdef SYS_gettid
|
||||
pid_t tid = syscall(SYS_gettid);
|
||||
#else
|
||||
#error "SYS_gettid unavailable on this system"
|
||||
#endif
|
||||
pid_t tid = thr_self();
|
||||
|
||||
return tid;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void logk(int level, const char *fmt, ...)
|
|||
if (level > max_loglevel)
|
||||
return;
|
||||
|
||||
cpu = sched_getcpu();
|
||||
cpu = 0;
|
||||
|
||||
if (likely(base_init_done)) {
|
||||
uint64_t us = microtime();
|
||||
|
|
22
base/mem.c
22
base/mem.c
|
@ -2,11 +2,11 @@
|
|||
* mem.c - memory management
|
||||
*/
|
||||
|
||||
#include <asm/mman.h>
|
||||
//#include <asm/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <numaif.h>
|
||||
//#include <numaif.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -31,7 +31,7 @@ long mbind(void *start, size_t len, int mode,
|
|||
const unsigned long *nmask, unsigned long maxnode,
|
||||
unsigned flags)
|
||||
{
|
||||
return syscall(__NR_mbind, start, len, mode, nmask, maxnode, flags);
|
||||
//return syscall(__NR_mbind, start, len, mode, nmask, maxnode, flags);
|
||||
}
|
||||
|
||||
static void sigbus_error(int sig)
|
||||
|
@ -41,7 +41,7 @@ static void sigbus_error(int sig)
|
|||
|
||||
static void touch_mapping(void *base, size_t len, size_t pgsize)
|
||||
{
|
||||
__sighandler_t s;
|
||||
sig_t s;
|
||||
char *pos;
|
||||
|
||||
/*
|
||||
|
@ -60,7 +60,7 @@ __mem_map_anom(void *base, size_t len, size_t pgsize,
|
|||
unsigned long *mask, int numa_policy)
|
||||
{
|
||||
void *addr;
|
||||
int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE;
|
||||
int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_PREFAULT_READ;
|
||||
|
||||
len = align_up(len, pgsize);
|
||||
|
||||
|
@ -71,7 +71,7 @@ __mem_map_anom(void *base, size_t len, size_t pgsize,
|
|||
case PGSIZE_4KB:
|
||||
break;
|
||||
case PGSIZE_2MB:
|
||||
flags |= MAP_HUGETLB;
|
||||
flags |= MAP_ALIGNED_SUPER;
|
||||
#ifdef MAP_HUGE_2MB
|
||||
flags |= MAP_HUGE_2MB;
|
||||
#endif
|
||||
|
@ -92,9 +92,9 @@ __mem_map_anom(void *base, size_t len, size_t pgsize,
|
|||
return MAP_FAILED;
|
||||
|
||||
BUILD_ASSERT(sizeof(unsigned long) * 8 >= NNUMA);
|
||||
if (mbind(addr, len, numa_policy, mask ? mask : NULL,
|
||||
mask ? NNUMA : 0, MPOL_MF_STRICT))
|
||||
goto fail;
|
||||
// if (mbind(addr, len, numa_policy, mask ? mask : NULL,
|
||||
// mask ? NNUMA : 0, MPOL_MF_STRICT))
|
||||
// goto fail;
|
||||
|
||||
touch_mapping(addr, len, pgsize);
|
||||
return addr;
|
||||
|
@ -116,7 +116,7 @@ fail:
|
|||
void *mem_map_anom(void *base, size_t len, size_t pgsize, int node)
|
||||
{
|
||||
unsigned long mask = (1 << node);
|
||||
return __mem_map_anom(base, len, pgsize, &mask, MPOL_BIND);
|
||||
return __mem_map_anom(base, len, pgsize, &mask, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ void *mem_map_shm(mem_key_t key, void *base, size_t len, size_t pgsize,
|
|||
case PGSIZE_4KB:
|
||||
break;
|
||||
case PGSIZE_2MB:
|
||||
flags |= SHM_HUGETLB;
|
||||
//flags |= SHM_HUGETLB;
|
||||
#ifdef SHM_HUGE_2MB
|
||||
flags |= SHM_HUGE_2MB;
|
||||
#endif
|
||||
|
|
|
@ -34,13 +34,13 @@ static int time_calibrate_tsc(void)
|
|||
struct timespec t_start, t_end;
|
||||
|
||||
cpu_serialize();
|
||||
if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) {
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &t_start) == 0) {
|
||||
uint64_t ns, end, start;
|
||||
double secs;
|
||||
|
||||
start = rdtsc();
|
||||
nanosleep(&sleeptime, NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &t_end);
|
||||
clock_gettime(CLOCK_MONOTONIC, &t_end);
|
||||
end = rdtscp(NULL);
|
||||
ns = ((t_end.tv_sec - t_start.tv_sec) * 1E9);
|
||||
ns += (t_end.tv_nsec - t_start.tv_nsec);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <asm/cpu.h>
|
||||
#include <base/compiler.h>
|
||||
|
||||
#ifndef __bswap16
|
||||
static inline uint16_t __bswap16(uint16_t val)
|
||||
{
|
||||
#ifdef HAS_BUILTIN_BSWAP
|
||||
|
@ -16,7 +17,9 @@ static inline uint16_t __bswap16(uint16_t val)
|
|||
((val & 0xff00U) >> 8));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __bswap32
|
||||
static inline uint32_t __bswap32(uint32_t val)
|
||||
{
|
||||
#ifdef HAS_BUILTIN_BSWAP
|
||||
|
@ -28,7 +31,9 @@ static inline uint32_t __bswap32(uint32_t val)
|
|||
((val & 0xff000000UL) >> 24));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __bswap64
|
||||
static inline uint64_t __bswap64(uint64_t val)
|
||||
{
|
||||
#ifdef HAS_BUILTIN_BSWAP
|
||||
|
@ -44,6 +49,7 @@ static inline uint64_t __bswap64(uint64_t val)
|
|||
((val & 0xff00000000000000ULL) >> 56));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __BYTE_ORDER
|
||||
#error __BYTE_ORDER is undefined
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef unsigned long virtaddr_t; /* virtual addresses */
|
|||
#define MAP_FAILED ((void *)-1)
|
||||
#endif
|
||||
|
||||
typedef unsigned int mem_key_t;
|
||||
typedef key_t mem_key_t;
|
||||
|
||||
extern void *mem_map_anom(void *base, size_t len, size_t pgsize, int node);
|
||||
extern void *mem_map_file(void *base, size_t len, int fd, off_t offset);
|
||||
|
|
|
@ -86,11 +86,7 @@ static inline pid_t gettid(void)
|
|||
{
|
||||
pid_t tid;
|
||||
|
||||
#ifdef SYS_gettid
|
||||
tid = syscall(SYS_gettid);
|
||||
#else
|
||||
#error "SYS_gettid unavailable on this system"
|
||||
#endif
|
||||
tid = syscall(SYS_thr_self);
|
||||
|
||||
return tid;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
#include <asm/cpu.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
|
||||
#include <sys/shm.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <base/thread.h>
|
||||
#include <iokernel/control.h>
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ucred.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static int controlfd;
|
||||
|
@ -227,7 +231,7 @@ static int control_recv_fds(int fd, int *fds, int n)
|
|||
static void control_add_client(void)
|
||||
{
|
||||
struct proc *p;
|
||||
struct ucred ucred;
|
||||
struct xucred ucred;
|
||||
socklen_t len;
|
||||
mem_key_t shm_key;
|
||||
size_t shm_len;
|
||||
|
@ -246,8 +250,8 @@ static void control_add_client(void)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
len = sizeof(struct ucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) {
|
||||
len = sizeof(struct xucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, &ucred, &len) == -1) {
|
||||
log_err("control: getsockopt() failed [%s]", strerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
@ -272,16 +276,15 @@ static void control_add_client(void)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
p = control_create_proc(shm_key, shm_len, ucred.pid, &fds[0], n_fds);
|
||||
p = control_create_proc(shm_key, shm_len, ucred.cr_pid, &fds[0], n_fds);
|
||||
if (!p) {
|
||||
log_err("control: failed to create process '%d'", ucred.pid);
|
||||
log_err("control: failed to create process '%d'", 0, ucred.cr_pid);
|
||||
goto fail_close_fds;
|
||||
}
|
||||
|
||||
if (!lrpc_send(&lrpc_control_to_data, DATAPLANE_ADD_CLIENT,
|
||||
(unsigned long) p)) {
|
||||
log_err("control: failed to inform dataplane of new client '%d'",
|
||||
ucred.pid);
|
||||
log_err("control: failed to inform dataplane of new client '%d'", ucred.cr_pid);
|
||||
goto fail_destroy_proc;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/_cpuset.h>
|
||||
#include <sys/cpuset.h>
|
||||
#include <sys/thr.h>
|
||||
#include <pthread_np.h>
|
||||
|
||||
#include <base/bitmap.h>
|
||||
#include <base/cpu.h>
|
||||
#include <base/hash.h>
|
||||
|
@ -603,7 +608,7 @@ struct thread *cores_add_core(struct proc *p)
|
|||
th_current->p->inflight_preempts++;
|
||||
BUG_ON(core_history[core].next);
|
||||
core_history[core].next = th;
|
||||
if (unlikely(syscall(SYS_tgkill, th_current->p->pid,
|
||||
if (unlikely(syscall(thr_kill2, th_current->p->pid,
|
||||
th_current->tid, SIGUSR1) < 0)) {
|
||||
WARN();
|
||||
}
|
||||
|
@ -618,13 +623,13 @@ struct thread *cores_add_core(struct proc *p)
|
|||
*/
|
||||
int cores_pin_thread(pid_t tid, int core)
|
||||
{
|
||||
cpu_set_t cpuset;
|
||||
cpuset_t cpuset;
|
||||
int ret;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(core, &cpuset);
|
||||
|
||||
ret = sched_setaffinity(tid, sizeof(cpu_set_t), &cpuset);
|
||||
ret = pthread_setaffinity_np(tid, sizeof(cpuset_t), &cpuset);
|
||||
if (ret < 0) {
|
||||
log_warn("cores: failed to set affinity for thread %d with err %d",
|
||||
tid, errno);
|
||||
|
|
|
@ -134,8 +134,8 @@ static int ioqueues_shm_setup(unsigned int threads)
|
|||
return ret;
|
||||
}
|
||||
|
||||
BUILD_ASSERT(sizeof(netcfg.mac) >= sizeof(mem_key_t));
|
||||
iok.key = *(mem_key_t*)(&netcfg.mac);
|
||||
BUILD_ASSERT(sizeof(netcfg.mac) >= sizeof(unsigned int));
|
||||
iok.key = *(unsigned int*)(&netcfg.mac);
|
||||
iok.key = rand_crc32c(iok.key);
|
||||
|
||||
/* map shared memory for control header, command queues, and egress pkts */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/eventfd.h>
|
||||
//#include <sys/eventfd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <base/atomic.h>
|
||||
|
|
Loading…
Reference in New Issue