Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp92649rdf; Mon, 20 Nov 2023 17:42:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGab9mD5JPo7wYNB76REGg3FxnsM7ZkoeoDKeeIArYg7IpvBLTjbOQk4Eto1zettSQq7ZXz X-Received: by 2002:a17:90b:388d:b0:282:e10b:34b6 with SMTP id mu13-20020a17090b388d00b00282e10b34b6mr6621202pjb.39.1700530933081; Mon, 20 Nov 2023 17:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700530933; cv=none; d=google.com; s=arc-20160816; b=LKc1IfDkwq2mjwisqR0uxsUMPOhQpbDOwC+34Xc1pFqB/pC+Q3fMEjtiO8IT2C79tT gbCQaX8ISCEdLodin2+zFOpcY6BeffNlBqgPVab1217Vf5iO47CsFkUvOrCj4gmNmS6v uEH2hxlpadw2JRz0DcYJNrVkDrEbieUXee7XTRSt0ipokf5ZQ6mcGUYPXOosFZX33YAG 25Z26O63LdmTA6BkwKH2rQi7LhOZS+puLZu3cH+B7NS6bUi5vqYy+qsySsp7/JYjM0hR vSyhYtxJ00a78HVF2PfBE0kpRSri3cI9u1F8VYg4Ekmqi0Zs/1g9zztv3hZM0sNYXZ6c SNYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=BLT8/0LWBFSi5cy70rgO9DjFN5vxOsgvqwWrMQdBzKk=; fh=Nc45KRJdYAy7X8hWM6rTQ9qfiBCnhcEizgRqNnbocn0=; b=zWlxpfA59X2zWPjpw8BmKY6CL8sPbjfDyfyKGesviqpFMqHPOkV0GELnwlm53NTnfV p25In+ZaSgaQwIVEQtXMnhX44WoYGDSTChx+MahmYMWglP76XIHIPVIRk0ORnI3aEcDN M6bMunK+0O/XV/qmJSgN1jYagwPpmYzVyK9D1RPNhOaGCVEC0JeF00Ml1jADxRXWkABV F5yDCaSdp2Jw+vjCf50WDwzRLPgBAsP7soVyOmnt86vg8uD7TAcl6G2HrHETmllDCfGv KDAcC7K3HnBadr+fkiWiAXrfhO3NbA4WWNKD+fGiCQkTpt4D6DiwbHU8mi4pO3EJN8rc T75A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id nw10-20020a17090b254a00b0027d30e575ccsi10085565pjb.115.2023.11.20.17.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 17:42:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 900BD80A7F19; Mon, 20 Nov 2023 17:42:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232990AbjKUBmB (ORCPT + 99 others); Mon, 20 Nov 2023 20:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjKUBmA (ORCPT ); Mon, 20 Nov 2023 20:42:00 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3EA6C7; Mon, 20 Nov 2023 17:41:55 -0800 (PST) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SZ6TY5vHZzsRMW; Tue, 21 Nov 2023 09:38:25 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 21 Nov 2023 09:41:53 +0800 Message-ID: <50c05422-20f1-7bc1-d245-76723d8e0ae0@huawei.com> Date: Tue, 21 Nov 2023 09:41:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] cpufreq: intel_pstate: Fix CPU lowest Frequency bug when offline/online for passive Content-Language: en-US To: "Rafael J. Wysocki" CC: , , Srinivas Pandruvada , Len Brown , Viresh Kumar , References: <20231107025838.2806500-1-ruanjinjie@huawei.com> <6c078e43-5dba-b980-5890-18c7b7cf7157@huawei.com> From: Jinjie Ruan In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 17:42:10 -0800 (PST) On 2023/11/21 1:16, Rafael J. Wysocki wrote: > On Mon, Nov 13, 2023 at 7:18 AM Jinjie Ruan wrote: >> >> Ping. > > I see the problem, but I'm not sure if the approach taken in the patch > is the best one, as it has side effects. Could you please make it more clear, what are the side effects? I'm not sure about the possible negative effects of the patch. > >> On 2023/11/7 10:58, Jinjie Ruan wrote: >>> There is a bug in passive mode for intel pstate when >>> CONFIG_X86_INTEL_PSTATE = y and configure intel_pstate = passive in command >>> line. On Ice Lake server, although the performance tuner is used, the CPU >>> have the lowest frequency in scaling_cur_freq after the CPU goes offline and >>> then goes online, running the same infinite loop load. >>> >>> How to reproduce: >>> >>> cat while_true.c >>> #include >>> void main(void) >>> { >>> while(1); >>> } >>> >>> [root@localhost freq_test]# cat test.sh >>> #!/bin/bash >>> >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_governor >>> taskset -c ${1} ./while_true & >>> sleep 1s >>> >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> echo 0 > /sys/devices/system/cpu/cpu${1}/online >>> >>> sleep 1s >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> sleep 1s >>> >>> echo 1 > /sys/devices/system/cpu/cpu${1}/online >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> taskset -c ${1} ./while_true & >>> >>> sleep 1s >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> sleep 1s >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> sleep 1s >>> cat /sys/devices/system/cpu/cpu${1}/cpufreq/scaling_cur_freq >>> >>> The CPU frequency is adjusted to the minimum after offline and online: >>> >>> [root@localhost freq_test]# sh test.sh 20 >>> 2300000 >>> performance >>> 2299977 >>> cat: /sys/devices/system/cpu/cpu20/cpufreq/scaling_cur_freq: Device or >>> resource busy >>> 800000 >>> 800000 >>> 800000 >>> 799992 >>> [root@localhost freq_test]# sh test.sh 21 >>> 2300000 >>> performance >>> 2300000 >>> cat: /sys/devices/system/cpu/cpu21/cpufreq/scaling_cur_freq: Device or >>> resource busy >>> 800000 >>> 800000 >>> 800000 >>> 800000 >>> >>> As in __cpufreq_driver_target(), the cpufreq core will not call intel >>> cpufreq's target() callback if the target freq is equal with policy->cur >>> and do not set CPUFREQ_NEED_UPDATE_LIMITS flag, but the hardware also not >>> proactively keep CPU with the policy->cur frequency. So also set >>> CPUFREQ_NEED_UPDATE_LIMITS for passive mode. After applying this patch, >>> the CPU frequency is consistent as what performance tuner expected after >>> CPU offline and online as below: >>> >>> [root@localhost freq_test]# sh test.sh 20 >>> 2300000 >>> performance >>> 2300000 >>> cat: /sys/devices/system/cpu/cpu20/cpufreq/scaling_cur_freq: Device or resource busy >>> 2300000 >>> 2300000 >>> 2299977 >>> 2299977 >>> [root@localhost freq_test]# sh test.sh 21 >>> 2300000 >>> performance >>> 2300000 >>> cat: /sys/devices/system/cpu/cpu21/cpufreq/scaling_cur_freq: Device or resource busy >>> 2300000 >>> 2300000 >>> 2300000 >>> 2300000 >>> [root@localhost freq_test]# cat /sys/devices/system/cpu/intel_pstate/status >>> passive >>> >>> Signed-off-by: Jinjie Ruan >>> --- >>> drivers/cpufreq/intel_pstate.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c >>> index a534a1f7f1ee..73403f1292b0 100644 >>> --- a/drivers/cpufreq/intel_pstate.c >>> +++ b/drivers/cpufreq/intel_pstate.c >>> @@ -3091,7 +3091,7 @@ static int intel_cpufreq_suspend(struct cpufreq_policy *policy) >>> } >>> >>> static struct cpufreq_driver intel_cpufreq = { >>> - .flags = CPUFREQ_CONST_LOOPS, >>> + .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS, >>> .verify = intel_cpufreq_verify_policy, >>> .target = intel_cpufreq_target, >>> .fast_switch = intel_cpufreq_fast_switch, >