From patchwork Tue Jan 17 06:16:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xinwu X-Patchwork-Id: 9520021 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 84C70601C3 for ; Tue, 17 Jan 2017 06:18:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 745E2284E7 for ; Tue, 17 Jan 2017 06:18:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67602284EB; Tue, 17 Jan 2017 06:18:51 +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=ham 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 E2778284E7 for ; Tue, 17 Jan 2017 06:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750770AbdAQGSt (ORCPT ); Tue, 17 Jan 2017 01:18:49 -0500 Received: from mga02.intel.com ([134.134.136.20]:46783 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750968AbdAQGSs (ORCPT ); Tue, 17 Jan 2017 01:18:48 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 16 Jan 2017 22:18:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,243,1477983600"; d="scan'208";a="1095044904" Received: from shsi06.sh.intel.com ([10.239.154.35]) by fmsmga001.fm.intel.com with ESMTP; 16 Jan 2017 22:18:43 -0800 From: xinwu.liu@intel.com To: rui.zhang@intel.com, edubezval@gmail.com, linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Liu, Xinwu" , "Zhang, Di" Subject: [PATCH v2] thermal/intel_powerclamp: Fix sched_setscheduler fail Date: Tue, 17 Jan 2017 14:16:41 +0800 Message-Id: <1484633801-25866-1-git-send-email-xinwu.liu@intel.com> X-Mailer: git-send-email 1.9.1 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 From: "Liu, Xinwu" The schedule policy of thread "kidle_inject" is SCHED_NORMAL: [ 772.796284] intel_powerclamp: Start idle injection to reduce power [ 772.825757] ------------[ cut here ]------------ [ 772.825877] WARNING: CPU: 0 PID: 2140 at ../../../../../../kernel/glv/kernel/sched/idle.c:298 play_idle+0x16f/0x230 [ 772.826096] Modules linked in: ip6table_raw iptable_raw hci_uart bluetooth rfkill_gpio cfg80211 imc_ipc(O) [ 772.826194] CPU: 0 PID: 2140 Comm: kidle_inject/0 Tainted: G IO 4.9.0-ge701680f3a17 #1 [ 772.826373] ffffc90001103d58 ffffffff813ba085 0000000000000000 0000000000000000 [ 772.826552] ffffc90001103d98 ffffffff810953e1 0000012a691441c0 0000000000000006 [ 772.826731] 0000000000000002 ffff88006a39d708 ffff8800691441c0 ffffe8ffffc0dab8 [ 772.826794] Call Trace: [ 772.826903] [] dump_stack+0x67/0x92 [ 772.827007] [] __warn+0xd1/0xf0 [ 772.827124] [] warn_slowpath_null+0x1d/0x20 [ 772.827234] [] play_idle+0x16f/0x230 [ 772.827365] [] ? __schedule+0x217/0x6f0 [ 772.827485] [] clamp_idle_injection_func+0x6a/0x1f0 [ 772.827612] [] kthread_worker_fn+0xdd/0x200 [ 772.827741] [] ? __kthread_init_worker+0x50/0x50 [ 772.827860] [] kthread+0x102/0x120 [ 772.828004] [] ? kthread_park+0x60/0x60 [ 772.828118] [] ret_from_fork+0x27/0x40 [ 772.828228] ---[ end trace bb738d5d79381554 ]--- Normaly, the user thread have not the capability "CAP_SYS_NICE" (and they shouldn't), it will fail to change the schedule policy. So, fix it by changing by themselves. Signed-off-by: Liu, Xinwu Signed-off-by: Zhang, Di --- drivers/thermal/intel_powerclamp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c index 83e6971..ea2d9cf 100644 --- a/drivers/thermal/intel_powerclamp.c +++ b/drivers/thermal/intel_powerclamp.c @@ -377,6 +377,7 @@ static bool powerclamp_adjust_controls(unsigned int target_ratio, return set_target_ratio + guard <= current_ratio; } +static DEFINE_PER_CPU(int, setscheduler_done); static void clamp_balancing_func(struct kthread_work *work) { struct powerclamp_worker_data *w_data; @@ -388,6 +389,10 @@ static void clamp_balancing_func(struct kthread_work *work) w_data = container_of(work, struct powerclamp_worker_data, balancing_work); + if (unlikely(this_cpu_read(setscheduler_done) == 0)) { + sched_setscheduler(current, SCHED_FIFO, &sparam); + this_cpu_inc(setscheduler_done); + } /* * make sure user selected ratio does not take effect until * the next round. adjust target_ratio if user has changed @@ -507,7 +512,6 @@ static void start_power_clamp_worker(unsigned long cpu) w_data->cpu = cpu; w_data->clamping = true; set_bit(cpu, cpu_clamping_mask); - sched_setscheduler(worker->task, SCHED_FIFO, &sparam); kthread_init_work(&w_data->balancing_work, clamp_balancing_func); kthread_init_delayed_work(&w_data->idle_injection_work, clamp_idle_injection_func);