2 * QEMU KVM support -- x86 virtual energy-related MSR.
4 * Copyright 2024 Red Hat, Inc. 2024
7 * Anthony Harivel <aharivel@redhat.com>
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.
18 #include "qemu/osdep.h"
19 #include "io/channel-socket.h"
20 #include "hw/i386/topology.h"
23 * Define the interval time in micro seconds between 2 samples of
26 #define MSR_ENERGY_THREAD_SLEEP_US 1000000.0
30 * @ thread_id: TID (thread ID)
31 * @ is_vcpu: true if TID is vCPU thread
32 * @ cpu_id: CPU number last executed on
33 * @ pkg_id: package number of the CPU
35 * @ vpkg: virtual package number
36 * @ acpi_id: APIC id of the vCPU
37 * @ utime: amount of clock ticks the thread
38 * has been scheduled in User mode
39 * @ stime: amount of clock ticks the thread
40 * has been scheduled in System mode
41 * @ delta_ticks: delta of utime+stime between
42 * the two samples (before/after sleep)
44 struct vmsr_thread_stat
{
45 unsigned int thread_id
;
51 unsigned long acpi_id
;
52 unsigned long long *utime
;
53 unsigned long long *stime
;
54 unsigned long long delta_ticks
;
59 * @ e_start: package energy counter before the sleep
60 * @ e_end: package energy counter after the sleep
61 * @ e_delta: delta of package energy counter
62 * @ e_ratio: store the energy ratio of non-vCPU thread
63 * @ nb_vcpu: number of vCPU running on this package
65 struct vmsr_package_energy_stat
{
73 typedef struct vmsr_thread_stat vmsr_thread_stat
;
74 typedef struct vmsr_package_energy_stat vmsr_package_energy_stat
;
76 char *vmsr_compute_default_paths(void);
77 void vmsr_read_thread_stat(pid_t pid
,
78 unsigned int thread_id
,
79 unsigned long long *utime
,
80 unsigned long long *stime
,
81 unsigned int *cpu_id
);
83 QIOChannelSocket
*vmsr_open_socket(const char *path
);
84 uint64_t vmsr_read_msr(uint32_t reg
, uint32_t cpu_id
,
85 uint32_t tid
, QIOChannelSocket
*sioc
);
86 void vmsr_delta_ticks(vmsr_thread_stat
*thd_stat
, int i
);
87 unsigned int vmsr_get_maxcpus(void);
88 unsigned int vmsr_get_max_physical_package(unsigned int max_cpus
);
89 unsigned int vmsr_count_cpus_per_package(unsigned int *package_count
,
90 unsigned int max_pkgs
);
91 int vmsr_get_physical_package_id(int cpu_id
);
92 pid_t
*vmsr_get_thread_ids(pid_t pid
, unsigned int *num_threads
);
93 double vmsr_get_ratio(uint64_t e_delta
,
94 unsigned long long delta_ticks
,
95 unsigned int maxticks
);
96 void vmsr_init_topo_info(X86CPUTopoInfo
*topo_info
, const MachineState
*ms
);
97 bool is_host_cpu_intel(void);
98 int is_rapl_enabled(void);
99 #endif /* VMSR_ENERGY_H */