From patchwork Fri May 4 08:08:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Yu X-Patchwork-Id: 10380141 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 4F56460353 for ; Fri, 4 May 2018 08:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F5B929300 for ; Fri, 4 May 2018 08:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31DD22936B; Fri, 4 May 2018 08:04:02 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 0502529300 for ; Fri, 4 May 2018 08:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751269AbeEDIDz (ORCPT ); Fri, 4 May 2018 04:03:55 -0400 Received: from mga03.intel.com ([134.134.136.65]:41126 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751124AbeEDIDz (ORCPT ); Fri, 4 May 2018 04:03:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 May 2018 01:03:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,361,1520924400"; d="scan'208";a="38367378" Received: from sandybridge-desktop.sh.intel.com ([10.239.160.116]) by orsmga007.jf.intel.com with ESMTP; 04 May 2018 01:03:51 -0700 From: Chen Yu To: "Rafael J. Wysocki" , Len Brown Cc: linux-kernel@vger.kernel.org, Chen Yu , Jacob Pan , Rui Zhang , linux-acpi@vger.kernel.org Subject: [PATCH][RFC] ACPI: acpi_pad: Do not launch acpi_pad threads on idle cpus Date: Fri, 4 May 2018 16:08:42 +0800 Message-Id: <1525421322-23431-1-git-send-email-yu.c.chen@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to current implementation of acpi_pad driver, it does not make sense to spawn any power saving threads on the cpus which are already idle - it might bring unnecessary overhead on these idle cpus and causes power waste. So verify the condition that if the number of 'busy' cpus exceeds the amount of the 'forced idle' cpus - This is applicable due to round-robin attribute of the power saving threads, otherwise ignore the setting/ACPI notification. Suggested-by: Lenny Szubowicz Suggested-by: Len Brown Cc: "Rafael J. Wysocki" Cc: Jacob Pan Cc: Rui Zhang Cc: linux-acpi@vger.kernel.org Signed-off-by: Chen Yu --- drivers/acpi/acpi_pad.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c index 552c1f7..190aa36 100644 --- a/drivers/acpi/acpi_pad.c +++ b/drivers/acpi/acpi_pad.c @@ -253,13 +253,36 @@ static void set_power_saving_task_num(unsigned int num) destroy_power_saving_task(); } } +/* + * Extra acpi_pad threads should not be created until + * the requested idle count is less than/equals to the + * number of the busy cpus - it does not make sense to + * throttle the idle cpus. + */ +static bool idle_cpu_valid(unsigned int num_cpus) +{ + int busy_nr = 0, i = 0; + + for_each_online_cpu(i) { + /* + * In case the acpi_pad threads are treated as + * idle in the future(as intel_powerclamp), + * the pad_busy_cpus_bits should be checked too. + */ + if (!idle_cpu(i)) + busy_nr++; + } + + return (busy_nr >= num_cpus) ? true : false; +} static void acpi_pad_idle_cpus(unsigned int num_cpus) { get_online_cpus(); num_cpus = min_t(unsigned int, num_cpus, num_online_cpus()); - set_power_saving_task_num(num_cpus); + if (idle_cpu_valid(num_cpus)) + set_power_saving_task_num(num_cpus); put_online_cpus(); }