From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: [PATCH 1/2] KVM: trace: Add event mask support Date: Wed, 13 Aug 2008 15:54:26 +0800 Message-ID: <200808131554.26482.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_yMpoInTomYbXyl4" Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mga01.intel.com ([192.55.52.88]:44837 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752262AbYHMHva (ORCPT ); Wed, 13 Aug 2008 03:51:30 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: --Boundary-00=_yMpoInTomYbXyl4 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =46rom bb7cc3fd1e549d38d6bda10a06feda9339de9d3e Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Wed, 13 Aug 2008 14:29:43 +0800 Subject: [PATCH] KVM: trace: Add event mask support Allow user space application to specify one or morefilter masks to=20 limit the events being captured via it. Signed-off-by: Feng (Eric) Liu Signed-off-by: Sheng Yang =2D-- include/linux/kvm.h | 7 +++++++ virt/kvm/kvm_trace.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm.h b/include/linux/kvm.h index d9ef7d3..05713f2 100644 =2D-- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -18,6 +18,9 @@ struct kvm_user_trace_setup { __u32 buf_size; /* sub_buffer size of each per-cpu */ __u32 buf_nr; /* the number of sub_buffers of each per-cpu */ + __u16 cat_mask; /* the tracing categories are enabled */ + __u16 pad1[3]; + __u64 act_bitmap[16]; /* the actions are enabled for each category=20 */ }; /* for KVM_CREATE_MEMORY_REGION */ @@ -292,6 +295,7 @@ struct kvm_s390_interrupt { }; #define KVM_TRC_SHIFT 16 +#define KVM_TRC_CAT_NR_BITS 12 /* * kvm trace categories */ @@ -305,6 +309,9 @@ struct kvm_s390_interrupt { #define KVM_TRC_VMEXIT (KVM_TRC_ENTRYEXIT + 0x02) #define KVM_TRC_PAGE_FAULT (KVM_TRC_HANDLER + 0x01) +#define KVM_TRC_CAT(evt) (((evt) >> KVM_TRC_SHIFT) & 0x0fff) +#define KVM_TRC_ACT(evt) ((evt) & (~0u >> KVM_TRC_SHIFT)) + #define KVM_TRC_HEAD_SIZE 12 #define KVM_TRC_CYCLE_SIZE 8 #define KVM_TRC_EXTRA_MAX 7 diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c index 41dcc84..bb4046c 100644 =2D-- a/virt/kvm/kvm_trace.c +++ b/virt/kvm/kvm_trace.c @@ -27,6 +27,8 @@ struct kvm_trace { int trace_state; + u16 cat_mask; + u64 act_bitmap[16]; struct rchan *rchan; struct dentry *lost_file; atomic_t lost_records; @@ -40,6 +42,23 @@ struct kvm_trace_probe { marker_probe_func *probe_func; }; +static inline int check_event_mask(struct kvm_trace *kt, u32 event) +{ + unsigned long category; + int i; + + category =3D KVM_TRC_CAT(event); + if (!(category & kt->cat_mask)) + return 1; + + i =3D find_first_bit(&category, KVM_TRC_CAT_NR_BITS); + + if (!test_bit(KVM_TRC_ACT(event), &kt->act_bitmap[i])) + return 1; + + return 0; +} + static inline int calc_rec_size(int timestamp, int extra) { int rec_size =3D KVM_TRC_HEAD_SIZE; @@ -56,12 +75,15 @@ static void kvm_add_trace(void *probe_private,=20 void *call_data, struct kvm_trace_rec rec; struct kvm_vcpu *vcpu; int i, size; =2D u32 extra; + u32 extra, event; if (unlikely(kt->trace_state !=3D KVM_TRACE_STATE_RUNNING)) return; =2D rec.rec_val =3D TRACE_REC_EVENT_ID(va_arg(*args, u32)); + event =3D TRACE_REC_EVENT_ID(va_arg(*args, u32)); + if (check_event_mask(kt, event)) + return; + vcpu =3D va_arg(*args, struct kvm_vcpu *); rec.pid =3D current->tgid; rec.vcpu_id =3D vcpu->vcpu_id; @@ -70,7 +92,7 @@ static void kvm_add_trace(void *probe_private, void=20 *call_data, WARN_ON(!(extra <=3D KVM_TRC_EXTRA_MAX)); extra =3D min_t(u32, extra, KVM_TRC_EXTRA_MAX); =2D rec.rec_val |=3D TRACE_REC_TCS(p->timestamp_in) + rec.rec_val =3D event | TRACE_REC_TCS(p->timestamp_in) | TRACE_REC_NUM_DATA_ARGS(extra); if (p->timestamp_in) { @@ -177,6 +199,8 @@ static int do_kvm_trace_enable(struct=20 kvm_user_trace_setup *kuts) if (!kt->rchan) goto err; + kt->cat_mask =3D kuts->cat_mask; + memcpy(kt->act_bitmap, kuts->act_bitmap, sizeof(kuts->act_bitmap)); kvm_trace =3D kt; for (i =3D 0; i < ARRAY_SIZE(kvm_trace_probes); i++) { =2D- 1.5.6 --Boundary-00=_yMpoInTomYbXyl4 Content-Type: text/x-diff; charset="us-ascii"; name="0001-KVM-trace-Add-event-mask-support.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-KVM-trace-Add-event-mask-support.patch" =46rom bb7cc3fd1e549d38d6bda10a06feda9339de9d3e Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Wed, 13 Aug 2008 14:29:43 +0800 Subject: [PATCH] KVM: trace: Add event mask support. Allow user space application to specify one or morefilter masks to limit the events being captured via it. Signed-off-by: Feng (Eric) Liu Signed-off-by: Sheng Yang =2D-- include/linux/kvm.h | 7 +++++++ virt/kvm/kvm_trace.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm.h b/include/linux/kvm.h index d9ef7d3..05713f2 100644 =2D-- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -18,6 +18,9 @@ struct kvm_user_trace_setup { __u32 buf_size; /* sub_buffer size of each per-cpu */ __u32 buf_nr; /* the number of sub_buffers of each per-cpu */ + __u16 cat_mask; /* the tracing categories are enabled */ + __u16 pad1[3]; + __u64 act_bitmap[16]; /* the actions are enabled for each category */ }; =20 /* for KVM_CREATE_MEMORY_REGION */ @@ -292,6 +295,7 @@ struct kvm_s390_interrupt { }; =20 #define KVM_TRC_SHIFT 16 +#define KVM_TRC_CAT_NR_BITS 12 /* * kvm trace categories */ @@ -305,6 +309,9 @@ struct kvm_s390_interrupt { #define KVM_TRC_VMEXIT (KVM_TRC_ENTRYEXIT + 0x02) #define KVM_TRC_PAGE_FAULT (KVM_TRC_HANDLER + 0x01) =20 +#define KVM_TRC_CAT(evt) (((evt) >> KVM_TRC_SHIFT) & 0x0fff) +#define KVM_TRC_ACT(evt) ((evt) & (~0u >> KVM_TRC_SHIFT)) + #define KVM_TRC_HEAD_SIZE 12 #define KVM_TRC_CYCLE_SIZE 8 #define KVM_TRC_EXTRA_MAX 7 diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c index 41dcc84..bb4046c 100644 =2D-- a/virt/kvm/kvm_trace.c +++ b/virt/kvm/kvm_trace.c @@ -27,6 +27,8 @@ =20 struct kvm_trace { int trace_state; + u16 cat_mask; + u64 act_bitmap[16]; struct rchan *rchan; struct dentry *lost_file; atomic_t lost_records; @@ -40,6 +42,23 @@ struct kvm_trace_probe { marker_probe_func *probe_func; }; =20 +static inline int check_event_mask(struct kvm_trace *kt, u32 event) +{ + unsigned long category; + int i; + + category =3D KVM_TRC_CAT(event); + if (!(category & kt->cat_mask)) + return 1; + + i =3D find_first_bit(&category, KVM_TRC_CAT_NR_BITS); + + if (!test_bit(KVM_TRC_ACT(event), &kt->act_bitmap[i])) + return 1; + + return 0; +} + static inline int calc_rec_size(int timestamp, int extra) { int rec_size =3D KVM_TRC_HEAD_SIZE; @@ -56,12 +75,15 @@ static void kvm_add_trace(void *probe_private, void *ca= ll_data, struct kvm_trace_rec rec; struct kvm_vcpu *vcpu; int i, size; =2D u32 extra; + u32 extra, event; =20 if (unlikely(kt->trace_state !=3D KVM_TRACE_STATE_RUNNING)) return; =20 =2D rec.rec_val =3D TRACE_REC_EVENT_ID(va_arg(*args, u32)); + event =3D TRACE_REC_EVENT_ID(va_arg(*args, u32)); + if (check_event_mask(kt, event)) + return; + vcpu =3D va_arg(*args, struct kvm_vcpu *); rec.pid =3D current->tgid; rec.vcpu_id =3D vcpu->vcpu_id; @@ -70,7 +92,7 @@ static void kvm_add_trace(void *probe_private, void *call= _data, WARN_ON(!(extra <=3D KVM_TRC_EXTRA_MAX)); extra =3D min_t(u32, extra, KVM_TRC_EXTRA_MAX); =20 =2D rec.rec_val |=3D TRACE_REC_TCS(p->timestamp_in) + rec.rec_val =3D event | TRACE_REC_TCS(p->timestamp_in) | TRACE_REC_NUM_DATA_ARGS(extra); =20 if (p->timestamp_in) { @@ -177,6 +199,8 @@ static int do_kvm_trace_enable(struct kvm_user_trace_se= tup *kuts) if (!kt->rchan) goto err; =20 + kt->cat_mask =3D kuts->cat_mask; + memcpy(kt->act_bitmap, kuts->act_bitmap, sizeof(kuts->act_bitmap)); kvm_trace =3D kt; =20 for (i =3D 0; i < ARRAY_SIZE(kvm_trace_probes); i++) { =2D-=20 1.5.6 --Boundary-00=_yMpoInTomYbXyl4--