Skip to content

Commit 8125bee

Browse files
committed
Fix an issue of LD_PRELOAD.
When there are no requests, add a lock window to prevent applications such as Nginx from being starved to death when they attempt to initialize and acquire a lock when idle_sleep is set to 0.
1 parent 5662ad1 commit 8125bee

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

adapter/syscall/ff_socket_ops.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ static pid_t
382382
ff_sys_fork(struct ff_fork_args *args)
383383
{
384384
void *parent = args->parent_thread_handle;
385-
/*
386-
* Linux has performed a real fork, and at this point,
387-
* we simply need to create a new thread and duplicate the file descriptors
385+
/*
386+
* Linux has performed a real fork, and at this point,
387+
* we simply need to create a new thread and duplicate the file descriptors
388388
* that the parent process has already opened.
389389
*/
390390
if (parent) {
@@ -706,7 +706,7 @@ ff_handle_each_context()
706706

707707
while(1) {
708708
nb_handled = tmp;
709-
if (nb_handled) {
709+
if (likely(nb_handled)) {
710710
for (i = 0; i < ff_so_zone->count; i++) {
711711
struct ff_so_context *sc = &ff_so_zone->sc[i];
712712

@@ -741,7 +741,15 @@ ff_handle_each_context()
741741
break;
742742
}
743743

744-
rte_pause();
744+
/*
745+
* When there are no requests, add a lock window to prevent applications such as Nginx from being starved
746+
* to death when they attempt to initialize and acquire a lock when idle_sleep is set to 0
747+
*/
748+
if (unlikely(!tmp)) {
749+
rte_spinlock_unlock(&ff_so_zone->lock);
750+
rte_pause();
751+
rte_spinlock_lock(&ff_so_zone->lock);
752+
}
745753
}
746754

747755
rte_spinlock_unlock(&ff_so_zone->lock);

0 commit comments

Comments
 (0)