• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 @@ -1,5 +1,6 @@
2  // SPDX-License-Identifier: GPL-2.0
3  #include <linux/kernel.h>
4 +#include <linux/bug.h>
5  #include <linux/compiler.h>
6  #include <linux/export.h>
7  #include <linux/string.h>
8 @@ -52,6 +53,7 @@
9  			struct list_head *a, struct list_head *b)
10  {
11  	struct list_head *tail = head;
12 +	u8 count = 0;
13 
14  	for (;;) {
15  		/* if equal, take 'a' -- important for sort stability */
16 @@ -77,6 +79,15 @@
17  	/* Finish linking remainder of list b on to tail */
18  	tail->next = b;
19  	do {
20 +		/*
21 +		 * If the merge is highly unbalanced (e.g. the input is
22 +		 * already sorted), this loop may run many iterations.
23 +		 * Continue callbacks to the client even though no
24 +		 * element comparison is needed, so the client's cmp()
25 +		 * routine can invoke cond_resched() periodically.
26 +		 */
27 +		if (unlikely(!++count))
28 +			cmp(priv, b, b);
29  		b->prev = tail;
30  		tail = b;
31  		b = b->next;
32