Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/lib/list_sort: remove redundant code for cond_resched handling

Since cond_resched() is not called in userspace, remove the redundant code
in userspace's list_sort() implementation. This change eliminates the
unused 'count' variable and the associated logic for invoking cmp()
periodically, which was intended to trigger cond_resched() in kernel
space.

The removed code includes:
- Declaration and increment of the 'count' variable.
- Conditional invocation of cmp() based on 'count'.

This cleanup simplifies merge_final(), avoids unnecessary overhead, and
has no impact on the functionality of list_sort() in userspace.

Link: https://lkml.kernel.org/r/20240525230206.1077536-1-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
6d74e1e3 7abcb84f

-10
-10
tools/lib/list_sort.c
··· 52 52 struct list_head *a, struct list_head *b) 53 53 { 54 54 struct list_head *tail = head; 55 - u8 count = 0; 56 55 57 56 for (;;) { 58 57 /* if equal, take 'a' -- important for sort stability */ ··· 77 78 /* Finish linking remainder of list b on to tail */ 78 79 tail->next = b; 79 80 do { 80 - /* 81 - * If the merge is highly unbalanced (e.g. the input is 82 - * already sorted), this loop may run many iterations. 83 - * Continue callbacks to the client even though no 84 - * element comparison is needed, so the client's cmp() 85 - * routine can invoke cond_resched() periodically. 86 - */ 87 - if (unlikely(!++count)) 88 - cmp(priv, b, b); 89 81 b->prev = tail; 90 82 tail = b; 91 83 b = b->next;