From patchwork Mon Oct 17 12:32:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 9379153 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B888A600CA for ; Mon, 17 Oct 2016 12:34:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB27229269 for ; Mon, 17 Oct 2016 12:34:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F81829271; Mon, 17 Oct 2016 12:34:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D0E929269 for ; Mon, 17 Oct 2016 12:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932692AbcJQMeA (ORCPT ); Mon, 17 Oct 2016 08:34:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:38084 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933987AbcJQMdQ (ORCPT ); Mon, 17 Oct 2016 08:33:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 32045ABC8; Mon, 17 Oct 2016 12:33:15 +0000 (UTC) From: Petr Mladek To: Jacob Pan , Zhang Rui , Thomas Gleixner Cc: Sebastian Andrzej Siewior , Eduardo Valentin , Tejun Heo , Peter Zijlstra , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH 1/3] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Date: Mon, 17 Oct 2016 14:32:50 +0200 Message-Id: <1476707572-32215-2-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1476707572-32215-1-git-send-email-pmladek@suse.com> References: <1476707572-32215-1-git-send-email-pmladek@suse.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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;