From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH 3/3] KVM: perf: kvm events analysis tool Date: Tue, 17 Jan 2012 10:37:11 +0800 Message-ID: <4F14DED7.3030002@linux.vnet.ibm.com> References: <4F13EE3D.2070602@linux.vnet.ibm.com> <4F13EEC5.8050807@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Avi Kivity , Marcelo Tosatti , LKML , KVM To: Stefan Hajnoczi Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 01/16/2012 06:08 PM, Stefan Hajnoczi wrote: > On Mon, Jan 16, 2012 at 9:32 AM, Xiao Guangrong > wrote: >> +DESCRIPTION >> +----------- >> +You can analyze some crucial events and statistics with this >> +'perf kvm-events' command. >=20 > This line is very general and does not explain which events/statistic= s > can be collected or how you can use that information. I suggest > making this description more specific. Explain that this subcommand > observers kvm.ko tracepoints and annotates/decodes them with > additional information (this is why I would use this command and not > raw perf record -e kvm:\*). >=20 Okay. >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD { SVM_EXIT_MONITOR, =EF=BF=BD =EF=BF= =BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD= =EF=BF=BD "monitor" }, \ >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD { SVM_EXIT_MWAIT, =EF=BF=BD =EF=BF=BD= =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD = =EF=BF=BD =EF=BF=BD "mwait" }, \ >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD { SVM_EXIT_XSETBV, =EF=BF=BD =EF=BF=BD= =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD = =EF=BF=BD =EF=BF=BD"xsetbv" }, \ >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD { SVM_EXIT_NPF, =EF=BF=BD =EF=BF=BD = =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF= =BF=BD =EF=BF=BD =EF=BF=BD "npf" } >=20 > All this copy-paste could be avoided by sharing this stuff with the > arch/x86/kvm/ code. >=20 I will try to combine them in the next version. >> +static void exit_event_decode_key(struct event_key *key, char decod= e[20]) >> +{ >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD const char *exit_reason =3D get_exit= _reason(key->info, key->key); >> + >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD memset(decode, 0, 20); >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD strncpy(decode, exit_reason, 20); >=20 > This is a bad pattern to follow when using strncpy(3) because if ther= e > was a strlen(exit_reason) =3D=3D 20 string then decode[] would not be > NUL-terminated. Right now it's safe but it's better to just use > strlcpy() and drop the memset(3). >=20 Good point. >> +static void mmio_event_decode_key(struct event_key *key, char decod= e[20]) >> +{ >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD memset(decode, 0, 20); >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD sprintf(decode, "%#lx:%s", key->key, >> + =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF=BD =EF=BF= =BD key->info =3D=3D KVM_TRACE_MMIO_READ ? "R" : "W"); >=20 > Please drop the memset and use snprintf(3) instead of sprintf(3). It > places the NUL-terminator and ensures you don't exceed the buffer > size. >=20 > Same pattern below. >=20 Will do, thanks Stefan! :)