Skip to contentSkip to conversation

xenoprof: fix up ability to disable it

PATCH Superseded Doug Goldstein 4 participants 6 messages Feb 9, 2016

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 xenoprof: fix up ability to disable it

Allow Xenoprof to be fully disabled when toggling the option off.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Boris Ostrovsky <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Jun Nakajima <[email protected]>
CC Kevin Tian <[email protected]>

---
change since v1:
- switch to #define empty 'functions' as suggested by Andrew Cooper

---
 xen/arch/x86/Makefile              | 2 +-
 xen/arch/x86/Rules.mk              | 2 ++
 xen/arch/x86/x86_64/compat/entry.S | 4 ++++
 xen/arch/x86/x86_64/entry.S        | 4 ++++
 xen/include/asm-x86/config.h       | 1 -
 xen/include/asm-x86/vpmu.h         | 9 +++++++++
 xen/include/asm-x86/xenoprof.h     | 7 +++++++
 xen/include/xen/xenoprof.h         | 4 ++++
 8 files changed, 31 insertions(+), 2 deletions(-)
xen/arch/x86/Makefile +1 -1
index 8e6e901..434d985 100644
@@ -3,7 +3,7 @@ subdir-y += cpu
 subdir-y += genapic
 subdir-y += hvm
 subdir-y += mm
-subdir-y += oprofile
+subdir-$(xenoprof) += oprofile
 subdir-y += x86_64
 
 obj-bin-y += alternative.init.o
xen/arch/x86/Rules.mk +2 -0
index a1cdae0..94e4efd 100644
@@ -10,6 +10,8 @@ CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic
 CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
 CFLAGS += '-D__OBJECT_LABEL__=$(subst /,$$,$(subst -,_,$(subst $(BASEDIR)/,,$(CURDIR))/$@))'
 
+CFLAGS-$(xenoprof) += -DCONFIG_XENOPROF
+
 # Prevent floating-point variables from creeping into Xen.
 CFLAGS += -msoft-float
 
xen/arch/x86/x86_64/compat/entry.S +4 -0
index 3088aa7..6424ed0 100644
@@ -394,6 +394,10 @@ compat_crash_page_fault:
 #define compat_kexec_op do_ni_hypercall
 #endif
 
+#ifndef CONFIG_XENOPROF
+#define compat_xenoprof_op do_ni_hypercall
+#endif
+
 ENTRY(compat_hypercall_table)
         .quad compat_set_trap_table     /*  0 */
         .quad do_mmu_update
xen/arch/x86/x86_64/entry.S +4 -0
index 94a54aa..0a73878 100644
@@ -727,6 +727,10 @@ ENTRY(exception_table)
 #define do_kexec_op do_ni_hypercall
 #endif
 
+#ifndef CONFIG_XENOPROF
+#define do_xenoprof_op do_ni_hypercall
+#endif
+
 ENTRY(hypercall_table)
         .quad do_set_trap_table     /*  0 */
         .quad do_mmu_update
xen/include/asm-x86/config.h +0 -1
index d97877d..a45d3ee 100644
@@ -47,7 +47,6 @@
 #define CONFIG_VGA 1
 #define CONFIG_VIDEO 1
 
-#define CONFIG_XENOPROF 1
 #define CONFIG_WATCHDOG 1
 
 #define CONFIG_MULTIBOOT 1
xen/include/asm-x86/vpmu.h +9 -0
index 67e73dc..4750a1f 100644
@@ -89,10 +89,14 @@ static inline void vpmu_clear(struct vpmu_struct *vpmu)
 {
     vpmu->flags = 0;
 }
+#ifdef CONFIG_XENOPROF
 static inline bool_t vpmu_is_set(const struct vpmu_struct *vpmu, const u32 mask)
 {
     return !!(vpmu->flags & mask);
 }
+#else
+#define vpmu_is_set(x, y) (!!0)
+#endif
 static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,
                                       const u32 mask)
 {
@@ -121,8 +125,13 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)
     return vpmu_do_msr(msr, msr_content, 0, 0);
 }
 
+#ifdef CONFIG_XENOPROF
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
+#else
+#define acquire_pmu_ownership(x) (1)
+#define release_pmu_ownership(x)
+#endif
 
 extern unsigned int vpmu_mode;
 extern unsigned int vpmu_features;
xen/include/asm-x86/xenoprof.h +7 -0
index b006ddc..9574f33 100644
@@ -67,9 +67,16 @@ void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *,
                  "xenoprof/x86 with autotranslated mode enabled"    \
                  "isn't supported yet\n");                          \
     } while (0)
+
+#ifdef CONFIG_XENOPROF
 int passive_domain_do_rdmsr(unsigned int msr, uint64_t *msr_content);
 int passive_domain_do_wrmsr(unsigned int msr, uint64_t msr_content);
 void passive_domain_destroy(struct vcpu *v);
+#else
+#define passive_domain_do_rdmsr(x, y) (0)
+#define passive_domain_do_wrmsr(x, y) (0)
+#define passive_domain_destroy(x)
+#endif
 
 #endif /* __ASM_X86_XENOPROF_H__ */
 
xen/include/xen/xenoprof.h +4 -0
index 7804e69..2dd084a 100644
@@ -74,7 +74,11 @@ int xenoprof_add_trace(struct vcpu *, uint64_t pc, int mode);
 #define PMU_OWNER_XENOPROF      1
 #define PMU_OWNER_HVM           2
 int acquire_pmu_ownship(int pmu_ownership);
+#ifdef CONFIG_XENOPROF
 void release_pmu_ownship(int pmu_ownership);
+#else
+#define release_pmu_ownship(x)
+#endif
 
 void xenoprof_log_event(struct vcpu *, const struct cpu_user_regs *,
                         uint64_t pc, int mode, int event);
Signature · 1 line
2.4.10
#1 lore raw

PATCH v2 2/2 build: convert xenoprof to Kconfig

Convert the xenoprof x86 build time option to Kconfig.

---
change since v1:
- fix name of Kconfig entry as suggested by Andrew Cooper

---
 xen/arch/x86/Makefile |  2 +-
 xen/arch/x86/Rules.mk |  3 ---
 xen/common/Kconfig    | 13 +++++++++++++
 xen/common/Makefile   |  2 +-
 4 files changed, 15 insertions(+), 5 deletions(-)
xen/arch/x86/Makefile +1 -1
index 434d985..1bcb08b 100644
@@ -3,7 +3,7 @@ subdir-y += cpu
 subdir-y += genapic
 subdir-y += hvm
 subdir-y += mm
-subdir-$(xenoprof) += oprofile
+subdir-$(CONFIG_XENOPROF) += oprofile
 subdir-y += x86_64
 
 obj-bin-y += alternative.init.o
xen/arch/x86/Rules.mk +0 -3
index 94e4efd..14519e3 100644
@@ -3,15 +3,12 @@
 
 HAS_NUMA := y
 HAS_CORE_PARKING := y
-xenoprof := y
 
 CFLAGS += -I$(BASEDIR)/include 
 CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic
 CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
 CFLAGS += '-D__OBJECT_LABEL__=$(subst /,$$,$(subst -,_,$(subst $(BASEDIR)/,,$(CURDIR))/$@))'
 
-CFLAGS-$(xenoprof) += -DCONFIG_XENOPROF
-
 # Prevent floating-point variables from creeping into Xen.
 CFLAGS += -msoft-float
 
xen/common/Kconfig +13 -0
index 6f404b4..8b06dfb 100644
@@ -84,6 +84,19 @@ config LATE_HWDOM
 
 	  If unsure, say N.
 
+# Adds support for Xenoprof
+config XENOPROF
+	bool "Xen Oprofile Support"
+	default y
+	depends on X86
+	---help---
+	  Xen OProfile (Xenoprof) is a system-wide profiler for Xen virtual
+	  machine environments, capable of profiling the Xen virtual machine
+	  monitor, multiple Linux guest operating systems, and applications
+	  running on them.
+
+	  If unsure, say Y.
+
 # Enable/Disable XSM support
 config XSM
 	bool "Xen Security Modules support"
xen/common/Makefile +1 -1
index 6e82b33..126d373 100644
@@ -62,7 +62,7 @@ obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4
 
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
-obj-$(xenoprof)    += xenoprof.o
+obj-$(CONFIG_XENOPROF)    += xenoprof.o
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o kernel.o memory.o multicall.o tmem_xen.o xlat.o)
 
Signature · 1 line
2.4.10
#2 lore raw

Re: [PATCH v2 2/2] build: convert xenoprof to Kconfig

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.02.16 at 05:15, <[email protected]> wrote:

Convert the xenoprof x86 build time option to Kconfig.

First of all it's not clear to me whether this really was ever meant to be a build time option. It's using := (not ?= ), and without there being a clear indication that this was intended I'm inclined to assume this is just the result of someone doing something in a, well, slightly broken way. Nevertheless I can see the point of wanting to disable this code, but I think that ...

xen/common/Kconfig config LATE_HWDOM · line 91

Quoted 11 lines
xen/common/Kconfig +5 -0
@@ -84,6 +84,19 @@ config LATE_HWDOM
 
 	  If unsure, say N.
 
+# Adds support for Xenoprof
+config XENOPROF
+	bool "Xen Oprofile Support"
+	default y
+	depends on X86

... this should then also depend on EXPERT.

Jan

#3 lore raw
In reply to Doug Goldstein
Quoted 5 lines · Doug Goldstein
xen/include/asm-x86/vpmu.h +0 -0
index 67e73dc..4750a1f 100644

xen/include/asm-x86/vpmu.h static inline void vpmu_clear(struct vpmu_struct *vpmu) · line 98

Quoted 10 lines
xen/include/asm-x86/vpmu.h +3 -0
@@ -89,10 +89,14 @@ static inline void vpmu_clear(struct vpmu_struct *vpmu)
 {
     vpmu->flags = 0;
 }
+#ifdef CONFIG_XENOPROF
 static inline bool_t vpmu_is_set(const struct vpmu_struct *vpmu, const u32 mask)
 {
     return !!(vpmu->flags & mask);
 }
+#else
+#define vpmu_is_set(x, y) (!!0)

Why vpmu_is_set()? this wasn't guarded in v1.

Quoted 5 lines
xen/include/asm-x86/vpmu.h +1 -0
+#endif
 static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,
                                       const u32 mask)
 {

xen/include/asm-x86/vpmu.h static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 133

Quoted 9 lines
xen/include/asm-x86/vpmu.h +4 -0
@@ -121,8 +125,13 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)
     return vpmu_do_msr(msr, msr_content, 0, 0);
 }
 
+#ifdef CONFIG_XENOPROF
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
+#else
+#define acquire_pmu_ownership(x) (1)
+#define release_pmu_ownership(x)

Yikes - we have two externs of acquire_pmu_ownership(). This is plain wrong and needs fixing as a separate patch.

These are xenoprof functions, so the externs in xenoprof.h are correct. These ones in vpmu.h should be deleted, and code should include xenoprof.h instead.

Quoted 12 lines
xen/include/asm-x86/vpmu.h +1 -0
+#endif
 
 extern unsigned int vpmu_mode;
 extern unsigned int vpmu_features;
xen/include/asm-x86/xenoprof.h +0 -0
index b006ddc..9574f33 100644
@@ -67,9 +67,16 @@ void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *,
                  "xenoprof/x86 with autotranslated mode enabled"    \
                  "isn't supported yet\n");                          \
     } while (0)

xen/include/asm-x86/xenoprof.h void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *, · line 79

Quoted 10 lines
xen/include/asm-x86/xenoprof.h +7 -0
+
+#ifdef CONFIG_XENOPROF
 int passive_domain_do_rdmsr(unsigned int msr, uint64_t *msr_content);
 int passive_domain_do_wrmsr(unsigned int msr, uint64_t msr_content);
 void passive_domain_destroy(struct vcpu *v);
+#else
+#define passive_domain_do_rdmsr(x, y) (0)
+#define passive_domain_do_wrmsr(x, y) (0)
+#define passive_domain_destroy(x)
+#endif

This looks much neater - Thanks.

However, please make static inline functions rather than macros, so that the arguments still get typechecked and evaluated even if !CONFIG_XENOPROF

passive_domain_destroy() is particular is problematic if one were to have a construct such as "if ( passive_domain_destroy() )" (although that specific one is not a good example in this case).

~Andrew

#4 lore raw
Quoted 63 lines · Andrew Cooper
Quoted 5 lines · Doug Goldstein
xen/include/asm-x86/vpmu.h +0 -0
index 67e73dc..4750a1f 100644

xen/include/asm-x86/vpmu.h static inline void vpmu_clear(struct vpmu_struct *vpmu) · line 98

Quoted 10 lines
xen/include/asm-x86/vpmu.h +3 -0
@@ -89,10 +89,14 @@ static inline void vpmu_clear(struct vpmu_struct *vpmu)
 {
     vpmu->flags = 0;
 }
+#ifdef CONFIG_XENOPROF
 static inline bool_t vpmu_is_set(const struct vpmu_struct *vpmu, const u32 mask)
 {
     return !!(vpmu->flags & mask);
 }
+#else
+#define vpmu_is_set(x, y) (!!0)

Why vpmu_is_set()? this wasn't guarded in v1.

Quoted 5 lines
xen/include/asm-x86/vpmu.h +1 -0
+#endif
 static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,
                                       const u32 mask)
 {

xen/include/asm-x86/vpmu.h static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 133

Quoted 9 lines
xen/include/asm-x86/vpmu.h +4 -0
@@ -121,8 +125,13 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)
     return vpmu_do_msr(msr, msr_content, 0, 0);
 }
 
+#ifdef CONFIG_XENOPROF
 extern int acquire_pmu_ownership(int pmu_ownership);
 extern void release_pmu_ownership(int pmu_ownership);
+#else
+#define acquire_pmu_ownership(x) (1)
+#define release_pmu_ownership(x)

Yikes - we have two externs of acquire_pmu_ownership(). This is plain wrong and needs fixing as a separate patch.

These are xenoprof functions, so the externs in xenoprof.h are correct. These ones in vpmu.h should be deleted, and code should include xenoprof.h instead.

Quoted 12 lines
xen/include/asm-x86/vpmu.h +1 -0
+#endif
 
 extern unsigned int vpmu_mode;
 extern unsigned int vpmu_features;
xen/include/asm-x86/xenoprof.h +0 -0
index b006ddc..9574f33 100644
@@ -67,9 +67,16 @@ void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *,
                  "xenoprof/x86 with autotranslated mode enabled"    \
                  "isn't supported yet\n");                          \
     } while (0)

xen/include/asm-x86/xenoprof.h void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *, · line 79

Quoted 10 lines
xen/include/asm-x86/xenoprof.h +7 -0
+
+#ifdef CONFIG_XENOPROF
 int passive_domain_do_rdmsr(unsigned int msr, uint64_t *msr_content);
 int passive_domain_do_wrmsr(unsigned int msr, uint64_t msr_content);
 void passive_domain_destroy(struct vcpu *v);
+#else
+#define passive_domain_do_rdmsr(x, y) (0)
+#define passive_domain_do_wrmsr(x, y) (0)
+#define passive_domain_destroy(x)
+#endif

This looks much neater - Thanks.

Quoted 8 lines

However, please make static inline functions rather than macros, so that the arguments still get typechecked and evaluated even if !CONFIG_XENOPROF

passive_domain_destroy() is particular is problematic if one were to have a construct such as "if ( passive_domain_destroy() )" (although that specific one is not a good example in this case).

~Andrew

One final thing to say. Most of the header file should be inside an #ifdef CONFIG_XENOPROF, with only the stub inlines in the else clause. This way none of the other internals are exposed to other Xen code if CONFIG_XENOPROF is enabled.

~Andrew

#5 lore raw
In reply to Andrew Cooper
Quoted 17 lines · Andrew Cooper
Quoted 5 lines · Doug Goldstein
xen/include/asm-x86/vpmu.h +0 -0
index 67e73dc..4750a1f 100644

xen/include/asm-x86/vpmu.h static inline void vpmu_clear(struct vpmu_struct *vpmu) · line 98

Quoted 10 lines
xen/include/asm-x86/vpmu.h +3 -0
@@ -89,10 +89,14 @@ static inline void vpmu_clear(struct vpmu_struct *vpmu)
  {
      vpmu->flags = 0;
  }
+#ifdef CONFIG_XENOPROF
  static inline bool_t vpmu_is_set(const struct vpmu_struct *vpmu, const u32 mask)
  {
      return !!(vpmu->flags & mask);
  }
+#else
+#define vpmu_is_set(x, y) (!!0)

Why vpmu_is_set()? this wasn't guarded in v1.

This looks wrong to me. vpmu_is_set() is almost exclusively used by VPMU code.

Quoted 9 lines
Quoted 9 lines
xen/include/asm-x86/vpmu.h +1 -0
+#endif
  static inline bool_t vpmu_are_all_set(const struct vpmu_struct *vpmu,
                                        const u32 mask)
  {
@@ -121,8 +125,13 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)
      return vpmu_do_msr(msr, msr_content, 0, 0);
  }
 
Quoted 6 lines

xen/include/asm-x86/vpmu.h static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) · line 133

Quoted 6 lines
xen/include/asm-x86/vpmu.h +4 -0
+#ifdef CONFIG_XENOPROF
  extern int acquire_pmu_ownership(int pmu_ownership);
  extern void release_pmu_ownership(int pmu_ownership);
+#else
+#define acquire_pmu_ownership(x) (1)
+#define release_pmu_ownership(x)

Hmm... acquire_pmu_ownship() vs acquire_pmu_ownership() and release_pmu_ownship() vs. release_pmu_ownership().

Since you are working with this code, can you also clean that up? It looks to me that at some point names got messed up.

-boris