tools/perf/check-header_ignore_hunks/lib/list_sort.c

Source file repositories/reference/linux-study-clean/tools/perf/check-header_ignore_hunks/lib/list_sort.c

File Facts

System
Linux kernel
Corpus path
tools/perf/check-header_ignore_hunks/lib/list_sort.c
Extension
.c
Size
681 bytes
Lines
25
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

@@ -50,6 +50,7 @@
 			struct list_head *a, struct list_head *b)
 {
 	struct list_head *tail = head;
+	u8 count = 0;
 
 	for (;;) {
 		/* if equal, take 'a' -- important for sort stability */
@@ -75,6 +76,15 @@
 	/* Finish linking remainder of list b on to tail */
 	tail->next = b;
 	do {
+		/*
+		 * If the merge is highly unbalanced (e.g. the input is
+		 * already sorted), this loop may run many iterations.
+		 * Continue callbacks to the client even though no
+		 * element comparison is needed, so the client's cmp()
+		 * routine can invoke cond_resched() periodically.
+		 */
+		if (unlikely(!++count))
+			cmp(priv, b, b);
 		b->prev = tail;
 		tail = b;
 		b = b->next;

Annotation

Implementation Notes