linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
@ 2021-10-21 12:01 Cai Huoqing
  2021-10-21 12:01 ` [PATCH 1/6] " Cai Huoqing
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

the helper macro kthread_run_on_cpu() inculdes
kthread_create_on_cpu/wake_up_process().
In some cases, use kthread_run_on_cpu() directly instead of
kthread_create_on_node/kthread_bind/wake_up_process() or
kthread_create_on_cpu/wake_up_process() or
kthreadd_create/kthread_bind/wake_up_process() to simplify the code.

Cai Huoqing (6):
  kthread: Add the helper macro kthread_run_on_cpu()
  RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
  ring-buffer: Make use of the helper macro kthread_run_on_cpu()
  rcutorture: Make use of the helper macro kthread_run_on_cpu()
  trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
  trace/hwlat: Make use of the helper macro kthread_run_on_cpu()

 drivers/infiniband/sw/siw/siw_main.c |  7 +++----
 include/linux/kthread.h              | 22 ++++++++++++++++++++++
 kernel/rcu/rcutorture.c              |  7 ++-----
 kernel/trace/ring_buffer.c           |  7 ++-----
 kernel/trace/trace_hwlat.c           |  6 +-----
 kernel/trace/trace_osnoise.c         |  3 +--
 6 files changed, 31 insertions(+), 21 deletions(-)

-- 
2.25.1


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

* [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 13:10   ` Steven Rostedt
  2021-10-21 12:01 ` [PATCH 2/6] RDMA/siw: Make use of " Cai Huoqing
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

the helper macro kthread_run_on_cpu() inculdes
kthread_create_on_cpu/wake_up_process().
In some cases, use kthread_run_on_cpu() directly instead of
kthread_create_on_node/kthread_bind/wake_up_process() or
kthread_create_on_cpu/wake_up_process() or
kthreadd_create/kthread_bind/wake_up_process() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 include/linux/kthread.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 346b0f269161..dfd125523aa9 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -56,6 +56,28 @@ bool kthread_is_per_cpu(struct task_struct *k);
 	__k;								   \
 })
 
+/**
+ * kthread_run_on_cpu - create and wake a cpu bound thread.
+ * @threadfn: the function to run until signal_pending(current).
+ * @data: data ptr for @threadfn.
+ * @cpu: The cpu on which the thread should be bound,
+ * @namefmt: printf-style name for the thread. Format is restricted
+ *	     to "name.*%u". Code fills in cpu number.
+ *
+ * Description: Convenient wrapper for kthread_create_on_node()
+ * followed by wake_up_process().  Returns the kthread or
+ * ERR_PTR(-ENOMEM).
+ */
+#define kthread_run_on_cpu(threadfn, data, cpu, namefmt)		  \
+({									  \
+	struct task_struct *__k						  \
+		= kthread_create_on_cpu(threadfn, data, cpu_to_node(cpu), \
+					namefmt);			  \
+	if (!IS_ERR(__k))						  \
+		wake_up_process(__k);					  \
+	__k;								  \
+})
+
 void free_kthread_struct(struct task_struct *k);
 void kthread_bind(struct task_struct *k, unsigned int cpu);
 void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
-- 
2.25.1


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

* [PATCH 2/6] RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
  2021-10-21 12:01 ` [PATCH 1/6] " Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 12:01 ` [PATCH 3/6] ring-buffer: " Cai Huoqing
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Repalce kthread_create/kthread_bind/wake_up_process()
with kthread_run_on_cpu() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 drivers/infiniband/sw/siw/siw_main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/siw/siw_main.c
index 9093e6a80b26..e5c586913d0b 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -98,15 +98,14 @@ static int siw_create_tx_threads(void)
 			continue;
 
 		siw_tx_thread[cpu] =
-			kthread_create(siw_run_sq, (unsigned long *)(long)cpu,
-				       "siw_tx/%d", cpu);
+			kthread_run_on_cpu(siw_run_sq,
+					   (unsigned long *)(long)cpu,
+					   cpu, "siw_tx/%u");
 		if (IS_ERR(siw_tx_thread[cpu])) {
 			siw_tx_thread[cpu] = NULL;
 			continue;
 		}
-		kthread_bind(siw_tx_thread[cpu], cpu);
 
-		wake_up_process(siw_tx_thread[cpu]);
 		assigned++;
 	}
 	return assigned;
-- 
2.25.1


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

* [PATCH 3/6] ring-buffer: Make use of the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
  2021-10-21 12:01 ` [PATCH 1/6] " Cai Huoqing
  2021-10-21 12:01 ` [PATCH 2/6] RDMA/siw: Make use of " Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 12:01 ` [PATCH 4/6] rcutorture: " Cai Huoqing
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Repalce kthread_create/kthread_bind/wake_up_process()
with kthread_run_on_cpu() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 kernel/trace/ring_buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index c5a3fbf19617..afb306e21e5b 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -5898,16 +5898,13 @@ static __init int test_ringbuffer(void)
 		rb_data[cpu].buffer = buffer;
 		rb_data[cpu].cpu = cpu;
 		rb_data[cpu].cnt = cpu;
-		rb_threads[cpu] = kthread_create(rb_test, &rb_data[cpu],
-						 "rbtester/%d", cpu);
+		rb_threads[cpu] = kthread_run_on_cpu(rb_test, &rb_data[cpu],
+						     cpu, "rbtester/%u");
 		if (WARN_ON(IS_ERR(rb_threads[cpu]))) {
 			pr_cont("FAILED\n");
 			ret = PTR_ERR(rb_threads[cpu]);
 			goto out_free;
 		}
-
-		kthread_bind(rb_threads[cpu], cpu);
- 		wake_up_process(rb_threads[cpu]);
 	}
 
 	/* Now create the rb hammer! */
-- 
2.25.1


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

* [PATCH 4/6] rcutorture: Make use of the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
                   ` (2 preceding siblings ...)
  2021-10-21 12:01 ` [PATCH 3/6] ring-buffer: " Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 12:01 ` [PATCH 5/6] trace/osnoise: " Cai Huoqing
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Repalce kthread_create_on_node//kthread_bind/wake_up_process()
with kthread_run_on_cpu() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 kernel/rcu/rcutorture.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 503e14e62e8f..6c3ba8c0d7ff 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2025,9 +2025,8 @@ static int rcutorture_booster_init(unsigned int cpu)
 	mutex_lock(&boost_mutex);
 	rcu_torture_disable_rt_throttle();
 	VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
-	boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
-						  cpu_to_node(cpu),
-						  "rcu_torture_boost");
+	boost_tasks[cpu] = kthread_run_on_cpu(rcu_torture_boost, NULL,
+					      cpu, "rcu_torture_boost_%u");
 	if (IS_ERR(boost_tasks[cpu])) {
 		retval = PTR_ERR(boost_tasks[cpu]);
 		VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
@@ -2036,8 +2035,6 @@ static int rcutorture_booster_init(unsigned int cpu)
 		mutex_unlock(&boost_mutex);
 		return retval;
 	}
-	kthread_bind(boost_tasks[cpu], cpu);
-	wake_up_process(boost_tasks[cpu]);
 	mutex_unlock(&boost_mutex);
 	return 0;
 }
-- 
2.25.1


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

* [PATCH 5/6] trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
                   ` (3 preceding siblings ...)
  2021-10-21 12:01 ` [PATCH 4/6] rcutorture: " Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 12:01 ` [PATCH 6/6] trace/hwlat: " Cai Huoqing
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Repalce kthread_create/kthread_bind/wake_up_process()
with kthread_run_on_cpu() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 kernel/trace/trace_osnoise.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index ce053619f289..cbd78fd5e491 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1525,7 +1525,7 @@ static int start_kthread(unsigned int cpu)
 #else
 	snprintf(comm, 24, "osnoise/%d", cpu);
 #endif
-	kthread = kthread_create_on_cpu(main, NULL, cpu, comm);
+	kthread = kthread_run_on_cpu(main, NULL, cpu, comm);
 
 	if (IS_ERR(kthread)) {
 		pr_err(BANNER "could not start sampling thread\n");
@@ -1534,7 +1534,6 @@ static int start_kthread(unsigned int cpu)
 	}
 
 	per_cpu(per_cpu_osnoise_var, cpu).kthread = kthread;
-	wake_up_process(kthread);
 
 	return 0;
 }
-- 
2.25.1


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

* [PATCH 6/6] trace/hwlat: Make use of the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
                   ` (4 preceding siblings ...)
  2021-10-21 12:01 ` [PATCH 5/6] trace/osnoise: " Cai Huoqing
@ 2021-10-21 12:01 ` Cai Huoqing
  2021-10-21 13:48 ` [PATCH 0/6] kthread: Add " Bernard Metzler
  2021-10-21 13:58 ` Cai,Huoqing
  7 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 12:01 UTC (permalink / raw)
  To: caihuoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Repalce kthread_create/kthread_bind/wake_up_process()
with kthread_run_on_cpu() to simplify the code.

Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
 kernel/trace/trace_hwlat.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 1b83d75eb103..0e555335f095 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -491,18 +491,14 @@ static void stop_per_cpu_kthreads(void)
 static int start_cpu_kthread(unsigned int cpu)
 {
 	struct task_struct *kthread;
-	char comm[24];
 
-	snprintf(comm, 24, "hwlatd/%d", cpu);
-
-	kthread = kthread_create_on_cpu(kthread_fn, NULL, cpu, comm);
+	kthread = kthread_run_on_cpu(kthread_fn, NULL, cpu, "hwlatd/%u");
 	if (IS_ERR(kthread)) {
 		pr_err(BANNER "could not start sampling thread\n");
 		return -ENOMEM;
 	}
 
 	per_cpu(hwlat_per_cpu_data, cpu).kthread = kthread;
-	wake_up_process(kthread);
 
 	return 0;
 }
-- 
2.25.1


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

* Re: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 ` [PATCH 1/6] " Cai Huoqing
@ 2021-10-21 13:10   ` Steven Rostedt
  2021-10-21 13:53     ` Cai Huoqing
  0 siblings, 1 reply; 15+ messages in thread
From: Steven Rostedt @ 2021-10-21 13:10 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Mathieu Desnoyers,
	Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

On Thu, 21 Oct 2021 20:01:30 +0800
Cai Huoqing <caihuoqing@baidu.com> wrote:

> the helper macro kthread_run_on_cpu() inculdes

 "includes"

> kthread_create_on_cpu/wake_up_process().
> In some cases, use kthread_run_on_cpu() directly instead of
> kthread_create_on_node/kthread_bind/wake_up_process() or
> kthread_create_on_cpu/wake_up_process() or
> kthreadd_create/kthread_bind/wake_up_process() to simplify the code.
> 
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> ---
>  include/linux/kthread.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/include/linux/kthread.h b/include/linux/kthread.h
> index 346b0f269161..dfd125523aa9 100644
> --- a/include/linux/kthread.h
> +++ b/include/linux/kthread.h
> @@ -56,6 +56,28 @@ bool kthread_is_per_cpu(struct task_struct *k);
>  	__k;								   \
>  })
>  
> +/**
> + * kthread_run_on_cpu - create and wake a cpu bound thread.
> + * @threadfn: the function to run until signal_pending(current).
> + * @data: data ptr for @threadfn.
> + * @cpu: The cpu on which the thread should be bound,
> + * @namefmt: printf-style name for the thread. Format is restricted
> + *	     to "name.*%u". Code fills in cpu number.
> + *
> + * Description: Convenient wrapper for kthread_create_on_node()
> + * followed by wake_up_process().  Returns the kthread or
> + * ERR_PTR(-ENOMEM).
> + */
> +#define kthread_run_on_cpu(threadfn, data, cpu, namefmt)		  \

Why is this a macro and not a static inline function?

-- Steve

> +({									  \
> +	struct task_struct *__k						  \
> +		= kthread_create_on_cpu(threadfn, data, cpu_to_node(cpu), \
> +					namefmt);			  \
> +	if (!IS_ERR(__k))						  \
> +		wake_up_process(__k);					  \
> +	__k;								  \
> +})
> +
>  void free_kthread_struct(struct task_struct *k);
>  void kthread_bind(struct task_struct *k, unsigned int cpu);
>  void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);


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

* Re: [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
                   ` (5 preceding siblings ...)
  2021-10-21 12:01 ` [PATCH 6/6] trace/hwlat: " Cai Huoqing
@ 2021-10-21 13:48 ` Bernard Metzler
  2021-10-21 14:07   ` Cai Huoqing
  2021-10-21 14:14   ` Bernard Metzler
  2021-10-21 13:58 ` Cai,Huoqing
  7 siblings, 2 replies; 15+ messages in thread
From: Bernard Metzler @ 2021-10-21 13:48 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: Doug Ledford, Jason Gunthorpe, Davidlohr Bueso, Paul E. McKenney,
	Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Joel Fernandes, Ingo Molnar, Daniel Bristot de Oliveira,
	linux-rdma, linux-kernel, rcu

-----"Cai Huoqing" <caihuoqing@baidu.com> wrote: -----

>To: <caihuoqing@baidu.com>
>From: "Cai Huoqing" <caihuoqing@baidu.com>
>Date: 10/21/2021 02:02PM
>Cc: "Bernard Metzler" <bmt@zurich.ibm.com>, "Doug Ledford"
><dledford@redhat.com>, "Jason Gunthorpe" <jgg@ziepe.ca>, "Davidlohr
>Bueso" <dave@stgolabs.net>, "Paul E. McKenney" <paulmck@kernel.org>,
>"Josh Triplett" <josh@joshtriplett.org>, "Steven Rostedt"
><rostedt@goodmis.org>, "Mathieu Desnoyers"
><mathieu.desnoyers@efficios.com>, "Lai Jiangshan"
><jiangshanlai@gmail.com>, "Joel Fernandes" <joel@joelfernandes.org>,
>"Ingo Molnar" <mingo@redhat.com>, "Daniel Bristot de Oliveira"
><bristot@kernel.org>, <linux-rdma@vger.kernel.org>,
><linux-kernel@vger.kernel.org>, <rcu@vger.kernel.org>
>Subject: [EXTERNAL] [PATCH 0/6] kthread: Add the helper macro
>kthread_run_on_cpu()
>
>the helper macro kthread_run_on_cpu() inculdes
>kthread_create_on_cpu/wake_up_process().
>In some cases, use kthread_run_on_cpu() directly instead of
>kthread_create_on_node/kthread_bind/wake_up_process() or
>kthread_create_on_cpu/wake_up_process() or
>kthreadd_create/kthread_bind/wake_up_process() to simplify the code.

I do not see kthread_bind() being covered by the helper,
as claimed? rcutorture, ring-buffer, siw are using it in
the code potentially being replaced by the helper.
kthread_bind() is best to be called before thread starts
running, so should be part of it.

Thanks,
Bernard.
>
>Cai Huoqing (6):
>  kthread: Add the helper macro kthread_run_on_cpu()
>  RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
>  ring-buffer: Make use of the helper macro kthread_run_on_cpu()
>  rcutorture: Make use of the helper macro kthread_run_on_cpu()
>  trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
>  trace/hwlat: Make use of the helper macro kthread_run_on_cpu()
>
> drivers/infiniband/sw/siw/siw_main.c |  7 +++----
> include/linux/kthread.h              | 22 ++++++++++++++++++++++
> kernel/rcu/rcutorture.c              |  7 ++-----
> kernel/trace/ring_buffer.c           |  7 ++-----
> kernel/trace/trace_hwlat.c           |  6 +-----
> kernel/trace/trace_osnoise.c         |  3 +--
> 6 files changed, 31 insertions(+), 21 deletions(-)
>
>-- 
>2.25.1
>
>

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

* Re: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 13:10   ` Steven Rostedt
@ 2021-10-21 13:53     ` Cai Huoqing
  2021-10-21 13:58       ` Steven Rostedt
  0 siblings, 1 reply; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 13:53 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Mathieu Desnoyers,
	Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

On 21 10月 21 09:10:01, Steven Rostedt wrote:
> On Thu, 21 Oct 2021 20:01:30 +0800
> Cai Huoqing <caihuoqing@baidu.com> wrote:
> 
> > the helper macro kthread_run_on_cpu() inculdes
> 
>  "includes"
> 
> > kthread_create_on_cpu/wake_up_process().
> > In some cases, use kthread_run_on_cpu() directly instead of
> > kthread_create_on_node/kthread_bind/wake_up_process() or
> > kthread_create_on_cpu/wake_up_process() or
> > kthreadd_create/kthread_bind/wake_up_process() to simplify the code.
> > 
> > Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> > ---
> >  include/linux/kthread.h | 22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> > 
> > diff --git a/include/linux/kthread.h b/include/linux/kthread.h
> > index 346b0f269161..dfd125523aa9 100644
> > --- a/include/linux/kthread.h
> > +++ b/include/linux/kthread.h
> > @@ -56,6 +56,28 @@ bool kthread_is_per_cpu(struct task_struct *k);
> >  	__k;								   \
> >  })
> >  
> > +/**
> > + * kthread_run_on_cpu - create and wake a cpu bound thread.
> > + * @threadfn: the function to run until signal_pending(current).
> > + * @data: data ptr for @threadfn.
> > + * @cpu: The cpu on which the thread should be bound,
> > + * @namefmt: printf-style name for the thread. Format is restricted
> > + *	     to "name.*%u". Code fills in cpu number.
> > + *
> > + * Description: Convenient wrapper for kthread_create_on_node()
> > + * followed by wake_up_process().  Returns the kthread or
> > + * ERR_PTR(-ENOMEM).
> > + */
> > +#define kthread_run_on_cpu(threadfn, data, cpu, namefmt)		  \
> 
> Why is this a macro and not a static inline function?
> 
> -- Steve
Hi,Thanks for your feedback,

I think using static inline function is nice, but here try to keep
consistent with the other macros,
sush as kthread_create/kthread_init_work...

Thanks,
Cai.
> 
> > +({									  \
> > +	struct task_struct *__k						  \
> > +		= kthread_create_on_cpu(threadfn, data, cpu_to_node(cpu), \
> > +					namefmt);			  \
> > +	if (!IS_ERR(__k))						  \
> > +		wake_up_process(__k);					  \
> > +	__k;								  \
> > +})
> > +
> >  void free_kthread_struct(struct task_struct *k);
> >  void kthread_bind(struct task_struct *k, unsigned int cpu);
> >  void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
> 

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

* RE: [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
                   ` (6 preceding siblings ...)
  2021-10-21 13:48 ` [PATCH 0/6] kthread: Add " Bernard Metzler
@ 2021-10-21 13:58 ` Cai,Huoqing
  7 siblings, 0 replies; 15+ messages in thread
From: Cai,Huoqing @ 2021-10-21 13:58 UTC (permalink / raw)
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

Hi, folks
V2 is here
https://lore.kernel.org/lkml/20211021122758.3092-2-caihuoqing@baidu.com/

> -----Original Message-----
> From: Cai,Huoqing <caihuoqing@baidu.com>
> Sent: 2021年10月21日 20:01
> To: Cai,Huoqing
> Cc: Bernard Metzler; Doug Ledford; Jason Gunthorpe; Davidlohr Bueso; Paul
> E. McKenney; Josh Triplett; Steven Rostedt; Mathieu Desnoyers; Lai
> Jiangshan; Joel Fernandes; Ingo Molnar; Daniel Bristot de Oliveira; linux-
> rdma@vger.kernel.org; linux-kernel@vger.kernel.org; rcu@vger.kernel.org
> Subject: [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
> 
> the helper macro kthread_run_on_cpu() inculdes
> kthread_create_on_cpu/wake_up_process().
> In some cases, use kthread_run_on_cpu() directly instead of
> kthread_create_on_node/kthread_bind/wake_up_process() or
> kthread_create_on_cpu/wake_up_process() or
> kthreadd_create/kthread_bind/wake_up_process() to simplify the code.
> 
> Cai Huoqing (6):
>   kthread: Add the helper macro kthread_run_on_cpu()
>   RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
>   ring-buffer: Make use of the helper macro kthread_run_on_cpu()
>   rcutorture: Make use of the helper macro kthread_run_on_cpu()
>   trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
>   trace/hwlat: Make use of the helper macro kthread_run_on_cpu()
> 
>  drivers/infiniband/sw/siw/siw_main.c |  7 +++----
>  include/linux/kthread.h              | 22 ++++++++++++++++++++++
>  kernel/rcu/rcutorture.c              |  7 ++-----
>  kernel/trace/ring_buffer.c           |  7 ++-----
>  kernel/trace/trace_hwlat.c           |  6 +-----
>  kernel/trace/trace_osnoise.c         |  3 +--
>  6 files changed, 31 insertions(+), 21 deletions(-)
> 
> --
> 2.25.1


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

* Re: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 13:53     ` Cai Huoqing
@ 2021-10-21 13:58       ` Steven Rostedt
  2021-10-22  3:05         ` Cai Huoqing
  0 siblings, 1 reply; 15+ messages in thread
From: Steven Rostedt @ 2021-10-21 13:58 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Mathieu Desnoyers,
	Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

On Thu, 21 Oct 2021 21:53:12 +0800
Cai Huoqing <caihuoqing@baidu.com> wrote:

> > > +/**
> > > + * kthread_run_on_cpu - create and wake a cpu bound thread.
> > > + * @threadfn: the function to run until signal_pending(current).
> > > + * @data: data ptr for @threadfn.
> > > + * @cpu: The cpu on which the thread should be bound,
> > > + * @namefmt: printf-style name for the thread. Format is restricted
> > > + *	     to "name.*%u". Code fills in cpu number.
> > > + *
> > > + * Description: Convenient wrapper for kthread_create_on_node()
> > > + * followed by wake_up_process().  Returns the kthread or
> > > + * ERR_PTR(-ENOMEM).
> > > + */
> > > +#define kthread_run_on_cpu(threadfn, data, cpu, namefmt)		  \  
> > 
> > Why is this a macro and not a static inline function?
> > 
> > -- Steve  
> Hi,Thanks for your feedback,
> 
> I think using static inline function is nice, but here try to keep
> consistent with the other macros,
> sush as kthread_create/kthread_init_work...

Which they did because they didn't want to use va_list to have variable
arguments, which you don't have.

Which begs the question, should you?

-- Steve

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

* Re: [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 13:48 ` [PATCH 0/6] kthread: Add " Bernard Metzler
@ 2021-10-21 14:07   ` Cai Huoqing
  2021-10-21 14:14   ` Bernard Metzler
  1 sibling, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-21 14:07 UTC (permalink / raw)
  To: Bernard Metzler
  Cc: Doug Ledford, Jason Gunthorpe, Davidlohr Bueso, Paul E. McKenney,
	Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Joel Fernandes, Ingo Molnar, Daniel Bristot de Oliveira,
	linux-rdma, linux-kernel, rcu

On 21 10月 21 13:48:15, Bernard Metzler wrote:
> -----"Cai Huoqing" <caihuoqing@baidu.com> wrote: -----
> 
> >To: <caihuoqing@baidu.com>
> >From: "Cai Huoqing" <caihuoqing@baidu.com>
> >Date: 10/21/2021 02:02PM
> >Cc: "Bernard Metzler" <bmt@zurich.ibm.com>, "Doug Ledford"
> ><dledford@redhat.com>, "Jason Gunthorpe" <jgg@ziepe.ca>, "Davidlohr
> >Bueso" <dave@stgolabs.net>, "Paul E. McKenney" <paulmck@kernel.org>,
> >"Josh Triplett" <josh@joshtriplett.org>, "Steven Rostedt"
> ><rostedt@goodmis.org>, "Mathieu Desnoyers"
> ><mathieu.desnoyers@efficios.com>, "Lai Jiangshan"
> ><jiangshanlai@gmail.com>, "Joel Fernandes" <joel@joelfernandes.org>,
> >"Ingo Molnar" <mingo@redhat.com>, "Daniel Bristot de Oliveira"
> ><bristot@kernel.org>, <linux-rdma@vger.kernel.org>,
> ><linux-kernel@vger.kernel.org>, <rcu@vger.kernel.org>
> >Subject: [EXTERNAL] [PATCH 0/6] kthread: Add the helper macro
> >kthread_run_on_cpu()
> >
> >the helper macro kthread_run_on_cpu() inculdes
> >kthread_create_on_cpu/wake_up_process().
> >In some cases, use kthread_run_on_cpu() directly instead of
> >kthread_create_on_node/kthread_bind/wake_up_process() or
> >kthread_create_on_cpu/wake_up_process() or
> >kthreadd_create/kthread_bind/wake_up_process() to simplify the code.
> 
> I do not see kthread_bind() being covered by the helper,
> as claimed? rcutorture, ring-buffer, siw are using it in
> the code potentially being replaced by the helper.
> kthread_bind() is best to be called before thread starts
> running, so should be part of it.
Hi,
kthread_bind() is already part of kthread_create_on_cpu which is
called by kthread_run_on_cpu() here.

Thanks,
Cai.
> 
> Thanks,
> Bernard.
> >
> >Cai Huoqing (6):
> >  kthread: Add the helper macro kthread_run_on_cpu()
> >  RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
> >  ring-buffer: Make use of the helper macro kthread_run_on_cpu()
> >  rcutorture: Make use of the helper macro kthread_run_on_cpu()
> >  trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
> >  trace/hwlat: Make use of the helper macro kthread_run_on_cpu()
> >
> > drivers/infiniband/sw/siw/siw_main.c |  7 +++----
> > include/linux/kthread.h              | 22 ++++++++++++++++++++++
> > kernel/rcu/rcutorture.c              |  7 ++-----
> > kernel/trace/ring_buffer.c           |  7 ++-----
> > kernel/trace/trace_hwlat.c           |  6 +-----
> > kernel/trace/trace_osnoise.c         |  3 +--
> > 6 files changed, 31 insertions(+), 21 deletions(-)
> >
> >-- 
> >2.25.1
> >
> >

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

* Re: Re: [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 13:48 ` [PATCH 0/6] kthread: Add " Bernard Metzler
  2021-10-21 14:07   ` Cai Huoqing
@ 2021-10-21 14:14   ` Bernard Metzler
  1 sibling, 0 replies; 15+ messages in thread
From: Bernard Metzler @ 2021-10-21 14:14 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: Doug Ledford, Jason Gunthorpe, Davidlohr Bueso, Paul E. McKenney,
	Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	Joel Fernandes, Ingo Molnar, Daniel Bristot de Oliveira,
	linux-rdma, linux-kernel, rcu

-----"Cai Huoqing" <caihuoqing@baidu.com> wrote: -----

>To: "Bernard Metzler" <BMT@zurich.ibm.com>
>From: "Cai Huoqing" <caihuoqing@baidu.com>
>Date: 10/21/2021 04:08PM
>Cc: "Doug Ledford" <dledford@redhat.com>, "Jason Gunthorpe"
><jgg@ziepe.ca>, "Davidlohr Bueso" <dave@stgolabs.net>, "Paul E.
>McKenney" <paulmck@kernel.org>, "Josh Triplett"
><josh@joshtriplett.org>, "Steven Rostedt" <rostedt@goodmis.org>,
>"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>, "Lai Jiangshan"
><jiangshanlai@gmail.com>, "Joel Fernandes" <joel@joelfernandes.org>,
>"Ingo Molnar" <mingo@redhat.com>, "Daniel Bristot de Oliveira"
><bristot@kernel.org>, <linux-rdma@vger.kernel.org>,
><linux-kernel@vger.kernel.org>, <rcu@vger.kernel.org>
>Subject: [EXTERNAL] Re: [PATCH 0/6] kthread: Add the helper macro
>kthread_run_on_cpu()
>
>On 21 10月 21 13:48:15, Bernard Metzler wrote:
>> -----"Cai Huoqing" <caihuoqing@baidu.com> wrote: -----
>> 
>> >To: <caihuoqing@baidu.com>
>> >From: "Cai Huoqing" <caihuoqing@baidu.com>
>> >Date: 10/21/2021 02:02PM
>> >Cc: "Bernard Metzler" <bmt@zurich.ibm.com>, "Doug Ledford"
>> ><dledford@redhat.com>, "Jason Gunthorpe" <jgg@ziepe.ca>,
>"Davidlohr
>> >Bueso" <dave@stgolabs.net>, "Paul E. McKenney"
><paulmck@kernel.org>,
>> >"Josh Triplett" <josh@joshtriplett.org>, "Steven Rostedt"
>> ><rostedt@goodmis.org>, "Mathieu Desnoyers"
>> ><mathieu.desnoyers@efficios.com>, "Lai Jiangshan"
>> ><jiangshanlai@gmail.com>, "Joel Fernandes"
><joel@joelfernandes.org>,
>> >"Ingo Molnar" <mingo@redhat.com>, "Daniel Bristot de Oliveira"
>> ><bristot@kernel.org>, <linux-rdma@vger.kernel.org>,
>> ><linux-kernel@vger.kernel.org>, <rcu@vger.kernel.org>
>> >Subject: [EXTERNAL] [PATCH 0/6] kthread: Add the helper macro
>> >kthread_run_on_cpu()
>> >
>> >the helper macro kthread_run_on_cpu() inculdes
>> >kthread_create_on_cpu/wake_up_process().
>> >In some cases, use kthread_run_on_cpu() directly instead of
>> >kthread_create_on_node/kthread_bind/wake_up_process() or
>> >kthread_create_on_cpu/wake_up_process() or
>> >kthreadd_create/kthread_bind/wake_up_process() to simplify the
>code.
>> 
>> I do not see kthread_bind() being covered by the helper,
>> as claimed? rcutorture, ring-buffer, siw are using it in
>> the code potentially being replaced by the helper.
>> kthread_bind() is best to be called before thread starts
>> running, so should be part of it.
>Hi,
>kthread_bind() is already part of kthread_create_on_cpu which is
>called by kthread_run_on_cpu() here.
>

Indeed! Thanks, Bernard.

>Thanks,
>Cai.
>> 
>> Thanks,
>> Bernard.
>> >
>> >Cai Huoqing (6):
>> >  kthread: Add the helper macro kthread_run_on_cpu()
>> >  RDMA/siw: Make use of the helper macro kthread_run_on_cpu()
>> >  ring-buffer: Make use of the helper macro kthread_run_on_cpu()
>> >  rcutorture: Make use of the helper macro kthread_run_on_cpu()
>> >  trace/osnoise: Make use of the helper macro kthread_run_on_cpu()
>> >  trace/hwlat: Make use of the helper macro kthread_run_on_cpu()
>> >
>> > drivers/infiniband/sw/siw/siw_main.c |  7 +++----
>> > include/linux/kthread.h              | 22 ++++++++++++++++++++++
>> > kernel/rcu/rcutorture.c              |  7 ++-----
>> > kernel/trace/ring_buffer.c           |  7 ++-----
>> > kernel/trace/trace_hwlat.c           |  6 +-----
>> > kernel/trace/trace_osnoise.c         |  3 +--
>> > 6 files changed, 31 insertions(+), 21 deletions(-)
>> >
>> >-- 
>> >2.25.1
>> >
>> >
>

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

* Re: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu()
  2021-10-21 13:58       ` Steven Rostedt
@ 2021-10-22  3:05         ` Cai Huoqing
  0 siblings, 0 replies; 15+ messages in thread
From: Cai Huoqing @ 2021-10-22  3:05 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Bernard Metzler, Doug Ledford, Jason Gunthorpe, Davidlohr Bueso,
	Paul E. McKenney, Josh Triplett, Mathieu Desnoyers,
	Lai Jiangshan, Joel Fernandes, Ingo Molnar,
	Daniel Bristot de Oliveira, linux-rdma, linux-kernel, rcu

On 21 10月 21 09:58:58, Steven Rostedt wrote:
> On Thu, 21 Oct 2021 21:53:12 +0800
> Cai Huoqing <caihuoqing@baidu.com> wrote:
> 
> > > > +/**
> > > > + * kthread_run_on_cpu - create and wake a cpu bound thread.
> > > > + * @threadfn: the function to run until signal_pending(current).
> > > > + * @data: data ptr for @threadfn.
> > > > + * @cpu: The cpu on which the thread should be bound,
> > > > + * @namefmt: printf-style name for the thread. Format is restricted
> > > > + *	     to "name.*%u". Code fills in cpu number.
> > > > + *
> > > > + * Description: Convenient wrapper for kthread_create_on_node()
> > > > + * followed by wake_up_process().  Returns the kthread or
> > > > + * ERR_PTR(-ENOMEM).
> > > > + */
> > > > +#define kthread_run_on_cpu(threadfn, data, cpu, namefmt)		  \  
> > > 
> > > Why is this a macro and not a static inline function?
> > > 
> > > -- Steve  
> > Hi,Thanks for your feedback,
> > 
> > I think using static inline function is nice, but here try to keep
> > consistent with the other macros,
> > sush as kthread_create/kthread_init_work...
> 
> Which they did because they didn't want to use va_list to have variable
> arguments, which you don't have.
> 
> Which begs the question, should you?
> 
> -- Steve
Hi, Thanks your reply.

I get it, V3 here:
https://lore.kernel.org/lkml/20211022025711.3673-2-caihuoqing@baidu.com/

Thanks,
Cai

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

end of thread, other threads:[~2021-10-22  3:05 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 12:01 [PATCH 0/6] kthread: Add the helper macro kthread_run_on_cpu() Cai Huoqing
2021-10-21 12:01 ` [PATCH 1/6] " Cai Huoqing
2021-10-21 13:10   ` Steven Rostedt
2021-10-21 13:53     ` Cai Huoqing
2021-10-21 13:58       ` Steven Rostedt
2021-10-22  3:05         ` Cai Huoqing
2021-10-21 12:01 ` [PATCH 2/6] RDMA/siw: Make use of " Cai Huoqing
2021-10-21 12:01 ` [PATCH 3/6] ring-buffer: " Cai Huoqing
2021-10-21 12:01 ` [PATCH 4/6] rcutorture: " Cai Huoqing
2021-10-21 12:01 ` [PATCH 5/6] trace/osnoise: " Cai Huoqing
2021-10-21 12:01 ` [PATCH 6/6] trace/hwlat: " Cai Huoqing
2021-10-21 13:48 ` [PATCH 0/6] kthread: Add " Bernard Metzler
2021-10-21 14:07   ` Cai Huoqing
2021-10-21 14:14   ` Bernard Metzler
2021-10-21 13:58 ` Cai,Huoqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).