Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp2260130pxb; Sat, 19 Feb 2022 06:34:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXUI+PP2BfRt079HBe8VHPH5egXXiGkDrnJqhWZkUBlJ45yjlWjKnV/GhgVlpTrIaTY7yz X-Received: by 2002:a17:90a:9482:b0:1b9:aaff:7eda with SMTP id s2-20020a17090a948200b001b9aaff7edamr13093230pjo.207.1645281256690; Sat, 19 Feb 2022 06:34:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645281256; cv=none; d=google.com; s=arc-20160816; b=z32dJ87dYYP4TG8TJK4xmwoGo3BlcpbQoUTKWNEBUHquOJ60TSezoiPCKcrD9Fkntc PYcq6F4lJxutVqY6VfwYT/uwbnXitZUCqjr3TsACf8aMHyErzW270qZ+KMGm3KBMk13K ROy3I+sHN+c+snQxkvh2idNP7TRvXtsVft7Q3vnRuJraTfxE7FwcfS5ter4bgGxScpKb t85rZDgeL+Y0/mykGeUusYF87ba4jm3HSG3Z/IkXUlvhgmSFIdoaUF9Eli4FfmKBdwCX Sasfw23tVcwnseGkApoGMXHO8mwTMvgrZLSayP3q7HMOAOXSXofbWKFKojFRm8Q/QoWy SEIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=rOpUiR8n3d/m0SdjK8sAMw/3CX7PN8XqlvE3BZ5rD0k=; b=wEZksD3333SfxG2zg0SLsC0wteiH9Kc0Z2mT5w4wZKx18V4ZDTNMQnoC79mC0E9Pxr GHgDDRUwCJorGnxFb+onoRTU+TkoqeR8SuyFrDWDQyqd8ID3DGMnV72cyNACbdCWVv8n HfhDJ258wVs2SFDGLBiIuc7MVEsODYbW9ZP65K7KSaNqtoHeSoXBt2BTnX6W4778yQAg E45//axvbJcneffmuzzKZ+bC9lbTWZDbjbO84kEeTrtyFg2h4UpXztVnsEphYK4qDEmk K4JcC6PKvY67FU16ctgOAAXZQclLkffg4/qsA7AYIUMTA1D0ObQb9MjZzVqbGzvZThLR O6Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=EGE1LgCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8si6664488plo.305.2022.02.19.06.34.00; Sat, 19 Feb 2022 06:34:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=EGE1LgCB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240239AbiBRXyO (ORCPT + 99 others); Fri, 18 Feb 2022 18:54:14 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbiBRXyM (ORCPT ); Fri, 18 Feb 2022 18:54:12 -0500 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A07D40A15 for ; Fri, 18 Feb 2022 15:53:54 -0800 (PST) Received: by mail-io1-xd33.google.com with SMTP id t11so3691019ioi.7 for ; Fri, 18 Feb 2022 15:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rOpUiR8n3d/m0SdjK8sAMw/3CX7PN8XqlvE3BZ5rD0k=; b=EGE1LgCBRl3NkHrHJw/T6Giq8BHqYXQjHi+CLUSqJR3UyprEz0GI72cPWPOH4usAiu OuslpHfqCLmRXJHhk6EL3QXf8NnPRpsgTtfbqyJSnVTX6ZYBOUYVb/78tXu5mlOIkm7d jX282FuwadAI0JSrM8kDvO44jcXyPPhyIxTMY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rOpUiR8n3d/m0SdjK8sAMw/3CX7PN8XqlvE3BZ5rD0k=; b=qwrxq1FWO4aGBDG8LVte70cz9qxoytuLRsRibUGbugdXiZG+xfnvGRfIv8sd2clCFi zen2UcBHMcbcN7sSxGT33eTOjC2/dH8u6z5RLeLW0IhlRJxkQLGGYOviM0oMOB7jWzB2 Mnb9RMFWBfZUPCvm0/qbVDdCIXqD/ECKoYmtRcn+ULdp63X4xbKAWWUZZGaTUO1tSLSN jw4h/twPjsYq521nGcX4cMso4NQ71AjtOAmYcX7YEQ9C0itKMHc6GFQ0OBtJ368MM7v9 5zfjiGCs2xkNu6+G5sPmtvamFgQznJFgYIPoHMAkkaGC7aADRy0AouDEY65kcQdZYaZT BANA== X-Gm-Message-State: AOAM530GHNurZUUQV7aVclhqgbX2BbK3EYRJLiH8r/vMpRRDHkdDHY6J bHsCJ+oWMy4WFenmoi2AzP3oKg== X-Received: by 2002:a05:6638:1405:b0:30d:69cd:f44 with SMTP id k5-20020a056638140500b0030d69cd0f44mr6883109jad.208.1645228433847; Fri, 18 Feb 2022 15:53:53 -0800 (PST) Received: from [192.168.1.128] ([71.205.29.0]) by smtp.gmail.com with ESMTPSA id r7sm2317316ilc.24.2022.02.18.15.53.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Feb 2022 15:53:53 -0800 (PST) Subject: Re: [PATCH RESEND v6 5/9] cpupower: Introduce ACPI CPPC library To: Huang Rui , "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Deepak Sharma , Alex Deucher , Mario Limonciello , Steven Noonan , Nathan Fontenot , Jinzhou Su , Xiaojian Du , Perry Yuan , Jassmine Meng , Borislav Petkov , Peter Zijlstra , Ingo Molnar , Viresh Kumar , Steven Rostedt , Giovanni Gherdovich , linux-kernel@vger.kernel.org, Shuah Khan References: <20220216073558.751071-1-ray.huang@amd.com> <20220216073558.751071-6-ray.huang@amd.com> From: Shuah Khan Message-ID: <5e7bfce4-f326-930b-4a25-15538f741167@linuxfoundation.org> Date: Fri, 18 Feb 2022 16:53:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220216073558.751071-6-ray.huang@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/16/22 12:35 AM, Huang Rui wrote: > Kernel ACPI subsytem introduced the sysfs attributes for acpi cppc > library in below path: > > /sys/devices/system/cpu/cpuX/acpi_cppc/ > > And these attributes will be used for AMD P-State driver to provide some > performance and frequency values. > > Signed-off-by: Huang Rui > --- > tools/power/cpupower/Makefile | 6 +-- > tools/power/cpupower/lib/acpi_cppc.c | 59 ++++++++++++++++++++++++++++ > tools/power/cpupower/lib/acpi_cppc.h | 21 ++++++++++ > 3 files changed, 83 insertions(+), 3 deletions(-) > create mode 100644 tools/power/cpupower/lib/acpi_cppc.c > create mode 100644 tools/power/cpupower/lib/acpi_cppc.h > > diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile > index 3b1594447f29..e9b6de314654 100644 > --- a/tools/power/cpupower/Makefile > +++ b/tools/power/cpupower/Makefile > @@ -143,9 +143,9 @@ UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \ > utils/helpers/bitmask.h \ > utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def > > -LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h > -LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c > -LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o > +LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h > +LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c > +LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o > LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS)) > > override CFLAGS += -pipe > diff --git a/tools/power/cpupower/lib/acpi_cppc.c b/tools/power/cpupower/lib/acpi_cppc.c > new file mode 100644 > index 000000000000..a07a8922eca2 > --- /dev/null > +++ b/tools/power/cpupower/lib/acpi_cppc.c > @@ -0,0 +1,59 @@ > +// SPDX-License-Identifier: GPL-2.0-only > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "cpupower_intern.h" > +#include "acpi_cppc.h" > + > +/* ACPI CPPC sysfs access ***********************************************/ > + > +static int acpi_cppc_read_file(unsigned int cpu, const char *fname, > + char *buf, size_t buflen) > +{ > + char path[SYSFS_PATH_MAX]; > + > + snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/acpi_cppc/%s", > + cpu, fname); > + return cpupower_read_sysfs(path, buf, buflen); > +} > + > +static const char *acpi_cppc_value_files[] = { > + [HIGHEST_PERF] = "highest_perf", > + [LOWEST_PERF] = "lowest_perf", > + [NOMINAL_PERF] = "nominal_perf", > + [LOWEST_NONLINEAR_PERF] = "lowest_nonlinear_perf", > + [LOWEST_FREQ] = "lowest_freq", > + [NOMINAL_FREQ] = "nominal_freq", > + [REFERENCE_PERF] = "reference_perf", > + [WRAPAROUND_TIME] = "wraparound_time" > +}; > + > +unsigned long acpi_cppc_get_data(unsigned cpu, enum acpi_cppc_value which) unsigned int cpu > +{ > + unsigned long long value; > + unsigned int len; > + char linebuf[MAX_LINE_LEN]; > + char *endp; > + > + if (which >= MAX_CPPC_VALUE_FILES) > + return 0; > + > + len = acpi_cppc_read_file(cpu, acpi_cppc_value_files[which], > + linebuf, sizeof(linebuf)); > + if (len == 0) > + return 0; > + > + value = strtoull(linebuf, &endp, 0); > + > + if (endp == linebuf || errno == ERANGE) > + return 0; > + > + return value; > +} > diff --git a/tools/power/cpupower/lib/acpi_cppc.h b/tools/power/cpupower/lib/acpi_cppc.h > new file mode 100644 > index 000000000000..576291155224 > --- /dev/null > +++ b/tools/power/cpupower/lib/acpi_cppc.h > @@ -0,0 +1,21 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#ifndef __ACPI_CPPC_H__ > +#define __ACPI_CPPC_H__ > + > +enum acpi_cppc_value { > + HIGHEST_PERF, > + LOWEST_PERF, > + NOMINAL_PERF, > + LOWEST_NONLINEAR_PERF, > + LOWEST_FREQ, > + NOMINAL_FREQ, > + REFERENCE_PERF, > + WRAPAROUND_TIME, > + MAX_CPPC_VALUE_FILES > +}; > + > +extern unsigned long acpi_cppc_get_data(unsigned cpu, extern prototype in .h? unsigned int cpu > + enum acpi_cppc_value which); > + > +#endif /* _ACPI_CPPC_H */ > thanks, -- Shuah