Skip to content

Commit

Permalink
Enable sysfeatures for ACCESSMODE=perf_event
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear committed Dec 2, 2024
1 parent 42865dd commit 3ee18d4
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 45 deletions.
29 changes: 24 additions & 5 deletions src/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,22 @@ int
HPMinit(void)
{
int ret = 0;
topology_init();
Configuration_t config = NULL;
ret = topology_init();
if (ret < 0)
{
errno = -ret;
ERROR_PRINT(Failed to initialize topology);
return ret;
}
ret = init_configuration();
if (ret < 0)
{
errno = -ret;
ERROR_PRINT(Failed to initialize configuration);
return ret;
}
config = get_configuration();
if (registeredCpuList == NULL)
{
registeredCpuList = malloc(cpuid_topology.numHWThreads* sizeof(int));
Expand All @@ -89,11 +104,11 @@ HPMinit(void)
if (access_init == NULL)
{
#if defined(__x86_64__) || defined(__i386__)
if (config.daemonMode == -1)
if (config->daemonMode == -2)
{
config.daemonMode = ACCESSMODE_DAEMON;
config->daemonMode = ACCESSMODE_DAEMON;
}
if (config.daemonMode == ACCESSMODE_DAEMON)
if (config->daemonMode == ACCESSMODE_DAEMON)
{
DEBUG_PLAIN_PRINT(DEBUGLEV_DEVELOP, Adjusting functions for x86 architecture in daemon mode);
access_init = &access_client_init;
Expand All @@ -102,7 +117,7 @@ HPMinit(void)
access_finalize = &access_client_finalize;
access_check = &access_client_check;
}
else if (config.daemonMode == ACCESSMODE_DIRECT)
else if (config->daemonMode == ACCESSMODE_DIRECT)
{
DEBUG_PLAIN_PRINT(DEBUGLEV_DEVELOP, Adjusting functions for x86 architecture in direct mode);
access_init = &access_x86_init;
Expand All @@ -111,6 +126,10 @@ HPMinit(void)
access_finalize = &access_x86_finalize;
access_check = &access_x86_check;
}
else
{
DEBUG_PLAIN_PRINT(DEBUGLEV_DEVELOP, HPMinit called in perf_event mode);
}
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ init_configuration(void)
{
config.daemonMode = ACCESSMODE_DIRECT;
}
else if (strcmp(value, "perf_event") == 0)
{
#ifdef LIKWID_USE_PERFEVENT
config.daemonMode = ACCESSMODE_PERF;
#else
ERROR_PRINT(Invalid access mode 'perf_event'. Library not built with 'perf_event' support);
#endif
}
}
else if (strcmp(name, "max_threads") == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/frequency_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ _freqInit(void)
if (freq_init_f == NULL)
{
#if defined(__x86_64__) || defined(__i386__)
if (config.daemonMode == -1)
if (config.daemonMode == -2)
{
config.daemonMode = ACCESSMODE_DAEMON;
}
Expand Down
33 changes: 32 additions & 1 deletion src/sysFeatures_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ int likwid_sysft_init_x86_amd(_SysFeatureList* out)
return (c > 0 ? 0 : -ENOTSUP);
}

static int amd_cpu_register_access_test()
{
int err = 0;
Configuration_t config = NULL;
err = init_configuration();
if (err < 0)
{
errno = -err;
ERROR_PRINT(Failed to initialize configuration);
return err;
}
config = get_configuration();
if (config->daemonMode == ACCESSMODE_PERF)
{
return 0;
}
err = HPMinit();
if (err < 0)
return err;
err = HPMaddThread(0);
if (err < 0)
return err;
return 1;
}

static int amd_cpu_l1_stream_getter(const LikwidDevice_t device, char** value)
{
return likwid_sysft_readmsr_bit_to_string(device, MSR_AMD19_PREFETCH_CONTROL, 0, true, value);
Expand Down Expand Up @@ -137,6 +162,7 @@ static _SysFeature amd_k19_cpu_prefetch_features[] = {
static const _SysFeatureList amd_k19_cpu_prefetch_feature_list = {
.num_features = ARRAY_COUNT(amd_k19_cpu_prefetch_features),
.features = amd_k19_cpu_prefetch_features,
.tester = amd_cpu_register_access_test,
};

static int amd_cpu_spec_ibrs_getter(const LikwidDevice_t device, char** value)
Expand Down Expand Up @@ -195,16 +221,19 @@ static _SysFeature amd_k17_cpu_speculation_features[] = {
static const _SysFeatureList amd_k19_cpu_speculation_feature_list = {
.num_features = ARRAY_COUNT(amd_k19_cpu_speculation_features),
.features = amd_k19_cpu_speculation_features,
.tester = amd_cpu_register_access_test,
};

static const _SysFeatureList amd_k17_cpu_speculation_feature_list = {
.num_features = ARRAY_COUNT(amd_k17_cpu_speculation_features),
.features = amd_k17_cpu_speculation_features,
.tester = amd_cpu_register_access_test,
};

static int amd_cpu_flush_l1(const LikwidDevice_t device, const char* value)
{
uint64_t flush;

int err = likwid_sysft_string_to_uint64(value, &flush);
if (err < 0)
return err;
Expand All @@ -224,6 +253,7 @@ static _SysFeature amd_k19_cpu_l1dflush_features[] = {
static const _SysFeatureList amd_k19_cpu_l1dflush_feature_list = {
.num_features = ARRAY_COUNT(amd_k19_cpu_l1dflush_features),
.features = amd_k19_cpu_l1dflush_features,
.tester = amd_cpu_register_access_test,
};

static int amd_cpu_hwconfig_cpddis_getter(const LikwidDevice_t device, char** value)
Expand All @@ -237,12 +267,13 @@ static int amd_cpu_hwconfig_cpddis_setter(const LikwidDevice_t device, const cha
}

static _SysFeature amd_k17_cpu_hwconfig_features[] = {
{"TurboMode", "cpufreq", "Specifies whether core performance boost is requested to be enabled or disabled", amd_cpu_hwconfig_cpddis_getter, amd_cpu_hwconfig_cpddis_setter, DEVICE_TYPE_HWTHREAD},
{"turbo_mode", "cpu_freq", "Specifies whether core performance boost is requested to be enabled or disabled", amd_cpu_hwconfig_cpddis_getter, amd_cpu_hwconfig_cpddis_setter, DEVICE_TYPE_HWTHREAD},
};

static const _SysFeatureList amd_k17_cpu_hwconfig_feature_list = {
.num_features = ARRAY_COUNT(amd_k17_cpu_hwconfig_features),
.features = amd_k17_cpu_hwconfig_features,
.tester = amd_cpu_register_access_test,
};

// models 0xA0 - 0xAF, 0x18
Expand Down
26 changes: 26 additions & 0 deletions src/sysFeatures_amd_rapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ static const _SysFeatureList amd_rapl_l3_feature_list = {
int likwid_sysft_init_amd_rapl(_SysFeatureList* out)
{
int err = 0;
Configuration_t config = NULL;
err = init_configuration();
if (err < 0)
{
errno = -err;
ERROR_PRINT(Failed to initialize configuration);
return err;
}
config = get_configuration();
if (config->daemonMode == ACCESSMODE_PERF)
{
DEBUG_PRINT(DEBUGLEV_INFO, No AMD RAPL support with accessmode=perf_event);
return 0;
}
if (amd_rapl_pkg_test())
{
DEBUG_PRINT(DEBUGLEV_INFO, Register AMD RAPL PKG domain);
Expand All @@ -207,6 +221,10 @@ int likwid_sysft_init_amd_rapl(_SysFeatureList* out)
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain PKG not supported);
}
}
else
{
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain PKG not supported);
}
if (amd_rapl_core_test())
{
DEBUG_PRINT(DEBUGLEV_INFO, Register AMD RAPL CORE domain);
Expand All @@ -216,6 +234,10 @@ int likwid_sysft_init_amd_rapl(_SysFeatureList* out)
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain CORE not supported);
}
}
else
{
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain CORE not supported);
}
if (amd_rapl_l3_test())
{
DEBUG_PRINT(DEBUGLEV_INFO, Register AMD RAPL L3 domain);
Expand All @@ -225,5 +247,9 @@ int likwid_sysft_init_amd_rapl(_SysFeatureList* out)
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain L3 not supported);
}
}
else
{
DEBUG_PRINT(DEBUGLEV_INFO, AMD RAPL domain L3 not supported);
}
return 0;
}
1 change: 1 addition & 0 deletions src/sysFeatures_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ int likwid_sysft_foreach_socket_testmsr_cb(uint64_t reg, likwid_sysft_msr_test_f
int err = topology_init();
if (err < 0)
return err;

err = HPMinit();
if (err < 0)
return err;
Expand Down
48 changes: 24 additions & 24 deletions src/sysFeatures_cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ static int cpufreq_acpi_test(void)
}

static _SysFeature cpufreq_acpi_features[] = {
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_acpi_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_acpi_min_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_acpi_max_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_acpi_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_acpi_min_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_acpi_max_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"avail_freqs", "cpu_freq", "Available CPU frequencies", cpufreq_acpi_avail_cpu_freqs_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_acpi_governor_getter, cpufreq_acpi_governor_setter, DEVICE_TYPE_HWTHREAD},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_acpi_governor_getter, /*cpufreq_acpi_governor_setter*/ NULL, DEVICE_TYPE_HWTHREAD},
{"avail_governors", "cpu_freq", "Available CPU frequency governors", cpufreq_acpi_avail_governors_getter, NULL, DEVICE_TYPE_HWTHREAD},
};

Expand Down Expand Up @@ -264,10 +264,10 @@ static int cpufreq_intel_pstate_test(void)
}

static _SysFeature cpufreq_pstate_features[] = {
{"base_freq", "cpu_freq", "Base CPU frequency", cpufreq_intel_pstate_base_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"base_freq", "cpu_freq", "Base CPU frequency", cpufreq_intel_pstate_base_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_intel_pstate_governor_getter, cpufreq_intel_pstate_governor_setter, DEVICE_TYPE_HWTHREAD},
{"avail_governors", "cpu_freq", "Available CPU frequency governors", cpufreq_intel_pstate_avail_governors_getter, NULL, DEVICE_TYPE_HWTHREAD},
};
Expand All @@ -288,9 +288,9 @@ static int cpufreq_intel_cpufreq_test(void)
/* INFO: Most sysfs entries are the same as for the intel_pstate driver,
* so they share the same getters. */
static _SysFeature cpufreq_intel_cpufreq_features[] = {
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_intel_pstate_governor_getter, cpufreq_intel_pstate_governor_setter, DEVICE_TYPE_HWTHREAD},
{"avail_governors", "cpu_freq", "Available CPU frequency governors", cpufreq_intel_pstate_avail_governors_getter, NULL, DEVICE_TYPE_HWTHREAD},
};
Expand Down Expand Up @@ -319,9 +319,9 @@ static int cpufreq_cppc_test(void)
}

static _SysFeature cpufreq_cppc_features[] = {
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"boost", "cpu_freq", "Turbo boost", cpufreq_cppc_boost_getter, cpufreq_cppc_boost_setter, DEVICE_TYPE_HWTHREAD},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_intel_pstate_governor_getter, cpufreq_intel_pstate_governor_setter, DEVICE_TYPE_HWTHREAD},
{"avail_governors", "cpu_freq", "Available CPU frequency governors", cpufreq_intel_pstate_avail_governors_getter, NULL, DEVICE_TYPE_HWTHREAD},
Expand All @@ -341,9 +341,9 @@ static int cpufreq_apple_cpufreq_test(void)
}

static _SysFeature cpufreq_apple_cpufreq_features[] = {
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD},
{"cur_cpu_freq", "cpu_freq", "Current CPU frequency", cpufreq_intel_pstate_cur_cpu_freq_getter, NULL, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"min_cpu_freq", "cpu_freq", "Minimal CPU frequency", cpufreq_intel_pstate_min_cpu_freq_getter, cpufreq_intel_pstate_min_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"max_cpu_freq", "cpu_freq", "Maximal CPU frequency", cpufreq_intel_pstate_max_cpu_freq_getter, cpufreq_intel_pstate_max_cpu_freq_setter, DEVICE_TYPE_HWTHREAD, NULL, "kHz"},
{"avail_freqs", "cpu_freq", "Available CPU frequencies", cpufreq_acpi_avail_cpu_freqs_getter, NULL, DEVICE_TYPE_HWTHREAD},
{"governor", "cpu_freq", "CPU frequency governor", cpufreq_intel_pstate_governor_getter, cpufreq_intel_pstate_governor_setter, DEVICE_TYPE_HWTHREAD},
{"avail_governors", "cpu_freq", "Available CPU frequency governors", cpufreq_intel_pstate_avail_governors_getter, NULL, DEVICE_TYPE_HWTHREAD},
Expand Down Expand Up @@ -418,7 +418,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
int err = 0;
if (cpufreq_intel_pstate_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering Intel Pstate knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering Intel Pstate knobs for cpufreq)
err = likwid_sysft_register_features(out, &cpufreq_pstate_feature_list);
if (err < 0)
{
Expand All @@ -427,7 +427,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
}
else if (cpufreq_intel_cpufreq_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering Intel Cpufreq knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering Intel Cpufreq knobs for cpufreq)
err = likwid_sysft_register_features(out, &cpufreq_intel_cpufreq_feature_list);
if (err < 0)
{
Expand All @@ -436,7 +436,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
}
else if (cpufreq_acpi_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering ACPI cpufreq knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering ACPI cpufreq knobs for cpufreq)
likwid_sysft_register_features(out, &cpufreq_acpi_feature_list);
if (err < 0)
{
Expand All @@ -445,7 +445,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
}
else if (cpufreq_cppc_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering CPPC cpufreq knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering CPPC cpufreq knobs for cpufreq)
likwid_sysft_register_features(out, &cpufreq_cppc_feature_list);
if (err < 0)
{
Expand All @@ -454,7 +454,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
}
else if (cpufreq_apple_cpufreq_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering Apple cpufreq knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering Apple cpufreq knobs for cpufreq)
likwid_sysft_register_features(out, &cpufreq_apple_cpufreq_feature_list);
if (err < 0)
{
Expand All @@ -464,7 +464,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)

if (cpufreq_epp_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering Energy Performance Preference knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering Energy Performance Preference knobs for cpufreq)
err = likwid_sysft_register_features(out, &cpufreq_epp_feature_list);
if (err < 0)
{
Expand All @@ -473,7 +473,7 @@ int likwid_sysft_init_cpufreq(_SysFeatureList* out)
}
if (cpufreq_scaling_driver_test())
{
DEBUG_PRINT(DEBUGLEV_DEVELOP, Registering Scaling Driver knobs for cpufreq)
DEBUG_PRINT(DEBUGLEV_INFO, Registering Scaling Driver knobs for cpufreq)
err = likwid_sysft_register_features(out, &cpufreq_scaling_driver_feature_list);
if (err < 0)
{
Expand Down
Loading

0 comments on commit 3ee18d4

Please sign in to comment.