Skip to content

Commit

Permalink
powerpc/perf: Add per-task/process monitoring to vpa_pmu driver
Browse files Browse the repository at this point in the history
Enhance the vpa_pmu driver with a feature to observe context switch
latency event for both per-task (tid) and per-pid (pid) option.
Couple of new helper functions are added to hide the abstraction of
reading the context switch latency counter from kvm_vcpu_arch struct
and these helper functions are defined in the "kvm/book3s_hv.c".

"PERF_ATTACH_TASK" flag is used to decide whether to read the counter
values from lppaca or kvm_vcpu_arch struct.

Signed-off-by: Kajol Jain <[email protected]>
Signed-off-by: Madhavan Srinivasan <[email protected]>
  • Loading branch information
kjain101 committed Nov 5, 2024
1 parent 7137295 commit 8bf7844
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions arch/powerpc/include/asm/kvm_book3s_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ void kvmhv_set_l2_counters_status(int cpu, bool status);
u64 kvmhv_get_l1_to_l2_cs_time(void);
u64 kvmhv_get_l2_to_l1_cs_time(void);
u64 kvmhv_get_l2_runtime_agg(void);
u64 kvmhv_get_l1_to_l2_cs_time_vcpu(void);
u64 kvmhv_get_l2_to_l1_cs_time_vcpu(void);
u64 kvmhv_get_l2_runtime_agg_vcpu(void);

#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */

Expand Down
42 changes: 42 additions & 0 deletions arch/powerpc/kvm/book3s_hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4210,6 +4210,48 @@ u64 kvmhv_get_l2_runtime_agg(void)
return tb_to_ns(be64_to_cpu(get_lppaca()->l2_runtime_tb));
}

u64 kvmhv_get_l1_to_l2_cs_time_vcpu(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vcpu_arch *arch;

vcpu = local_paca->kvm_hstate.kvm_vcpu;
if (vcpu) {
arch = &vcpu->arch;
return arch->l1_to_l2_cs;
} else {
return 0;
}
}

u64 kvmhv_get_l2_to_l1_cs_time_vcpu(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vcpu_arch *arch;

vcpu = local_paca->kvm_hstate.kvm_vcpu;
if (vcpu) {
arch = &vcpu->arch;
return arch->l2_to_l1_cs;
} else {
return 0;
}
}

u64 kvmhv_get_l2_runtime_agg_vcpu(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vcpu_arch *arch;

vcpu = local_paca->kvm_hstate.kvm_vcpu;
if (vcpu) {
arch = &vcpu->arch;
return arch->l2_runtime_agg;
} else {
return 0;
}
}

#else
int kvmhv_get_l2_counters_status(void)
{
Expand Down
15 changes: 12 additions & 3 deletions arch/powerpc/perf/vpa-pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,22 @@ static unsigned long get_counter_data(struct perf_event *event)

switch (config) {
case L1_TO_L2_CS_LAT:
data = kvmhv_get_l1_to_l2_cs_time();
if (event->attach_state & PERF_ATTACH_TASK)
data = kvmhv_get_l1_to_l2_cs_time_vcpu();
else
data = kvmhv_get_l1_to_l2_cs_time();
break;
case L2_TO_L1_CS_LAT:
data = kvmhv_get_l2_to_l1_cs_time();
if (event->attach_state & PERF_ATTACH_TASK)
data = kvmhv_get_l2_to_l1_cs_time_vcpu();
else
data = kvmhv_get_l2_to_l1_cs_time();
break;
case L2_RUNTIME_AGG:
data = kvmhv_get_l2_runtime_agg();
if (event->attach_state & PERF_ATTACH_TASK)
data = kvmhv_get_l2_runtime_agg_vcpu();
else
data = kvmhv_get_l2_runtime_agg();
break;
default:
data = 0;
Expand Down

0 comments on commit 8bf7844

Please sign in to comment.