All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@suse.de>
To: Artem Bityutskiy <dedekind1@gmail.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	Linux PM Mailing List <linux-pm@vger.kernel.org>
Subject: Re: [PATCH] tools/power/turbostat: fix compatibility with older kernels
Date: Wed, 27 Jan 2021 19:59:57 +0100	[thread overview]
Message-ID: <20210127185957.GD8115@zn.tnic> (raw)
In-Reply-To: <20210127132444.981120-1-dedekind1@gmail.com>

On Wed, Jan 27, 2021 at 03:24:44PM +0200, Artem Bityutskiy wrote:
> From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
> 
> Commit
> 
> 6d6501d912a9 tools/power/turbostat: Read energy_perf_bias from sysfs
> 
> added a useful EPB print by reading EPB from sysfs's 'energy_perf_bias' file.
> However, older kernels, which do not necessarily have that sysfs file (e.g.,
> Centos 7's stock kernel does not have it). As a result, turbostat fails with
> older kernels.
> 
> This patch fixes the problem by ignoring the sysfs file read errors.
> 
> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
> ---
>  tools/power/x86/turbostat/turbostat.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
> index 389ea5209a83..12e014f2c24b 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -1839,7 +1839,9 @@ int get_epb(int cpu)
>  
>  	sprintf(path, "/sys/devices/system/cpu/cpu%d/power/energy_perf_bias", cpu);
>  
> -	fp = fopen_or_die(path, "r");
> +	fp = fopen(path, "r");
> +	if (!fp)
> +		return -1;
>  
>  	ret = fscanf(fp, "%d", &epb);
>  	if (ret != 1)

So I was under the impression that things in tools/ are tied to the
kernel version they're shipped with. Which means, you should probably
get the one from the centos kernel.

However, if this is supposed to work on older kernels too, then

  6d6501d912a9 ("tools/power/turbostat: Read energy_perf_bias from sysfs")

would need to be extended to first test the sysfs file's existence and
if not there, fall back to the MSR reading...

-- 
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg

  reply	other threads:[~2021-01-27 19:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 13:24 [PATCH] tools/power/turbostat: fix compatibility with older kernels Artem Bityutskiy
2021-01-27 18:59 ` Borislav Petkov [this message]
2021-01-27 20:15   ` Doug Smythies
2021-01-27 20:33     ` Borislav Petkov
2021-01-28 17:10       ` Borislav Petkov
2021-02-03 11:06 ` [tip: x86/urgent] tools/power/turbostat: Fallback to an MSR read for EPB tip-bot2 for Borislav Petkov

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=20210127185957.GD8115@zn.tnic \
    --to=bp@suse.de \
    --cc=dedekind1@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.