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"
|
|
|
|
|
2023-02-19 17:28:04 +08:00
|
|
|
bool smt_on(void)
|
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
|
2023-02-19 17:28:04 +08:00
|
|
|
cached_result = cpu_topology__smt_on(online_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
|
|
|
|
2023-02-19 17:28:04 +08:00
|
|
|
bool core_wide(bool system_wide, const char *user_requested_cpu_list)
|
2022-09-01 01:49:23 +08:00
|
|
|
{
|
|
|
|
/* 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. */
|
2023-02-19 17:28:04 +08:00
|
|
|
if (!smt_on())
|
2022-09-01 01:49:23 +08:00
|
|
|
return true;
|
|
|
|
|
2023-02-19 17:28:04 +08:00
|
|
|
return cpu_topology__core_wide(online_topology(), user_requested_cpu_list);
|
2022-09-01 01:49:23 +08:00
|
|
|
}
|