From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: [PATCH 2/2][REPOST] kvm: user: Add event mask support in kvmtrace. Date: Wed, 25 Jun 2008 16:41:19 +0800 Message-ID: <200806251641.19985.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_vSgYI3BGRXpVZ86" To: kvm@vger.kernel.org Return-path: Received: from mga09.intel.com ([134.134.136.24]:50928 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365AbYFYIlB (ORCPT ); Wed, 25 Jun 2008 04:41:01 -0400 Sender: kvm-owner@vger.kernel.org List-ID: --Boundary-00=_vSgYI3BGRXpVZ86 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =46rom 0456679ed9444d153c60e41dfc556b7ca4d6277f Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Wed, 25 Jun 2008 16:40:56 +0800 Subject: [PATCH] kvm: user: Add event mask support in kvmtrace. Signed-off-by: Feng (Eric) Liu =2D-- user/kvmtrace.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++= +-- 1 files changed, 53 insertions(+), 3 deletions(-) diff --git a/user/kvmtrace.c b/user/kvmtrace.c index 876ac27..a7b2071 100644 =2D-- a/user/kvmtrace.c +++ b/user/kvmtrace.c @@ -54,7 +54,7 @@ static char kvmtrace_version[] =3D "0.1"; #define max(a, b) ((a) > (b) ? (a) : (b)) =2D#define S_OPTS "r:o:w:?Vb:n:D:" +#define S_OPTS "r:o:w:?Vb:n:D:e:" static struct option l_opts[] =3D { { .name =3D "relay", @@ -99,6 +99,12 @@ static struct option l_opts[] =3D { .val =3D 'D' }, { + .name =3D "event_mask", + .has_arg =3D required_argument, + .flag =3D NULL, + .val =3D 'e' + }, + { .name =3D NULL, } }; @@ -154,6 +160,8 @@ static char *output_dir; static int stop_watch; static unsigned long buf_size =3D BUF_SIZE; static unsigned long buf_nr =3D BUF_NR; +static int cat_mask =3D ~0u; +static unsigned long long act_bitmap[16]; static unsigned int page_size; #define for_each_cpu_online(cpu) \ @@ -175,6 +183,13 @@ static void handle_sigint(__attribute__((__unused__)) = int=20 sig) done =3D 1; } +static inline int valid_mask_opt(int x) +{ + return ((1 << KVM_TRC_SHIFT) <=3D x) && + (x < (1 << (KVM_TRC_CAT_NR_BITS + KVM_TRC_SHIFT))) && + (0 <=3D KVM_TRC_ACT(x)) && (KVM_TRC_ACT(x) < 64); +} + static int get_lost_records() { int fd; @@ -473,6 +488,8 @@ static int start_trace(void) memset(&kuts, 0, sizeof(kuts)); kuts.buf_size =3D trace_information.buf_size =3D buf_size; kuts.buf_nr =3D trace_information.buf_nr =3D buf_nr; + kuts.cat_mask =3D cat_mask; + memcpy(kuts.act_bitmap, act_bitmap, sizeof(act_bitmap)); if (ioctl(trace_information.fd , KVM_TRACE_ENABLE, &kuts) < 0) { perror("KVM_TRACE_ENABLE"); @@ -587,13 +604,21 @@ static void show_stats(void) static char usage_str[] =3D \ "[ -r debugfs path ] [ -D output dir ] [ -b buffer size ]\n" \ =2D "[ -n number of buffers] [ -o ] [ -w time ] [ -V ]\n\n" \ + "[ -n number of buffers] [ -o ] [ -e event mask ]" \ + "[ -w time ] [ -V ]\n\n" \ "\t-r Path to mounted debugfs, defaults to /sys/kernel/debug\n" \ "\t-o File(s) to send output to\n" \ "\t-D Directory to prepend to output file names\n" \ "\t-w Stop after defined time, in seconds\n" \ "\t-b Sub buffer size in KiB\n" \ "\t-n Number of sub buffers\n" \ + "\t-e Only trace specified categories or actions.\n" \ + "\t kvmtrace defaults to collecting all events can be traced.\n" \ + "\t To limit the events being captured, you can specify filter.\n" \ + "\t if you want to trace all the actions of one category," \ + " set action to zero. \n" \ + "\t eg: -e 0x00010000 -e 00020001 trace entryexit and PAGE_FAULT \n" \ + "\t -e 0x00020005 -e 00020006 trace IO_READ and IO_WRITE. \n" \ "\t-V Print program version info\n\n"; static void show_usage(char *prog) @@ -604,7 +629,7 @@ static void show_usage(char *prog) void parse_args(int argc, char **argv) { =2D int c; + int c, cat_mask_tmp =3D 0; while ((c =3D getopt_long(argc, argv, S_OPTS, l_opts, NULL)) >=3D 0) { switch (c) { @@ -647,6 +672,26 @@ void parse_args(int argc, char **argv) case 'D': output_dir =3D optarg; break; + case 'e': { + int index, mask; + + if ((sscanf(optarg, "%x", &mask) !=3D 1) || + !valid_mask_opt(mask)) { + fprintf(stderr, + "Invalid event mask (%u)\n", mask); + exit(EXIT_FAILURE); + } + cat_mask_tmp |=3D KVM_TRC_CAT(mask); + index =3D ffs(KVM_TRC_CAT(mask)) - 1; + if (KVM_TRC_ACT(mask) =3D=3D 0) + act_bitmap[index] =3D ~0ull; + else { + if (act_bitmap[index] =3D=3D ~0ull) + act_bitmap[index] =3D 0; + act_bitmap[index] |=3D 1 << KVM_TRC_ACT(mask); + } + break; + } default: show_usage(argv[0]); } @@ -654,12 +699,17 @@ void parse_args(int argc, char **argv) if (optind < argc || output_name =3D=3D NULL) show_usage(argv[0]); + + if (cat_mask_tmp !=3D 0) + cat_mask =3D cat_mask_tmp; } int main(int argc, char *argv[]) { struct statfs st; + memset(act_bitmap, ~0u, sizeof(act_bitmap)); + parse_args(argc, argv); if (!debugfs_path) =2D- 1.5.5 --Boundary-00=_vSgYI3BGRXpVZ86 Content-Type: text/x-diff; charset="utf-8"; name="0001-kvm-user-Add-event-mask-support-in-kvmtrace.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-kvm-user-Add-event-mask-support-in-kvmtrace.patch" =46rom 0456679ed9444d153c60e41dfc556b7ca4d6277f Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Wed, 25 Jun 2008 16:40:56 +0800 Subject: [PATCH] kvm: user: Add event mask support in kvmtrace. Signed-off-by: Feng (Eric) Liu =2D-- user/kvmtrace.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++= +-- 1 files changed, 53 insertions(+), 3 deletions(-) diff --git a/user/kvmtrace.c b/user/kvmtrace.c index 876ac27..a7b2071 100644 =2D-- a/user/kvmtrace.c +++ b/user/kvmtrace.c @@ -54,7 +54,7 @@ static char kvmtrace_version[] =3D "0.1"; =20 #define max(a, b) ((a) > (b) ? (a) : (b)) =20 =2D#define S_OPTS "r:o:w:?Vb:n:D:" +#define S_OPTS "r:o:w:?Vb:n:D:e:" static struct option l_opts[] =3D { { .name =3D "relay", @@ -99,6 +99,12 @@ static struct option l_opts[] =3D { .val =3D 'D' }, { + .name =3D "event_mask", + .has_arg =3D required_argument, + .flag =3D NULL, + .val =3D 'e' + }, + { .name =3D NULL, } }; @@ -154,6 +160,8 @@ static char *output_dir; static int stop_watch; static unsigned long buf_size =3D BUF_SIZE; static unsigned long buf_nr =3D BUF_NR; +static int cat_mask =3D ~0u; +static unsigned long long act_bitmap[16]; static unsigned int page_size; =20 #define for_each_cpu_online(cpu) \ @@ -175,6 +183,13 @@ static void handle_sigint(__attribute__((__unused__)) = int sig) done =3D 1; } =20 +static inline int valid_mask_opt(int x) +{ + return ((1 << KVM_TRC_SHIFT) <=3D x) && + (x < (1 << (KVM_TRC_CAT_NR_BITS + KVM_TRC_SHIFT))) && + (0 <=3D KVM_TRC_ACT(x)) && (KVM_TRC_ACT(x) < 64); +} + static int get_lost_records() { int fd; @@ -473,6 +488,8 @@ static int start_trace(void) memset(&kuts, 0, sizeof(kuts)); kuts.buf_size =3D trace_information.buf_size =3D buf_size; kuts.buf_nr =3D trace_information.buf_nr =3D buf_nr; + kuts.cat_mask =3D cat_mask; + memcpy(kuts.act_bitmap, act_bitmap, sizeof(act_bitmap)); =20 if (ioctl(trace_information.fd , KVM_TRACE_ENABLE, &kuts) < 0) { perror("KVM_TRACE_ENABLE"); @@ -587,13 +604,21 @@ static void show_stats(void) =20 static char usage_str[] =3D \ "[ -r debugfs path ] [ -D output dir ] [ -b buffer size ]\n" \ =2D "[ -n number of buffers] [ -o ] [ -w time ] [ -V ]\n\n" \ + "[ -n number of buffers] [ -o ] [ -e event mask ]" \ + "[ -w time ] [ -V ]\n\n" \ "\t-r Path to mounted debugfs, defaults to /sys/kernel/debug\n" \ "\t-o File(s) to send output to\n" \ "\t-D Directory to prepend to output file names\n" \ "\t-w Stop after defined time, in seconds\n" \ "\t-b Sub buffer size in KiB\n" \ "\t-n Number of sub buffers\n" \ + "\t-e Only trace specified categories or actions.\n" \ + "\t kvmtrace defaults to collecting all events can be traced.\n" \ + "\t To limit the events being captured, you can specify filter.\n" \ + "\t if you want to trace all the actions of one category," \ + " set action to zero. \n" \ + "\t eg: -e 0x00010000 -e 00020001 trace entryexit and PAGE_FAULT \n" \ + "\t -e 0x00020005 -e 00020006 trace IO_READ and IO_WRITE. \n" \ "\t-V Print program version info\n\n"; =20 static void show_usage(char *prog) @@ -604,7 +629,7 @@ static void show_usage(char *prog) =20 void parse_args(int argc, char **argv) { =2D int c; + int c, cat_mask_tmp =3D 0; =20 while ((c =3D getopt_long(argc, argv, S_OPTS, l_opts, NULL)) >=3D 0) { switch (c) { @@ -647,6 +672,26 @@ void parse_args(int argc, char **argv) case 'D': output_dir =3D optarg; break; + case 'e': { + int index, mask; + + if ((sscanf(optarg, "%x", &mask) !=3D 1) || + !valid_mask_opt(mask)) { + fprintf(stderr, + "Invalid event mask (%u)\n", mask); + exit(EXIT_FAILURE); + } + cat_mask_tmp |=3D KVM_TRC_CAT(mask); + index =3D ffs(KVM_TRC_CAT(mask)) - 1; + if (KVM_TRC_ACT(mask) =3D=3D 0) + act_bitmap[index] =3D ~0ull; + else { + if (act_bitmap[index] =3D=3D ~0ull) + act_bitmap[index] =3D 0; + act_bitmap[index] |=3D 1 << KVM_TRC_ACT(mask); + } + break; + } default: show_usage(argv[0]); } @@ -654,12 +699,17 @@ void parse_args(int argc, char **argv) =20 if (optind < argc || output_name =3D=3D NULL) show_usage(argv[0]); + + if (cat_mask_tmp !=3D 0) + cat_mask =3D cat_mask_tmp; } =20 int main(int argc, char *argv[]) { struct statfs st; =20 + memset(act_bitmap, ~0u, sizeof(act_bitmap)); + parse_args(argc, argv); =20 if (!debugfs_path) =2D-=20 1.5.5 --Boundary-00=_vSgYI3BGRXpVZ86--