DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Hunt <david.hunt@intel.com>
To: David Marchand <david.marchand@redhat.com>,
	"Burakov, Anatoly" <anatoly.burakov@intel.com>
Cc: dev <dev@dpdk.org>,
	Richael.Zhuang@arm.com,
	Stephen Hemminger <stephen@networkplumber.org>,
	"Pattan, Reshma" <reshma.pattan@intel.com>, nd <nd@arm.com>
Subject: Re: [dpdk-dev] [PATCH v6 2/2] power: refactor pstate and acpi code
Date: Thu, 8 Jul 2021 14:33:19 +0100	[thread overview]
Message-ID: <b9acb12e-6912-b482-3e0e-d270a59f7214@intel.com> (raw)
In-Reply-To: <CAJFAV8yuF_SoUgMRT4VZr9J_+BdxXmGLD2fWykvFvhe82TFxTw@mail.gmail.com>


On 8/7/2021 1:49 PM, David Marchand wrote:
> On Wed, Jun 23, 2021 at 2:04 PM David Hunt <david.hunt@intel.com> wrote:
>> From: Anatoly Burakov <anatoly.burakov@intel.com>
>>
>> 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 <anatoly.burakov@intel.com>
>> Signed-off-by: David Hunt <david.hunt@intel.com>
>>
>> ---
>> 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 <limits.h>
>> +#include <stdlib.h>
>>   #include <stdio.h>
>>   #include <string.h>
>>
>> +#include <rte_log.h>
>> +#include <rte_string_fns.h>
>> +
>>   #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 <inttypes.h>
>
> +#include <rte_common.h>
> +
>   #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)).


Thanks, David, good suggestions.  I'll make those changes and respin.

Rgds,
Dave.


>

  reply	other threads:[~2021-07-08 13:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 15:05 [dpdk-dev] [PATCH 21.08] power: refactor pstate sysfs handling Anatoly Burakov
2021-04-02  9:27 ` [dpdk-dev] [21.08 v2] " Anatoly Burakov
2021-04-02 17:45 ` [dpdk-dev] [PATCH 21.08] " Stephen Hemminger
2021-04-06 10:06   ` Burakov, Anatoly
2021-04-02 17:46 ` Stephen Hemminger
2021-04-06 10:05   ` Burakov, Anatoly
2021-04-22 15:08     ` [dpdk-dev] [21.08 PATCH v3 1/1] " Anatoly Burakov
2021-04-23 11:03       ` [dpdk-dev] [21.08 PATCH v4 1/2] power: don't use rte prefix in internal code Anatoly Burakov
2021-05-31 10:23         ` David Hunt
2021-06-22 12:43         ` [dpdk-dev] [PATCH v2 " David Hunt
2021-06-22 12:43           ` [dpdk-dev] [PATCH v2 2/2] power: refactor pstate and acpi code David Hunt
2021-06-22 13:00             ` David Hunt
2021-06-22 12:59           ` [dpdk-dev] [PATCH v2 1/2] power: don't use rte prefix in internal code David Hunt
2021-06-22 12:58         ` [dpdk-dev] [PATCH v5 " David Hunt
2021-06-22 12:58           ` [dpdk-dev] [PATCH v5 2/2] power: refactor pstate and acpi code David Hunt
2021-06-22 13:27             ` David Hunt
2021-06-23  8:54               ` Richael Zhuang
2021-06-23  9:00                 ` David Hunt
2021-06-23 12:03           ` [dpdk-dev] [PATCH v6 1/2] power: don't use rte prefix in internal code David Hunt
2021-06-23 12:03             ` [dpdk-dev] [PATCH v6 2/2] power: refactor pstate and acpi code David Hunt
2021-06-23 12:27               ` Burakov, Anatoly
2021-06-30  5:32               ` Richael Zhuang
2021-07-08 12:49               ` David Marchand
2021-07-08 13:33                 ` David Hunt [this message]
2021-07-08 15:38             ` [dpdk-dev] [PATCH v7 1/2] power: don't use rte prefix in internal code David Hunt
2021-07-08 15:38               ` [dpdk-dev] [PATCH v7 2/2] power: refactor pstate and acpi code David Hunt
2021-07-08 20:41               ` [dpdk-dev] [PATCH v7 1/2] power: don't use rte prefix in internal code David Marchand
2021-04-23 11:03       ` [dpdk-dev] [21.08 PATCH v4 2/2] power: refactor pstate and acpi code Anatoly Burakov
2021-05-07  2:13         ` Richael Zhuang
2021-05-07  9:49           ` Burakov, Anatoly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9acb12e-6912-b482-3e0e-d270a59f7214@intel.com \
    --to=david.hunt@intel.com \
    --cc=Richael.Zhuang@arm.com \
    --cc=anatoly.burakov@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=nd@arm.com \
    --cc=reshma.pattan@intel.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).