2 * Performance event support for s390x
4 * Copyright IBM Corp. 2012
5 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (version 2 only)
9 * as published by the Free Software Foundation.
11 #define KMSG_COMPONENT "perf"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kernel.h>
15 #include <linux/perf_event.h>
16 #include <linux/percpu.h>
17 #include <linux/export.h>
19 #include <asm/cpu_mf.h>
20 #include <asm/lowcore.h>
21 #include <asm/processor.h>
23 const char *perf_pmu_name(void)
25 if (cpum_cf_avail() || cpum_sf_avail())
26 return "CPU-measurement facilities (CPUMF)";
29 EXPORT_SYMBOL(perf_pmu_name
);
31 int perf_num_counters(void)
36 num
+= PERF_CPUM_CF_MAX_CTR
;
40 EXPORT_SYMBOL(perf_num_counters
);
42 void perf_event_print_debug(void)
44 struct cpumf_ctr_info cf_info
;
51 local_irq_save(flags
);
53 cpu
= smp_processor_id();
54 memset(&cf_info
, 0, sizeof(cf_info
));
55 if (!qctri(&cf_info
)) {
56 pr_info("CPU[%i] CPUM_CF: ver=%u.%u A=%04x E=%04x C=%04x\n",
57 cpu
, cf_info
.cfvn
, cf_info
.csvn
,
58 cf_info
.auth_ctl
, cf_info
.enable_ctl
, cf_info
.act_ctl
);
59 print_hex_dump_bytes("CPUMF Query: ", DUMP_PREFIX_OFFSET
,
60 &cf_info
, sizeof(cf_info
));
63 local_irq_restore(flags
);
66 /* See also arch/s390/kernel/traps.c */
67 static unsigned long __store_trace(struct perf_callchain_entry
*entry
,
69 unsigned long low
, unsigned long high
)
71 struct stack_frame
*sf
;
75 sp
= sp
& PSW_ADDR_INSN
;
76 if (sp
< low
|| sp
> high
- sizeof(*sf
))
78 sf
= (struct stack_frame
*) sp
;
79 perf_callchain_store(entry
, sf
->gprs
[8] & PSW_ADDR_INSN
);
80 /* Follow the backchain. */
83 sp
= sf
->back_chain
& PSW_ADDR_INSN
;
86 if (sp
<= low
|| sp
> high
- sizeof(*sf
))
88 sf
= (struct stack_frame
*) sp
;
89 perf_callchain_store(entry
,
90 sf
->gprs
[8] & PSW_ADDR_INSN
);
92 /* Zero backchain detected, check for interrupt frame. */
93 sp
= (unsigned long) (sf
+ 1);
94 if (sp
<= low
|| sp
> high
- sizeof(*regs
))
96 regs
= (struct pt_regs
*) sp
;
97 perf_callchain_store(entry
, sf
->gprs
[8] & PSW_ADDR_INSN
);
103 void perf_callchain_kernel(struct perf_callchain_entry
*entry
,
104 struct pt_regs
*regs
)
107 struct stack_frame
*head_sf
;
112 head
= regs
->gprs
[15];
113 head_sf
= (struct stack_frame
*) head
;
115 if (!head_sf
|| !head_sf
->back_chain
)
118 head
= head_sf
->back_chain
;
119 head
= __store_trace(entry
, head
, S390_lowcore
.async_stack
- ASYNC_SIZE
,
120 S390_lowcore
.async_stack
);
122 __store_trace(entry
, head
, S390_lowcore
.thread_info
,
123 S390_lowcore
.thread_info
+ THREAD_SIZE
);