All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3] lib/sort: Move swap, cmp and cmp_r function types for wider use
@ 2019-10-07 13:56 Andy Shevchenko
  2019-10-07 13:56 ` [PATCH v1 2/3] lib/bsearch: Use generic type for comparator function Andy Shevchenko
  2019-10-07 13:56 ` [PATCH v1 3/3] tracing: " Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2019-10-07 13:56 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, Steven Rostedt, George Spelvin
  Cc: Andy Shevchenko

The function types for swap, cmp and cmp_r functions are already
being in use by modules.

Move them to types.h that everybody in kernel will be able to use
generic types instead of custom ones.

This adds more sense to the comment in bsearch() later on.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/sort.h  |  8 ++++----
 include/linux/types.h |  5 +++++
 lib/sort.c            | 15 +++++----------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/linux/sort.h b/include/linux/sort.h
index 61b96d0ebc44..b5898725fe9d 100644
--- a/include/linux/sort.h
+++ b/include/linux/sort.h
@@ -5,12 +5,12 @@
 #include <linux/types.h>
 
 void sort_r(void *base, size_t num, size_t size,
-	    int (*cmp)(const void *, const void *, const void *),
-	    void (*swap)(void *, void *, int),
+	    cmp_r_func_t cmp_func,
+	    swap_func_t swap_func,
 	    const void *priv);
 
 void sort(void *base, size_t num, size_t size,
-	  int (*cmp)(const void *, const void *),
-	  void (*swap)(void *, void *, int));
+	  cmp_func_t cmp_func,
+	  swap_func_t swap_func);
 
 #endif
diff --git a/include/linux/types.h b/include/linux/types.h
index 05030f608be3..85c0e7b18153 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -225,5 +225,10 @@ struct callback_head {
 typedef void (*rcu_callback_t)(struct rcu_head *head);
 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
 
+typedef void (*swap_func_t)(void *a, void *b, int size);
+
+typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv);
+typedef int (*cmp_func_t)(const void *a, const void *b);
+
 #endif /*  __ASSEMBLY__ */
 #endif /* _LINUX_TYPES_H */
diff --git a/lib/sort.c b/lib/sort.c
index d54cf97e9548..3ad454411997 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -117,8 +117,6 @@ static void swap_bytes(void *a, void *b, size_t n)
 	} while (n);
 }
 
-typedef void (*swap_func_t)(void *a, void *b, int size);
-
 /*
  * The values are arbitrary as long as they can't be confused with
  * a pointer, but small integers make for the smallest compare
@@ -144,12 +142,9 @@ static void do_swap(void *a, void *b, size_t size, swap_func_t swap_func)
 		swap_func(a, b, (int)size);
 }
 
-typedef int (*cmp_func_t)(const void *, const void *);
-typedef int (*cmp_r_func_t)(const void *, const void *, const void *);
 #define _CMP_WRAPPER ((cmp_r_func_t)0L)
 
-static int do_cmp(const void *a, const void *b,
-		  cmp_r_func_t cmp, const void *priv)
+static int do_cmp(const void *a, const void *b, cmp_r_func_t cmp, const void *priv)
 {
 	if (cmp == _CMP_WRAPPER)
 		return ((cmp_func_t)(priv))(a, b);
@@ -202,8 +197,8 @@ static size_t parent(size_t i, unsigned int lsbit, size_t size)
  * it less suitable for kernel use.
  */
 void sort_r(void *base, size_t num, size_t size,
-	    int (*cmp_func)(const void *, const void *, const void *),
-	    void (*swap_func)(void *, void *, int size),
+	    cmp_r_func_t cmp_func,
+	    swap_func_t swap_func,
 	    const void *priv)
 {
 	/* pre-scale counters for performance */
@@ -269,8 +264,8 @@ void sort_r(void *base, size_t num, size_t size,
 EXPORT_SYMBOL(sort_r);
 
 void sort(void *base, size_t num, size_t size,
-	  int (*cmp_func)(const void *, const void *),
-	  void (*swap_func)(void *, void *, int size))
+	  cmp_func_t cmp_func,
+	  swap_func_t swap_func)
 {
 	return sort_r(base, num, size, _CMP_WRAPPER, swap_func, cmp_func);
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/3] lib/bsearch: Use generic type for comparator function
  2019-10-07 13:56 [PATCH v1 1/3] lib/sort: Move swap, cmp and cmp_r function types for wider use Andy Shevchenko
@ 2019-10-07 13:56 ` Andy Shevchenko
  2019-10-07 13:56 ` [PATCH v1 3/3] tracing: " Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2019-10-07 13:56 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, Steven Rostedt, George Spelvin
  Cc: Andy Shevchenko

Comparator function type, cmp_func_t, is defined in the types.h,
use it in bsearch() and, thus, add more sense to the corresponding
comment in the code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/bsearch.h | 2 +-
 lib/bsearch.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/bsearch.h b/include/linux/bsearch.h
index 62b1eb348858..8ed53d7524ea 100644
--- a/include/linux/bsearch.h
+++ b/include/linux/bsearch.h
@@ -5,6 +5,6 @@
 #include <linux/types.h>
 
 void *bsearch(const void *key, const void *base, size_t num, size_t size,
-	      int (*cmp)(const void *key, const void *elt));
+	      cmp_func_t cmp);
 
 #endif /* _LINUX_BSEARCH_H */
diff --git a/lib/bsearch.c b/lib/bsearch.c
index 8baa83968162..8b3aae5ae77a 100644
--- a/lib/bsearch.c
+++ b/lib/bsearch.c
@@ -29,7 +29,7 @@
  * the same comparison function for both sort() and bsearch().
  */
 void *bsearch(const void *key, const void *base, size_t num, size_t size,
-	      int (*cmp)(const void *key, const void *elt))
+	      cmp_func_t cmp)
 {
 	const char *pivot;
 	int result;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 3/3] tracing: Use generic type for comparator function
  2019-10-07 13:56 [PATCH v1 1/3] lib/sort: Move swap, cmp and cmp_r function types for wider use Andy Shevchenko
  2019-10-07 13:56 ` [PATCH v1 2/3] lib/bsearch: Use generic type for comparator function Andy Shevchenko
@ 2019-10-07 13:56 ` Andy Shevchenko
  2019-10-18 20:04   ` Steven Rostedt
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2019-10-07 13:56 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, Steven Rostedt, George Spelvin
  Cc: Andy Shevchenko

Comparator function type, cmp_func_t, is defined in the types.h,
use it in the code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/trace/ftrace.c       | 12 ++++++------
 kernel/trace/trace_branch.c |  8 ++++----
 kernel/trace/trace_stat.c   |  6 ++----
 kernel/trace/trace_stat.h   |  2 +-
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 62a50bf399d6..3bf9e805c46c 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -462,10 +462,10 @@ static void *function_stat_start(struct tracer_stat *trace)
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /* function graph compares on total time */
-static int function_stat_cmp(void *p1, void *p2)
+static int function_stat_cmp(const void *p1, const void *p2)
 {
-	struct ftrace_profile *a = p1;
-	struct ftrace_profile *b = p2;
+	const struct ftrace_profile *a = p1;
+	const struct ftrace_profile *b = p2;
 
 	if (a->time < b->time)
 		return -1;
@@ -476,10 +476,10 @@ static int function_stat_cmp(void *p1, void *p2)
 }
 #else
 /* not function graph compares against hits */
-static int function_stat_cmp(void *p1, void *p2)
+static int function_stat_cmp(const void *p1, const void *p2)
 {
-	struct ftrace_profile *a = p1;
-	struct ftrace_profile *b = p2;
+	const struct ftrace_profile *a = p1;
+	const struct ftrace_profile *b = p2;
 
 	if (a->counter < b->counter)
 		return -1;
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index 3ea65cdff30d..88e158d27965 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -244,7 +244,7 @@ static int annotated_branch_stat_headers(struct seq_file *m)
 	return 0;
 }
 
-static inline long get_incorrect_percent(struct ftrace_branch_data *p)
+static inline long get_incorrect_percent(const struct ftrace_branch_data *p)
 {
 	long percent;
 
@@ -332,10 +332,10 @@ annotated_branch_stat_next(void *v, int idx)
 	return p;
 }
 
-static int annotated_branch_stat_cmp(void *p1, void *p2)
+static int annotated_branch_stat_cmp(const void *p1, const void *p2)
 {
-	struct ftrace_branch_data *a = p1;
-	struct ftrace_branch_data *b = p2;
+	const struct ftrace_branch_data *a = p1;
+	const struct ftrace_branch_data *b = p2;
 
 	long percent_a, percent_b;
 
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
index 75bf1bcb4a8a..dd9960a2dd0c 100644
--- a/kernel/trace/trace_stat.c
+++ b/kernel/trace/trace_stat.c
@@ -72,9 +72,7 @@ static void destroy_session(struct stat_session *session)
 	kfree(session);
 }
 
-typedef int (*cmp_stat_t)(void *, void *);
-
-static int insert_stat(struct rb_root *root, void *stat, cmp_stat_t cmp)
+static int insert_stat(struct rb_root *root, void *stat, cmp_func_t cmp)
 {
 	struct rb_node **new = &(root->rb_node), *parent = NULL;
 	struct stat_node *data;
@@ -112,7 +110,7 @@ static int insert_stat(struct rb_root *root, void *stat, cmp_stat_t cmp)
  * This one will force an insertion as right-most node
  * in the rbtree.
  */
-static int dummy_cmp(void *p1, void *p2)
+static int dummy_cmp(const void *p1, const void *p2)
 {
 	return -1;
 }
diff --git a/kernel/trace/trace_stat.h b/kernel/trace/trace_stat.h
index 8786d17caf49..31d7dc5bf1db 100644
--- a/kernel/trace/trace_stat.h
+++ b/kernel/trace/trace_stat.h
@@ -16,7 +16,7 @@ struct tracer_stat {
 	void			*(*stat_start)(struct tracer_stat *trace);
 	void			*(*stat_next)(void *prev, int idx);
 	/* Compare two entries for stats sorting */
-	int			(*stat_cmp)(void *p1, void *p2);
+	cmp_func_t		stat_cmp;
 	/* Print a stat entry */
 	int			(*stat_show)(struct seq_file *s, void *p);
 	/* Release an entry */
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 3/3] tracing: Use generic type for comparator function
  2019-10-07 13:56 ` [PATCH v1 3/3] tracing: " Andy Shevchenko
@ 2019-10-18 20:04   ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2019-10-18 20:04 UTC (permalink / raw)
  To: Andy Shevchenko, Andrew Morton; +Cc: linux-kernel, George Spelvin

On Mon,  7 Oct 2019 16:56:56 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

Hi Andy,

FYI, when sending more than one patch, you should have a cover letter.

Andrew,

Do you want to take this series?

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> Comparator function type, cmp_func_t, is defined in the types.h,
> use it in the code.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  kernel/trace/ftrace.c       | 12 ++++++------
>  kernel/trace/trace_branch.c |  8 ++++----
>  kernel/trace/trace_stat.c   |  6 ++----
>  kernel/trace/trace_stat.h   |  2 +-
>  4 files changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 62a50bf399d6..3bf9e805c46c 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -462,10 +462,10 @@ static void *function_stat_start(struct tracer_stat *trace)
>  
>  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
>  /* function graph compares on total time */
> -static int function_stat_cmp(void *p1, void *p2)
> +static int function_stat_cmp(const void *p1, const void *p2)
>  {
> -	struct ftrace_profile *a = p1;
> -	struct ftrace_profile *b = p2;
> +	const struct ftrace_profile *a = p1;
> +	const struct ftrace_profile *b = p2;
>  
>  	if (a->time < b->time)
>  		return -1;
> @@ -476,10 +476,10 @@ static int function_stat_cmp(void *p1, void *p2)
>  }
>  #else
>  /* not function graph compares against hits */
> -static int function_stat_cmp(void *p1, void *p2)
> +static int function_stat_cmp(const void *p1, const void *p2)
>  {
> -	struct ftrace_profile *a = p1;
> -	struct ftrace_profile *b = p2;
> +	const struct ftrace_profile *a = p1;
> +	const struct ftrace_profile *b = p2;
>  
>  	if (a->counter < b->counter)
>  		return -1;
> diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
> index 3ea65cdff30d..88e158d27965 100644
> --- a/kernel/trace/trace_branch.c
> +++ b/kernel/trace/trace_branch.c
> @@ -244,7 +244,7 @@ static int annotated_branch_stat_headers(struct seq_file *m)
>  	return 0;
>  }
>  
> -static inline long get_incorrect_percent(struct ftrace_branch_data *p)
> +static inline long get_incorrect_percent(const struct ftrace_branch_data *p)
>  {
>  	long percent;
>  
> @@ -332,10 +332,10 @@ annotated_branch_stat_next(void *v, int idx)
>  	return p;
>  }
>  
> -static int annotated_branch_stat_cmp(void *p1, void *p2)
> +static int annotated_branch_stat_cmp(const void *p1, const void *p2)
>  {
> -	struct ftrace_branch_data *a = p1;
> -	struct ftrace_branch_data *b = p2;
> +	const struct ftrace_branch_data *a = p1;
> +	const struct ftrace_branch_data *b = p2;
>  
>  	long percent_a, percent_b;
>  
> diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
> index 75bf1bcb4a8a..dd9960a2dd0c 100644
> --- a/kernel/trace/trace_stat.c
> +++ b/kernel/trace/trace_stat.c
> @@ -72,9 +72,7 @@ static void destroy_session(struct stat_session *session)
>  	kfree(session);
>  }
>  
> -typedef int (*cmp_stat_t)(void *, void *);
> -
> -static int insert_stat(struct rb_root *root, void *stat, cmp_stat_t cmp)
> +static int insert_stat(struct rb_root *root, void *stat, cmp_func_t cmp)
>  {
>  	struct rb_node **new = &(root->rb_node), *parent = NULL;
>  	struct stat_node *data;
> @@ -112,7 +110,7 @@ static int insert_stat(struct rb_root *root, void *stat, cmp_stat_t cmp)
>   * This one will force an insertion as right-most node
>   * in the rbtree.
>   */
> -static int dummy_cmp(void *p1, void *p2)
> +static int dummy_cmp(const void *p1, const void *p2)
>  {
>  	return -1;
>  }
> diff --git a/kernel/trace/trace_stat.h b/kernel/trace/trace_stat.h
> index 8786d17caf49..31d7dc5bf1db 100644
> --- a/kernel/trace/trace_stat.h
> +++ b/kernel/trace/trace_stat.h
> @@ -16,7 +16,7 @@ struct tracer_stat {
>  	void			*(*stat_start)(struct tracer_stat *trace);
>  	void			*(*stat_next)(void *prev, int idx);
>  	/* Compare two entries for stats sorting */
> -	int			(*stat_cmp)(void *p1, void *p2);
> +	cmp_func_t		stat_cmp;
>  	/* Print a stat entry */
>  	int			(*stat_show)(struct seq_file *s, void *p);
>  	/* Release an entry */


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-18 20:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-07 13:56 [PATCH v1 1/3] lib/sort: Move swap, cmp and cmp_r function types for wider use Andy Shevchenko
2019-10-07 13:56 ` [PATCH v1 2/3] lib/bsearch: Use generic type for comparator function Andy Shevchenko
2019-10-07 13:56 ` [PATCH v1 3/3] tracing: " Andy Shevchenko
2019-10-18 20:04   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.