Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3317162ybt; Mon, 22 Jun 2020 22:18:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL5jcV4Mo2+mhJPtj8sCaJ6lQc7isYSNoVQbUg8Tt1X4EgjdynKMVW2iXH3qwRiifoQdJ3 X-Received: by 2002:a17:906:950c:: with SMTP id u12mr8840504ejx.37.1592889507037; Mon, 22 Jun 2020 22:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592889507; cv=none; d=google.com; s=arc-20160816; b=RY+oGJxHOnUB+t5e7UtzcX2QMSRQMRPiu+Y4Xeb5S2LYldSfNnr/FxowWAojjUUZfa PVQ3UIjO5LvuyjhDAS8knpVEdh1gsT85jmODg38qBQAEy+NpgZ4UsZ4aB0CmHu7ILoXt zlLMwXrTQDfpQZSvaQy7ZAoI6U4KGhy1COZZROcA8R/PZtXYdWVQ07amNBC0xFogsgYq 5+LBgfts6SnVWYdR/5ueSWe5vAZXO5zKNI3GbWm0dCDiRvUp6PkEl7UxqSUrDeiPuMHC isD7xYvIwwD3V6q/UIfQPAvzwHj6Y48sCTWnj5LbQNcgF3G4ttS4upNossPGdvq2/+0E FJjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3phtSZElnKhAKAsJ0GkPo5emlqkKBgqm+SMemI7XzZE=; b=K3OhEKg3ih6v3MC2Og1uYX1BXqhh66q9fpH9S8WsHX8xJ3TKmUteIJkpxAe4SF6buF 3SJcVZ0ruoUgr0e9MA7MuREddyhZlpw+ZAgNKBQi5HEk0xrrLJR+mFMPHBIDM8vwBzh7 BmFmqkMZUnQhpaHwQFD/wH/0pYjFIJBnA2GO4hMlVbhiH8hvSX32eUfx6JW6x49EpRPL LoImmbuLI/GgQtFIcy0htuM9r/PMwsZyUOGABsm9O3WyM3aElQofPrs5tkFYNjPhaF+f 6SP3q3RQqYIdss337dDuyikGybu/+E9thmWkbiFY6BVZq4m6M8OQ/1CjjzOWJqLWsmeC Q0Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yTd34Wi8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si10921522edr.177.2020.06.22.22.18.04; Mon, 22 Jun 2020 22:18:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yTd34Wi8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728767AbgFWFPS (ORCPT + 99 others); Tue, 23 Jun 2020 01:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbgFWFPR (ORCPT ); Tue, 23 Jun 2020 01:15:17 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D304C061795 for ; Mon, 22 Jun 2020 22:15:17 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id j12so7312418pfn.10 for ; Mon, 22 Jun 2020 22:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3phtSZElnKhAKAsJ0GkPo5emlqkKBgqm+SMemI7XzZE=; b=yTd34Wi8nuuX1GjOPwJKiPvV3apHnv1PBY5cE3Txgjq7ZhCA5x5CVfF/3zOXQLo+RA UNoQkrET3GF3kqKwRgcoppDliQzeTcK5pE8JNYIku0KWis95i5MicFo/DyTaGlMENdEY OFOz6j8HmYJpWGOqHNoD3yOZh32eNXcWVEGB/n87Lt2YBNoQ3uq5eoV3lQCNVvD/6zvb a+tOvufVyKXv4E1Jb7Jum/3U8uqBsq1WG1sfdom6B0K1GUaIJcK3oShUwQo1MLjAcAZ5 3paxC0VY98zUkGERCN58qkatsvsXvocT/RKh02WsluOPObokqUMkHKtqRAP/q3VBhzu3 RO2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3phtSZElnKhAKAsJ0GkPo5emlqkKBgqm+SMemI7XzZE=; b=cijUMFOhrn+DfJGX/e82H/dmOZ52zz2DHvQ4Y/SDIoOYD/L+TsIOJhrrJ2MacdL4pk 26ib9iP9SsYqyMfZLDZm8yMFuZnDk4QloCE7eikXfRxTw4qbou/DKvdNgjnZ9cSMjiHt 4eY2XelLLGvA932OyPsOIRgJmZipl2q8WVO3TurLoQfy5lX+OPmTnKt0ICO3KpX8KRa2 FQh/xK3w5XjiqeWf69papt1BrMIC39jjkXVUf3Gv3r79/Nijyr8KwiqnnV89YWgmfl/r 0AXwk9J27mfZ9mJxhy9bu8Z9ED2mus/KV76EUjqFxvBy3AiB/k7CkOkZWoprQX1KeoQt yjMw== X-Gm-Message-State: AOAM533MWlr3PPF7DT2sULIXWBxfxHp/Wlx4y6TlZUJQWALgUQHCe/1Y /DBVBIGYHkggqEImW9r/kgMQMw== X-Received: by 2002:aa7:9184:: with SMTP id x4mr23054383pfa.271.1592889317007; Mon, 22 Jun 2020 22:15:17 -0700 (PDT) Received: from localhost ([122.172.111.76]) by smtp.gmail.com with ESMTPSA id o1sm16562358pfu.70.2020.06.22.22.15.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2020 22:15:16 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Xiongfeng Wang , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: cppc: Reorder code and remove apply_hisi_workaround variable Date: Tue, 23 Jun 2020 10:45:11 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the current approach we have an extra check in the cppc_cpufreq_get_rate() callback, which checks if hisilicon's get rate implementation should be used instead. While it works fine, the approach isn't very straight forward, over that we have an extra check in the routine. Rearrange code and update the cpufreq driver's get() callback pointer directly for the hisilicon case. This gets the extra variable is removed and the extra check isn't required anymore as well. Signed-off-by: Viresh Kumar --- Xiongfeng Wang, will it be possible for you to give this a try as I can't really test it locally. drivers/cpufreq/cppc_cpufreq.c | 91 ++++++++++++++++------------------ 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 257d726a4456..03a21daddbec 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -45,8 +45,6 @@ struct cppc_workaround_oem_info { u32 oem_revision; }; -static bool apply_hisi_workaround; - static struct cppc_workaround_oem_info wa_info[] = { { .oem_id = "HISI ", @@ -59,50 +57,6 @@ static struct cppc_workaround_oem_info wa_info[] = { } }; -static unsigned int cppc_cpufreq_perf_to_khz(struct cppc_cpudata *cpu, - unsigned int perf); - -/* - * HISI platform does not support delivered performance counter and - * reference performance counter. It can calculate the performance using the - * platform specific mechanism. We reuse the desired performance register to - * store the real performance calculated by the platform. - */ -static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpunum) -{ - struct cppc_cpudata *cpudata = all_cpu_data[cpunum]; - u64 desired_perf; - int ret; - - ret = cppc_get_desired_perf(cpunum, &desired_perf); - if (ret < 0) - return -EIO; - - return cppc_cpufreq_perf_to_khz(cpudata, desired_perf); -} - -static void cppc_check_hisi_workaround(void) -{ - struct acpi_table_header *tbl; - acpi_status status = AE_OK; - int i; - - status = acpi_get_table(ACPI_SIG_PCCT, 0, &tbl); - if (ACPI_FAILURE(status) || !tbl) - return; - - for (i = 0; i < ARRAY_SIZE(wa_info); i++) { - if (!memcmp(wa_info[i].oem_id, tbl->oem_id, ACPI_OEM_ID_SIZE) && - !memcmp(wa_info[i].oem_table_id, tbl->oem_table_id, ACPI_OEM_TABLE_ID_SIZE) && - wa_info[i].oem_revision == tbl->oem_revision) { - apply_hisi_workaround = true; - break; - } - } - - acpi_put_table(tbl); -} - /* Callback function used to retrieve the max frequency from DMI */ static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private) { @@ -402,9 +356,6 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) struct cppc_cpudata *cpu = all_cpu_data[cpunum]; int ret; - if (apply_hisi_workaround) - return hisi_cppc_cpufreq_get_rate(cpunum); - ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t0); if (ret) return ret; @@ -455,6 +406,48 @@ static struct cpufreq_driver cppc_cpufreq_driver = { .name = "cppc_cpufreq", }; +/* + * HISI platform does not support delivered performance counter and + * reference performance counter. It can calculate the performance using the + * platform specific mechanism. We reuse the desired performance register to + * store the real performance calculated by the platform. + */ +static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpunum) +{ + struct cppc_cpudata *cpudata = all_cpu_data[cpunum]; + u64 desired_perf; + int ret; + + ret = cppc_get_desired_perf(cpunum, &desired_perf); + if (ret < 0) + return -EIO; + + return cppc_cpufreq_perf_to_khz(cpudata, desired_perf); +} + +static void cppc_check_hisi_workaround(void) +{ + struct acpi_table_header *tbl; + acpi_status status = AE_OK; + int i; + + status = acpi_get_table(ACPI_SIG_PCCT, 0, &tbl); + if (ACPI_FAILURE(status) || !tbl) + return; + + for (i = 0; i < ARRAY_SIZE(wa_info); i++) { + if (!memcmp(wa_info[i].oem_id, tbl->oem_id, ACPI_OEM_ID_SIZE) && + !memcmp(wa_info[i].oem_table_id, tbl->oem_table_id, ACPI_OEM_TABLE_ID_SIZE) && + wa_info[i].oem_revision == tbl->oem_revision) { + /* Overwrite the get() callback */ + cppc_cpufreq_driver.get = hisi_cppc_cpufreq_get_rate; + break; + } + } + + acpi_put_table(tbl); +} + static int __init cppc_cpufreq_init(void) { int i, ret = 0; -- 2.25.0.rc1.19.g042ed3e048af