Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751665AbdIMCAj (ORCPT ); Tue, 12 Sep 2017 22:00:39 -0400 Received: from mga09.intel.com ([134.134.136.24]:29715 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751444AbdIMCAi (ORCPT ); Tue, 12 Sep 2017 22:00:38 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,385,1500966000"; d="asc'?scan'208";a="311027197" Date: Wed, 13 Sep 2017 09:54:25 +0800 From: "Du, Changbin" To: Arnaldo Carvalho de Melo Cc: "Du, Changbin" , peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: Does perf-annotate work correctly? Message-ID: <20170913015425.GA607@intel.com> References: <20170912101035.GA21638@intel.com> <20170912143350.GA3452@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dDRMvlgZJXvWKvBx" Content-Disposition: inline In-Reply-To: <20170912143350.GA3452@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10896 Lines: 249 --dDRMvlgZJXvWKvBx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 12, 2017 at 11:33:50AM -0300, Arnaldo Carvalho de Melo wrote: > Em Tue, Sep 12, 2017 at 06:10:35PM +0800, Du, Changbin escreveu: > > When a annotate a symbol, I find the annotated C source code doesn't ma= tch assembly code. > > So I cannot determine which line of C code has much overhead withou gdb= 's help. > >=20 > > Here is a example result of function apic_has_interrupt_for_ppr() in kv= m module. >=20 > Ok, was this using the module .ko file or /proc/kcore? You forgot to > cut'n'paste the first line on the screen. >=20 It is arch/x86/kvm/kvm.ko. > Also, how did you use gdb? >=20 $ gdb arch/x86/kvm/kvm.ko $ (gdb) disassemble /s apic_has_interrupt_for_ppr > perf uses objdump to do the disassembly, and depending on how it is used > (live system, post processing on a different machine, permissions) it > may use different files to do the disassembly. >=20 But objdump has same out as gdb. (Always on same machine, and no binary cha= nged.) $ objdump -d -S arch/x86/kvm/kvm.o =2E.. static int apic_has_interrupt_for_ppr(struct kvm_lapic *apic, u32 ppr) { 3b4a0: e8 00 00 00 00 callq 3b4a5 3b4a5: 55 push %rbp 3b4a6: 48 89 e5 mov %rsp,%rbp 3b4a9: 48 83 ec 08 sub $0x8,%rsp int highest_irr; if (kvm_x86_ops->sync_pir_to_irr && apic->vcpu->arch.apicv_active) 3b4ad: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 3b4b4 3b4b4: 48 8b 80 38 02 00 00 mov 0x238(%rax),%rax 3b4bb: 48 85 c0 test %rax,%rax 3b4be: 74 10 je 3b4d0 3b4c0: 48 8b 97 88 00 00 00 mov 0x88(%rdi),%rdx 3b4c7: 80 ba 28 03 00 00 00 cmpb $0x0,0x328(%rdx) 3b4ce: 75 3a jne 3b50a /* * Note that irr_pending is just a hint. It will be always * true with virtual interrupt delivery enabled. */ if (!apic->irr_pending) 3b4d0: 80 bf 91 00 00 00 00 cmpb $0x0,0x91(%rdi) 3b4d7: 74 2a je 3b503 3b4d9: 48 8b 8f a0 00 00 00 mov 0xa0(%rdi),%rcx static int find_highest_vector(void *bitmap) { int vec; u32 *reg; for (vec =3D MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; 3b4e0: b8 e0 00 00 00 mov $0xe0,%eax vec >=3D 0; vec -=3D APIC_VECTORS_PER_REG) { reg =3D bitmap + REG_POS(vec); if (*reg) 3b4e5: 89 c2 mov %eax,%edx 3b4e7: c1 fa 05 sar $0x5,%edx 3b4ea: c1 e2 04 shl $0x4,%edx 3b4ed: 48 63 d2 movslq %edx,%rdx 3b4f0: 8b 94 11 00 02 00 00 mov 0x200(%rcx,%rdx,1),%edx 3b4f7: 85 d2 test %edx,%edx 3b4f9: 75 2d jne 3b528 > Please provide more detailed information on the exact command line > arguments and usage scenario. > =20 > - Arnaldo >=20 > > =E2=94=82580 __clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu-= >arch.apic_attention); =E2=96=92 > > =E2=94=82581 } = =E2=96=92 > > =E2=94=82 = =E2=96=92 > > =E2=94=82583 static int apic_has_interrupt_for_ppr(struct kvm_la= pic *apic, u32 ppr) =E2=96=92 > > =E2=94=82584 { = =E2=96=92 > > 0.88 =E2=94=8230: cmpb $0x0,0x91(%rdi) = =E2=96=92 > > 2.54 =E2=94=82 =E2=86=93 je 63 = =E2=96=92 > > 0.20 =E2=94=82 mov 0xa0(%rdi),%rcx = =E2=96=92 > > =E2=94=82581 int highest_irr; = =E2=96=92 > > =E2=94=82582 if (kvm_x86_ops->sync_pir_to_irr && apic->v= cpu->arch.apicv_active) =E2=96=92 > > 4.91 =E2=94=82 mov $0xe0,%eax x = =E2=96=92 > > 1.46 =E2=94=8245: mov %eax,%edx x = =E2=96=92 > > 0.02 =E2=94=82 sar $0x5,%edx x = =E2=96=92 > > 3.57 =E2=94=82 shl $0x4,%edx x = =E2=96=92 > > 3.34 =E2=94=82 movslq %edx,%rdx x = =E2=96=92 > > 1.25 =E2=94=82 mov 0x200(%rcx,%rdx,1),%edx x = =E2=96=92 > > 42.44 =E2=94=82 test %edx,%edx x = =E2=96=92 > > 0.01 =E2=94=82 =E2=94=8C=E2=94=80=E2=94=80jne 88 = x =E2=96=92 > > 3.48 =E2=94=82 =E2=94=82 sub $0x20,%eax x= =E2=96=92 > > 2.24 =E2=94=82 =E2=94=82 cmp $0xffffffe0,%eax x= =E2=96=92 > > =E2=94=82586=E2=94=82apic_find_highest_irr(): = =E2=96=92 > > =E2=94=82 =E2=94=82 = =E2=96=92 > > =E2=94=82407=E2=94=82 /* = =E2=96=92 > > =E2=94=82408=E2=94=82 * Note that irr_pending is just a = hint. It will be always =E2=96=92 > > =E2=94=82409=E2=94=82 * true with virtual interrupt deli= very enabled. =E2=96=92 > > =E2=94=82410=E2=94=82 */ = =E2=96=92 > > =E2=94=82411=E2=94=82 if (!apic->irr_pending) = =E2=96=92 > > =E2=94=82 =E2=94=82=E2=86=91 jne 45 = =E2=96=92 > > 0.62 =E2=94=8263:=E2=94=82 mov $0xffffffff,%eax = =E2=97=86 > > 0.83 =E2=94=82 =E2=94=82 leaveq = =E2=96=92 > > 13.52 =E2=94=82 =E2=94=82=E2=86=90 retq = =E2=96=92 > > =E2=94=826a:=E2=94=82 mov %esi,-0x4(%rbp) = =E2=96=92 > > =E2=94=82 =E2=94=82 mov %rdx,%rdi = =E2=96=92 > > =E2=94=82418=E2=94=82find_highest_vector(): = =E2=96=92 > > =E2=94=82340=E2=94=82static int find_highest_vector(void *bitmap= ) =E2=96=92 > > =E2=94=82341=E2=94=82{ = =E2=96=92 > > =E2=94=82342=E2=94=82 int vec; = =E2=96=92 > > =E2=94=82343=E2=94=82 u32 *reg; = =E2=96=92 > > =E2=94=82 =E2=94=82 = =E2=96=92 > > =E2=94=82345=E2=94=82 for (vec =3D MAX_APIC_VECTOR - APIC= _VECTORS_PER_REG; =E2=96=92 > > =E2=94=82 =E2=94=82=E2=86=92 callq *%rax = =E2=96=92 > > =E2=94=82 =E2=94=82 mov -0x4(%rbp),%esi = =E2=96=92 > > =E2=94=82343=E2=94=82 vec >=3D 0; vec -=3D APIC_VECT= ORS_PER_REG) { =E2=96=92 > > =E2=94=82344=E2=94=82 reg =3D bitmap + REG_POS(ve= c); =E2=96=92 > > =E2=94=82345=E2=94=82 if (*reg) = =E2=96=92 > > 0.05 =E2=94=8275:=E2=94=82 cmp $0xffffffff,%eax = =E2=96=92 > > =E2=94=82 =E2=94=82=E2=86=91 je 63 = =E2=96=92 > > 1.95 =E2=94=82 =E2=94=82 mov %eax,%edx = =E2=96=92 > > 1.45 =E2=94=82 =E2=94=82 and $0xf0,%edx = =20 > >=20 > >=20 > > Look at the assembly code block where I have put a 'x' on the right. Ap= parently the > > assembly code doesn't match the C source code arrounded. Let's look the= correct disassemble > > result from gdb: > >=20 > > 340 for (vec =3D MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; > > 0x000000000003b4e0 <+64>: mov $0xe0,%eax > >=20 > > 342 reg =3D bitmap + REG_POS(vec); > > 343 if (*reg) > > 0x000000000003b4e5 <+69>: mov %eax,%edx > > 0x000000000003b4e7 <+71>: sar $0x5,%edx > > 0x000000000003b4ea <+74>: shl $0x4,%edx > > 0x000000000003b4ed <+77>: movslq %edx,%rdx > > 0x000000000003b4f0 <+80>: mov 0x200(%rcx,%rdx,1),%edx > > 0x000000000003b4f7 <+87>: test %edx,%edx > > 0x000000000003b4f9 <+89>: jne 0x3b528 > >=20 > > 341 vec >=3D 0; vec -=3D APIC_VECTORS_PER_REG) { > > 0x000000000003b4fb <+91>: sub $0x20,%eax > >=20 > > 340 for (vec =3D MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; > > 0x000000000003b4fe <+94>: cmp $0xffffffe0,%eax > > 0x000000000003b501 <+97>: jne 0x3b4e5 > >=20 > >=20 > > Compared to gdb, perf-annoate has messed up. is it a bug or just perf i= s not as perfect as gdb? > >=20 > > --=20 > > Thanks, > > Changbin Du >=20 >=20 --=20 Thanks, Changbin Du --dDRMvlgZJXvWKvBx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJZuI/RAAoJEAanuZwLnPNUsY4H/0oj9aSI0yAPbFNT1m2tXfHU rZykqiXYB3Vfgma5oHSasQLcuOxKOWslvB2iWH7NicE5YiS0IujuSzUEJLDw0AGu 5M1bkdF+Bv5SeRTnp1gCLdgUotSAC2j0zQ8jycqIu5Osx7/5qSAeiMGDCD4hTVwe eqLMw4tkWwTWlKV92kqeW9UutYJ8P7LTaZEEj63hF9JBkdJyDQys1NleQZT5sE0k lbQL+CkI73N/M+kAKsUUVRgAUbMw8r+hwaVb7P9qClAOKARl1Php1OjaxOzgmtg7 84I1QHF3Ld8bJrIgIoyEOhgFXbFwhLu/+7u+W3OZ5YqAiSfFZyq8+rp+oiD+OwE= =Wcym -----END PGP SIGNATURE----- --dDRMvlgZJXvWKvBx--