| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Performance event support - PPC 8xx |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 19 | 15 | #include <asm/firmware.h> |
|---|
| 20 | 16 | #include <asm/ptrace.h> |
|---|
| 21 | 17 | #include <asm/code-patching.h> |
|---|
| 18 | +#include <asm/inst.h> |
|---|
| 22 | 19 | |
|---|
| 23 | 20 | #define PERF_8xx_ID_CPU_CYCLES 1 |
|---|
| 24 | 21 | #define PERF_8xx_ID_HW_INSTRUCTIONS 2 |
|---|
| .. | .. |
|---|
| 31 | 28 | |
|---|
| 32 | 29 | extern unsigned long itlb_miss_counter, dtlb_miss_counter; |
|---|
| 33 | 30 | 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; |
|---|
| 37 | 31 | |
|---|
| 38 | 32 | static atomic_t insn_ctr_ref; |
|---|
| 39 | 33 | static atomic_t itlb_miss_ref; |
|---|
| .. | .. |
|---|
| 103 | 97 | break; |
|---|
| 104 | 98 | case PERF_8xx_ID_ITLB_LOAD_MISS: |
|---|
| 105 | 99 | 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); |
|---|
| 107 | 101 | |
|---|
| 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); |
|---|
| 112 | 103 | } |
|---|
| 113 | 104 | val = itlb_miss_counter; |
|---|
| 114 | 105 | break; |
|---|
| 115 | 106 | case PERF_8xx_ID_DTLB_LOAD_MISS: |
|---|
| 116 | 107 | 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); |
|---|
| 118 | 109 | |
|---|
| 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); |
|---|
| 122 | 111 | } |
|---|
| 123 | 112 | val = dtlb_miss_counter; |
|---|
| 124 | 113 | break; |
|---|
| .. | .. |
|---|
| 164 | 153 | |
|---|
| 165 | 154 | static void mpc8xx_pmu_del(struct perf_event *event, int flags) |
|---|
| 166 | 155 | { |
|---|
| 167 | | - /* mfspr r10, SPRN_SPRG_SCRATCH0 */ |
|---|
| 168 | | - unsigned int insn = PPC_INST_MFSPR | __PPC_RS(R10) | |
|---|
| 169 | | - __PPC_SPR(SPRN_SPRG_SCRATCH0); |
|---|
| 170 | | - |
|---|
| 171 | 156 | mpc8xx_pmu_read(event); |
|---|
| 172 | 157 | |
|---|
| 173 | 158 | /* If it was the last user, stop counting to avoid useles overhead */ |
|---|
| .. | .. |
|---|
| 180 | 165 | break; |
|---|
| 181 | 166 | case PERF_8xx_ID_ITLB_LOAD_MISS: |
|---|
| 182 | 167 | 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); |
|---|
| 187 | 173 | } |
|---|
| 188 | 174 | break; |
|---|
| 189 | 175 | case PERF_8xx_ID_DTLB_LOAD_MISS: |
|---|
| 190 | 176 | 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); |
|---|
| 194 | 182 | } |
|---|
| 195 | 183 | break; |
|---|
| 196 | 184 | } |
|---|