From: Stefan Hajnoczi <stefanha@gmail.com>
To: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Avi Kivity <avi@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>
Subject: Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
Date: Mon, 16 Jan 2012 10:08:40 +0000 [thread overview]
Message-ID: <CAJSP0QVxR9sYYh_Vr6ZKAU-YrWpjgL5jpiKz2zt7eJxV_kgaOg@mail.gmail.com> (raw)
In-Reply-To: <4F13EEC5.8050807@linux.vnet.ibm.com>
On Mon, Jan 16, 2012 at 9:32 AM, Xiao Guangrong
<xiaoguangrong@linux.vnet.ibm.com> wrote:
> +DESCRIPTION
> +-----------
> +You can analyze some crucial events and statistics with this
> +'perf kvm-events' command.
This line is very general and does not explain which events/statistics
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:\*).
> + { SVM_EXIT_MONITOR, "monitor" }, \
> + { SVM_EXIT_MWAIT, "mwait" }, \
> + { SVM_EXIT_XSETBV, "xsetbv" }, \
> + { SVM_EXIT_NPF, "npf" }
All this copy-paste could be avoided by sharing this stuff with the
arch/x86/kvm/ code.
> +static void exit_event_decode_key(struct event_key *key, char decode[20])
> +{
> + const char *exit_reason = get_exit_reason(key->info, key->key);
> +
> + memset(decode, 0, 20);
> + strncpy(decode, exit_reason, 20);
This is a bad pattern to follow when using strncpy(3) because if there
was a strlen(exit_reason) == 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).
> +}
> +
> +static struct kvm_events_ops exit_events = {
> + .is_begain_event = exit_event_begain,
> + .is_end_event = exit_event_end,
> + .get_key = exit_event_get_key,
> + .decode_key = exit_event_decode_key,
> + .name = "VM-EXIT"
> +};
> +
> +#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
> +#define KVM_TRACE_MMIO_READ 1
> +#define KVM_TRACE_MMIO_WRITE 2
> +static bool mmio_event_begain(struct event *event, void *data)
> +{
> + if (!strcmp(event->name, "kvm_mmio")) {
> + long type = raw_field_value(event, "type", data);
> +
> + if (type != KVM_TRACE_MMIO_READ_UNSATISFIED)
> + return true;
> + };
> +
> + return false;
> +}
> +
> +static bool mmio_event_end(struct event *event)
> +{
> + return !strcmp(event->name, "kvm_mmio_done");
> +}
> +
> +static struct event_key mmio_event_get_key(struct event *event, void *data)
> +{
> + struct event_key key;
> +
> + key.key = raw_field_value(event, "gpa", data);
> + key.info = raw_field_value(event, "type", data);
> +
> + return key;
> +}
> +
> +static void mmio_event_decode_key(struct event_key *key, char decode[20])
> +{
> + memset(decode, 0, 20);
> + sprintf(decode, "%#lx:%s", key->key,
> + key->info == KVM_TRACE_MMIO_READ ? "R" : "W");
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.
Same pattern below.
next prev parent reply other threads:[~2012-01-16 10:08 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-16 9:30 [RFC][PATCH] KVM: perf: a smart tool to analyse kvm events Xiao Guangrong
2012-01-16 9:31 ` [PATCH 1/3] KVM: trace mmio read event properly Xiao Guangrong
2012-01-16 10:18 ` Avi Kivity
2012-01-17 2:36 ` Xiao Guangrong
2012-01-16 9:32 ` [PATCH 2/3] KVM: improve trace events of vmexit/mmio/ioport Xiao Guangrong
2012-01-16 9:38 ` Avi Kivity
2012-01-17 2:28 ` Xiao Guangrong
2012-01-17 11:55 ` Marcelo Tosatti
2012-01-17 17:31 ` David Ahern
2012-01-18 2:32 ` Xiao Guangrong
2012-01-18 5:34 ` David Ahern
2012-01-24 12:44 ` Avi Kivity
2012-01-16 9:32 ` [PATCH 3/3] KVM: perf: kvm events analysis tool Xiao Guangrong
2012-01-16 10:04 ` Avi Kivity
2012-01-17 2:30 ` Xiao Guangrong
2012-01-24 12:49 ` Avi Kivity
2012-01-16 10:08 ` Stefan Hajnoczi [this message]
2012-01-17 2:37 ` Xiao Guangrong
2012-01-17 11:59 ` Marcelo Tosatti
2012-01-24 12:51 ` Avi Kivity
2012-01-16 10:11 ` [RFC][PATCH] KVM: perf: a smart tool to analyse kvm events Avi Kivity
2012-01-17 2:30 ` Xiao Guangrong
2012-01-16 22:53 ` David Ahern
2012-01-17 2:41 ` Xiao Guangrong
2012-01-17 4:49 ` David Ahern
2012-02-09 9:06 [PATCH v4 0/3] KVM: perf: kvm events analysis tool Xiao Guangrong
2012-02-09 9:09 ` [PATCH 3/3] " Xiao Guangrong
2012-02-13 3:04 ` David Ahern
2012-02-13 5:00 ` Xiao Guangrong
2012-02-20 23:47 ` David Ahern
2012-02-21 3:52 ` Xiao Guangrong
2012-02-21 4:58 ` David Ahern
2012-02-27 4:57 ` Xiao Guangrong
2012-02-13 5:32 David Ahern
2012-02-13 10:06 ` Xiao Guangrong
2012-02-13 15:52 ` David Ahern
2012-02-16 4:59 ` Xiao Guangrong
2012-02-16 5:05 ` David Ahern
2012-02-16 5:33 ` Xiao Guangrong
2012-02-16 16:35 ` Arnaldo Carvalho de Melo
2012-03-06 8:55 [PATCH v5 0/3] " Xiao Guangrong
2012-03-06 8:58 ` [PATCH 3/3] " Xiao Guangrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJSP0QVxR9sYYh_Vr6ZKAU-YrWpjgL5jpiKz2zt7eJxV_kgaOg@mail.gmail.com \
--to=stefanha@gmail.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=xiaoguangrong@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).