Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * CPU-measurement facilities |
| 3 | * |
| 4 | * Copyright IBM Corp. 2012 |
| 5 | * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> |
| 6 | * Jan Glauber <jang@linux.vnet.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License (version 2 only) |
| 10 | * as published by the Free Software Foundation. |
| 11 | */ |
Jan Glauber | b03d541a | 2012-03-23 11:13:05 +0100 | [diff] [blame] | 12 | #ifndef _ASM_S390_CPU_MF_H |
| 13 | #define _ASM_S390_CPU_MF_H |
| 14 | |
Li Zefan | cb16b91 | 2013-03-07 17:35:53 +0800 | [diff] [blame] | 15 | #include <linux/errno.h> |
Heiko Carstens | 1e3cab2 | 2012-03-30 09:40:55 +0200 | [diff] [blame] | 16 | #include <asm/facility.h> |
| 17 | |
Jan Glauber | b03d541a | 2012-03-23 11:13:05 +0100 | [diff] [blame] | 18 | #define CPU_MF_INT_SF_IAE (1 << 31) /* invalid entry address */ |
| 19 | #define CPU_MF_INT_SF_ISE (1 << 30) /* incorrect SDBT entry */ |
| 20 | #define CPU_MF_INT_SF_PRA (1 << 29) /* program request alert */ |
| 21 | #define CPU_MF_INT_SF_SACA (1 << 23) /* sampler auth. change alert */ |
| 22 | #define CPU_MF_INT_SF_LSDA (1 << 22) /* loss of sample data alert */ |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 23 | #define CPU_MF_INT_CF_CACA (1 << 7) /* counter auth. change alert */ |
| 24 | #define CPU_MF_INT_CF_LCDA (1 << 6) /* loss of counter data alert */ |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 25 | #define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA) |
| 26 | #define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \ |
| 27 | CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \ |
| 28 | CPU_MF_INT_SF_LSDA) |
| 29 | |
| 30 | /* CPU measurement facility support */ |
| 31 | static inline int cpum_cf_avail(void) |
| 32 | { |
Hendrik Brueckner | 23d18e8 | 2013-02-11 18:11:09 +0100 | [diff] [blame] | 33 | return MACHINE_HAS_LPP && test_facility(67); |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static inline int cpum_sf_avail(void) |
| 37 | { |
Hendrik Brueckner | 23d18e8 | 2013-02-11 18:11:09 +0100 | [diff] [blame] | 38 | return MACHINE_HAS_LPP && test_facility(68); |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
| 42 | struct cpumf_ctr_info { |
| 43 | u16 cfvn; |
| 44 | u16 auth_ctl; |
| 45 | u16 enable_ctl; |
| 46 | u16 act_ctl; |
| 47 | u16 max_cpu; |
| 48 | u16 csvn; |
| 49 | u16 max_cg; |
| 50 | u16 reserved1; |
| 51 | u32 reserved2[12]; |
| 52 | } __packed; |
| 53 | |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 54 | /* QUERY SAMPLING INFORMATION block */ |
| 55 | struct hws_qsi_info_block { /* Bit(s) */ |
| 56 | unsigned int b0_13:14; /* 0-13: zeros */ |
Hendrik Brueckner | 7e75fc3 | 2013-12-13 11:42:44 +0100 | [diff] [blame] | 57 | unsigned int as:1; /* 14: basic-sampling authorization */ |
| 58 | unsigned int ad:1; /* 15: diag-sampling authorization */ |
| 59 | unsigned int b16_21:6; /* 16-21: zeros */ |
| 60 | unsigned int es:1; /* 22: basic-sampling enable control */ |
| 61 | unsigned int ed:1; /* 23: diag-sampling enable control */ |
| 62 | unsigned int b24_29:6; /* 24-29: zeros */ |
| 63 | unsigned int cs:1; /* 30: basic-sampling activation control */ |
| 64 | unsigned int cd:1; /* 31: diag-sampling activation control */ |
| 65 | unsigned int bsdes:16; /* 4-5: size of basic sampling entry */ |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 66 | unsigned int dsdes:16; /* 6-7: size of diagnostic sampling entry */ |
| 67 | unsigned long min_sampl_rate; /* 8-15: minimum sampling interval */ |
| 68 | unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/ |
| 69 | unsigned long tear; /* 24-31: TEAR contents */ |
| 70 | unsigned long dear; /* 32-39: DEAR contents */ |
| 71 | unsigned int rsvrd0; /* 40-43: reserved */ |
| 72 | unsigned int cpu_speed; /* 44-47: CPU speed */ |
| 73 | unsigned long long rsvrd1; /* 48-55: reserved */ |
| 74 | unsigned long long rsvrd2; /* 56-63: reserved */ |
| 75 | } __packed; |
| 76 | |
| 77 | /* SET SAMPLING CONTROLS request block */ |
| 78 | struct hws_lsctl_request_block { |
| 79 | unsigned int s:1; /* 0: maximum buffer indicator */ |
| 80 | unsigned int h:1; /* 1: part. level reserved for VM use*/ |
| 81 | unsigned long long b2_53:52;/* 2-53: zeros */ |
Hendrik Brueckner | 7e75fc3 | 2013-12-13 11:42:44 +0100 | [diff] [blame] | 82 | unsigned int es:1; /* 54: basic-sampling enable control */ |
| 83 | unsigned int ed:1; /* 55: diag-sampling enable control */ |
| 84 | unsigned int b56_61:6; /* 56-61: - zeros */ |
| 85 | unsigned int cs:1; /* 62: basic-sampling activation control */ |
| 86 | unsigned int cd:1; /* 63: diag-sampling activation control */ |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 87 | unsigned long interval; /* 8-15: sampling interval */ |
| 88 | unsigned long tear; /* 16-23: TEAR contents */ |
| 89 | unsigned long dear; /* 24-31: DEAR contents */ |
| 90 | /* 32-63: */ |
| 91 | unsigned long rsvrd1; /* reserved */ |
| 92 | unsigned long rsvrd2; /* reserved */ |
| 93 | unsigned long rsvrd3; /* reserved */ |
| 94 | unsigned long rsvrd4; /* reserved */ |
| 95 | } __packed; |
| 96 | |
Hendrik Brueckner | 7e75fc3 | 2013-12-13 11:42:44 +0100 | [diff] [blame] | 97 | struct hws_basic_entry { |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 98 | unsigned int def:16; /* 0-15 Data Entry Format */ |
| 99 | unsigned int R:4; /* 16-19 reserved */ |
| 100 | unsigned int U:4; /* 20-23 Number of unique instruct. */ |
| 101 | unsigned int z:2; /* zeros */ |
| 102 | unsigned int T:1; /* 26 PSW DAT mode */ |
| 103 | unsigned int W:1; /* 27 PSW wait state */ |
| 104 | unsigned int P:1; /* 28 PSW Problem state */ |
| 105 | unsigned int AS:2; /* 29-30 PSW address-space control */ |
| 106 | unsigned int I:1; /* 31 entry valid or invalid */ |
| 107 | unsigned int:16; |
| 108 | unsigned int prim_asn:16; /* primary ASN */ |
| 109 | unsigned long long ia; /* Instruction Address */ |
| 110 | unsigned long long gpp; /* Guest Program Parameter */ |
| 111 | unsigned long long hpp; /* Host Program Parameter */ |
| 112 | } __packed; |
| 113 | |
Hendrik Brueckner | 7e75fc3 | 2013-12-13 11:42:44 +0100 | [diff] [blame] | 114 | struct hws_diag_entry { |
| 115 | unsigned int def:16; /* 0-15 Data Entry Format */ |
| 116 | unsigned int R:14; /* 16-19 and 20-30 reserved */ |
| 117 | unsigned int I:1; /* 31 entry valid or invalid */ |
| 118 | u8 data[]; /* Machine-dependent sample data */ |
| 119 | } __packed; |
| 120 | |
| 121 | struct hws_combined_entry { |
| 122 | struct hws_basic_entry basic; /* Basic-sampling data entry */ |
| 123 | struct hws_diag_entry diag; /* Diagnostic-sampling data entry */ |
| 124 | } __packed; |
| 125 | |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 126 | struct hws_trailer_entry { |
Hendrik Brueckner | fcc77f5 | 2013-12-12 17:26:51 +0100 | [diff] [blame] | 127 | union { |
| 128 | struct { |
| 129 | unsigned int f:1; /* 0 - Block Full Indicator */ |
| 130 | unsigned int a:1; /* 1 - Alert request control */ |
| 131 | unsigned int t:1; /* 2 - Timestamp format */ |
| 132 | unsigned long long:61; /* 3 - 63: Reserved */ |
| 133 | }; |
| 134 | unsigned long long flags; /* 0 - 63: All indicators */ |
| 135 | }; |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 136 | unsigned long long overflow; /* 64 - sample Overflow count */ |
Hendrik Brueckner | 443d4be | 2013-12-12 17:38:50 +0100 | [diff] [blame] | 137 | unsigned char timestamp[16]; /* 16 - 31 timestamp */ |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 138 | unsigned long long reserved1; /* 32 -Reserved */ |
| 139 | unsigned long long reserved2; /* */ |
| 140 | unsigned long long progusage1; /* 48 - reserved for programming use */ |
| 141 | unsigned long long progusage2; /* */ |
| 142 | } __packed; |
| 143 | |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 144 | /* Query counter information */ |
| 145 | static inline int qctri(struct cpumf_ctr_info *info) |
| 146 | { |
| 147 | int rc = -EINVAL; |
| 148 | |
| 149 | asm volatile ( |
| 150 | "0: .insn s,0xb28e0000,%1\n" |
| 151 | "1: lhi %0,0\n" |
| 152 | "2:\n" |
| 153 | EX_TABLE(1b, 2b) |
| 154 | : "+d" (rc), "=Q" (*info)); |
| 155 | return rc; |
| 156 | } |
| 157 | |
| 158 | /* Load CPU-counter-set controls */ |
| 159 | static inline int lcctl(u64 ctl) |
| 160 | { |
| 161 | int cc; |
| 162 | |
| 163 | asm volatile ( |
| 164 | " .insn s,0xb2840000,%1\n" |
| 165 | " ipm %0\n" |
| 166 | " srl %0,28\n" |
| 167 | : "=d" (cc) : "m" (ctl) : "cc"); |
| 168 | return cc; |
| 169 | } |
| 170 | |
| 171 | /* Extract CPU counter */ |
Heiko Carstens | e238c15 | 2016-06-20 14:06:54 +0200 | [diff] [blame] | 172 | static inline int __ecctr(u64 ctr, u64 *content) |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 173 | { |
Heiko Carstens | e238c15 | 2016-06-20 14:06:54 +0200 | [diff] [blame] | 174 | register u64 _content asm("4") = 0; |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 175 | int cc; |
| 176 | |
| 177 | asm volatile ( |
| 178 | " .insn rre,0xb2e40000,%0,%2\n" |
| 179 | " ipm %1\n" |
| 180 | " srl %1,28\n" |
Heiko Carstens | e238c15 | 2016-06-20 14:06:54 +0200 | [diff] [blame] | 181 | : "=d" (_content), "=d" (cc) : "d" (ctr) : "cc"); |
| 182 | *content = _content; |
| 183 | return cc; |
| 184 | } |
| 185 | |
| 186 | /* Extract CPU counter */ |
| 187 | static inline int ecctr(u64 ctr, u64 *val) |
| 188 | { |
| 189 | u64 content; |
| 190 | int cc; |
| 191 | |
| 192 | cc = __ecctr(ctr, &content); |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 193 | if (!cc) |
| 194 | *val = content; |
| 195 | return cc; |
| 196 | } |
| 197 | |
Martin Schwidefsky | 10ad34b | 2015-01-14 17:52:10 +0100 | [diff] [blame] | 198 | /* Store CPU counter multiple for the MT utilization counter set */ |
| 199 | static inline int stcctm5(u64 num, u64 *val) |
| 200 | { |
| 201 | typedef struct { u64 _[num]; } addrtype; |
| 202 | int cc; |
| 203 | |
| 204 | asm volatile ( |
| 205 | " .insn rsy,0xeb0000000017,%2,5,%1\n" |
| 206 | " ipm %0\n" |
| 207 | " srl %0,28\n" |
| 208 | : "=d" (cc), "=Q" (*(addrtype *) val) : "d" (num) : "cc"); |
| 209 | return cc; |
| 210 | } |
| 211 | |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 212 | /* Query sampling information */ |
| 213 | static inline int qsi(struct hws_qsi_info_block *info) |
| 214 | { |
| 215 | int cc; |
| 216 | cc = 1; |
| 217 | |
| 218 | asm volatile( |
| 219 | "0: .insn s,0xb2860000,0(%1)\n" |
| 220 | "1: lhi %0,0\n" |
| 221 | "2:\n" |
| 222 | EX_TABLE(0b, 2b) EX_TABLE(1b, 2b) |
| 223 | : "=d" (cc), "+a" (info) |
| 224 | : "m" (*info) |
| 225 | : "cc", "memory"); |
| 226 | |
| 227 | return cc ? -EINVAL : 0; |
| 228 | } |
| 229 | |
| 230 | /* Load sampling controls */ |
| 231 | static inline int lsctl(struct hws_lsctl_request_block *req) |
| 232 | { |
| 233 | int cc; |
| 234 | |
| 235 | cc = 1; |
| 236 | asm volatile( |
| 237 | "0: .insn s,0xb2870000,0(%1)\n" |
| 238 | "1: ipm %0\n" |
| 239 | " srl %0,28\n" |
| 240 | "2:\n" |
| 241 | EX_TABLE(0b, 2b) EX_TABLE(1b, 2b) |
| 242 | : "+d" (cc), "+a" (req) |
| 243 | : "m" (*req) |
| 244 | : "cc", "memory"); |
| 245 | |
| 246 | return cc ? -EINVAL : 0; |
| 247 | } |
| 248 | |
| 249 | /* Sampling control helper functions */ |
| 250 | |
Hendrik Brueckner | 8c069ff | 2013-12-12 16:32:47 +0100 | [diff] [blame] | 251 | #include <linux/time.h> |
| 252 | |
| 253 | static inline unsigned long freq_to_sample_rate(struct hws_qsi_info_block *qsi, |
| 254 | unsigned long freq) |
| 255 | { |
| 256 | return (USEC_PER_SEC / freq) * qsi->cpu_speed; |
| 257 | } |
| 258 | |
| 259 | static inline unsigned long sample_rate_to_freq(struct hws_qsi_info_block *qsi, |
| 260 | unsigned long rate) |
| 261 | { |
| 262 | return USEC_PER_SEC * qsi->cpu_speed / rate; |
| 263 | } |
| 264 | |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 265 | #define SDB_TE_ALERT_REQ_MASK 0x4000000000000000UL |
| 266 | #define SDB_TE_BUFFER_FULL_MASK 0x8000000000000000UL |
| 267 | |
Hendrik Brueckner | 443d4be | 2013-12-12 17:38:50 +0100 | [diff] [blame] | 268 | /* Return TOD timestamp contained in an trailer entry */ |
| 269 | static inline unsigned long long trailer_timestamp(struct hws_trailer_entry *te) |
| 270 | { |
| 271 | /* TOD in STCKE format */ |
| 272 | if (te->t) |
| 273 | return *((unsigned long long *) &te->timestamp[1]); |
| 274 | |
| 275 | /* TOD in STCK format */ |
| 276 | return *((unsigned long long *) &te->timestamp[0]); |
| 277 | } |
| 278 | |
Hendrik Brueckner | cf48ad8 | 2013-12-11 12:15:52 +0100 | [diff] [blame] | 279 | /* Return pointer to trailer entry of an sample data block */ |
| 280 | static inline unsigned long *trailer_entry_ptr(unsigned long v) |
| 281 | { |
| 282 | void *ret; |
| 283 | |
| 284 | ret = (void *) v; |
| 285 | ret += PAGE_SIZE; |
| 286 | ret -= sizeof(struct hws_trailer_entry); |
| 287 | |
| 288 | return (unsigned long *) ret; |
| 289 | } |
| 290 | |
| 291 | /* Return if the entry in the sample data block table (sdbt) |
| 292 | * is a link to the next sdbt */ |
| 293 | static inline int is_link_entry(unsigned long *s) |
| 294 | { |
| 295 | return *s & 0x1ul ? 1 : 0; |
| 296 | } |
| 297 | |
| 298 | /* Return pointer to the linked sdbt */ |
| 299 | static inline unsigned long *get_next_sdbt(unsigned long *s) |
| 300 | { |
| 301 | return (unsigned long *) (*s & ~0x1ul); |
| 302 | } |
Hendrik Brueckner | 212188a | 2012-03-23 11:13:06 +0100 | [diff] [blame] | 303 | #endif /* _ASM_S390_CPU_MF_H */ |