From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755739AbcK1VrD (ORCPT ); Mon, 28 Nov 2016 16:47:03 -0500 Received: from mga11.intel.com ([192.55.52.93]:23833 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755369AbcK1Vqn (ORCPT ); Mon, 28 Nov 2016 16:46:43 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,565,1473145200"; d="scan'208";a="36490934" From: Jacob Pan To: LKML , Linux PM , Rafael Wysocki , Eduardo Valentin , Zhang Rui Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Arjan van de Ven , Srinivas Pandruvada , Len Brown , Petr Mladek , Sebastian Andrzej Siewior , Jacob Pan Subject: [PATCH 1/4] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Date: Mon, 28 Nov 2016 13:44:49 -0800 Message-Id: <1480369492-23901-2-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1480369492-23901-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1480369492-23901-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Petr Mladek This patch removes a code duplication. It does not modify the functionality. Signed-off-by: Petr Mladek CC: Zhang Rui CC: Eduardo Valentin CC: Jacob Pan CC: Sebastian Andrzej Siewior CC: linux-pm@vger.kernel.org Acked-by: Jacob Pan --- 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 afada65..8a60772 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.9.1