From f44e8da41c495d7b94e6500e31f89d8006e5aa04 Mon Sep 17 00:00:00 2001 From: jhibbits Date: Fri, 14 Mar 2014 04:35:18 +0000 Subject: MFC r262547 Fix callchain capture for hwpmc(4). While here, some style(9) fixes, too. --- sys/dev/hwpmc/hwpmc_powerpc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_powerpc.c b/sys/dev/hwpmc/hwpmc_powerpc.c index 0efae5e..19207cd 100644 --- a/sys/dev/hwpmc/hwpmc_powerpc.c +++ b/sys/dev/hwpmc/hwpmc_powerpc.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -60,10 +61,14 @@ pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, cc[frames++] = PMC_TRAPFRAME_TO_PC(tf); sp = (uintptr_t *)PMC_TRAPFRAME_TO_FP(tf); - for (frames = 1; frames < maxsamples; frames++) { + for (; frames < maxsamples; frames++) { if (!INKERNEL(sp)) break; +#ifdef __powerpc64__ + cc[frames++] = sp[2]; +#else cc[frames++] = sp[1]; +#endif sp = (uintptr_t *)*sp; } return (frames); @@ -72,12 +77,14 @@ pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, static int powerpc_switch_in(struct pmc_cpu *pc, struct pmc_process *pp) { + return (0); } static int powerpc_switch_out(struct pmc_cpu *pc, struct pmc_process *pp) { + return (0); } @@ -111,6 +118,7 @@ powerpc_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc) int powerpc_get_config(int cpu, int ri, struct pmc **ppm) { + *ppm = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc; return (0); @@ -182,11 +190,23 @@ pmc_save_user_callchain(uintptr_t *cc, int maxsamples, cc[frames++] = PMC_TRAPFRAME_TO_PC(tf); sp = (uintptr_t *)PMC_TRAPFRAME_TO_FP(tf); - for (frames = 1; frames < maxsamples; frames++) { + for (; frames < maxsamples; frames++) { if (!INUSER(sp)) break; - cc[frames++] = fuword(sp + 1); - sp = (uintptr_t *)fuword(sp); +#ifdef __powerpc64__ + /* Check if 32-bit mode. */ + if (!(tf->srr1 & PSL_SF)) { + cc[frames++] = fuword32((uint32_t *)sp + 1); + sp = (uintptr_t *)(uintptr_t)fuword32(sp); + } else { + cc[frames++] = fuword(sp + 2); + sp = (uintptr_t *)fuword(sp); + } +#else + cc[frames++] = fuword32((uint32_t *)sp + 1); + sp = (uintptr_t *)fuword32(sp); +#endif } + return (frames); } -- cgit v1.1