2022-08-31 00:48:39 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2022-09-01 01:49:22 +08:00
|
|
|
#include <string.h>
|
2017-08-12 07:26:22 +08:00
|
|
|
#include "api/fs/fs.h"
|
2022-09-01 01:49:22 +08:00
|
|
|
#include "cputopo.h"
|
2017-08-12 07:26:22 +08:00
|
|
|
#include "smt.h"
|
|
|
|
|
2022-09-01 01:49:22 +08:00
|
|
|
bool smt_on(const struct cpu_topology *topology)
|
2017-08-12 07:26:22 +08:00
|
|
|
{
|
|
|
|
static bool cached;
|
2022-09-01 01:49:22 +08:00
|
|
|
static bool cached_result;
|
|
|
|
int fs_value;
|
2017-08-12 07:26:22 +08:00
|
|
|
|
|
|
|
if (cached)
|
|
|
|
return cached_result;
|
|
|
|
|
2022-09-01 01:49:22 +08:00
|
|
|
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);
|
2017-08-12 07:26:22 +08:00
|
|
|
|
2021-11-24 08:12:30 +08:00
|
|
|
cached = true;
|
2017-08-12 07:26:22 +08:00
|
|
|
return cached_result;
|
|
|
|
}
|
2022-09-01 01:49:23 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|