lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20121114013716.5338.37763.stgit@yunodevel>
Date:	Wed, 14 Nov 2012 10:37:26 +0900
From:	Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@...achi.com>
To:	linux-kernel@...r.kernel.org
Cc:	"H. Peter Anvin" <hpa@...or.com>, kvm@...r.kernel.org,
	Joerg Roedel <joerg.roedel@....com>,
	David Sharp <dhsharp@...gle.com>,
	Marcelo Tosatti <mtosatti@...hat.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Hidehiro Kawai <hidehiro.kawai.ez@...achi.com>,
	Ingo Molnar <mingo@...hat.com>, Avi Kivity <avi@...hat.com>,
	yrl.pp-manager.tt@...achi.com,
	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Thomas Gleixner <tglx@...utronix.de>
Subject: [RFC PATCH 2/2] tools: Add a tool for merging trace data of a guest
 and a host

This tool merges trace data of a guest and a host in chronological order.
Note that this tool is used only for a guest and a host. (not for multiple
guests)

- How to use
1. Get trace data of the host and guest via ssh, virtio-serial, or virtio-trace

2. Get TSC offset after applied patch "kvm/vmx: Print TSC_OFFSET information
   when TSC offset value is written to VMCS"
$ dmesg | grep kvm
[   57.717180] kvm: ([PID]) write TSC offset [TSC offset], now clock [HOST TSC]

3. Use this tool
$ ./trace-merge.pl <TSC offset> <host data> <guest data>

h        qemu-kvm-2687  [003] d...50550079203669: kvm_exit: [detail]
h        qemu-kvm-2687  [003] d...50550079206816: kvm_entry: [detail]
g            comm-3826  [000] d.h.50550079226331: sched_wakeup: [detail]
h        qemu-kvm-2687  [003] d...50550079240656: kvm_exit: [detail]
h        qemu-kvm-2687  [003] d...50550079243467: kvm_entry: [detail]
h        qemu-kvm-2687  [003] d...50550079256103: kvm_exit: [detail]
h        qemu-kvm-2687  [003] d...50550079268391: kvm_entry: [detail]
g            comm-3826  [000] d...50550079279266: sched_switch: [detail]
h        qemu-kvm-2687  [003] d...50550079280829: kvm_exit: [detail]
h        qemu-kvm-2687  [003] d...50550079286028: kvm_entry: [detail]
|
\----guest/host

Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@...achi.com>
---
 tools/scripts/trace-merge/trace-merge.pl |  109 ++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100755 tools/scripts/trace-merge/trace-merge.pl

diff --git a/tools/scripts/trace-merge/trace-merge.pl b/tools/scripts/trace-merge/trace-merge.pl
new file mode 100755
index 0000000..e0b080c
--- /dev/null
+++ b/tools/scripts/trace-merge/trace-merge.pl
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+#
+# Tool for merging and sorting trace data of a guest and host
+#
+# Created by Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@...achi.com>
+#
+# - How to use
+#   ./trace-merge.pl <TSC offset> <host data> <guest data>
+#
+use strict;
+use bigint;
+
+my %all_data_info = ();
+my @merged_data = ();
+my @sorted_data = ();
+
+&read_all_data();
+&merge_guest_host_data();
+&sort_data_by_tsc();
+&output_data();
+
+sub read_all_data {
+	# TSC offset value is very big ull value.
+	# This value is actually negative, so we calculate the value here.
+	$all_data_info{"tsc_offset"} = &convert_tscoffset($ARGV[0]);
+	if ($all_data_info{"tsc_offset"} == 0) {
+		die "TSC should not be 0";
+	}
+
+	if (!open(HOST_DATA, $ARGV[1])) {
+		die "Cannot open host file: $!"
+	}
+	my @host_data = <HOST_DATA>;
+	close(HOST_DATA);
+
+	if (!open(GUEST_DATA, $ARGV[2])) {
+		die "Cannot open guest file: $!"
+	}
+	my @guest_data = <GUEST_DATA>;
+	close(GUEST_DATA);
+
+	$all_data_info{"host_data"} = \@host_data;
+	$all_data_info{"guest_data"} = \@guest_data;
+}
+
+sub merge_guest_host_data {
+	&guest_push_data();
+	&host_push_data();
+}
+
+sub sort_data_by_tsc {
+	no strict 'refs';
+	@sorted_data = sort {$a->{tsc} <=> $b->{tsc}} @merged_data;
+}
+
+sub output_data {
+	foreach my $line (@sorted_data) {
+		print "$line->{name}$line->{comm}$line->{tsc}$line->{event}\n";
+	}
+}
+
+sub guest_push_data {
+	&make_data_list(1);
+}
+
+sub host_push_data {
+	&make_data_list(0);
+}
+
+#
+# If this function is used for guest's data,
+# subtract TSC offset from guest's TSC value.
+#
+# NOTE: guest's TSC is added TSC offset to actual TSC when the guest boots.
+#
+sub make_data_list {
+	my $is_guest = $_[0];
+	my @data = ();
+	my $name = "";
+	my $list = "";
+	my $tsc_offset = 0;
+
+	if ($is_guest eq 1) {
+		$name = "g";
+		@data = @{$all_data_info{"guest_data"}};
+		$tsc_offset = $all_data_info{"tsc_offset"};
+	} else {
+		$name = "h";
+		@data = @{$all_data_info{"host_data"}};
+	}
+
+	foreach my $line (@data) {
+		chomp($line);
+
+		if ($line =~ /^(.+\[[0-9]+\].{5})([0-9]+)(:.+)/) {
+			$list = {
+				name	=> $name,
+				comm	=> $1,
+				tsc	=> $2 - $tsc_offset,
+				event	=> $3
+			};
+			push(@merged_data, $list);
+		}
+	}
+}
+
+sub convert_tscoffset {
+	return $_[0] - (1 << 64);
+}


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ