All of lore.kernel.org
 help / color / mirror / Atom feed
From: ehrhardt@linux.vnet.ibm.com
To: kvm@vger.kernel.org
Cc: hollisb@us.ibm.com, avi@qumranet.com, kvm-ppc@vger.kernel.org,
	ehrhardt@linux.vnet.ibm.com
Subject: [PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3
Date: Mon, 07 Jul 2008 13:56:49 +0000	[thread overview]
Message-ID: <1215439013-11480-2-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1215439013-11480-1-git-send-email-ehrhardt@linux.vnet.ibm.com>

[PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3

From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
From: Jerone Young <jyoung5@us.ibm.com>

This patch fixes kvmtrace use on big endian systems. When using bit fields the
compiler will lay data out in the wrong order expected when laid down into a
file.
This fixes it by using one variable instead of using bit fields.

Updates in v3:
	- fixed macro definition bug in v2
	- ensured in macro operator order
	- fixed whitespace/indent issues
	- removed superfluous initialization

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---

[diffstat]
 include/linux/kvm.h  |   17 ++++++++++++++---
 virt/kvm/kvm_trace.c |   19 ++++++++++---------
 2 files changed, 24 insertions(+), 12 deletions(-)

[diff]

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -311,9 +311,13 @@
 
 /* This structure represents a single trace buffer record. */
 struct kvm_trace_rec {
-	__u32 event:28;
-	__u32 extra_u32:3;
-	__u32 cycle_in:1;
+	/* variable rec_val
+	 * is split into:
+	 * bits 0 - 27  -> event id
+	 * bits 28 -30  -> number of extra data args of size u32
+	 * bits 31      -> binary indicator for if tsc is in record
+	 */
+	__u32 rec_val;
 	__u32 pid;
 	__u32 vcpu_id;
 	union {
@@ -326,6 +330,13 @@
 		} nocycle;
 	} u;
 } __attribute__((packed));
+
+#define TRACE_REC_EVENT_ID(val) \
+		(0x0fffffff & (val))
+#define TRACE_REC_NUM_DATA_ARGS(val) \
+		(0x70000000 & ((val) << 28))
+#define TRACE_REC_TCS(val) \
+		(0x80000000 & ((val) << 31))
 
 #define KVMIO 0xAE
 
diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c
--- a/virt/kvm/kvm_trace.c
+++ b/virt/kvm/kvm_trace.c
@@ -54,12 +54,13 @@
 	struct kvm_trace *kt = kvm_trace;
 	struct kvm_trace_rec rec;
 	struct kvm_vcpu *vcpu;
-	int    i, extra, size;
+	int    i, size;
+	u32    extra;
 
 	if (unlikely(kt->trace_state != KVM_TRACE_STATE_RUNNING))
 		return;
 
-	rec.event	= va_arg(*args, u32);
+	rec.rec_val	= TRACE_REC_EVENT_ID(va_arg(*args, u32));
 	vcpu		= va_arg(*args, struct kvm_vcpu *);
 	rec.pid		= current->tgid;
 	rec.vcpu_id	= vcpu->vcpu_id;
@@ -67,21 +68,21 @@
 	extra   	= va_arg(*args, u32);
 	WARN_ON(!(extra <= KVM_TRC_EXTRA_MAX));
 	extra 		= min_t(u32, extra, KVM_TRC_EXTRA_MAX);
-	rec.extra_u32   = extra;
 
-	rec.cycle_in 	= p->cycle_in;
-
-	if (rec.cycle_in) {
+	rec.rec_val |= TRACE_REC_TCS(p->cycle_in)
+			| TRACE_REC_NUM_DATA_ARGS(extra);
+	
+	if (p->cycle_in) {
 		rec.u.cycle.cycle_u64 = get_cycles();
 
-		for (i = 0; i < rec.extra_u32; i++)
+		for (i = 0; i < extra; i++)
 			rec.u.cycle.extra_u32[i] = va_arg(*args, u32);
 	} else {
-		for (i = 0; i < rec.extra_u32; i++)
+		for (i = 0; i < extra; i++)
 			rec.u.nocycle.extra_u32[i] = va_arg(*args, u32);
 	}
 
-	size = calc_rec_size(rec.cycle_in, rec.extra_u32 * sizeof(u32));
+	size = calc_rec_size(p->cycle_in, extra * sizeof(u32));
 	relay_write(kt->rchan, &rec, size);
 }
 

WARNING: multiple messages have this Message-ID (diff)
From: ehrhardt@linux.vnet.ibm.com
To: kvm@vger.kernel.org
Cc: hollisb@us.ibm.com, avi@qumranet.com, kvm-ppc@vger.kernel.org,
	ehrhardt@linux.vnet.ibm.com
Subject: [PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3
Date: Mon,  7 Jul 2008 15:56:49 +0200	[thread overview]
Message-ID: <1215439013-11480-2-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1215439013-11480-1-git-send-email-ehrhardt@linux.vnet.ibm.com>

[PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3

From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
From: Jerone Young <jyoung5@us.ibm.com>

This patch fixes kvmtrace use on big endian systems. When using bit fields the
compiler will lay data out in the wrong order expected when laid down into a
file.
This fixes it by using one variable instead of using bit fields.

Updates in v3:
	- fixed macro definition bug in v2
	- ensured in macro operator order
	- fixed whitespace/indent issues
	- removed superfluous initialization

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---

[diffstat]
 include/linux/kvm.h  |   17 ++++++++++++++---
 virt/kvm/kvm_trace.c |   19 ++++++++++---------
 2 files changed, 24 insertions(+), 12 deletions(-)

[diff]

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -311,9 +311,13 @@
 
 /* This structure represents a single trace buffer record. */
 struct kvm_trace_rec {
-	__u32 event:28;
-	__u32 extra_u32:3;
-	__u32 cycle_in:1;
+	/* variable rec_val
+	 * is split into:
+	 * bits 0 - 27  -> event id
+	 * bits 28 -30  -> number of extra data args of size u32
+	 * bits 31      -> binary indicator for if tsc is in record
+	 */
+	__u32 rec_val;
 	__u32 pid;
 	__u32 vcpu_id;
 	union {
@@ -326,6 +330,13 @@
 		} nocycle;
 	} u;
 } __attribute__((packed));
+
+#define TRACE_REC_EVENT_ID(val) \
+		(0x0fffffff & (val))
+#define TRACE_REC_NUM_DATA_ARGS(val) \
+		(0x70000000 & ((val) << 28))
+#define TRACE_REC_TCS(val) \
+		(0x80000000 & ((val) << 31))
 
 #define KVMIO 0xAE
 
diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c
--- a/virt/kvm/kvm_trace.c
+++ b/virt/kvm/kvm_trace.c
@@ -54,12 +54,13 @@
 	struct kvm_trace *kt = kvm_trace;
 	struct kvm_trace_rec rec;
 	struct kvm_vcpu *vcpu;
-	int    i, extra, size;
+	int    i, size;
+	u32    extra;
 
 	if (unlikely(kt->trace_state != KVM_TRACE_STATE_RUNNING))
 		return;
 
-	rec.event	= va_arg(*args, u32);
+	rec.rec_val	= TRACE_REC_EVENT_ID(va_arg(*args, u32));
 	vcpu		= va_arg(*args, struct kvm_vcpu *);
 	rec.pid		= current->tgid;
 	rec.vcpu_id	= vcpu->vcpu_id;
@@ -67,21 +68,21 @@
 	extra   	= va_arg(*args, u32);
 	WARN_ON(!(extra <= KVM_TRC_EXTRA_MAX));
 	extra 		= min_t(u32, extra, KVM_TRC_EXTRA_MAX);
-	rec.extra_u32   = extra;
 
-	rec.cycle_in 	= p->cycle_in;
-
-	if (rec.cycle_in) {
+	rec.rec_val |= TRACE_REC_TCS(p->cycle_in)
+			| TRACE_REC_NUM_DATA_ARGS(extra);
+	
+	if (p->cycle_in) {
 		rec.u.cycle.cycle_u64 = get_cycles();
 
-		for (i = 0; i < rec.extra_u32; i++)
+		for (i = 0; i < extra; i++)
 			rec.u.cycle.extra_u32[i] = va_arg(*args, u32);
 	} else {
-		for (i = 0; i < rec.extra_u32; i++)
+		for (i = 0; i < extra; i++)
 			rec.u.nocycle.extra_u32[i] = va_arg(*args, u32);
 	}
 
-	size = calc_rec_size(rec.cycle_in, rec.extra_u32 * sizeof(u32));
+	size = calc_rec_size(p->cycle_in, extra * sizeof(u32));
 	relay_write(kt->rchan, &rec, size);
 }
 

  reply	other threads:[~2008-07-07 13:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-07 13:56 [PATCH 0/5] kvmtrace: add powerpc support for KVM_TRACE ehrhardt
2008-07-07 13:56 ` ehrhardt
2008-07-07 13:56 ` ehrhardt [this message]
2008-07-07 13:56   ` [PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3 ehrhardt
2008-07-07 13:56 ` [PATCH 2/5] kvmtrace: make cycle calculation architecture aware ehrhardt
2008-07-07 13:56   ` ehrhardt
2008-07-07 15:45   ` Hollis Blanchard
2008-07-07 15:45     ` Hollis Blanchard
2008-07-09  8:25     ` Christian Ehrhardt
2008-07-09  8:25       ` Christian Ehrhardt
2008-07-07 16:37   ` Hollis Blanchard
2008-07-07 16:37     ` Hollis Blanchard
2008-07-09  9:17     ` Christian Ehrhardt
2008-07-09  9:17       ` Christian Ehrhardt
2008-07-09 15:03       ` Hollis Blanchard
2008-07-09 15:03         ` Hollis Blanchard
2008-07-10 10:22         ` Yang, Sheng
2008-07-10 10:22           ` Yang, Sheng
2008-07-10 10:24           ` Yang, Sheng
2008-07-10 10:24             ` Yang, Sheng
2008-07-10 13:32           ` Avi Kivity
2008-07-10 13:32             ` Avi Kivity
2008-07-11  1:06             ` Yang, Sheng
2008-07-11  1:06               ` Yang, Sheng
2008-07-11  7:34             ` Carsten Otte
2008-07-11  7:34               ` Carsten Otte
2008-07-11 15:19               ` Hollis Blanchard
2008-07-11 15:19                 ` Hollis Blanchard
2008-07-13 15:41               ` Avi Kivity
2008-07-13 15:41                 ` Avi Kivity
2008-07-14  7:44                 ` Christian Borntraeger
2008-07-14  7:44                   ` Christian Borntraeger
2008-07-07 13:56 ` [PATCH 3/5] kvmppc: kvmtrace: enable KVM_TRACE building for powerpc ehrhardt
2008-07-07 13:56   ` ehrhardt
2008-07-07 13:56 ` [PATCH 4/5] kvmppc: kvmtrace: adds trace points for ppc tlb activity v2 ehrhardt
2008-07-07 13:56   ` ehrhardt
2008-07-07 13:56 ` [PATCH 5/5] kvmppc: kvmtrace: trace powerpc instruction emulation ehrhardt
2008-07-07 13:56   ` ehrhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1215439013-11480-2-git-send-email-ehrhardt@linux.vnet.ibm.com \
    --to=ehrhardt@linux.vnet.ibm.com \
    --cc=avi@qumranet.com \
    --cc=hollisb@us.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.