cpu_mf.h 8.8 KB

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