From: "Alex Bennée" <alex.bennee@linaro.org>
To: Robert Foley <robert.foley@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
robhenry@microsoft.com, aaron@os.amperecomputing.com,
"Emilio G. Cota" <cota@braap.org>,
kuhn.chenqun@huawei.com, Peter Puhov <peter.puhov@linaro.org>
Subject: Re: [PATCH v1 8/9] plugins: new hwprofile plugin
Date: Wed, 03 Jun 2020 12:43:10 +0100 [thread overview]
Message-ID: <87sgfc5q9d.fsf@linaro.org> (raw)
In-Reply-To: <CAEyhzFvTF7Sh1ugq_O9CwADf3LmkWjdCHqmafQC0wkDMKQH1=A@mail.gmail.com>
Robert Foley <robert.foley@linaro.org> writes:
> Hi,
>
> On Tue, 2 Jun 2020 at 11:46, Alex Bennée <alex.bennee@linaro.org> wrote:
> <snip>
>> diff --git a/tests/plugin/hwprofile.c b/tests/plugin/hwprofile.c
>> new file mode 100644
>> index 00000000000..f5e0639e762
>> --- /dev/null
>> +++ b/tests/plugin/hwprofile.c
> <snip>
>> +static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
>> + uint64_t vaddr, void *udata)
>> +{
>> + struct qemu_plugin_hwaddr *hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr);
>> +
>> + if (!hwaddr || !qemu_plugin_hwaddr_is_io(hwaddr)) {
>> + return;
>> + } else {
>> + char *name = qemu_plugin_hwaddr_device_name(hwaddr);
>> + DeviceCounts *counts;
>> +
>> + g_mutex_lock(&lock);
>> + counts = (DeviceCounts *) g_hash_table_lookup(devices, name);
>> + if (!counts) {
>> + uint64_t off = qemu_plugin_hwaddr_device_offset(hwaddr);
>> + uint64_t base = vaddr - off;
>> + counts = new_count(name, base);
>> + } else {
>> + g_free(name);
>> + }
>> +
>> + if (detail) {
>> + uint64_t off = qemu_plugin_hwaddr_device_offset(hwaddr);
>> + IOLocationCounts *io_count = g_hash_table_lookup(counts->access_pattern, &off);
>> + if (!io_count) {
>> + io_count = new_location(off);
>> + g_hash_table_insert(counts->access_pattern, &off, io_count);
>> + }
>> + if (qemu_plugin_mem_is_store(meminfo)) {
>> + io_count->writes++;
>> + io_count->cpu_write |= (1 << cpu_index);
>> + } else {
>> + io_count->reads++;
>> + io_count->cpu_read |= (1 << cpu_index);
>> + }
>> + } else {
>> + if (qemu_plugin_mem_is_store(meminfo)) {
>> + counts->total_writes++;
>> + counts->cpu_write |= (1 << cpu_index);
>> + } else {
>> + counts->total_reads++;
>> + counts->cpu_read |= (1 << cpu_index);
>
> The bitmasks cpu_read and cpu_write are ints. Maybe to account for
> larger core counts
I could make them uint64_t and then just warn if we exceed that on start-up.
>> 32, we could assert if the cpu_index is >= 32?
>
>> + }
>> + }
>> + g_mutex_unlock(&lock);
>> + }
>> +}
>> +
>> +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>> +{
>> + size_t n = qemu_plugin_tb_n_insns(tb);
>> + size_t i;
>> +
>> + for (i = 0; i < n; i++) {
>> + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
>> + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_haddr,
>> + QEMU_PLUGIN_CB_NO_REGS,
>> + rw, NULL);
>> + }
>> +}
>> +
>> +QEMU_PLUGIN_EXPORT
>> +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
>> + int argc, char **argv)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < argc; i++) {
>> + char *opt = argv[i];
>> + if (g_strcmp0(opt, "read") == 0) {
>> + rw = QEMU_PLUGIN_MEM_R;
>> + } else if (g_strcmp0(opt, "write") == 0) {
>> + rw = QEMU_PLUGIN_MEM_W;
>> + } else if (g_strcmp0(opt, "detail") == 0) {
>
> When testing out the options, I noticed that
> if we supply arguments of "read", and "write", then we will only get
> the last one set, "write", since rw gets overwritten.
> One option would be to error out if more than one of these read/write
> args is supplied.
Yeah the option parsing is a little clunky although given the way you
pass them from the QEMU command line perhaps not too worth finessing.
The default is rw so you make a conscious decision to only care about one
or the other.
All you can really do is fail to initialise the plugin. Hopefully the
output should be enough clue.
>
> Reviewed-by: Robert Foley <robert.foley@linaro.org>
> Tested-by: Robert Foley <robert.foley@linaro.org>
Thanks.
Out of interest what did you measure? Are there any useful use cases you can
think of?
>
>> + detail = true;
>> + } else {
>> + fprintf(stderr, "option parsing failed: %s\n", opt);
>> + return -1;
>> + }
>> + }
>> +
>> + plugin_init();
>> +
>> + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
>> + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
>> + return 0;
>> +}
>> diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile
>> index b3250e2504c..d87b8d40699 100644
>> --- a/tests/plugin/Makefile
>> +++ b/tests/plugin/Makefile
>> @@ -14,6 +14,7 @@ NAMES += hotblocks
>> NAMES += howvec
>> NAMES += hotpages
>> NAMES += lockstep
>> +NAMES += hwprofile
>>
>> SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
>>
>> --
>> 2.20.1
>>
--
Alex Bennée
next prev parent reply other threads:[~2020-06-03 11:44 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 15:46 [PATCH v1 0/9] plugins/next (bug fixes, hwprofile, lockstep) Alex Bennée
2020-06-02 15:46 ` [PATCH v1 1/9] plugins: new lockstep plugin for debugging TCG changes Alex Bennée
2020-06-02 15:46 ` [PATCH v1 2/9] qemu-plugin.h: add missing include <stddef.h> to define size_t Alex Bennée
2020-06-02 15:46 ` [PATCH v1 3/9] scripts/clean-includes: Mark 'qemu/qemu-plugin.h' as special header Alex Bennée
2020-06-02 15:46 ` [PATCH v1 4/9] tests/plugin: correctly honour io_count Alex Bennée
2020-06-02 17:07 ` Philippe Mathieu-Daudé
2020-06-02 15:46 ` [PATCH v1 5/9] cputlb: ensure we re-fill the TLB if it has reset Alex Bennée
2020-06-02 16:34 ` Richard Henderson
2020-06-02 16:56 ` Alex Bennée
2020-06-02 15:46 ` [PATCH v1 6/9] hw/virtio/pci: include vdev name in registered PCI sections Alex Bennée
2020-06-02 15:59 ` Philippe Mathieu-Daudé
2020-06-04 11:35 ` Michael S. Tsirkin
2020-06-02 15:46 ` [PATCH v1 7/9] plugins: add API to return a name for a IO device Alex Bennée
2020-06-02 16:06 ` Clement Deschamps
2020-06-08 3:45 ` Emilio G. Cota
2020-06-08 6:20 ` Philippe Mathieu-Daudé
2020-06-08 8:06 ` Alex Bennée
2020-06-09 4:09 ` Emilio G. Cota
2020-06-09 11:09 ` Alex Bennée
2020-06-10 2:32 ` Emilio G. Cota
2020-06-02 15:46 ` [PATCH v1 8/9] plugins: new hwprofile plugin Alex Bennée
2020-06-02 19:16 ` Robert Foley
2020-06-03 11:43 ` Alex Bennée [this message]
2020-06-03 15:42 ` Robert Foley
2020-06-03 17:26 ` Alex Bennée
2020-06-03 15:48 ` Peter Maydell
2020-06-03 17:23 ` Alex Bennée
2020-06-02 15:46 ` [PATCH v1 9/9] .travis.yml: allow failure for unreliable hosts Alex Bennée
2020-06-03 8:18 ` Philippe Mathieu-Daudé
2020-06-03 12:40 ` Philippe Mathieu-Daudé
2020-06-11 11:20 ` Thomas Huth
2020-06-02 17:03 ` [PATCH v1 0/9] plugins/next (bug fixes, hwprofile, lockstep) no-reply
2020-06-02 19:16 ` no-reply
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=87sgfc5q9d.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aaron@os.amperecomputing.com \
--cc=cota@braap.org \
--cc=kuhn.chenqun@huawei.com \
--cc=peter.puhov@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=robert.foley@linaro.org \
--cc=robhenry@microsoft.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).