Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55CF5C433EF for ; Fri, 12 Nov 2021 18:29:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 02DCD6103D for ; Fri, 12 Nov 2021 18:29:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 02DCD6103D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.225360.389173 (Exim 4.92) (envelope-from ) id 1mlbI3-0001qH-5K; Fri, 12 Nov 2021 18:28:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 225360.389173; Fri, 12 Nov 2021 18:28:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mlbI3-0001ol-1I; Fri, 12 Nov 2021 18:28:43 +0000 Received: by outflank-mailman (input) for mailman id 225360; Fri, 12 Nov 2021 18:28:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mlbI2-0001mj-1B for xen-devel@lists.xenproject.org; Fri, 12 Nov 2021 18:28:42 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 59da1cbc-43e6-11ec-a9d2-d9f7a1cc8784; Fri, 12 Nov 2021 19:28:39 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 59da1cbc-43e6-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1636741719; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gE6ojH/9khVrVKykrTMSiRo+XcJAwIMNkluytopjuas=; b=W5ZgdwGwRyoc6NgkwCy3jIVb5WTb0OXBQ8owlYygafHOrr3cAAVFfxVQ mOwR1IdDgwDM+b4eDsWUCQiPX8iN3uPn3AAYAiS7bwmllmB1djrj9UFp/ 4Tr1/GQzQ4ExPIHz871e7XcyRntO0kE8F4PhgpZFBIbzbRnBcwLD7RFN0 E=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: kWZSW1am1N+hPGsg89ZLrOJu+LkvFAXAI3SXbkDSCvPk9cw8UaXBiYne4tDn0OgiAMlfOIT1/r B6pw46GM5Yhlq94NQZi6VD6kIUAIV/106tULner0OisnMa1mghpInWqb5EbuZ4kDXaJgO8JISl A9afvxwBt6OhI4MBmFtmcZEktFxJ4q66NHrMCJlTJU9rnmhh5DnlieWlmB/E8cGc46QGgMvbVo N2M4n7JSdYYk5uKKkn26zy8Iv/mH07rIhgD/buwE5FLButQFDcTDn2cXP28s38JhPXx6I4OCiF UTUYTzxsBFVrcvG1/SiXfMCf X-SBRS: 5.1 X-MesageID: 57713708 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:AeXwVamO/hUKfHP6FsAYC4Ho5gxMIURdPkR7XQ2eYbSJt1+Wr1Gzt xIaWWzSOP3bNzOje98lYYq39k9V78WAyodkTAU6rXsxHyMWpZLJC+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klYJqus/hDJ8dmI+F/+bwx1+NwQ tkEZ96EXqZFRAPY9mlPdpL6toFjKkim3FrcIyq/bTEjVJd8XAiVqMT8dw7i+XBWXCq6vMczu ZO60QbfTcZRTghuFp+OOvmu00mwrT4Wn+crBxnEJdxaeUPN9ol2KnOu0q9rcp9UcRian2mUz QebBxsctNLhmY5t/Ymbn72AoqeoD/B6QhhQEV7E4OvkLiLd5Gein9NNCb7aYTDHWWro06y+f uEJnerkOfgKkVsW4YpxF7FnkfA369f1/uIIyw1lGDPAbkixC6MmKX6DhJEduqpIz75fmA23R kPQpYUKZeTXYJvoQAwLOQ4oTuWfzvVFyDDd4MM8LFj++CIqrqGMVl9fPkXUhSFQRFev3FjJH Qv1VBYq1jGC IronPort-HdrOrdr: A9a23:b3nVZKrwLRE5ByXIOsqSEPMaV5oTeYIsimQD101hICG8cqSj+f xG+85rrCMc6QxhPk3I9urhBEDtex/hHNtOkOws1NSZLW7bUQmTXeJfBOLZqlWKcUDDH6xmpM NdmsBFeaXN5DNB7PoSjjPWLz9Z+qjkzJyV X-IronPort-AV: E=Sophos;i="5.87,230,1631592000"; d="scan'208";a="57713708" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 2/3] x86/cpufreq: Rework APERF/MPERF handling Date: Fri, 12 Nov 2021 18:28:17 +0000 Message-ID: <20211112182818.30223-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211112182818.30223-1-andrew.cooper3@citrix.com> References: <20211112182818.30223-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Currently, each feature_detect() (called on CPU add) hook for both cpufreq drivers duplicates cpu_has_aperfmperf in a per-cpu datastructure, and edits cpufreq_driver.getavg to point at get_measured_perf(). As all parts of this are vendor-neutral, drop the function pointer and duplicated boolean, and call get_measured_perf() directly. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu Slightly RFC. This does introduce an arch-specific call into a nominally arch-neutral driver, but struct cpufreq_policy already had x86-specifics in it so this is apparently ok. A (less desirable) alternative would be to keep the function pointer, and patch it in the BSP path, not every AP based on BSP data. Either way, with patching moved out of feature_detect(), the main cpufreq_driver object can become __ro_after_init (in principle), and all calls optimised with alternative_call(). --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 +------- xen/arch/x86/acpi/cpufreq/powernow.c | 6 ------ xen/drivers/cpufreq/utility.c | 9 +++------ xen/include/acpi/cpufreq/cpufreq.h | 2 -- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index 2251c87f9e42..f26cd6649e7a 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -275,7 +275,7 @@ unsigned int get_measured_perf(unsigned int cpu, unsigned int flag) return 0; policy = per_cpu(cpufreq_cpu_policy, cpu); - if (!policy || !policy->aperf_mperf) + if ( !policy || !cpu_has_aperfmperf ) return 0; switch (flag) @@ -345,12 +345,6 @@ static void feature_detect(void *info) struct cpufreq_policy *policy = info; unsigned int eax; - if ( cpu_has_aperfmperf ) - { - policy->aperf_mperf = 1; - cpufreq_driver.getavg = get_measured_perf; - } - eax = cpuid_eax(6); if (eax & 0x2) { policy->turbo = CPUFREQ_TURBO_ENABLED; diff --git a/xen/arch/x86/acpi/cpufreq/powernow.c b/xen/arch/x86/acpi/cpufreq/powernow.c index 80095dfd14b4..82d7827e17c1 100644 --- a/xen/arch/x86/acpi/cpufreq/powernow.c +++ b/xen/arch/x86/acpi/cpufreq/powernow.c @@ -205,12 +205,6 @@ static void feature_detect(void *info) struct cpufreq_policy *policy = info; unsigned int edx; - if ( cpu_has_aperfmperf ) - { - policy->aperf_mperf = 1; - cpufreq_driver.getavg = get_measured_perf; - } - edx = cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES); if ((edx & CPB_CAPABLE) == CPB_CAPABLE) { policy->turbo = CPUFREQ_TURBO_ENABLED; diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index b93895d4dddc..9eb7ecedcd29 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -381,12 +381,9 @@ int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag) if (!cpu_online(cpu) || !(policy = per_cpu(cpufreq_cpu_policy, cpu))) return 0; - if (cpufreq_driver.getavg) - { - freq_avg = cpufreq_driver.getavg(cpu, flag); - if (freq_avg > 0) - return freq_avg; - } + freq_avg = get_measured_perf(cpu, flag); + if ( freq_avg > 0 ) + return freq_avg; return policy->cur; } diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index e88b20bfed4f..4958d3f7d315 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -72,7 +72,6 @@ struct cpufreq_policy { s8 turbo; /* tristate flag: 0 for unsupported * -1 for disable, 1 for enabled * See CPUFREQ_TURBO_* below for defines */ - bool_t aperf_mperf; /* CPU has APERF/MPERF MSRs */ }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy); @@ -162,7 +161,6 @@ struct cpufreq_driver { unsigned int target_freq, unsigned int relation); unsigned int (*get)(unsigned int cpu); - unsigned int (*getavg)(unsigned int cpu, unsigned int flag); int (*exit)(struct cpufreq_policy *policy); }; -- 2.11.0