hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/arch/powerpc/perf/8xx-pmu.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Performance event support - PPC 8xx
34 *
45 * Copyright 2016 Christophe Leroy, CS Systemes d'Information
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
106 */
117
128 #include <linux/kernel.h>
....@@ -19,6 +15,7 @@
1915 #include <asm/firmware.h>
2016 #include <asm/ptrace.h>
2117 #include <asm/code-patching.h>
18
+#include <asm/inst.h>
2219
2320 #define PERF_8xx_ID_CPU_CYCLES 1
2421 #define PERF_8xx_ID_HW_INSTRUCTIONS 2
....@@ -31,9 +28,6 @@
3128
3229 extern unsigned long itlb_miss_counter, dtlb_miss_counter;
3330 extern atomic_t instruction_counter;
34
-extern unsigned int itlb_miss_perf, dtlb_miss_perf;
35
-extern unsigned int itlb_miss_exit_1, itlb_miss_exit_2;
36
-extern unsigned int dtlb_miss_exit_1, dtlb_miss_exit_2, dtlb_miss_exit_3;
3731
3832 static atomic_t insn_ctr_ref;
3933 static atomic_t itlb_miss_ref;
....@@ -103,22 +97,17 @@
10397 break;
10498 case PERF_8xx_ID_ITLB_LOAD_MISS:
10599 if (atomic_inc_return(&itlb_miss_ref) == 1) {
106
- unsigned long target = (unsigned long)&itlb_miss_perf;
100
+ unsigned long target = patch_site_addr(&patch__itlbmiss_perf);
107101
108
- patch_branch(&itlb_miss_exit_1, target, 0);
109
-#ifndef CONFIG_PIN_TLB_TEXT
110
- patch_branch(&itlb_miss_exit_2, target, 0);
111
-#endif
102
+ patch_branch_site(&patch__itlbmiss_exit_1, target, 0);
112103 }
113104 val = itlb_miss_counter;
114105 break;
115106 case PERF_8xx_ID_DTLB_LOAD_MISS:
116107 if (atomic_inc_return(&dtlb_miss_ref) == 1) {
117
- unsigned long target = (unsigned long)&dtlb_miss_perf;
108
+ unsigned long target = patch_site_addr(&patch__dtlbmiss_perf);
118109
119
- patch_branch(&dtlb_miss_exit_1, target, 0);
120
- patch_branch(&dtlb_miss_exit_2, target, 0);
121
- patch_branch(&dtlb_miss_exit_3, target, 0);
110
+ patch_branch_site(&patch__dtlbmiss_exit_1, target, 0);
122111 }
123112 val = dtlb_miss_counter;
124113 break;
....@@ -164,10 +153,6 @@
164153
165154 static void mpc8xx_pmu_del(struct perf_event *event, int flags)
166155 {
167
- /* mfspr r10, SPRN_SPRG_SCRATCH0 */
168
- unsigned int insn = PPC_INST_MFSPR | __PPC_RS(R10) |
169
- __PPC_SPR(SPRN_SPRG_SCRATCH0);
170
-
171156 mpc8xx_pmu_read(event);
172157
173158 /* If it was the last user, stop counting to avoid useles overhead */
....@@ -180,17 +165,20 @@
180165 break;
181166 case PERF_8xx_ID_ITLB_LOAD_MISS:
182167 if (atomic_dec_return(&itlb_miss_ref) == 0) {
183
- patch_instruction(&itlb_miss_exit_1, insn);
184
-#ifndef CONFIG_PIN_TLB_TEXT
185
- patch_instruction(&itlb_miss_exit_2, insn);
186
-#endif
168
+ /* mfspr r10, SPRN_SPRG_SCRATCH0 */
169
+ struct ppc_inst insn = ppc_inst(PPC_INST_MFSPR | __PPC_RS(R10) |
170
+ __PPC_SPR(SPRN_SPRG_SCRATCH0));
171
+
172
+ patch_instruction_site(&patch__itlbmiss_exit_1, insn);
187173 }
188174 break;
189175 case PERF_8xx_ID_DTLB_LOAD_MISS:
190176 if (atomic_dec_return(&dtlb_miss_ref) == 0) {
191
- patch_instruction(&dtlb_miss_exit_1, insn);
192
- patch_instruction(&dtlb_miss_exit_2, insn);
193
- patch_instruction(&dtlb_miss_exit_3, insn);
177
+ /* mfspr r10, SPRN_DAR */
178
+ struct ppc_inst insn = ppc_inst(PPC_INST_MFSPR | __PPC_RS(R10) |
179
+ __PPC_SPR(SPRN_DAR));
180
+
181
+ patch_instruction_site(&patch__dtlbmiss_exit_1, insn);
194182 }
195183 break;
196184 }