contrib/plugins/hotblocks: Minor bug fixes and add limit argument
cover contrib/plugins/hotblocks: Minor bug fixes and add limit argument
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than
PRId64
docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argument
contrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/5 contrib/plugins/hotblocks: Correctly free sorted counts list
g_list_free should be passed the head of the list.
--- contrib/plugins/hotblocks.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
contrib/plugins/hotblocks.c +5 -4
@@ -73,15 +73,16 @@ static void exec_count_free(gpointer key, gpointer value, gpointer user_data)static void plugin_exit (qemu_plugin_id_t id,void *p) {g_autoptr (GString) report =g_string_new ("collected " ); -GList *counts, *it; +GList *counts, *sorted_counts, *it;int i;g_string_append_printf (report,"%d entries in the hash table\n" ,g_hash_table_size (hotblocks)); counts =g_hash_table_get_values (hotblocks); - it =g_list_sort_with_data (counts, cmp_exec_count,NULL ); + sorted_counts =g_list_sort_with_data (counts, cmp_exec_count,NULL ); -if (it) { +if (sorted_counts) { + it = sorted_counts;g_string_append_printf (report,"pc, tcount, icount, ecount\n" );for (i =0 ; i < limit && it->next; i++, it = it->next) {
@@ -94,7 +95,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) qemu_plugin_scoreboard_u64(rec->exec_count))); } -g_list_free (it); +g_list_free (sorted_counts); }qemu_plugin_outs (report->str);
Signature · 1 line
2.50.1
Re: [PATCH 1/5] contrib/plugins/hotblocks: Correctly free sorted counts list
Quoted 42 lines · Alex Bradbury
g_list_freeshould be passed the head of the list.Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)contrib/plugins/hotblocks.c +5
-5@@ -73,15 +73,16 @@ static void exec_count_free(gpointer key, gpointer value, gpointer user_data)static void plugin_exit (qemu_plugin_id_t id,void *p) {g_autoptr (GString) report =g_string_new ("collected " ); -GList *counts, *it; +GList *counts, *sorted_counts, *it;int i;g_string_append_printf (report,"%d entries in the hash table\n" ,g_hash_table_size (hotblocks)); counts =g_hash_table_get_values (hotblocks); - it =g_list_sort_with_data (counts, cmp_exec_count,NULL ); + sorted_counts =g_list_sort_with_data (counts, cmp_exec_count,NULL ); -if (it) { +if (sorted_counts) { + it = sorted_counts;g_string_append_printf (report,"pc, tcount, icount, ecount\n" );for (i =0 ; i < limit && it->next; i++, it = it->next) {@@ -94,7 +95,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) qemu_plugin_scoreboard_u64(rec->exec_count))); } -g_list_free (it); +g_list_free (sorted_counts); }qemu_plugin_outs (report->str); --
Quoted 3 lines
2.50.1
This looks correct to me. g_hash_table_get_values documentation says the returned value must be freed with g_list_free, but g_list_sort_with_data might change the list head, so neither counts nor it should be freed, but sorted_counts which is the new list head like the commit message says.
Re: [PATCH 1/5] contrib/plugins/hotblocks: Correctly free sorted counts list
In reply to Alex BradburyQuoted 6 lines · Alex Bradbury
g_list_freeshould be passed the head of the list.Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Thanks for catching this.
PATCH 2/5 contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks
In reply to Alex BradburyThe logic to iterate over the hottest blocks will never reach the last item in the list, as it checks it->next != NULL before entering the loop. It's hard to trigger this off-by-one error with the default limit=20, but it is a bug and is problematic if that default is changed to something larger.
--- contrib/plugins/hotblocks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
contrib/plugins/hotblocks.c +1 -2
@@ -82,10 +82,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) sorted_counts =g_list_sort_with_data (counts, cmp_exec_count,NULL );if (sorted_counts) { - it = sorted_counts;g_string_append_printf (report,"pc, tcount, icount, ecount\n" ); -for (i =0 ; i < limit && it->next; i++, it = it->next) { +for (i =0 , it = sorted_counts; i < limit && it; i++, it = it->next) {ExecCount *rec = (ExecCount *) it->data; g_string_append_printf( report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n",
Signature · 1 line
2.50.1
Re: [PATCH 2/5] contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks
Quoted 10 lines · Alex Bradbury
The logic to iterate over the hottest blocks will never reach the last item in the list, as it checks
it->next != NULLbefore entering the loop. It's hard to trigger this off-by-one error with the default limit=20, but it is a bug and is problematic if that default is changed to something larger.Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Thanks for this one too.
PATCH 3/5 contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than PRId64
In reply to Alex Bradburyqemu_plugin_u64_sum returns a uint64_t, so PRIu64 is the correct format specifier.
--- contrib/plugins/hotblocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/plugins/hotblocks.c +1 -1
@@ -87,7 +87,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)for (i =0 , it = sorted_counts; i < limit && it; i++, it = it->next) {ExecCount *rec = (ExecCount *) it->data; g_string_append_printf( - report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", + report, "0x%016"PRIx64", %d, %ld, %"PRIu64"\n", rec->start_addr, rec->trans_count, rec->insns, qemu_plugin_u64_sum(
Signature · 1 line
2.50.1
Re: [PATCH 3/5] contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than PRId64
Quoted 23 lines · Alex Bradbury
qemu_plugin_u64_sumreturns auint64_t, so PRIu64 is the correct format specifier.Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)contrib/plugins/hotblocks.c +1
-2@@ -87,7 +87,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)for (i =0 , it = sorted_counts; i < limit && it; i++, it = it->next) {ExecCount *rec = (ExecCount *) it->data; g_string_append_printf( - report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", + report, "0x%016"PRIx64", %d, %ld, %"PRIu64"\n", rec->start_addr, rec->trans_count, rec->insns, qemu_plugin_u64_sum( --
Quoted 3 lines
2.50.1
Re: [PATCH 3/5] contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than PRId64
In reply to Alex BradburyQuoted 7 lines · Alex Bradbury
qemu_plugin_u64_sumreturns auint64_t, so PRIu64 is the correct format specifier.Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 4/5 docs/about/emulation: Add documentation for hotblocks plugin arguments
In reply to Alex BradburyCurrently just 'inline'.
--- docs/about/emulation.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
docs/about/emulation.rst +10 -0
@@ -463,6 +463,16 @@ Example:: 0x000000004002b0, 1, 4, 66087 ... +Behaviour can be tweaked with the following arguments: + +.. list-table:: Hot Blocks plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - inline=true|false + - Use faster inline addition of a single counter. Hot Pages .........
Signature · 1 line
2.50.1
Re: [PATCH 4/5] docs/about/emulation: Add documentation for hotblocks plugin arguments
Quoted 6 lines · Alex Bradbury
Currently just 'inline'.
Signed-off-by Alex Bradbury <[email protected]>--- docs/about/emulation.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
PATCH 5/5 contrib/plugins/hotblocks: Allow limit to be set as a command line argument
In reply to Alex BradburyAlso add documentation for this argument. This allows the default of 20 to be overridden, and is helpful for using the hotblocks plugin for analysis scripts that require collecting data on a larger number of blocks (e.g. setting limit=0 to dump information on all blocks).
--- contrib/plugins/hotblocks.c | 10 +++++++++- docs/about/emulation.rst | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-)
contrib/plugins/hotblocks.c +9 -1
@@ -84,7 +84,8 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)if (sorted_counts) {g_string_append_printf (report,"pc, tcount, icount, ecount\n" ); -for (i =0 , it = sorted_counts; i < limit && it; i++, it = it->next) { +for (i =0 , it = sorted_counts; (limit ==0 || i < limit) && it; + i++, it = it->next) {ExecCount *rec = (ExecCount *) it->data; g_string_append_printf( report, "0x%016"PRIx64", %d, %ld, %"PRIu64"\n",
@@ -170,6 +171,13 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,fprintf (stderr,"boolean argument parsing failed: %s\n" , opt);return -1 ; } + }else if (g_strcmp0 (tokens[0 ],"limit" ) ==0 ) { +char *endptr =NULL ; + limit =g_ascii_strtoull (tokens[1 ], &endptr,10 ); +if (endptr == tokens[1 ] || *endptr !='\0' ) { +fprintf (stderr,"unsigned integer parsing failed: %s\n" , opt); +return -1 ; + } }else {fprintf (stderr,"option parsing failed: %s\n" , opt);return -1 ;
docs/about/emulation.rst +2 -0
@@ -473,6 +473,8 @@ Behaviour can be tweaked with the following arguments: - Description * - inline=true|false - Use faster inline addition of a single counter. + * - limit=N + - The number of blocks to be printed. (Default: N = 20, use 0 for no limit). Hot Pages .........
Signature · 1 line
2.50.1
Re: [PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument
Quoted 10 lines · Alex Bradbury
Also add documentation for this argument. This allows the default of 20 to be overridden, and is helpful for using the hotblocks plugin for analysis scripts that require collecting data on a larger number of blocks (e.g. setting limit=0 to dump information on all blocks).
Signed-off-by Alex Bradbury <[email protected]>--- contrib/plugins/hotblocks.c | 10 +++++++++- docs/about/emulation.rst | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-)
That's a good idea, thanks!
Hi Alex,
Quoted 22 lines · Alex Bradbury
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Printuint64_twith PRIu64 rather thanPRId64docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argument
Quoted 8 lines
contrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)--
2.50.1
I think the mailing list ate up your first patch. Not your fault though. I did not receive it in my inbox and it's not on lore.kernel.org either:
Quoted 18 lines
$ b4 shazam [email protected] Grabbing thread from lore.kernel.org/all/[email protected]/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 5 messages in the thread Looking for additional code-review trailers on lore.kernel.org Analyzing 0 code-review messages Checking attestation on all messages, may take a moment... --- ERROR: missing [1/5]! ✗ [PATCH 2/5] contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 3/5] contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than PRId64 ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 4/5] docs/about/emulation: Add documentation for hotblocks plugin arguments ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument ✗ BADSIG: DKIM/igalia.com
Quoted 8 lines
--- Total patches: 4 --- WARNING: Thread incomplete! Applying: contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks Patch failed at 0001 contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks error: sha1 information is lacking or useless (contrib/plugins/hotblocks.c). error: could not build fake ancestor
Could you resend it?
Quoted 29 lines · Manos Pitsidianakis
Hi Alex,
Quoted 26 lines · Alex Bradbury
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Printuint64_twith PRIu64 rather thanPRId64docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argumentcontrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
Quoted 8 lines
Quoted 4 lines
--
2.50.1I think the mailing list ate up your first patch. Not your fault though. I did not receive it in my inbox and it's not on lore.kernel.org either:
Thanks for taking a look - it seems like it's made it through now
https://lore.kernel.org/qemu-devel/cf5a00136738b981a12270b76572e8d502daf208.1753857212.git.asb@igalia.com/
Best,
Alex
Quoted 65 lines · Manos Pitsidianakis
Hi Alex,
Quoted 22 lines · Alex Bradbury
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Printuint64_twith PRIu64 rather thanPRId64docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argumentQuoted 8 lines
contrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)--
2.50.1I think the mailing list ate up your first patch. Not your fault though. I did not receive it in my inbox and it's not on lore.kernel.org either:
Quoted 18 lines
$ b4 shazam [email protected] Grabbing thread from lore.kernel.org/all/[email protected]/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 5 messages in the thread Looking for additional code-review trailers on lore.kernel.org Analyzing 0 code-review messages Checking attestation on all messages, may take a moment... --- ERROR: missing [1/5]! ✗ [PATCH 2/5] contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 3/5] contrib/plugins/hotblocks: Print uint64_t with PRIu64 rather than PRId64 ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 4/5] docs/about/emulation: Add documentation for hotblocks plugin arguments ✗ BADSIG: DKIM/igalia.com ✗ [PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument ✗ BADSIG: DKIM/igalia.comQuoted 8 lines
--- Total patches: 4 --- WARNING: Thread incomplete! Applying: contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks Patch failed at 0001 contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks error: sha1 information is lacking or useless (contrib/plugins/hotblocks.c). error: could not build fake ancestor
Quoted 1 line
Could you resend it?
I've been lucky to receive it, probably because I'm in direct copy as a plugins reviewer.
However, it would be better for the mailing list if you could resend it indeed Alex (you can apply the reviewed-by at the same time, so this v2 "adds" something).
Regards,
Pierrick
Quoted 11 lines · Alex Bradbury
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Thanks for contributing Alex.
As you probably read, in case a v2 is expected (the plugins maintainer Alex will be back next week, he might have additional comments), you can add the "Reviewed-by" tags you already collected to your commits by ammending their messages. For the rest, your series looks good to me.
Regards,
Pierrick
Quoted 14 lines
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Printuint64_twith PRIu64 rather thanPRId64docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argumentcontrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
Quoted 16 lines · Alex Bradbury
This series contains one minor feature addition and a series of small bugfixes/improvements. The addition that motivates the submission is to add a limit argument for the hotblocks plugin, allowing you to control how many blocks are printed rather than being hardcoded to the 20 most executed. Setting limit=0 and dumping information about all executed blocks is incredibly helpful for an analysis script I have downstream.
This is my first contribution to QEMU. I've attempted to follow all of the guidance in the "Submitting a Patch" guide, but apologies if I missed anything.
Alex Bradbury (5):
contrib/plugins/hotblocks: Correctly free sorted counts list contrib/plugins/hotblocks: Fix off by one error in iteration of sorted
blocks
contrib/plugins/hotblocks: Printuint64_twith PRIu64 rather than
Quoted 9 lines
PRId64docs/about/emulation: Add documentation for hotblocks plugin arguments contrib/plugins/hotblocks: Allow limit to be set as a command line
argumentcontrib/plugins/hotblocks.c | 20 ++++++++++++++------ docs/about/emulation.rst | 12 ++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
This was merged into master (a8e6997ef).
Thank you for your contribution!
Regards,
Pierrick