cpu_mf.h 8.8 KB

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