forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/min_heap: introduce non-inline versions of min heap API functions
Patch series "Enhance min heap API with non-inline functions and optimizations", v2. Add non-inline versions of the min heap API functions in lib/min_heap.c and updates all users outside of kernel/events/core.c to use these non-inline versions. To mitigate the performance impact of indirect function calls caused by the non-inline versions of the swap and compare functions, a builtin swap has been introduced that swaps elements based on their size. Additionally, it micro-optimizes the efficiency of the min heap by pre-scaling the counter, following the same approach as in lib/sort.c. Documentation for the min heap API has also been added to the core-api section. This patch (of 10): All current min heap API functions are marked with '__always_inline'. However, as the number of users increases, inlining these functions everywhere leads to a increase in kernel size. In performance-critical paths, such as when perf events are enabled and min heap functions are called on every context switch, it is important to retain the inline versions for optimal performance. To balance this, the original inline functions are kept, and additional non-inline versions of the functions have been added in lib/min_heap.c. Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kuan-Wei Chiu <[email protected]> Suggested-by: Andrew Morton <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Ching-Chun (Jim) Huang <[email protected]> Cc: Coly Li <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Kuan-Wei Chiu <[email protected]> Cc: "Liang, Kan" <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Matthew Sakai <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
- Loading branch information
1 parent
dabddd6
commit 92a8b22
Showing
9 changed files
with
167 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -780,3 +780,6 @@ config FIRMWARE_TABLE | |
|
||
config UNION_FIND | ||
bool | ||
|
||
config MIN_HEAP | ||
bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/export.h> | ||
#include <linux/min_heap.h> | ||
|
||
void __min_heap_init(min_heap_char *heap, void *data, int size) | ||
{ | ||
__min_heap_init_inline(heap, data, size); | ||
} | ||
EXPORT_SYMBOL(__min_heap_init); | ||
|
||
void *__min_heap_peek(struct min_heap_char *heap) | ||
{ | ||
return __min_heap_peek_inline(heap); | ||
} | ||
EXPORT_SYMBOL(__min_heap_peek); | ||
|
||
bool __min_heap_full(min_heap_char *heap) | ||
{ | ||
return __min_heap_full_inline(heap); | ||
} | ||
EXPORT_SYMBOL(__min_heap_full); | ||
|
||
void __min_heap_sift_down(min_heap_char *heap, int pos, size_t elem_size, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
__min_heap_sift_down_inline(heap, pos, elem_size, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_sift_down); | ||
|
||
void __min_heap_sift_up(min_heap_char *heap, size_t elem_size, size_t idx, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
__min_heap_sift_up_inline(heap, elem_size, idx, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_sift_up); | ||
|
||
void __min_heapify_all(min_heap_char *heap, size_t elem_size, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
__min_heapify_all_inline(heap, elem_size, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heapify_all); | ||
|
||
bool __min_heap_pop(min_heap_char *heap, size_t elem_size, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
return __min_heap_pop_inline(heap, elem_size, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_pop); | ||
|
||
void __min_heap_pop_push(min_heap_char *heap, const void *element, size_t elem_size, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
__min_heap_pop_push_inline(heap, element, elem_size, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_pop_push); | ||
|
||
bool __min_heap_push(min_heap_char *heap, const void *element, size_t elem_size, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
return __min_heap_push_inline(heap, element, elem_size, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_push); | ||
|
||
bool __min_heap_del(min_heap_char *heap, size_t elem_size, size_t idx, | ||
const struct min_heap_callbacks *func, void *args) | ||
{ | ||
return __min_heap_del_inline(heap, elem_size, idx, func, args); | ||
} | ||
EXPORT_SYMBOL(__min_heap_del); |