mirror of
https://github.com/torvalds/linux.git
synced 2026-11-28 01:13:11 +00:00
It is possible to optimize metrics when all SMT threads (CPUs) on a core are measuring events in system wide mode. For example, TMA metrics defines CORE_CLKS for Sandybrdige as: if SMT is disabled: CPU_CLK_UNHALTED.THREAD if SMT is enabled and recording on all SMT threads: CPU_CLK_UNHALTED.THREAD_ANY / 2 if SMT is enabled and not recording on all SMT threads: (CPU_CLK_UNHALTED.THREAD/2)* (1+CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE/CPU_CLK_UNHALTED.REF_XCLK ) That is two more events are necessary when not gathering counts on all SMT threads. To distinguish all SMT threads on a core vs system wide (all CPUs) call the new property core wide. Add a core wide test that determines the property from user requested CPUs, the topology and system wide. System wide is required as other processes running on a SMT thread will change the counts. Signed-off-by: Ian Rogers <[email protected]> Cc: Ahmad Yasin <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Caleb Biggers <[email protected]> Cc: Florian Fischer <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Kshipra Bopardikar <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Miaoqian Lin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Perry Taylor <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Xing Zhengjun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
38 lines
916 B
C
38 lines
916 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include <string.h>
|
|
#include "api/fs/fs.h"
|
|
#include "cputopo.h"
|
|
#include "smt.h"
|
|
|
|
bool smt_on(const struct cpu_topology *topology)
|
|
{
|
|
static bool cached;
|
|
static bool cached_result;
|
|
int fs_value;
|
|
|
|
if (cached)
|
|
return cached_result;
|
|
|
|
if (sysfs__read_int("devices/system/cpu/smt/active", &fs_value) >= 0)
|
|
cached_result = (fs_value == 1);
|
|
else
|
|
cached_result = cpu_topology__smt_on(topology);
|
|
|
|
cached = true;
|
|
return cached_result;
|
|
}
|
|
|
|
bool core_wide(bool system_wide, const char *user_requested_cpu_list,
|
|
const struct cpu_topology *topology)
|
|
{
|
|
/* If not everything running on a core is being recorded then we can't use core_wide. */
|
|
if (!system_wide)
|
|
return false;
|
|
|
|
/* Cheap case that SMT is disabled and therefore we're inherently core_wide. */
|
|
if (!smt_on(topology))
|
|
return true;
|
|
|
|
return cpu_topology__core_wide(topology, user_requested_cpu_list);
|
|
}
|