hv: trace: show cpu usage of vms in pcpu sharing case

To maximize the cpu utilization, core 0 is usually shared by service
vm and guest vm. But there are no statistics to show the cpu occupation
of each vm.

This patch is to provide cpu usage statistic for users. To calculate
it, a new trace event is added and marked in scheduling context switch,
accompanying with a new python script to analyze the data from acrntrace
output.

Tracked-On: #8621
Signed-off-by: nacui <na.cui@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Reviewed-by: Haiwei Li <haiwei.li@intel.com>
This commit is contained in:
nacui
2024-06-14 11:16:25 +08:00
committed by acrnsi-robot
parent 926f2346df
commit 512c98fd79
6 changed files with 216 additions and 2 deletions

View File

@@ -13,6 +13,7 @@
#include <schedule.h>
#include <sprintf.h>
#include <asm/irq.h>
#include <trace.h>
bool is_idle_thread(const struct thread_object *obj)
{
@@ -172,6 +173,7 @@ void schedule(void)
struct thread_object *next = &per_cpu(idle, pcpu_id);
struct thread_object *prev = ctl->curr_obj;
uint64_t rflag;
char name[16];
obtain_schedule_lock(pcpu_id, &rflag);
if (ctl->scheduler->pick_next != NULL) {
@@ -182,6 +184,10 @@ void schedule(void)
/* If we picked different sched object, switch context */
if (prev != next) {
if (prev != NULL) {
memcpy_erms(name, prev->name, 4);
memcpy_erms(name + 4, next->name, 4);
memset(name + 8, 0, sizeof(name) - 8);
TRACE_16STR(TRACE_SCHED_NEXT, name);
if (prev->switch_out != NULL) {
prev->switch_out(prev);
}

View File

@@ -111,7 +111,7 @@ void TRACE_6C(uint32_t evid, uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4, uin
#define TRACE_ENTER TRACE_16STR(TRACE_FUNC_ENTER, __func__)
#define TRACE_EXIT TRACE_16STR(TRACE_FUNC_EXIT, __func__)
static inline void TRACE_16STR(uint32_t evid, const char name[])
void TRACE_16STR(uint32_t evid, const char name[])
{
struct trace_entry entry;
uint16_t cpu_id = get_pcpu_id();

View File

@@ -20,6 +20,10 @@
#define TRACE_VM_EXIT 0x10U
#define TRACE_VM_ENTER 0X11U
/* event to calculate cpu usage with shared pcpu */
#define TRACE_SCHED_NEXT 0x20U
#define TRACE_VMEXIT_ENTRY 0x10000U
#define TRACE_VMEXIT_EXCEPTION_OR_NMI (TRACE_VMEXIT_ENTRY + 0x00000000U)
@@ -44,5 +48,6 @@
void TRACE_2L(uint32_t evid, uint64_t e, uint64_t f);
void TRACE_4I(uint32_t evid, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
void TRACE_6C(uint32_t evid, uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4, uint8_t b1, uint8_t b2);
void TRACE_16STR(uint32_t evid, const char name[]);
#endif /* TRACE_H */