cpupower/rapl_monitor.patch
Tomáš Chvátal 65567d6f5a Accepting request 752877 from home:trenn:branches:hardware
- Update intel-speed-select to latest 5.5-rc1 kernel version
  latest mainline commit:
  commit b3abfd778bf1dbdd
- Update cpupower to latest 5.5-rc1 kernel version
  latest mainline commit:
  commit 4611a4fb0cce3
  Fixes aperf/mperf monitoring on latest AMD Rome CPUs (bsc#1152967)
- Fix library API breakage (bsc#1154240)
A libcpupower_fix_api_cpufreq_get_frequencies_breakage.patch

OBS-URL: https://build.opensuse.org/request/show/752877
OBS-URL: https://build.opensuse.org/package/show/hardware/cpupower?expand=0&rev=102
2019-12-02 12:03:46 +00:00

193 lines
5.2 KiB
Diff

cpupower: rapl monitor - shows the used power consumption in uj for each rapl domain
Signed-off-by: Thomas Renninger <trenn@suse.com>
Index: cpupower-5.5/Makefile
===================================================================
--- cpupower-5.5.orig/Makefile 2019-11-28 14:44:23.261812260 +0100
+++ cpupower-5.5/Makefile 2019-11-28 14:44:28.457812540 +0100
@@ -131,6 +131,7 @@ UTIL_OBJS = utils/helpers/amd.o utils/h
utils/idle_monitor/hsw_ext_idle.o \
utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
+ utils/idle_monitor/rapl_monitor.o \
utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
utils/cpuidle-set.o utils/powercap-info.o
Index: cpupower-5.5/utils/idle_monitor/cpupower-monitor.c
===================================================================
--- cpupower-5.5.orig/utils/idle_monitor/cpupower-monitor.c 2019-11-28 14:44:23.261812260 +0100
+++ cpupower-5.5/utils/idle_monitor/cpupower-monitor.c 2019-11-28 14:44:28.457812540 +0100
@@ -457,9 +457,10 @@ int cmd_monitor(int argc, char **argv)
print_results(1, cpu);
}
- for (num = 0; num < avail_monitors; num++)
- monitors[num]->unregister();
-
+ for (num = 0; num < avail_monitors; num++) {
+ if (monitors[num]->unregister)
+ monitors[num]->unregister();
+ }
cpu_topology_release(cpu_top);
return 0;
}
Index: cpupower-5.5/utils/idle_monitor/idle_monitors.def
===================================================================
--- cpupower-5.5.orig/utils/idle_monitor/idle_monitors.def 2019-11-28 14:44:23.261812260 +0100
+++ cpupower-5.5/utils/idle_monitor/idle_monitors.def 2019-11-28 14:44:28.457812540 +0100
@@ -4,5 +4,6 @@ DEF(intel_nhm)
DEF(intel_snb)
DEF(intel_hsw_ext)
DEF(mperf)
+DEF(rapl)
#endif
DEF(cpuidle_sysfs)
Index: cpupower-5.5/utils/idle_monitor/rapl_monitor.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ cpupower-5.5/utils/idle_monitor/rapl_monitor.c 2019-11-28 14:44:54.909813966 +0100
@@ -0,0 +1,141 @@
+/*
+ * (C) 2016 Thomas Renninger <trenn@suse.com>
+ *
+ * Licensed under the terms of the GNU GPL License version 2.
+ *
+ */
+
+#if defined(__i386__) || defined(__x86_64__)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <time.h>
+#include <string.h>
+
+#include <pci/pci.h>
+
+#include "idle_monitor/cpupower-monitor.h"
+#include "helpers/helpers.h"
+#include "powercap.h"
+
+#define MAX_RAPL_ZONES 10
+
+int rapl_zone_count = 0;
+cstate_t rapl_zones[MAX_RAPL_ZONES];
+struct powercap_zone *rapl_zones_pt[MAX_RAPL_ZONES] = { 0 };
+
+unsigned long long rapl_zone_previous_count[MAX_RAPL_ZONES];
+unsigned long long rapl_zone_current_count[MAX_RAPL_ZONES];
+unsigned long long rapl_max_count;
+
+static int rapl_get_count_uj(unsigned int id, unsigned long long *count,
+ unsigned int cpu)
+{
+ if (rapl_zones_pt[id] == NULL)
+ /* error */
+ return -1;
+
+ *count = rapl_zone_current_count[id] - rapl_zone_previous_count[id];
+
+ return 0;
+}
+
+static int powercap_count_zones(struct powercap_zone *zone)
+{
+ if (rapl_zone_count >= MAX_RAPL_ZONES)
+ return -1;
+
+ if (!zone->has_energy_uj)
+ return 0;
+
+ strncpy(rapl_zones[rapl_zone_count].name, zone->name, CSTATE_NAME_LEN - 1);
+ strcpy(rapl_zones[rapl_zone_count].desc, "");
+ rapl_zones[rapl_zone_count].id = rapl_zone_count;
+ rapl_zones[rapl_zone_count].range = RANGE_MACHINE;
+ rapl_zones[rapl_zone_count].get_count = rapl_get_count_uj;
+ rapl_zones_pt[rapl_zone_count] = zone;
+ rapl_zone_count++;
+
+ return 0;
+}
+
+static int rapl_start(void)
+{
+ int i, ret;
+ uint64_t uj_val;
+
+ for (i = 0; i < rapl_zone_count; i++) {
+ ret = powercap_get_energy_uj(rapl_zones_pt[i], &uj_val);
+ if (ret)
+ return ret;
+ rapl_zone_previous_count[i] = uj_val;
+ }
+
+ return 0;
+}
+
+static int rapl_stop(void)
+{
+ int i;
+ uint64_t uj_val;
+
+ for (i = 0; i < rapl_zone_count; i++) {
+ int ret;
+ ret = powercap_get_energy_uj(rapl_zones_pt[i], &uj_val);
+ if (ret)
+ return ret;
+ rapl_zone_current_count[i] = uj_val;
+ if (rapl_max_count < uj_val)
+ rapl_max_count = uj_val - rapl_zone_previous_count[i];
+ }
+ return 0;
+}
+
+struct cpuidle_monitor *rapl_register(void)
+{
+ struct powercap_zone *root_zone;
+ char line[MAX_LINE_LEN] = "";
+ int ret, val;
+
+ ret = powercap_get_driver(line, MAX_LINE_LEN);
+ if (ret < 0) {
+ dprint("No powercapping driver loaded\n");
+ return NULL;
+ }
+
+ dprint("Driver: %s\n", line);
+ ret = powercap_get_enabled(&val);
+ if (ret < 0)
+ return NULL;
+ if (!val) {
+ dprint("Powercapping is disabled\n");
+ return NULL;
+ }
+
+ dprint("Powercap domain hierarchy:\n\n");
+ root_zone = powercap_init_zones();
+
+ if (root_zone == NULL) {
+ dprint("No powercap info found\n");
+ return NULL;
+ }
+
+ powercap_walk_zones(root_zone, powercap_count_zones);
+ rapl_monitor.hw_states_num = rapl_zone_count;
+
+ return &rapl_monitor;
+}
+
+struct cpuidle_monitor rapl_monitor = {
+ .name = "RAPL",
+ .hw_states = rapl_zones,
+ .hw_states_num = 0,
+ .start = rapl_start,
+ .stop = rapl_stop,
+ .do_register = rapl_register,
+ .flags.needs_root = 0,
+ .overflow_s = 60 * 60 * 24 * 100, /* To be implemented */
+};
+
+#endif