support mutli ff_so_zones.

This commit is contained in:
fengbojiang 2023-04-27 18:34:44 +08:00
parent 3240dd0dad
commit 8ae79cd438
3 changed files with 26 additions and 9 deletions

View File

@ -1881,8 +1881,9 @@ ff_hook_fork(void)
ERR_LOG("ff_hook_fork\n");
#ifdef FF_MULTI_SC
/* Let the child process inherit the specified sc */
/* Let the child process inherit the specified sc and ff_so_zone*/
sc = scs[current_worker_id].sc;
ff_so_zone = ff_so_zones[current_worker_id];
#endif
if (sc) {
@ -1895,16 +1896,16 @@ ff_hook_fork(void)
/* Parent process set refcount. */
if (pid > 0) {
sc->refcount++;
ERR_LOG("parent process, chilid pid:%d, sc:%p, sc->refcount:%d\n",
pid, sc, sc->refcount);
ERR_LOG("parent process, chilid pid:%d, sc:%p, sc->refcount:%d, ff_so_zone:%p\n",
pid, sc, sc->refcount, ff_so_zone);
#ifdef FF_MULTI_SC
current_worker_id++;
ERR_LOG("parent process, current_worker_id++:%d\n", current_worker_id);
#endif
}
else if (pid == 0) {
ERR_LOG("chilid process, sc:%p, sc->refcount:%d\n",
sc, sc->refcount);
ERR_LOG("chilid process, sc:%p, sc->refcount:%d, ff_so_zone:%p\n",
sc, sc->refcount, ff_so_zone);
#ifdef FF_MULTI_SC
ERR_LOG("chilid process, current_worker_id:%d\n", current_worker_id);
#endif
@ -2217,6 +2218,7 @@ ff_adapter_exit()
int i;
for (i = 0; i < worker_id; i ++) {
ERR_LOG("pthread self tid:%lu, detach sc:%p\n", pthread_self(), scs[i].sc);
ff_so_zone = ff_so_zones[i];
ff_detach_so_context(scs[i].sc);
}
} else

View File

@ -14,6 +14,9 @@
static uint16_t ff_max_so_context = SOCKET_OPS_CONTEXT_MAX_NUM;
__FF_THREAD struct ff_socket_ops_zone *ff_so_zone;
#ifdef FF_MULTI_SC
struct ff_socket_ops_zone *ff_so_zones[SOCKET_OPS_CONTEXT_MAX_NUM] = {NULL};
#endif
static inline int
is_power_of_2(uint64_t n)
@ -124,18 +127,22 @@ ff_create_so_memzone()
}
struct ff_so_context *
ff_attach_so_context(int proc_id)
ff_attach_so_context(int idx)
{
struct ff_so_context *sc = NULL;
uint16_t i;
DEBUG_LOG("proc_id:%d, ff_so_zone:%p\n", proc_id, ff_so_zone);
#ifdef FF_MULTI_SC
ff_so_zone = ff_so_zones[idx];
#endif
DEBUG_LOG("proc_id:%d, ff_so_zone:%p\n", idx, ff_so_zone);
if (ff_so_zone == NULL) {
const struct rte_memzone *mz;
char zn[64];
snprintf(zn, sizeof(zn), SOCKET_OPS_ZONE_NAME, proc_id);
snprintf(zn, sizeof(zn), SOCKET_OPS_ZONE_NAME, idx);
ERR_LOG("To lookup memzone:%s\n", zn);
mz = rte_memzone_lookup(zn);
@ -145,6 +152,11 @@ ff_attach_so_context(int proc_id)
}
ff_so_zone = mz->addr;
#ifdef FF_MULTI_SC
ff_so_zones[idx] = ff_so_zone;
ERR_LOG("FF_MULTI_SC f_so_zones[%d]:%p\n", idx, ff_so_zones[idx]);
#endif
}
rte_spinlock_lock(&ff_so_zone->lock);
@ -172,7 +184,7 @@ ff_attach_so_context(int proc_id)
if (unlikely(i == ff_so_zone->count)) {
ERR_LOG("Attach memzone failed: instance %d no free context,"
" fetel error of so status, all sc inuse, count:%d, free:%d\n",
proc_id, ff_so_zone->count, ff_so_zone->free);
idx, ff_so_zone->count, ff_so_zone->free);
sc = NULL;
}

View File

@ -113,6 +113,9 @@ struct ff_so_context {
} __attribute__((aligned(RTE_CACHE_LINE_SIZE)));
extern __FF_THREAD struct ff_socket_ops_zone *ff_so_zone;
#ifdef FF_MULTI_SC
extern struct ff_socket_ops_zone *ff_so_zones[SOCKET_OPS_CONTEXT_MAX_NUM];
#endif
/* For primary process */
int ff_set_max_so_context(uint16_t count);