From: Hans Rosenfeld <hans.rosenfeld@amd.com>
To: <hpa@zytor.com>
Cc: <tglx@linutronix.de>, <mingo@elte.hu>, <andi@firstfloor.org>,
<suresh.b.siddha@intel.com>, <eranian@google.com>,
<brgerst@gmail.com>, <robert.richter@amd.com>,
<Andreas.Herrmann3@amd.com>, <x86@kernel.org>,
<linux-kernel@vger.kernel.org>,
Hans Rosenfeld <hans.rosenfeld@amd.com>
Subject: [PATCH 8/8] x86, xsave: add kernel support for AMDs Lightweight Profiling (LWP)
Date: Wed, 7 Dec 2011 21:00:23 +0100 [thread overview]
Message-ID: <1323288023-26147-2-git-send-email-hans.rosenfeld@amd.com> (raw)
In-Reply-To: <1323288023-26147-1-git-send-email-hans.rosenfeld@amd.com>
This patch extends the xsave structure to support the LWP state. The
xstate feature bit for LWP is added to XCNTXT_NONLAZY, thereby enabling
kernel support for saving/restoring LWP state. The LWP state is also
saved/restored on signal entry/return, just like all other xstates. LWP
state needs to be reset (disabled) when entering a signal handler.
v2:
When copying xstates for fork/clone, disable LWP in the new copy so that
new tasks start with LWP disabled as required by the LWP specification.
Signed-off-by: Hans Rosenfeld <hans.rosenfeld@amd.com>
---
arch/x86/include/asm/i387.h | 4 ++++
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/include/asm/processor.h | 12 ++++++++++++
arch/x86/include/asm/sigcontext.h | 12 ++++++++++++
arch/x86/include/asm/xsave.h | 3 ++-
arch/x86/kernel/xsave.c | 5 +++++
6 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
index 7812d55..cfd0be9 100644
--- a/arch/x86/include/asm/i387.h
+++ b/arch/x86/include/asm/i387.h
@@ -326,6 +326,10 @@ static inline void fpu_free(struct fpu *fpu)
static inline void fpu_copy(struct fpu *dst, struct fpu *src)
{
memcpy(dst->state, src->state, xstate_size);
+
+ /* disable LWP in the copy */
+ if (pcntxt_mask & XSTATE_LWP)
+ dst->state->xsave.xsave_hdr.xstate_bv &= ~XSTATE_LWP;
}
extern void fpu_finit(struct fpu *fpu);
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index d52609a..2d9cf3c 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -136,6 +136,7 @@
#define MSR_AMD64_IBSDCPHYSAD 0xc0011039
#define MSR_AMD64_IBSCTL 0xc001103a
#define MSR_AMD64_IBSBRTARGET 0xc001103b
+#define MSR_AMD64_LWP_CBADDR 0xc0000106
/* Fam 15h MSRs */
#define MSR_F15H_PERF_CTL 0xc0010200
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 0d1171c..bb31ab6 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -353,6 +353,17 @@ struct ymmh_struct {
u32 ymmh_space[64];
};
+struct lwp_struct {
+ u64 lwpcb_addr;
+ u32 flags;
+ u32 buf_head_offset;
+ u64 buf_base;
+ u32 buf_size;
+ u32 filters;
+ u64 saved_event_record[4];
+ u32 event_counter[16];
+};
+
struct xsave_hdr_struct {
u64 xstate_bv;
u64 reserved1[2];
@@ -363,6 +374,7 @@ struct xsave_struct {
struct i387_fxsave_struct i387;
struct xsave_hdr_struct xsave_hdr;
struct ymmh_struct ymmh;
+ struct lwp_struct lwp;
/* new processor state extensions will go here */
} __attribute__ ((packed, aligned (64)));
diff --git a/arch/x86/include/asm/sigcontext.h b/arch/x86/include/asm/sigcontext.h
index 04459d2..0a58b82 100644
--- a/arch/x86/include/asm/sigcontext.h
+++ b/arch/x86/include/asm/sigcontext.h
@@ -274,6 +274,17 @@ struct _ymmh_state {
__u32 ymmh_space[64];
};
+struct _lwp_state {
+ __u64 lwpcb_addr;
+ __u32 flags;
+ __u32 buf_head_offset;
+ __u64 buf_base;
+ __u32 buf_size;
+ __u32 filters;
+ __u64 saved_event_record[4];
+ __u32 event_counter[16];
+};
+
/*
* Extended state pointed by the fpstate pointer in the sigcontext.
* In addition to the fpstate, information encoded in the xstate_hdr
@@ -284,6 +295,7 @@ struct _xstate {
struct _fpstate fpstate;
struct _xsave_hdr xstate_hdr;
struct _ymmh_state ymmh;
+ struct _lwp_state lwp;
/* new processor state extensions go here */
};
diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
index 10e0e45..789a140 100644
--- a/arch/x86/include/asm/xsave.h
+++ b/arch/x86/include/asm/xsave.h
@@ -9,6 +9,7 @@
#define XSTATE_FP 0x1
#define XSTATE_SSE 0x2
#define XSTATE_YMM 0x4
+#define XSTATE_LWP (1ULL << 62)
#define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE)
@@ -24,7 +25,7 @@
* These are the features that the OS can handle currently.
*/
#define XCNTXT_LAZY (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
-#define XCNTXT_NONLAZY 0
+#define XCNTXT_NONLAZY (XSTATE_LWP)
#ifdef CONFIG_NONLAZY_XSTATES
#define XCNTXT_MASK (XCNTXT_LAZY | XCNTXT_NONLAZY)
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index ce329ff..2022069 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -249,6 +249,11 @@ int save_xstates_sigframe(void __user *buf, unsigned int size)
return err;
}
+ if (pcntxt_mask & XSTATE_LWP) {
+ xsave->xsave_hdr.xstate_bv &= ~XSTATE_LWP;
+ wrmsrl(MSR_AMD64_LWP_CBADDR, 0);
+ }
+
return 1;
}
--
1.7.5.4
next prev parent reply other threads:[~2011-12-07 20:02 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-29 12:41 [PATCH 0/9] rework of extended state handling, LWP support Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 1/9] x86, xsave: warn on #NM exceptions caused by the kernel Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 2/9] x86, xsave: cleanup fpu/xsave support Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 3/9] x86, xsave: cleanup fpu/xsave signal frame setup Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 4/9] x86, xsave: rework fpu/xsave support Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 5/9] x86, xsave: remove unused code Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 6/9] x86, xsave: more cleanups Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 7/9] x86, xsave: remove lazy allocation of xstate area Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 8/9] x86, xsave: add support for non-lazy xstates Hans Rosenfeld
2011-11-29 12:41 ` [PATCH 9/9] x86, xsave: add kernel support for AMDs Lightweight Profiling (LWP) Hans Rosenfeld
2011-11-29 21:31 ` [PATCH 0/9] rework of extended state handling, LWP support Andi Kleen
2011-11-30 17:37 ` Hans Rosenfeld
2011-11-30 21:52 ` Andi Kleen
2011-12-01 20:36 ` Hans Rosenfeld
2011-12-02 2:01 ` H. Peter Anvin
2011-12-02 11:20 ` Hans Rosenfeld
2011-12-07 19:57 ` Hans Rosenfeld
2011-12-07 20:00 ` [PATCH 7/8] x86, xsave: add support for non-lazy xstates Hans Rosenfeld
2011-12-07 20:00 ` Hans Rosenfeld [this message]
2011-12-05 10:22 ` [PATCH 0/9] rework of extended state handling, LWP support Ingo Molnar
2011-12-16 16:07 ` Hans Rosenfeld
2011-12-16 16:12 ` [RFC 1/5] x86, perf: Implement software-activation of lwp Hans Rosenfeld
2011-12-16 16:12 ` [RFC 2/5] perf: adds prototype for a new perf-context-type Hans Rosenfeld
2011-12-16 16:12 ` [RFC 3/5] perf: adds a new pmu-initialization-call Hans Rosenfeld
2011-12-16 16:12 ` [RFC 4/5] x86, perf: implements lwp-perf-integration (rc1) Hans Rosenfeld
2011-12-18 8:04 ` Ingo Molnar
2011-12-18 15:22 ` Benjamin Block
2011-12-18 23:43 ` Ingo Molnar
2011-12-19 9:09 ` Robert Richter
2011-12-19 10:54 ` Ingo Molnar
2011-12-19 11:12 ` Avi Kivity
2011-12-19 11:40 ` Ingo Molnar
2011-12-19 11:58 ` Avi Kivity
2011-12-19 18:13 ` Benjamin
2011-12-20 8:56 ` Ingo Molnar
2011-12-20 9:15 ` Ingo Molnar
2011-12-20 9:47 ` Avi Kivity
2011-12-20 10:09 ` Ingo Molnar
2011-12-20 15:27 ` Joerg Roedel
2011-12-20 18:40 ` Ingo Molnar
2011-12-21 0:07 ` Joerg Roedel
2011-12-21 12:34 ` Ingo Molnar
2011-12-21 12:44 ` Avi Kivity
2011-12-21 13:22 ` Ingo Molnar
2011-12-21 22:49 ` Joerg Roedel
2011-12-23 10:53 ` Ingo Molnar
2011-12-21 11:46 ` Gleb Natapov
2011-12-23 10:56 ` Ingo Molnar
2011-12-20 15:48 ` Vince Weaver
2011-12-20 18:27 ` Ingo Molnar
2011-12-20 22:47 ` Vince Weaver
2011-12-21 12:00 ` Ingo Molnar
2011-12-21 13:55 ` Vince Weaver
2011-12-16 16:12 ` [RFC 5/5] x86, perf: adds support for the LWP threshold-int Hans Rosenfeld
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=1323288023-26147-2-git-send-email-hans.rosenfeld@amd.com \
--to=hans.rosenfeld@amd.com \
--cc=Andreas.Herrmann3@amd.com \
--cc=andi@firstfloor.org \
--cc=brgerst@gmail.com \
--cc=eranian@google.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=robert.richter@amd.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®