Received: by 10.192.165.148 with SMTP id m20csp1097017imm; Sat, 5 May 2018 04:50:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrl01oSmaoTVf1IkDzQHTKIQGHEWhuRwqDqxia61OtbO5EbPYLCzNpT8l0dQRqLKZXHNE6t X-Received: by 2002:a17:902:341:: with SMTP id 59-v6mr9902922pld.324.1525521054342; Sat, 05 May 2018 04:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525521054; cv=none; d=google.com; s=arc-20160816; b=UZq+BbxH28y/NvgZkp93Sqac5vLRUwJc2nncm0S8Iz+JVDSzR57eTOh3TolyQwwEn7 EM9mJPG+wJCM+8kma9/lmDxL9vr3+42ADzJFD972t9ImNpOeohT6Wbhn9MPBgZRNGjAO gLMa09GYx++7/Ww3GDTDapKI+UGWckBru2Iul3R/CARy8xTT06DVcMlxqAcPvVqZPCoT LxAP08aylTkiQT0T/zt50OUYb5K9YQJRvFSuovHWCWhpcCd/F0s0cXmipWn/B69UEojh UzmVCW6Q7tltEPKDYYhunWTzdGk5cHhbfFTBBSsLKuUnZQoXNL8GdCyHiO5/CcWf+05V bqzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ajMlLC7qkwGyGQZZNBmuYgFkyegJDDpPkK7wf4viMW0=; b=dD5JxIF+SEwVPB/J1Xj6OlqZgYtn1qCzYmZX4vKYcpdNuoUW/DgBVKBidHIuclpaDN i04GDDLdW590nFf02h63OkYaKzg6zdBjiqwqKsIl2z9CBXkSd8suSOsfpnvFp3ymaJgu Kd92WCtojoert6ogrQIQph+DI3kFmRTuxvINswDp7j9qVjYUUC7mwhzvawSM7BAU1oqT +Y4WKzJtsOBGTFGSkR7cHVF22Qa5GM0SHP8smwPItIvZwaE+Wna/Za9Hz/JHqvWvWWva 64a64+8P3hokYpq4L9fLEA02GHvS3+4a6TUMkU+OmNmsLTLlcI2SZgnwE0nB+A9kKAmT SjeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2-v6si17640842plh.259.2018.05.05.04.50.40; Sat, 05 May 2018 04:50:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751376AbeEELsl (ORCPT + 99 others); Sat, 5 May 2018 07:48:41 -0400 Received: from mga11.intel.com ([192.55.52.93]:41516 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbeEELsk (ORCPT ); Sat, 5 May 2018 07:48:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 May 2018 04:48:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,365,1520924400"; d="scan'208";a="56183747" Received: from sandybridge-desktop.sh.intel.com ([10.239.160.116]) by orsmga002.jf.intel.com with ESMTP; 05 May 2018 04:48:37 -0700 From: Chen Yu To: "Rafael J. Wysocki" , Len Brown Cc: linux-kernel@vger.kernel.org, Chen Yu , Lenny Szubowicz , Jacob Pan , Rui Zhang , linux-acpi@vger.kernel.org Subject: [PATCH][RFC v2] ACPI: acpi_pad: Do not launch acpi_pad threads on idle cpus Date: Sat, 5 May 2018 19:53:22 +0800 Message-Id: <1525521202-32519-1-git-send-email-yu.c.chen@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 is met. 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: Lenny Szubowicz Cc: Len Brown Cc: Jacob Pan Cc: Rui Zhang Cc: linux-acpi@vger.kernel.org Signed-off-by: Chen Yu --- drivers/acpi/acpi_pad.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c index 552c1f7..515e60e 100644 --- a/drivers/acpi/acpi_pad.c +++ b/drivers/acpi/acpi_pad.c @@ -254,12 +254,62 @@ static void set_power_saving_task_num(unsigned int num) } } +/* + * 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. + */ +#define SAMPLE_INTERVAL_JIF 20 + +static u64 get_idle_time(int cpu) +{ + u64 idle, idle_usecs = -1ULL; + + idle_usecs = get_cpu_idle_time_us(cpu, NULL); + + if (idle_usecs == -1ULL) + idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; + else + idle = idle_usecs * NSEC_PER_USEC; + + return idle; +} + +static bool idle_nr_valid(unsigned int num_cpus) +{ + int busy_nr = 0, i = 0, load_thresh = 100 - idle_pct; + + if (!num_cpus) + return true; + + for_each_online_cpu(i) { + u64 wall_time, idle_time; + unsigned int elapsed_delta, idle_delta, load; + + wall_time = jiffies64_to_nsecs(get_jiffies_64()); + idle_time = get_idle_time(i); + /* Wait and see... */ + schedule_timeout_uninterruptible(SAMPLE_INTERVAL_JIF); + + idle_delta = get_idle_time(i) - idle_time; + elapsed_delta = jiffies64_to_nsecs(get_jiffies_64()) - wall_time; + idle_delta = (idle_delta > elapsed_delta) ? elapsed_delta : idle_delta; + load = 100 * (elapsed_delta - idle_delta) / elapsed_delta; + if (load >= load_thresh) + 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_nr_valid(num_cpus)) + set_power_saving_task_num(num_cpus); put_online_cpus(); } -- 2.7.4