Skip to content

Commit 641d51f

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 22608e4 commit 641d51f

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
@@ -371,9 +371,9 @@ static pid_t
371371
ff_sys_fork(struct ff_fork_args *args)
372372
{
373373
void *parent = args->parent_thread_handle;
374-
/*
375-
* Linux has performed a real fork, and at this point,
376-
* we simply need to create a new thread and duplicate the file descriptors
374+
/*
375+
* Linux has performed a real fork, and at this point,
376+
* we simply need to create a new thread and duplicate the file descriptors
377377
* that the parent process has already opened.
378378
*/
379379
if (parent) {
@@ -590,7 +590,7 @@ ff_handle_each_context()
590590

591591
while(1) {
592592
nb_handled = tmp;
593-
if (nb_handled) {
593+
if (likely(nb_handled)) {
594594
for (i = 0; i < ff_so_zone->count; i++) {
595595
struct ff_so_context *sc = &ff_so_zone->sc[i];
596596

@@ -625,7 +625,15 @@ ff_handle_each_context()
625625
break;
626626
}
627627

628-
rte_pause();
628+
/*
629+
* When there are no requests, add a lock window to prevent applications such as Nginx from being starved
630+
* to death when they attempt to initialize and acquire a lock when idle_sleep is set to 0
631+
*/
632+
if (unlikely(!tmp)) {
633+
rte_spinlock_unlock(&ff_so_zone->lock);
634+
rte_pause();
635+
rte_spinlock_lock(&ff_so_zone->lock);
636+
}
629637
}
630638

631639
rte_spinlock_unlock(&ff_so_zone->lock);

0 commit comments

Comments
 (0)