From patchwork Sun Apr 18 03:30:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5b6Q56aP5rW3?= X-Patchwork-Id: 423910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3191C433ED for ; Sun, 18 Apr 2021 03:30:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4CAE61248 for ; Sun, 18 Apr 2021 03:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237216AbhDRDbK (ORCPT ); Sat, 17 Apr 2021 23:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237212AbhDRDbK (ORCPT ); Sat, 17 Apr 2021 23:31:10 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65629C06174A; Sat, 17 Apr 2021 20:30:43 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id r13so12270597pjf.2; Sat, 17 Apr 2021 20:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=b8hpyDKfB8kYMTlAMk33KCFRc04U8eD4yoRmXwd6/1k=; b=QD9CvGDnpgRbWHneXST4f0L73kDAKrhp4XF44qas6zt/UnZrKPbSzqonZ8FAnE//RE h3NtPhR2ozMriSrwaz8NzPEw52O0CSH2zQMETAV2Na7scbXV2z1+W2nnvfQL7Y+iimev Zj7HnYlGYEQneF0qmxYiKrEaEtIUfcR41XhxcZt1g9LakIUuE4A8UKDvy47qWbMJ5l1q TCHiofw7fJuy/Vxj6/hd8ZeIhSUczGAYrRn6X2DR4W0Wb4vflMHu+e/ouXO5Vtw0200L 69L942WvYdPzXzKSOX+0R48uFimIsCBFRGqR1ya3b25A5zKMZSb2DhQWr+tN1MBPv7+S Zw8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=b8hpyDKfB8kYMTlAMk33KCFRc04U8eD4yoRmXwd6/1k=; b=Z0piDkGHSfIHxGfbGW6+lRjq/0LglB1TYArHCzfGqCZlvtyJJUlnQSCyd2wwVisptD ELpY14v/H7ixT1k9LAi+rNO60nlTS/7189VxPSCwVGrf0GUav7AO6BGUVjB7rxHXZ1Jv XlSU7zg6nVni6/Kjd8relTiUhlIseUA5TNQKqYViUYcHbO+sVzF9sRDcbp6Y+pH9ql60 8ZZVJwHIwKeyXfuczC/rMNzl9Y/dGALqibew2nlLr+BLl2nV7pQzLOH6Knr/rN60nzUu +yVDnhf+FXEnDTSV6SiuycinmQFnLsrHyMINJq6mAoKgtLeaC81HUYYMVb0uedr6y6Vw 1Ijw== X-Gm-Message-State: AOAM53186FCqrQFHRAExawIIslSRB6rOFKei+zP8kSE+8li/ekPa+OWT OW6oMSXCCUXA7n9VrOpOe1bCBRrlnPFlGt6ANz0= X-Google-Smtp-Source: ABdhPJxVwmX7HDYx/7rgGE7WvOdjl595q58oeRIUlN4t0gD4eCaKlyLuuhwsjLOnNPEVKMVjCI2qTQ== X-Received: by 2002:a17:90b:302:: with SMTP id ay2mr17772293pjb.84.1618716643019; Sat, 17 Apr 2021 20:30:43 -0700 (PDT) Received: from MacBook-Pro.local ([154.48.252.71]) by smtp.gmail.com with ESMTPSA id a26sm8803126pff.149.2021.04.17.20.30.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Apr 2021 20:30:42 -0700 (PDT) From: =?utf-8?b?5b6Q56aP5rW3?= Subject: [PATCH v3 2/2] cpupower: Fix amd cpu (family >= 0x17) active state issue To: shuah@kernel.org, Shuah Khan , Thomas Renninger Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, lishujin@kuaishou.com, xufuhai Message-ID: <6e35df20-753a-6c9c-8786-3fc87cdd17ba@gmail.com> Date: Sun, 18 Apr 2021 11:30:38 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: xufuhai If the read_msr function is executed by a non-root user, the function returns -1, which means that there is no permission to access /dev/cpu/%d/msr, but cpufreq_has_boost_support should also return -1 immediately, and should not follow the original logic to return 0, which will cause amd The cpupower tool returns the boost active state as 0. Reproduce procedure: cpupower frequency-info Reported-by: yangrui Signed-off-by: xufuhai Signed-off-by: chenguanqiao Signed-off-by: lishujin Reviewed-by: Thomas Renninger --- tools/power/cpupower/utils/helpers/misc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.24.3 (Apple Git-128) diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index fc6e34511721..565f8c414396 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -16,7 +16,7 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, int *states) { - int ret; + int ret = 0; unsigned long long val; *support = *active = *states = 0; @@ -30,18 +30,21 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, */ if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) { - if (!read_msr(cpu, MSR_AMD_HWCR, &val)) { + /* + * no permission to access /dev/cpu/%d/msr, return -1 immediately, + * and should not follow the original logic to return 0 + */ + ret = read_msr(cpu, MSR_AMD_HWCR, &val); + if (!ret) { if (!(val & CPUPOWER_AMD_CPBDIS)) *active = 1; } } else { ret = amd_pci_get_num_boost_states(active, states); - if (ret) - return ret; } } else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) *support = *active = 1; - return 0; + return ret; } int cpupower_intel_get_perf_bias(unsigned int cpu)