master
h 96 lines 3 KB
Raw
1 /*
2 * QEMU KVM support -- x86 virtual energy-related MSR.
3 *
4 * Copyright 2024 Red Hat, Inc. 2024
5 *
6 * Author:
7 * Anthony Harivel <aharivel@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13
14 #ifndef VMSR_ENERGY_H
15 #define VMSR_ENERGY_H
16
17 #include "io/channel-socket.h"
18 #include "hw/i386/topology.h"
19
20 /*
21 * Define the interval time in micro seconds between 2 samples of
22 * energy related MSRs
23 */
24 #define MSR_ENERGY_THREAD_SLEEP_US 1000000.0
25
26 /*
27 * Thread statistic
28 * @ thread_id: TID (thread ID)
29 * @ is_vcpu: true if TID is vCPU thread
30 * @ cpu_id: CPU number last executed on
31 * @ pkg_id: package number of the CPU
32 * @ vcpu_id: vCPU ID
33 * @ vpkg: virtual package number
34 * @ acpi_id: APIC id of the vCPU
35 * @ utime: amount of clock ticks the thread
36 * has been scheduled in User mode
37 * @ stime: amount of clock ticks the thread
38 * has been scheduled in System mode
39 * @ delta_ticks: delta of utime+stime between
40 * the two samples (before/after sleep)
41 */
42 struct vmsr_thread_stat {
43 unsigned int thread_id;
44 bool is_vcpu;
45 unsigned int cpu_id;
46 unsigned int pkg_id;
47 unsigned int vpkg_id;
48 unsigned int vcpu_id;
49 unsigned long acpi_id;
50 unsigned long long *utime;
51 unsigned long long *stime;
52 unsigned long long delta_ticks;
53 };
54
55 /*
56 * Package statistic
57 * @ e_start: package energy counter before the sleep
58 * @ e_end: package energy counter after the sleep
59 * @ e_delta: delta of package energy counter
60 * @ e_ratio: store the energy ratio of non-vCPU thread
61 * @ nb_vcpu: number of vCPU running on this package
62 */
63 struct vmsr_package_energy_stat {
64 uint64_t e_start;
65 uint64_t e_end;
66 uint64_t e_delta;
67 uint64_t e_ratio;
68 unsigned int nb_vcpu;
69 };
70
71 typedef struct vmsr_thread_stat vmsr_thread_stat;
72 typedef struct vmsr_package_energy_stat vmsr_package_energy_stat;
73
74 char *vmsr_compute_default_paths(void);
75 void vmsr_read_thread_stat(pid_t pid,
76 unsigned int thread_id,
77 unsigned long long *utime,
78 unsigned long long *stime,
79 unsigned int *cpu_id);
80
81 QIOChannelSocket *vmsr_open_socket(const char *path);
82 uint64_t vmsr_read_msr(uint32_t reg, uint32_t cpu_id,
83 uint32_t tid, QIOChannelSocket *sioc);
84 void vmsr_delta_ticks(vmsr_thread_stat *thd_stat, int i);
85 unsigned int vmsr_get_maxcpus(void);
86 unsigned int vmsr_get_max_physical_package(unsigned int max_cpus);
87 unsigned int vmsr_count_cpus_per_package(unsigned int *package_count,
88 unsigned int max_pkgs);
89 int vmsr_get_physical_package_id(int cpu_id);
90 pid_t *vmsr_get_thread_ids(pid_t pid, unsigned int *num_threads);
91 double vmsr_get_ratio(uint64_t e_delta,
92 unsigned long long delta_ticks,
93 unsigned int maxticks);
94 void vmsr_init_topo_info(X86CPUTopoInfo *topo_info, const MachineState *ms);
95 int is_rapl_enabled(void);
96 #endif /* VMSR_ENERGY_H */