mirror of https://github.com/F-Stack/f-stack.git
Add refcoount in sc for fork and detach.
This commit is contained in:
parent
dd7dc378ef
commit
ac0321e70e
|
@ -1452,8 +1452,28 @@ ff_hook_epoll_wait(int epfd, struct epoll_event *events,
|
|||
pid_t
|
||||
ff_hook_fork(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
DEBUG_LOG("ff_hook_fork\n");
|
||||
return ff_linux_fork();
|
||||
if (sc) {
|
||||
rte_spinlock_lock(&sc->lock);
|
||||
}
|
||||
|
||||
pid = ff_linux_fork();
|
||||
|
||||
if (sc) {
|
||||
/* Parent process set refcount. */
|
||||
if (pid > 0) {
|
||||
sc->refcount++;
|
||||
}
|
||||
|
||||
/* Parent process unlock sc, fork success of failed. */
|
||||
if (pid != 0) {
|
||||
rte_spinlock_unlock(&sc->lock);
|
||||
}
|
||||
}
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -91,6 +91,7 @@ ff_create_so_memzone()
|
|||
rte_spinlock_init(&sc->lock);
|
||||
sc->status = FF_SC_IDLE;
|
||||
sc->idx = i;
|
||||
sc->refcount = 0;
|
||||
//so_zone_tmp->inuse[i] = 0;
|
||||
|
||||
if (sem_init(&sc->wait_sem, 1, 0) == -1) {
|
||||
|
@ -161,6 +162,7 @@ ff_attach_so_context(int proc_id)
|
|||
ff_so_zone->inuse[idx] = 1;
|
||||
rte_spinlock_init(&sc->lock);
|
||||
sc->status = FF_SC_IDLE;
|
||||
sc->refcount = 1;
|
||||
ff_so_zone->free--;
|
||||
ff_so_zone->idx = idx + 1;
|
||||
break;
|
||||
|
@ -191,20 +193,30 @@ ff_detach_so_context(struct ff_so_context *sc)
|
|||
return;
|
||||
}
|
||||
|
||||
ERR_LOG("detach sc:%p, ops:%d, status:%d, idx:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
ERR_LOG("detach sc:%p, ops:%d, status:%d, idx:%d, sc->refcount:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, sc->refcount, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
|
||||
rte_spinlock_lock(&ff_so_zone->lock);
|
||||
rte_spinlock_lock(&sc->lock);
|
||||
|
||||
if (ff_so_zone->inuse[sc->idx] == 1) {
|
||||
ff_so_zone->inuse[sc->idx] = 0;
|
||||
if (sc->refcount > 1) {
|
||||
ERR_LOG("sc refcount > 1, to sub it, sc:%p, ops:%d, status:%d, idx:%d, sc->refcount:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, sc->refcount, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
sc->refcount--;
|
||||
} else {
|
||||
ERR_LOG("sc refcount is 1, to detach it, sc:%p, ops:%d, status:%d, idx:%d, sc->refcount:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, sc->refcount, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
if (ff_so_zone->inuse[sc->idx] == 1) {
|
||||
ff_so_zone->inuse[sc->idx] = 0;
|
||||
|
||||
ff_so_zone->free++;
|
||||
ff_so_zone->idx = sc->idx;
|
||||
ff_so_zone->free++;
|
||||
ff_so_zone->idx = sc->idx;
|
||||
}
|
||||
}
|
||||
|
||||
ERR_LOG("detach sc:%p, ops:%d, status:%d, idx:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
ERR_LOG("detach sc:%p, ops:%d, status:%d, idx:%d, sc->refcount:%d, inuse:%d, so free:%u, idx:%u\n",
|
||||
sc, sc->ops, sc->status, sc->idx, sc->refcount, ff_so_zone->inuse[sc->idx], ff_so_zone->free, ff_so_zone->idx);
|
||||
|
||||
rte_spinlock_unlock(&sc->lock);
|
||||
rte_spinlock_unlock(&ff_so_zone->lock);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ struct ff_socket_ops_zone {
|
|||
} __attribute__((aligned(RTE_CACHE_LINE_SIZE)));
|
||||
|
||||
struct ff_so_context {
|
||||
/* CACHE LINE 0 */
|
||||
enum FF_SOCKET_OPS ops;
|
||||
enum FF_SO_CONTEXT_STATUS status;
|
||||
void *args;
|
||||
|
@ -105,7 +106,9 @@ struct ff_so_context {
|
|||
|
||||
sem_t wait_sem; /* 32 bytes */
|
||||
|
||||
// listen fd, refcount..
|
||||
/* CACHE LINE 1 */
|
||||
/* listen fd, refcount.. */
|
||||
int refcount;
|
||||
} __attribute__((aligned(RTE_CACHE_LINE_SIZE)));
|
||||
|
||||
extern __FF_THREAD struct ff_socket_ops_zone *ff_so_zone;
|
||||
|
|
Loading…
Reference in New Issue