From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8431BA0C4A; Thu, 8 Jul 2021 14:49:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 474E640696; Thu, 8 Jul 2021 14:49:20 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 32D964014F for ; Thu, 8 Jul 2021 14:49:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625748557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lyHz+xt8TBHQEpB6B2zm5vEaG4YtyJI2e4UMbDYQKm4=; b=Yghzh7qHKIxYISCqDTnGejLf3rmhCrxY4AFHIwA4HV9/+Iv1KbbecmPJ2rvmO7XmTf32Z9 kzQlSx75lT/lndsVjXPAOnEoiqORMjWeCm4Yshr8u5cbHWOOa3pD7LLe/B4G3/+gNfwltB 2wMvmy8WX9y2IYpk9+oi1+i7Fq91qhM= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-EMNmlEpqMxmEP91UKtoDdA-1; Thu, 08 Jul 2021 08:49:16 -0400 X-MC-Unique: EMNmlEpqMxmEP91UKtoDdA-1 Received: by mail-vk1-f199.google.com with SMTP id j5-20020a1fa0050000b0290256e0128074so1148966vke.8 for ; Thu, 08 Jul 2021 05:49:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lyHz+xt8TBHQEpB6B2zm5vEaG4YtyJI2e4UMbDYQKm4=; b=Kf04aNEPruoDkA0cpe89pQFu2EX6+Hcg/Z1ce7YpGgKa6L1AYLXzNKsq7C5DK+eKNQ 3ccjE49BasCcspWe+HN559Es5HYPiTQSLv9KItmP9NPEzGRq06wPWCJDqUKY8pQg91Sc jyvIFghE2prjeaby+zrob7gAa3czkOySfkSg525ZnnBX53o4atuTIIJY+R9CdYYEf5hP RQVSteMc9CSyf3LJHfVam99A4/XDn+FfHWAkzQVJpen/uZ9/NVacwRS4+/jJQHVKuHeY tcsydqiqS7pQ6/zlTfrUZF14NkSYFfBjltCXfOMv2RkDD7PUp6oucm3Dsg+vlpsi3ppK O2Bg== X-Gm-Message-State: AOAM531+qEC5fXZO8t4I1M0fF6T7sbL1cVdrdUuoNFxh8L5ktZ9K0TIm 6166LOaM1QVk4epZsL36t/K/INak+gBQV4EeiA//wKgF/yUHA5bj1i6F08FodMQNR9oJOtf5QuJ w+ANJDLiS8Vvimtr20MY= X-Received: by 2002:a67:df85:: with SMTP id x5mr27866118vsk.17.1625748555761; Thu, 08 Jul 2021 05:49:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbHkZKh6aS/s3D3aXRwixHOY2GyPWjOAtU95RXbDfUOiAdTM4c73X3xc1y3Ge8sMXrq8jif5fpXmO3/1C3k6c= X-Received: by 2002:a67:df85:: with SMTP id x5mr27866091vsk.17.1625748555555; Thu, 08 Jul 2021 05:49:15 -0700 (PDT) MIME-Version: 1.0 References: <20210622125853.2798-1-david.hunt@intel.com> <20210623120342.36321-1-david.hunt@intel.com> <20210623120342.36321-2-david.hunt@intel.com> In-Reply-To: <20210623120342.36321-2-david.hunt@intel.com> From: David Marchand Date: Thu, 8 Jul 2021 14:49:04 +0200 Message-ID: To: David Hunt , "Burakov, Anatoly" Cc: dev , Richael.Zhuang@arm.com, Stephen Hemminger , "Pattan, Reshma" , nd Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v6 2/2] power: refactor pstate and acpi code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, Jun 23, 2021 at 2:04 PM David Hunt wrote: > > From: Anatoly Burakov > > Currently, ACPI and PSTATE modes have lots of code duplication, > confusing logic, and a bunch of other issues that can, and have, led to > various bugs and resource leaks. > > This commit factors out the common parts of sysfs reading/writing for > ACPI and PSTATE drivers. > > Signed-off-by: Anatoly Burakov > Signed-off-by: David Hunt > > --- > changes in v5 > * fixed bugs raised by Richael Zhuang in review - open file rw+, etc. > * removed FOPS* and FOPEN* macros, which contained control statements. > * fixed some checkpatch warnings. > changes in v6 > * fixed check of fputs return, negative on error. > --- > lib/power/meson.build | 7 + > lib/power/power_acpi_cpufreq.c | 192 ++++------------ > lib/power/power_common.c | 146 ++++++++++++ > lib/power/power_common.h | 17 ++ > lib/power/power_pstate_cpufreq.c | 374 ++++++++++--------------------- > 5 files changed, 335 insertions(+), 401 deletions(-) > > diff --git a/lib/power/meson.build b/lib/power/meson.build > index c1097d32f1..74c5f3a294 100644 > --- a/lib/power/meson.build > +++ b/lib/power/meson.build > @@ -5,6 +5,13 @@ if not is_linux > build = false > reason = 'only supported on Linux' > endif > + > +# we do some snprintf magic so silence format-nonliteral > +flag_nonliteral = '-Wno-format-nonliteral' > +if cc.has_argument(flag_nonliteral) > + cflags += flag_nonliteral > +endif > + This can be removed with __rte_format_printf tag + API change below. > sources = files( > 'guest_channel.c', > 'power_acpi_cpufreq.c', [snip] > diff --git a/lib/power/power_common.c b/lib/power/power_common.c > index 67e3318ec7..4deb343dae 100644 > --- a/lib/power/power_common.c > +++ b/lib/power/power_common.c > @@ -3,13 +3,20 @@ > */ > > #include > +#include > #include > #include > > +#include > +#include > + > #include "power_common.h" > > #define POWER_SYSFILE_SCALING_DRIVER \ > "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver" > +#define POWER_SYSFILE_GOVERNOR \ > + "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor" > +#define POWER_CONVERT_TO_DECIMAL 10 > > int > cpufreq_check_scaling_driver(const char *driver_name) > @@ -58,3 +65,142 @@ cpufreq_check_scaling_driver(const char *driver_name) > */ > return 1; > } cpufreq_check_scaling_driver can use open_core_sysfs_file, right? > + > +int > +open_core_sysfs_file(const char *template, unsigned int core, const char *mode, > + FILE **f) > +{ > + char fullpath[PATH_MAX]; > + FILE *tmpf; > + > + /* silenced -Wformat-nonliteral here */ > + snprintf(fullpath, sizeof(fullpath), template, core); > + tmpf = fopen(fullpath, mode); > + *f = tmpf; > + if (tmpf == NULL) > + return -1; > + > + return 0; > +} @@ -67,14 +67,15 @@ cpufreq_check_scaling_driver(const char *driver_name) } int -open_core_sysfs_file(const char *template, unsigned int core, const char *mode, - FILE **f) +open_core_sysfs_file(FILE **f, const char *mode, const char *format, ...) { char fullpath[PATH_MAX]; + va_list ap; FILE *tmpf; - /* silenced -Wformat-nonliteral here */ - snprintf(fullpath, sizeof(fullpath), template, core); + va_start(ap, format); + vsnprintf(fullpath, sizeof(fullpath), format, ap); + va_end(ap); tmpf = fopen(fullpath, mode); *f = tmpf; if (tmpf == NULL) With declaration in .h as: @@ -7,6 +7,8 @@ #include +#include + #define RTE_POWER_INVALID_FREQ_INDEX (~0) @@ -21,8 +23,8 @@ int cpufreq_check_scaling_driver(const char *driver); int power_set_governor(unsigned int lcore_id, const char *new_governor, char *orig_governor, size_t orig_governor_len); -int open_core_sysfs_file(const char *template, unsigned int core, - const char *mode, FILE **f); +int open_core_sysfs_file(FILE **f, const char *mode, const char *format, ...) + __rte_format_printf(3, 4); int read_core_sysfs_u32(FILE *f, uint32_t *val); int read_core_sysfs_s(FILE *f, char *buf, unsigned int len); int write_core_sysfs_s(FILE *f, const char *str); This leaves the possibility to use any kind of formats. And to be honest, I did not manage to make gcc happy otherwise (even when passing __rte_format_printf(3, 0)). -- David Marchand