mirror of https://github.com/F-Stack/f-stack.git
Fixed some issue in multi instances.
This commit is contained in:
parent
edcac626c5
commit
0efc8b3374
|
@ -95,17 +95,6 @@
|
|||
return ret; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Per thread separate initialization dpdk lib and attach sc when needed,
|
||||
* such as listen same port in different threads, and socket can use in own thread.
|
||||
*
|
||||
* Otherwise, one socket can use in all threads.
|
||||
*/
|
||||
#ifdef FF_THREAD_SOCKET
|
||||
#define __FF_THREAD __thread
|
||||
#else
|
||||
#define __FF_THREAD
|
||||
#endif
|
||||
static __FF_THREAD int inited = 0;
|
||||
static __FF_THREAD struct ff_so_context *sc;
|
||||
|
||||
|
@ -1428,6 +1417,7 @@ ff_adapter_init()
|
|||
}
|
||||
|
||||
if (proc_inited == 0) {
|
||||
/* May conflict */
|
||||
rte_spinlock_init(&worker_id_lock);
|
||||
rte_spinlock_lock(&worker_id_lock);
|
||||
|
||||
|
@ -1453,14 +1443,11 @@ ff_adapter_init()
|
|||
*/
|
||||
char *ff_init_lcore_id = getenv(FF_INITIAL_LCORE_ID_STR);
|
||||
if (ff_init_lcore_id != NULL) {
|
||||
char *pos = strchr(ff_init_lcore_id, '=');
|
||||
if (pos != NULL) {
|
||||
initial_lcore_id = (uint64_t)strtoull(pos, NULL, 16);
|
||||
if (initial_lcore_id > ((uint64_t)INITIAL_LCORE_ID_MAX) /*== UINT64_MAX*/) {
|
||||
initial_lcore_id = INITIAL_LCORE_ID_DEFAULT;
|
||||
ERR_LOG("get invalid FF_INITIAL_LCORE_ID=%s, to use default value 0x%0lx\n",
|
||||
ff_init_lcore_id, initial_lcore_id);
|
||||
}
|
||||
initial_lcore_id = (uint64_t)strtoull(ff_init_lcore_id, NULL, 16);
|
||||
if (initial_lcore_id > ((uint64_t)INITIAL_LCORE_ID_MAX) /*== UINT64_MAX*/) {
|
||||
initial_lcore_id = INITIAL_LCORE_ID_DEFAULT;
|
||||
ERR_LOG("get invalid FF_INITIAL_LCORE_ID=%s, to use default value 0x%0lx\n",
|
||||
ff_init_lcore_id, initial_lcore_id);
|
||||
}
|
||||
ERR_LOG("get FF_INITIAL_LCORE_ID=%s, use 0x%0lx\n",
|
||||
ff_init_lcore_id, initial_lcore_id);
|
||||
|
@ -1470,20 +1457,16 @@ ff_adapter_init()
|
|||
initial_lcore_id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get environment variable FF_NB_FSTACK_INSTANCE to set nb_procs.
|
||||
*/
|
||||
char *ff_nb_procs = getenv(FF_NB_FSTACK_INSTANCE_STR);
|
||||
if (ff_nb_procs != NULL) {
|
||||
char *pos = strchr(ff_nb_procs, '=');
|
||||
if (pos != NULL) {
|
||||
nb_procs = (uint32_t)strtoul(pos, NULL, 10);
|
||||
if (nb_procs == -1 /*UINT32_MAX*/) {
|
||||
nb_procs = NB_FSTACK_INSTANCE_DEFAULT;
|
||||
ERR_LOG("get invalid FF_NB_FSTACK_INSTANCE=%s, to use default value %d\n",
|
||||
ff_nb_procs, nb_procs);
|
||||
}
|
||||
nb_procs = (uint32_t)strtoul(ff_nb_procs, NULL, 10);
|
||||
if (nb_procs == -1 /*UINT32_MAX*/) {
|
||||
nb_procs = NB_FSTACK_INSTANCE_DEFAULT;
|
||||
ERR_LOG("get invalid FF_NB_FSTACK_INSTANCE=%s, to use default value %d\n",
|
||||
ff_nb_procs, nb_procs);
|
||||
}
|
||||
ERR_LOG("get FF_NB_FSTACK_INSTANCE=%s, use %d\n",
|
||||
ff_nb_procs, nb_procs);
|
||||
|
@ -1493,6 +1476,30 @@ ff_adapter_init()
|
|||
nb_procs);
|
||||
}
|
||||
|
||||
char buf[RTE_MAX_LCORE] = {0};
|
||||
sprintf(buf, "-c%lx", initial_lcore_id/* << worker_id*/);
|
||||
|
||||
char *dpdk_argv[] = {
|
||||
"ff-adapter", buf, "-n4",
|
||||
"--proc-type=secondary",
|
||||
/* RTE_LOG_WARNING */
|
||||
"--log-level=5",
|
||||
};
|
||||
|
||||
printf("\n");
|
||||
DEBUG_LOG("rte_eal_init, argc:%ld/%ld=%ld\n", sizeof(dpdk_argv), sizeof(dpdk_argv[0]), sizeof(dpdk_argv)/sizeof(dpdk_argv[0]));
|
||||
for (int i=0; i < sizeof(dpdk_argv)/sizeof(dpdk_argv[0]); i++) {
|
||||
printf("%s ", dpdk_argv[i]);
|
||||
}
|
||||
printf("\n");
|
||||
ret = rte_eal_init(sizeof(dpdk_argv)/sizeof(dpdk_argv[0]),
|
||||
dpdk_argv);
|
||||
DEBUG_LOG("rte_eal_init ret:%d\n", ret);
|
||||
if (ret < 0) {
|
||||
ERR_LOG("ff_adapter_init failed with EAL initialization\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (proc_inited == 0) {
|
||||
proc_inited = 1;
|
||||
}
|
||||
|
@ -1500,30 +1507,7 @@ ff_adapter_init()
|
|||
rte_spinlock_lock(&worker_id_lock);
|
||||
}
|
||||
|
||||
char buf[RTE_MAX_LCORE] = {0};
|
||||
sprintf(buf, "-c%lx", initial_lcore_id << worker_id);
|
||||
|
||||
char *dpdk_argv[] = {
|
||||
"ff-adapter", buf, "-n4",
|
||||
"--proc-type=secondary",
|
||||
/* RTE_LOG_WARNING */
|
||||
"--log-level=5",
|
||||
};
|
||||
|
||||
printf("\n");
|
||||
DEBUG_LOG("rte_eal_init, argc:%ld/%ld=%ld\n", sizeof(dpdk_argv), sizeof(dpdk_argv[0]), sizeof(dpdk_argv)/sizeof(dpdk_argv[0]));
|
||||
for (int i=0; i < sizeof(dpdk_argv)/sizeof(dpdk_argv[0]); i++) {
|
||||
printf("%s ", dpdk_argv[i]);
|
||||
}
|
||||
printf("\n");
|
||||
ret = rte_eal_init(sizeof(dpdk_argv)/sizeof(dpdk_argv[0]),
|
||||
dpdk_argv);
|
||||
DEBUG_LOG("rte_eal_init ret:%d\n", ret);
|
||||
if (ret < 0) {
|
||||
ERR_LOG("ff_adapter_init failed with EAL initialization\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEBUG_LOG("worker_id:%d, nb_procs:%d\n", worker_id, nb_procs);
|
||||
sc = ff_attach_so_context(worker_id % nb_procs);
|
||||
if (sc == NULL) {
|
||||
ERR_LOG("ff_attach_so_context failed\n");
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define SOCKET_OPS_CONTEXT_NAME "ff_so_context_"
|
||||
|
||||
static uint16_t ff_max_so_context = SOCKET_OPS_CONTEXT_MAX_NUM;
|
||||
struct ff_socket_ops_zone *ff_so_zone;
|
||||
__FF_THREAD struct ff_socket_ops_zone *ff_so_zone;
|
||||
|
||||
static inline int
|
||||
is_power_of_2(uint64_t n)
|
||||
|
@ -125,6 +125,8 @@ ff_attach_so_context(int proc_id)
|
|||
struct ff_so_context *sc = NULL;
|
||||
uint16_t i;
|
||||
|
||||
DEBUG_LOG("proc_id:%d, ff_so_zone:%p\n", proc_id, ff_so_zone);
|
||||
|
||||
if (ff_so_zone == NULL) {
|
||||
const struct rte_memzone *mz;
|
||||
char zn[64];
|
||||
|
@ -157,7 +159,7 @@ ff_attach_so_context(int proc_id)
|
|||
rte_spinlock_init(&sc->lock);
|
||||
sc->status = FF_SC_IDLE;
|
||||
ff_so_zone->free--;
|
||||
ff_so_zone->idx = idx;
|
||||
ff_so_zone->idx = idx + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
static int ff_sys_kqueue(struct ff_kqueue_args *args);
|
||||
static int ff_sys_kevent(struct ff_kevent_args *args);
|
||||
|
||||
extern struct ff_socket_ops_zone *ff_so_zone;
|
||||
|
||||
#define FF_MAX_BOUND_NUM 8
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,18 @@
|
|||
#include <rte_atomic.h>
|
||||
#include <rte_spinlock.h>
|
||||
|
||||
/*
|
||||
* Per thread separate initialization dpdk lib and attach sc when needed,
|
||||
* such as listen same port in different threads, and socket can use in own thread.
|
||||
*
|
||||
* Otherwise, one socket can use in all threads.
|
||||
*/
|
||||
#ifdef FF_THREAD_SOCKET
|
||||
#define __FF_THREAD __thread
|
||||
#else
|
||||
#define __FF_THREAD
|
||||
#endif
|
||||
|
||||
#define ERR_LOG(fmt, ...) do { \
|
||||
printf("file:%s, line:%u, fun:%s, "fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
@ -92,7 +104,7 @@ struct ff_so_context {
|
|||
// listen fd, refcount..
|
||||
} __attribute__((packed));
|
||||
|
||||
extern struct ff_socket_ops_zone *ff_so_zone;
|
||||
extern __FF_THREAD struct ff_socket_ops_zone *ff_so_zone;
|
||||
|
||||
/* For primary process */
|
||||
int ff_set_max_so_context(uint16_t count);
|
||||
|
|
Loading…
Reference in New Issue