Kernelschedc

list_for_each_safe(curr, next, &q->task_list, task_list) { unsigned flags = curr->flags;

if (curr->func(curr, mode, sync, key) &&

(flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)

break;

The list is scanned repeatedly until there are either no further tasks or until the number of exclusive tasks specified by nr_exclusive has been woken up. This restriction is used to avoid a problem known as the thundering herd. If several processes are waiting for exclusive access to a resource, it makes no sense to wake all waiting processes because all but one will have to be put back to sleep. nr_exclusive generalizes this restriction.

The most frequently used wake_up function sets nr_exclusive to 1 and thus makes sure that only one exclusive task is woken up.

Recall from above that wq_flag_exclusive tasks are added to the end of the wait queue. This implementation ensures that in mixed queues all normal tasks are woken up first, and only then is the restriction for exclusive tasks taken into consideration.

It is useful to wake all processes in a wait queue if the processes are waiting for a data transfer to terminate. This is because the data of several processes can be read at the same time without mutual interference.

Continue reading here: Completions

Was this article helpful?

0 0