encounter a problem about xenalyze
Hi, George.
Per your suggesion, I tried to add some code to xenalyze.c to analyze some newly added events. To have more understanding, you can read the patch at the bottom. In this patch, I try to count how many times a given vcpu is added and removed from a pi blocking list. After collecting some data, I compared the result of different decoder, xenalyze and xentrace_format. I found that xentrace_format shows one vcpu is added and removed 2499 times respectively. But xenalyze shows the identical vcpu is added 2499 times and removed only about 700 times. Some other vcpus also encounter this weird thing.
Could give me some suggestion to debug this problem? Or, are there some bugs in this patch?
Thanks
Chao
---8<---
From 01c10aa7edcded99017d88ac4a7fff19168f132d Mon Sep 17 00:00:00 2001
From: Chao Gao <[email protected]>
Date: Wed, 26 Apr 2017 03:39:06 +0800
Subject: [PATCH 1/3] VT-d PI: track the vcpu number in pi blocking list
This patch adds a field, counter, in struct vmx_pi_blocking_vcpu to track how many entries are on the pi blocking list. In order to analyze list operation frequence and obtain the list length, add some relevant events to xentrace and some associated code in xenalyze.
--- tools/xentrace/formats | 2 + tools/xentrace/xenalyze.c | 95 ++++++++++++++++++++++++++++++++++++++++- xen/arch/x86/hvm/vmx/vmx.c | 30 ++++++++++--- xen/include/asm-x86/hvm/trace.h | 2 + xen/include/public/trace.h | 2 + 5 files changed, 124 insertions(+), 7 deletions(-)
tools/xentrace/formats +2 -0
@@ -125,6 +125,8 @@ 0x00082020 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) INTR_WINDOW [ value = 0x%(1)08x ] 0x00082021 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) NPF [ gpa = 0x%(2)08x%(1)08x mfn = 0x%(4)08x%(3)08x qual = 0x%(5)04x p2mt = 0x%(6)04x ] 0x00082023 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) TRAP [ vector = 0x%(1)02x ] +0x00082026 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) PI_LIST_ADD [ domid = 0x%(1)04x vcpu = 0x%(2)04x, pcpu = 0x%(3)04x, #entry = 0x%(4)04x ] +0x00082027 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) PI_LIST_DEL [ domid = 0x%(1)04x vcpu = 0x%(2)04x ] 0x0010f001 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) page_grant_map [ domid = %(1)d ] 0x0010f002 CPU%(cpu)d %(tsc)d (+%(reltsc)8d) page_grant_unmap [ domid = %(1)d ]
tools/xentrace/xenalyze.c +93 -2
167 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vmx.c +25 -5
@@ -82,6 +82,7 @@ static int vmx_vmfunc_intercept(struct cpu_user_regs *regs);struct vmx_pi_blocking_vcpu {struct list_head list;spinlock_t lock; +uint32_t counter; };/*
@@ -119,6 +120,9 @@ static void vmx_vcpu_block(struct vcpu *v)*/ ASSERT (old_lock ==NULL ); +per_cpu (vmx_pi_blocking, v->processor).counter++; +TRACE_4D (TRC_HVM_PI_LIST_ADD , v->domain->domain_id, v->vcpu_id, + v->processor,per_cpu (vmx_pi_blocking, v->processor).counter);list_add_tail (&v->arch.hvm_vmx.pi_blocking.list, &per_cpu (vmx_pi_blocking, v->processor).list);spin_unlock_irqrestore (pi_blocking_list_lock, flags);
@@ -186,6 +190,9 @@ static void vmx_pi_unblock_vcpu(struct vcpu *v) {ASSERT (v->arch.hvm_vmx.pi_blocking.lock == pi_blocking_list_lock);list_del (&v->arch.hvm_vmx.pi_blocking.list); +container_of (pi_blocking_list_lock, + struct vmx_pi_blocking_vcpu, lock)->counter--; +TRACE_2D (TRC_HVM_PI_LIST_DEL , v->domain->domain_id, v->vcpu_id); v->arch.hvm_vmx.pi_blocking.lock =NULL ; }
@@ -220,6 +227,8 @@ void vmx_pi_desc_fixup(unsigned int cpu)list_for_each_entry_safe (vmx, tmp, blocked_vcpus, pi_blocking.list) { + struct vcpu *v = container_of(vmx, struct vcpu, arch.hvm_vmx); +/* * Suppress notification or we may miss an interrupt when the * target cpu is dying.
@@ -234,8 +243,10 @@ void vmx_pi_desc_fixup(unsigned int cpu)if (pi_test_on (&vmx->pi_desc) ) {list_del (&vmx->pi_blocking.list); +TRACE_2D (TRC_HVM_PI_LIST_DEL , v->domain->domain_id, v->vcpu_id); +per_cpu (vmx_pi_blocking, cpu).counter--; vmx->pi_blocking.lock =NULL ; - vcpu_unblock(container_of(vmx, struct vcpu, arch.hvm_vmx)); +vcpu_unblock (v); }else {
@@ -258,6 +269,11 @@ void vmx_pi_desc_fixup(unsigned int cpu)list_move (&vmx->pi_blocking.list, &per_cpu (vmx_pi_blocking, new_cpu).list); +per_cpu (vmx_pi_blocking, cpu).counter--; +per_cpu (vmx_pi_blocking, new_cpu).counter++; +TRACE_2D (TRC_HVM_PI_LIST_DEL , v->domain->domain_id, v->vcpu_id); +TRACE_4D (TRC_HVM_PI_LIST_ADD , v->domain->domain_id, v->vcpu_id, + new_cpu,per_cpu (vmx_pi_blocking, new_cpu).counter); vmx->pi_blocking.lock = new_lock;spin_unlock (new_lock);
@@ -2358,9 +2374,9 @@ static struct hvm_function_table __initdata vmx_function_table = {static void pi_wakeup_interrupt (struct cpu_user_regs *regs) {struct arch_vmx_struct *vmx, *tmp; -spinlock_t *lock = &per_cpu (vmx_pi_blocking,smp_processor_id ()).lock; -struct list_head *blocked_vcpus = - &per_cpu (vmx_pi_blocking,smp_processor_id ()).list; +unsigned int cpu =smp_processor_id (); +spinlock_t *lock = &per_cpu (vmx_pi_blocking, cpu).lock; +struct list_head *blocked_vcpus = &per_cpu (vmx_pi_blocking, cpu).list;ack_APIC_irq ();this_cpu (irq_count)++;
@@ -2376,10 +2392,14 @@ static void pi_wakeup_interrupt(struct cpu_user_regs *regs) {if (pi_test_on (&vmx->pi_desc) ) { + struct vcpu *v = container_of(vmx, struct vcpu, arch.hvm_vmx); +list_del (&vmx->pi_blocking.list); +TRACE_2D (TRC_HVM_PI_LIST_DEL , v->domain->domain_id, v->vcpu_id); +per_cpu (vmx_pi_blocking, cpu).counter--;ASSERT (vmx->pi_blocking.lock == lock); vmx->pi_blocking.lock =NULL ; - vcpu_unblock(container_of(vmx, struct vcpu, arch.hvm_vmx)); +vcpu_unblock (v); } }
xen/include/asm-x86/hvm/trace.h +2 -0
@@ -54,6 +54,8 @@#define DO_TRC_HVM_TRAP DEFAULT_HVM_MISC#define DO_TRC_HVM_TRAP_DEBUG DEFAULT_HVM_MISC#define DO_TRC_HVM_VLAPIC DEFAULT_HVM_MISC +#define DO_TRC_HVM_PI_LIST_ADD DEFAULT_HVM_MISC +#define DO_TRC_HVM_PI_LIST_DEL DEFAULT_HVM_MISC#define TRC_PAR_LONG (par) ((par)&0xFFFFFFFF),((par)>>32)
xen/include/public/trace.h +2 -0
@@ -234,6 +234,8 @@#define TRC_HVM_TRAP (TRC_HVM_HANDLER + 0x23)#define TRC_HVM_TRAP_DEBUG (TRC_HVM_HANDLER + 0x24)#define TRC_HVM_VLAPIC (TRC_HVM_HANDLER + 0x25) +#define TRC_HVM_PI_LIST_ADD (TRC_HVM_HANDLER + 0x26) +#define TRC_HVM_PI_LIST_DEL (TRC_HVM_HANDLER + 0x27)#define TRC_HVM_IOPORT_WRITE (TRC_HVM_HANDLER + 0x216)#define TRC_HVM_IOMEM_WRITE (TRC_HVM_HANDLER + 0x217)
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 11 lines · Chao Gao
Hi, George.
Per your suggesion, I tried to add some code to
xenalyze.cto analyze some newly added events. To have more understanding, you can read the patch at the bottom. In this patch, I try to count how many times a given vcpu is added and removed from a pi blocking list. After collecting some data, I compared the result of different decoder, xenalyze andxentrace_format. I found thatxentrace_formatshows one vcpu is added and removed 2499 times respectively. But xenalyze shows the identical vcpu is added 2499 times and removed only about 700 times. Some other vcpus also encounter this weird thing.
Hi, George. I found the cause. It is for removing one vcpu from pi blocking list can happen in various contexts. Some contexts can't pass toplevel_assert_check().
Thanks
Chao
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel