From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>
Subject: [rfc, PATCH v1 1/1] min_heap: Make use of cmp_func_t and swap_func_t types
Date: Thu, 17 Aug 2023 20:06:56 +0300 [thread overview]
Message-ID: <20230817170656.731066-1-andriy.shevchenko@linux.intel.com> (raw)
The types.h defines standard types for comparator and swap functions.
Convert min_heap to use it.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/min_heap.h | 8 ++++----
kernel/events/core.c | 4 ++--
lib/test_min_heap.c | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h
index 44077837385f..14da37caa235 100644
--- a/include/linux/min_heap.h
+++ b/include/linux/min_heap.h
@@ -26,8 +26,8 @@ struct min_heap {
*/
struct min_heap_callbacks {
int elem_size;
- bool (*less)(const void *lhs, const void *rhs);
- void (*swp)(void *lhs, void *rhs);
+ cmp_func_t less;
+ swap_func_t swp;
};
/* Sift the element at pos down the heap. */
@@ -55,7 +55,7 @@ void min_heapify(struct min_heap *heap, int pos,
}
if (smallest == parent)
break;
- func->swp(smallest, parent);
+ func->swp(smallest, parent, func->elem_size);
if (smallest == left)
pos = (pos * 2) + 1;
else
@@ -127,7 +127,7 @@ void min_heap_push(struct min_heap *heap, const void *element,
parent = data + ((pos - 1) / 2) * func->elem_size;
if (func->less(parent, child))
break;
- func->swp(parent, child);
+ func->swp(parent, child, func->elem_size);
}
}
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c72a41f11af..fa344b916290 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3639,7 +3639,7 @@ void __perf_event_task_sched_out(struct task_struct *task,
perf_cgroup_switch(next);
}
-static bool perf_less_group_idx(const void *l, const void *r)
+static int perf_less_group_idx(const void *l, const void *r)
{
const struct perf_event *le = *(const struct perf_event **)l;
const struct perf_event *re = *(const struct perf_event **)r;
@@ -3647,7 +3647,7 @@ static bool perf_less_group_idx(const void *l, const void *r)
return le->group_index < re->group_index;
}
-static void swap_ptr(void *l, void *r)
+static void swap_ptr(void *l, void *r, int size)
{
void **lp = l, **rp = r;
diff --git a/lib/test_min_heap.c b/lib/test_min_heap.c
index 7b01b4387cfb..63d0b2f6c060 100644
--- a/lib/test_min_heap.c
+++ b/lib/test_min_heap.c
@@ -11,17 +11,17 @@
#include <linux/printk.h>
#include <linux/random.h>
-static __init bool less_than(const void *lhs, const void *rhs)
+static __init int less_than(const void *lhs, const void *rhs)
{
return *(int *)lhs < *(int *)rhs;
}
-static __init bool greater_than(const void *lhs, const void *rhs)
+static __init int greater_than(const void *lhs, const void *rhs)
{
return *(int *)lhs > *(int *)rhs;
}
-static __init void swap_ints(void *lhs, void *rhs)
+static __init void swap_ints(void *lhs, void *rhs, int size)
{
int temp = *(int *)lhs;
--
2.40.0.1.gaa8946217a0b
next reply other threads:[~2023-08-17 17:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 17:06 Andy Shevchenko [this message]
2023-08-17 17:51 ` Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230817170656.731066-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®