Re: [PATCH v2 3/3] perf tool: simplify checking active smt

From: Arnaldo Carvalho de Melo
Date: Wed Apr 29 2020 - 14:16:16 EST


Em Wed, Apr 29, 2020 at 07:23:41PM +0300, Konstantin Khlebnikov escreveu:
> SMT now could be disabled via "/sys/devices/system/cpu/smt/control".
> Status shown in "/sys/devices/system/cpu/smt/active" simply as "0" / "1".
>
> If this knob isn't here then fallback to checking topology as before.

I've manually applied this one, thanks, please check my perf/core branch
later before resending 2/3, thanks.

- Arnaldo

> Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
> ---
> tools/perf/util/smt.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/util/smt.c b/tools/perf/util/smt.c
> index dc37b5abd1c3..c398528d1006 100644
> --- a/tools/perf/util/smt.c
> +++ b/tools/perf/util/smt.c
> @@ -19,6 +19,9 @@ int smt_on(void)
> if (cached)
> return cached_result;
>
> + if (sysfs__read_int("devices/system/cpu/smt/active", &active) > 0)
> + goto done;
> +
> ncpu = sysconf(_SC_NPROCESSORS_CONF);
> for (cpu = 0; cpu < ncpu; cpu++) {
> char fn[256];
> @@ -37,6 +40,7 @@ int smt_on(void)
> active = str && (strchr(str, ',') != NULL || strchr(str, '-') != NULL);
> free(str);
>
> +done:
> if (!cached) {
> cached_result = active;
> cached = true;
>

--

- Arnaldo