powerpc: Instrument Hypervisor Calls
PATCH 1/1 powerpc: Instrument Hypervisor Calls
Hi Paul,
This patch addresses the issues you brought up with the previous version. The most important issue being range checking of opcodes so the code does not write outside the array. You also suggested doing a load from TOC instead of LOAD_REG_ADDR, because LOAD_REG_ADDR turns into 5 instructions. I 'think' LOAD_REG_ADDR only turns into 5 instructions on 32 bit systems. It is a single load from TOC on 64 bits as we are using it.
Here it is:
Add instrumentation for hypervisor calls on pseries. Call statistics include number of calls, wall time and cpu cycles (if available) and are made available via debugfs. Instrumentation code is behind the HCALL_STATS config option and has no impact if not enabled.
--
arch/powerpc/Kconfig.debug +14 -0
@@ -18,6 +18,20 @@ config DEBUG_STACK_USAGE This option will slow down process creation somewhat. +config HCALL_STATS + bool "Hypervisor call instrumentation" + depends on PPC_PSERIES && DEBUG_FS + help + Adds code to keep track of the number of hypervisor calls made and + the amount of time spent in hypervisor callsr. Wall time spent in + each call is always calculated, and if available CPU cycles spent + are also calculated. A directory named hcall_inst is added at the + root of the debugfs filesystem. Within the hcall_inst directory + are files that contain CPU specific call statistics. + + This option will add a small amount of overhead to all hypervisor + calls. + config DEBUGGER bool "Enable debugger hooks" depends on DEBUG_KERNEL
arch/powerpc/kernel/asm-offsets.c +7 -0
@@ -137,6 +137,7 @@ int main(void)DEFINE (PACA_USER_TIME , offsetof(struct paca_struct , user_time));DEFINE (PACA_SYSTEM_TIME , offsetof(struct paca_struct , system_time));DEFINE (PACA_SLBSHADOWPTR , offsetof(struct paca_struct , slb_shadow_ptr)); +DEFINE (PACA_DATA_OFFSET , offsetof(struct paca_struct , data_offset));DEFINE (SLBSHADOW_STACKVSID , offsetof(struct slb_shadow, save_area[SLB_NUM_BOLTED - 1].vsid));
@@ -165,6 +166,12 @@ int main(void)/* Create extra stack space for SRR0 and SRR1 when calling prom/rtas. */ DEFINE (PROM_FRAME_SIZE ,STACK_FRAME_OVERHEAD +sizeof (struct pt_regs ) +16 );DEFINE (RTAS_FRAME_SIZE ,STACK_FRAME_OVERHEAD +sizeof (struct pt_regs ) +16 ); + +/* hcall statistics */ +DEFINE (HCALL_STAT_SIZE ,sizeof (struct hcall_stats )); +DEFINE (HCALL_STAT_CALLS , offsetof(struct hcall_stats , num_calls)); +DEFINE (HCALL_STAT_TB , offsetof(struct hcall_stats , tb_total)); +DEFINE (HCALL_STAT_PURR , offsetof(struct hcall_stats , purr_total));#endif /* CONFIG_PPC64 */ DEFINE(GPR0, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[0])); DEFINE(GPR1, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[1]));
arch/powerpc/platforms/pseries/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_EEH) += eeh.o eeh_cache.o e obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o obj-$(CONFIG_HVCS) += hvcserver.o +obj-$(CONFIG_HCALL_STATS) += hvCall_inst.o
arch/powerpc/platforms/pseries/hvCall.S +72 -0
113 lines not on this page · raw message
arch/powerpc/platforms/pseries/hvCall_inst.c +129 -0
129 lines not on this page · raw message
include/asm-powerpc/hvcall.h +11 -1
@@ -208,7 +208,7 @@#define H_JOIN 0x298#define H_VASI_STATE 0x2A4#define H_ENABLE_CRQ 0x2B0 -#define MAX_HCALL_OPCODES (H_ENABLE_CRQ >> 2) +#define MAX_HCALL_OPCODE H_ENABLE_CRQ#ifndef __ASSEMBLY__
@@ -246,6 +246,16 @@ long plpar_hcall(unsigned long opcode, u#define PLPAR_HCALL9_BUFSIZE 9long plpar_hcall9 (unsigned long opcode,unsigned long *retbuf, ...); +/* For hcall instrumentation. One structure per-hcall, per-CPU */ +struct hcall_stats { +unsigned long num_calls;/* number of calls (on this CPU) */ +unsigned long tb_total;/* total wall time (mftb) of calls. */ +unsigned long purr_total;/* total cpu time (PURR) of calls. */ +}; +void update_hcall_stats (unsigned long opcode,unsigned long tb_delta, +unsigned long purr_delta); +#define HCALL_STAT_ARRAY_SIZE ((MAX_HCALL_OPCODE >> 2) + 1) +#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_HVCALL_H */
Quoted 2 lines · Mike Kravetz
I 'think'
LOAD_REG_ADDRonly turns into 5 instructions on 32 bit systems. It is a single load from TOC on 64 bits as we are using it.
You're right, David (Gibson) cleaned that up some time ago. In fact it's only 2 instructions on 32-bit systems, and it is a TOC load on 64-bit systems.
Paul.