From patchwork Thu Aug 10 16:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Reed X-Patchwork-Id: 1819976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=R20qUu0c; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMCY96bRmz1yfB for ; Fri, 11 Aug 2023 02:48:29 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qU8pi-0008Gi-3v; Thu, 10 Aug 2023 16:48:22 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qU8pg-0008GK-CD for kernel-team@lists.ubuntu.com; Thu, 10 Aug 2023 16:48:20 +0000 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 339E63F17B for ; Thu, 10 Aug 2023 16:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691686100; bh=NUu+GcjwZvQ4gXZWRrFff9/UBxUAWItBZ9r8cgRjbpY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R20qUu0cuZzadoWa/9TYUyxkr6H8cQJS6z1ipN8Pg7OeRe9zG5aw0F3RkpHstIUgd fSFM4iN3+4O863v8bPnnkXfepv0/ersdOPqzH7zUclEShtz/KMknAYRWXS5HV9zkWn aT4EtbpBnZqjIaCNglABk8Lq3QwHSHzenWsZUrhnWGvrnQdN6Aa1ZcN4/ThkcTq9ci K7OMhSK+Dr+BjU36AMQ07XfFdsGptNaX+KWieaz7a/1Nv+6rHh0hHdxogS5YCnnoxi OMYEK12uByrgh1DI75ZeaorYWlNtx5HbR/QfGVGhI5smflmoJOvsX4W/vb+M2igBSh 9q8vq9EkUC3fg== Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3a5ad6088f8so1295155b6e.0 for ; Thu, 10 Aug 2023 09:48:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691686099; x=1692290899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NUu+GcjwZvQ4gXZWRrFff9/UBxUAWItBZ9r8cgRjbpY=; b=FZ67DtLiWnX646defmP7BLfmZIM4krY84B9yuHwu5NtIJOqgyPeOYnjRyy6Z8Gp4mi lx3hfeUDEiMkHWSSCoLCdV3ghCMn1F52bjyrJcuuRnnfqzRGklQeP4I9gqCKLfimKNJr Xjid7IVEmHM8uA1Z0wQC1vtbskmYkcUHY63uLZkCmvrEXenuR50zeGt0+T7uNzeLLmmS +FSz8AZE+aB/Q2UOJbzZwRGtgJpu9PXZvnq6zwfGJGL9L6NEehm4XZmvn0uCvI1w+2do NJc+eoLlQ5pSGZn0xsCqguAT3IGcyR14iaDW430BsNgxcjeCDGEPeRHVvVWUOenRhzYt TXpg== X-Gm-Message-State: AOJu0Yxh4ZfOYVZH8mmxf5C38/IkQGCEW+TAxXLRPIn+pRY7BGv1aAeG br4VuPNHNKf5pYSiovZsXdC5TX0Xi+5SMDPUViNXt+DdIb9lzbI9KuZdVALt4hficQErxZ5A0Ef JbAcyf7rcbBnQiw02hsQVhP/L6XtRjbRD/WhLH/ZnWfypf+x5gA== X-Received: by 2002:a05:6808:4342:b0:3a7:45e0:c0eb with SMTP id dx2-20020a056808434200b003a745e0c0ebmr2950700oib.24.1691686098927; Thu, 10 Aug 2023 09:48:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmNemB3YxkLNGtLVgEZP5nv/Qq+UvjmnnPwYei6esqRndXD24vwpiUUnRX0yhUvEmMCEfArw== X-Received: by 2002:a05:6808:4342:b0:3a7:45e0:c0eb with SMTP id dx2-20020a056808434200b003a745e0c0ebmr2950685oib.24.1691686098595; Thu, 10 Aug 2023 09:48:18 -0700 (PDT) Received: from localhost ([2600:1700:1d0:5e50:5f6e:425d:6f12:c332]) by smtp.gmail.com with ESMTPSA id l10-20020a54450a000000b003a79a5cc3bfsm838214oil.41.2023.08.10.09.48.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:48:18 -0700 (PDT) From: Michael Reed To: kernel-team@lists.ubuntu.com Subject: [SRU J/L/M][PATCH 1/1] cpufreq: intel_pstate: Fix scaling for hybrid-capable Date: Thu, 10 Aug 2023 11:48:14 -0500 Message-Id: <20230810164814.12262-2-michael.reed@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230810164814.12262-1-michael.reed@canonical.com> References: <20230810164814.12262-1-michael.reed@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Srinivas Pandruvada https://bugs.launchpad.net/bugs/2030924 Some system BIOS configuration may provide option to disable E-cores. As part of this change, CPUID feature for hybrid (Leaf 7 sub leaf 0, EDX[15] = 0) may not be set. But HWP performance limits will still be using a scaling factor like any other hybrid enabled system. The current check for applying scaling factor will fail when hybrid CPUID feature is not set and the only way to make sure that scaling should be applied by checking CPPC nominal frequency and nominal performance. First, or systems predating Alder Lake, the CPPC nominal frequency and nominal performance are 0, which can be used to distinguish those systems from hybrid systems with disabled E-cores. Second, if the CPPC nominal frequency and nominal performance are defined, which indicates the need to use a special scaling factor, and the nominal performance value multiplied by 100 is not equal to the nominal frequency one, use hybrid scaling factor. This can be done for all HWP systems without additional CPU model check. Signed-off-by: Srinivas Pandruvada [ rjw: Subject and changelog edits, removal of unneeded parens, comment edits ] Signed-off-by: Rafael J. Wysocki (cherry picked from commit 0fcfc9e51990246a9813475716746ff5eb98c6aa) Signed-off-by: Michael Reed --- drivers/cpufreq/intel_pstate.c | 58 ++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ed26ae6659b7..1e6a1245b86b 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -298,6 +298,13 @@ static bool hwp_boost __read_mostly; static struct cpufreq_driver *intel_pstate_driver __read_mostly; +#define HYBRID_SCALING_FACTOR 78741 + +static inline int core_get_scaling(void) +{ + return 100000; +} + #ifdef CONFIG_ACPI static bool acpi_ppc; #endif @@ -396,6 +403,26 @@ static int intel_pstate_get_cppc_guaranteed(int cpu) return cppc_perf.nominal_perf; } + +static int intel_pstate_cppc_get_scaling(int cpu) +{ + struct cppc_perf_caps cppc_perf; + int ret; + + ret = cppc_get_perf_caps(cpu, &cppc_perf); + + /* + * If the nominal frequency and the nominal performance are not + * zero and the ratio between them is not 100, return the hybrid + * scaling factor. + */ + if (!ret && cppc_perf.nominal_perf && cppc_perf.nominal_freq && + cppc_perf.nominal_perf * 100 != cppc_perf.nominal_freq) + return HYBRID_SCALING_FACTOR; + + return core_get_scaling(); +} + #else /* CONFIG_ACPI_CPPC_LIB */ static inline void intel_pstate_set_itmt_prio(int cpu) { @@ -502,6 +529,11 @@ static inline int intel_pstate_get_cppc_guaranteed(int cpu) { return -ENOTSUPP; } + +static int intel_pstate_cppc_get_scaling(int cpu) +{ + return core_get_scaling(); +} #endif /* CONFIG_ACPI_CPPC_LIB */ /** @@ -1764,11 +1796,6 @@ static int core_get_turbo_pstate(int cpu) return ret; } -static inline int core_get_scaling(void) -{ - return 100000; -} - static u64 core_get_val(struct cpudata *cpudata, int pstate) { u64 val; @@ -1805,16 +1832,28 @@ static void hybrid_get_type(void *data) *cpu_type = get_this_hybrid_cpu_type(); } -static int hybrid_get_cpu_scaling(int cpu) +static int hwp_get_cpu_scaling(int cpu) { u8 cpu_type = 0; smp_call_function_single(cpu, hybrid_get_type, &cpu_type, 1); /* P-cores have a smaller perf level-to-freqency scaling factor. */ if (cpu_type == 0x40) - return 78741; + return HYBRID_SCALING_FACTOR; - return core_get_scaling(); + /* Use default core scaling for E-cores */ + if (cpu_type == 0x20) + return core_get_scaling(); + + /* + * If reached here, this system is either non-hybrid (like Tiger + * Lake) or hybrid-capable (like Alder Lake or Raptor Lake) with + * no E cores (in which case CPUID for hybrid support is 0). + * + * The CPPC nominal_frequency field is 0 for non-hybrid systems, + * so the default core scaling will be used for them. + */ + return intel_pstate_cppc_get_scaling(cpu); } static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) @@ -3270,8 +3309,7 @@ static int __init intel_pstate_init(void) if (!default_driver) default_driver = &intel_pstate; - if (boot_cpu_has(X86_FEATURE_HYBRID_CPU)) - pstate_funcs.get_cpu_scaling = hybrid_get_cpu_scaling; + pstate_funcs.get_cpu_scaling = hwp_get_cpu_scaling; goto hwp_cpu_matched; }