Skip to content

Commit 1d8d90d

Browse files
Ingo Molnarpenberg
Ingo Molnar
authored andcommitted
kvm tools: Dump vCPUs in order
* Ingo Molnar <mingo@elte.hu> wrote: > The patch below addresses these concerns, serializes the output, tidies up the > printout, resulting in this new output: There's one bug remaining that my patch does not address: the vCPUs are not printed in order: # vCPU #0's dump: # vCPU #2's dump: # vCPU torvalds#24's dump: # vCPU #5's dump: # vCPU torvalds#39's dump: # vCPU torvalds#38's dump: # vCPU torvalds#51's dump: # vCPU torvalds#11's dump: # vCPU torvalds#10's dump: # vCPU torvalds#12's dump: This is undesirable as the order of printout is highly random, so successive dumps are difficult to compare. The patch below serializes the signalling itself. (this is on top of the previous patch) The patch also tweaks the vCPU printout line a bit so that it does not start with '#', which is discarded if such messages are pasted into Git commit messages. Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Pekka Enberg <penberg@kernel.org>
1 parent 4cd62c7 commit 1d8d90d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tools/kvm/kvm-run.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <kvm/term.h>
2626
#include <kvm/ioport.h>
2727
#include <kvm/threadpool.h>
28+
#include <kvm/barrier.h>
2829

2930
/* header files for gitish interface */
3031
#include <kvm/kvm-run.h>
@@ -132,7 +133,7 @@ static const struct option options[] = {
132133
* Serialize debug printout so that the output of multiple vcpus does not
133134
* get mixed up:
134135
*/
135-
static DEFINE_MUTEX(printout_mutex);
136+
static int printout_done;
136137

137138
static void handle_sigusr1(int sig)
138139
{
@@ -141,13 +142,13 @@ static void handle_sigusr1(int sig)
141142
if (!cpu)
142143
return;
143144

144-
mutex_lock(&printout_mutex);
145-
printf("\n#\n# vCPU #%ld's dump:\n#\n", cpu->cpu_id);
145+
printf("\n #\n # vCPU #%ld's dump:\n #\n", cpu->cpu_id);
146146
kvm_cpu__show_registers(cpu);
147147
kvm_cpu__show_code(cpu);
148148
kvm_cpu__show_page_tables(cpu);
149149
fflush(stdout);
150-
mutex_unlock(&printout_mutex);
150+
printout_done = 1;
151+
mb();
151152
}
152153

153154
static void handle_sigquit(int sig)
@@ -160,7 +161,15 @@ static void handle_sigquit(int sig)
160161
if (!cpu)
161162
continue;
162163

164+
printout_done = 0;
163165
pthread_kill(cpu->thread, SIGUSR1);
166+
/*
167+
* Wait for the vCPU to dump state before signalling
168+
* the next thread. Since this is debug code it does
169+
* not matter that we are burning CPU time a bit:
170+
*/
171+
while (!printout_done)
172+
mb();
164173
}
165174

166175
serial8250__inject_sysrq(kvm);

0 commit comments

Comments
 (0)