Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1501936

[PATCH 1/3] thermal/intel_powerclamp: Remove duplicated code that starts the kthread

From Petr Mladek <pmladek@suse.com>
Newsgroups linux.kernel
Subject [PATCH 1/3] thermal/intel_powerclamp: Remove duplicated code that starts the kthread
Date 2016-10-17 14:40 +0200
Message-ID <stfmW-3uj-17@gated-at.bofh.it> (permalink)
References <stfmV-3uj-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch removes a code duplication. It does not modify
the functionality.

Signed-off-by: Petr Mladek <pmladek@suse.com>
CC: Zhang Rui <rui.zhang@intel.com>
CC: Eduardo Valentin <edubezval@gmail.com>
CC: Jacob Pan <jacob.jun.pan@linux.intel.com>
CC: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
CC: linux-pm@vger.kernel.org
Acked-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
 drivers/thermal/intel_powerclamp.c | 45 +++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 0e4dc0afcfd2..63657d193db5 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -508,10 +508,27 @@ static void poll_pkg_cstate(struct work_struct *dummy)
 		schedule_delayed_work(&poll_pkg_cstate_work, HZ);
 }
 
+static void start_power_clamp_thread(unsigned long cpu)
+{
+	struct task_struct **p = per_cpu_ptr(powerclamp_thread, cpu);
+	struct task_struct *thread;
+
+	thread = kthread_create_on_node(clamp_thread,
+					(void *) cpu,
+					cpu_to_node(cpu),
+					"kidle_inject/%ld", cpu);
+	if (IS_ERR(thread))
+		return;
+
+	/* bind to cpu here */
+	kthread_bind(thread, cpu);
+	wake_up_process(thread);
+	*p = thread;
+}
+
 static int start_power_clamp(void)
 {
 	unsigned long cpu;
-	struct task_struct *thread;
 
 	set_target_ratio = clamp(set_target_ratio, 0U, MAX_TARGET_RATIO - 1);
 	/* prevent cpu hotplug */
@@ -527,20 +544,7 @@ static int start_power_clamp(void)
 
 	/* start one thread per online cpu */
 	for_each_online_cpu(cpu) {
-		struct task_struct **p =
-			per_cpu_ptr(powerclamp_thread, cpu);
-
-		thread = kthread_create_on_node(clamp_thread,
-						(void *) cpu,
-						cpu_to_node(cpu),
-						"kidle_inject/%ld", cpu);
-		/* bind to cpu here */
-		if (likely(!IS_ERR(thread))) {
-			kthread_bind(thread, cpu);
-			wake_up_process(thread);
-			*p = thread;
-		}
-
+		start_power_clamp_thread(cpu);
 	}
 	put_online_cpus();
 
@@ -572,7 +576,6 @@ static int powerclamp_cpu_callback(struct notifier_block *nfb,
 				unsigned long action, void *hcpu)
 {
 	unsigned long cpu = (unsigned long)hcpu;
-	struct task_struct *thread;
 	struct task_struct **percpu_thread =
 		per_cpu_ptr(powerclamp_thread, cpu);
 
@@ -581,15 +584,7 @@ static int powerclamp_cpu_callback(struct notifier_block *nfb,
 
 	switch (action) {
 	case CPU_ONLINE:
-		thread = kthread_create_on_node(clamp_thread,
-						(void *) cpu,
-						cpu_to_node(cpu),
-						"kidle_inject/%lu", cpu);
-		if (likely(!IS_ERR(thread))) {
-			kthread_bind(thread, cpu);
-			wake_up_process(thread);
-			*percpu_thread = thread;
-		}
+		start_power_clamp_thread(cpu);
 		/* prefer BSP as controlling CPU */
 		if (cpu == 0) {
 			control_cpu = 0;
-- 
1.8.5.6

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] thermal/intel_powerclamp: Conversion to kthread worker API and new CPU hotplug state Petr Mladek <pmladek@suse.com> - 2016-10-17 14:40 +0200
  [PATCH 2/3] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek <pmladek@suse.com> - 2016-10-17 14:40 +0200
  [PATCH 1/3] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek <pmladek@suse.com> - 2016-10-17 14:40 +0200
  [PATCH 3/3] thermal/intel_powerclamp: Convert to CPU hotplug state Petr Mladek <pmladek@suse.com> - 2016-10-17 14:40 +0200
    Re: [PATCH 3/3] thermal/intel_powerclamp: Convert to CPU hotplug  state Jacob Pan <jacob.jun.pan@linux.intel.com> - 2016-10-21 22:20 +0200
      Re: [PATCH 3/3] thermal/intel_powerclamp: Convert to CPU hotplug  state Petr Mladek <pmladek@suse.com> - 2016-10-24 17:50 +0200
        Re: [PATCH 3/3] thermal/intel_powerclamp: Convert to CPU hotplug  state Jacob Pan <jacob.jun.pan@linux.intel.com> - 2016-10-24 19:00 +0200

csiph-web