Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * CPU-measurement facilities
0004  *
0005  *  Copyright IBM Corp. 2012, 2018
0006  *  Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
0007  *         Jan Glauber <jang@linux.vnet.ibm.com>
0008  */
0009 #ifndef _ASM_S390_CPU_MF_H
0010 #define _ASM_S390_CPU_MF_H
0011 
0012 #include <linux/errno.h>
0013 #include <asm/asm-extable.h>
0014 #include <asm/facility.h>
0015 
0016 asm(".include \"asm/cpu_mf-insn.h\"\n");
0017 
0018 #define CPU_MF_INT_SF_IAE   (1 << 31)   /* invalid entry address */
0019 #define CPU_MF_INT_SF_ISE   (1 << 30)   /* incorrect SDBT entry */
0020 #define CPU_MF_INT_SF_PRA   (1 << 29)   /* program request alert */
0021 #define CPU_MF_INT_SF_SACA  (1 << 23)   /* sampler auth. change alert */
0022 #define CPU_MF_INT_SF_LSDA  (1 << 22)   /* loss of sample data alert */
0023 #define CPU_MF_INT_CF_MTDA  (1 << 15)   /* loss of MT ctr. data alert */
0024 #define CPU_MF_INT_CF_CACA  (1 <<  7)   /* counter auth. change alert */
0025 #define CPU_MF_INT_CF_LCDA  (1 <<  6)   /* loss of counter data alert */
0026 #define CPU_MF_INT_CF_MASK  (CPU_MF_INT_CF_MTDA|CPU_MF_INT_CF_CACA| \
0027                  CPU_MF_INT_CF_LCDA)
0028 #define CPU_MF_INT_SF_MASK  (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE|   \
0029                  CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA|  \
0030                  CPU_MF_INT_SF_LSDA)
0031 
0032 #define CPU_MF_SF_RIBM_NOTAV    0x1     /* Sampling unavailable */
0033 
0034 /* CPU measurement facility support */
0035 static inline int cpum_cf_avail(void)
0036 {
0037     return test_facility(40) && test_facility(67);
0038 }
0039 
0040 static inline int cpum_sf_avail(void)
0041 {
0042     return test_facility(40) && test_facility(68);
0043 }
0044 
0045 
0046 struct cpumf_ctr_info {
0047     u16   cfvn;
0048     u16   auth_ctl;
0049     u16   enable_ctl;
0050     u16   act_ctl;
0051     u16   max_cpu;
0052     u16   csvn;
0053     u16   max_cg;
0054     u16   reserved1;
0055     u32   reserved2[12];
0056 } __packed;
0057 
0058 /* QUERY SAMPLING INFORMATION block */
0059 struct hws_qsi_info_block {     /* Bit(s) */
0060     unsigned int b0_13:14;      /* 0-13: zeros           */
0061     unsigned int as:1;      /* 14: basic-sampling authorization  */
0062     unsigned int ad:1;      /* 15: diag-sampling authorization   */
0063     unsigned int b16_21:6;      /* 16-21: zeros          */
0064     unsigned int es:1;      /* 22: basic-sampling enable control */
0065     unsigned int ed:1;      /* 23: diag-sampling enable control  */
0066     unsigned int b24_29:6;      /* 24-29: zeros          */
0067     unsigned int cs:1;      /* 30: basic-sampling activation control */
0068     unsigned int cd:1;      /* 31: diag-sampling activation control */
0069     unsigned int bsdes:16;      /* 4-5: size of basic sampling entry */
0070     unsigned int dsdes:16;      /* 6-7: size of diagnostic sampling entry */
0071     unsigned long min_sampl_rate; /* 8-15: minimum sampling interval */
0072     unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/
0073     unsigned long tear;     /* 24-31: TEAR contents      */
0074     unsigned long dear;     /* 32-39: DEAR contents      */
0075     unsigned int rsvrd0:24;     /* 40-42: reserved           */
0076     unsigned int ribm:8;        /* 43: Reserved by IBM       */
0077     unsigned int cpu_speed;     /* 44-47: CPU speed          */
0078     unsigned long long rsvrd1;  /* 48-55: reserved           */
0079     unsigned long long rsvrd2;  /* 56-63: reserved           */
0080 } __packed;
0081 
0082 /* SET SAMPLING CONTROLS request block */
0083 struct hws_lsctl_request_block {
0084     unsigned int s:1;       /* 0: maximum buffer indicator   */
0085     unsigned int h:1;       /* 1: part. level reserved for VM use*/
0086     unsigned long long b2_53:52;/* 2-53: zeros           */
0087     unsigned int es:1;      /* 54: basic-sampling enable control */
0088     unsigned int ed:1;      /* 55: diag-sampling enable control  */
0089     unsigned int b56_61:6;      /* 56-61: - zeros            */
0090     unsigned int cs:1;      /* 62: basic-sampling activation control */
0091     unsigned int cd:1;      /* 63: diag-sampling activation control  */
0092     unsigned long interval;     /* 8-15: sampling interval       */
0093     unsigned long tear;     /* 16-23: TEAR contents      */
0094     unsigned long dear;     /* 24-31: DEAR contents      */
0095     /* 32-63:                            */
0096     unsigned long rsvrd1;       /* reserved              */
0097     unsigned long rsvrd2;       /* reserved              */
0098     unsigned long rsvrd3;       /* reserved              */
0099     unsigned long rsvrd4;       /* reserved              */
0100 } __packed;
0101 
0102 struct hws_basic_entry {
0103     unsigned int def:16;        /* 0-15  Data Entry Format       */
0104     unsigned int R:4;       /* 16-19 reserved            */
0105     unsigned int U:4;       /* 20-23 Number of unique instruct.  */
0106     unsigned int z:2;       /* zeros                 */
0107     unsigned int T:1;       /* 26 PSW DAT mode           */
0108     unsigned int W:1;       /* 27 PSW wait state         */
0109     unsigned int P:1;       /* 28 PSW Problem state      */
0110     unsigned int AS:2;      /* 29-30 PSW address-space control   */
0111     unsigned int I:1;       /* 31 entry valid or invalid     */
0112     unsigned int CL:2;      /* 32-33 Configuration Level     */
0113     unsigned int H:1;       /* 34 Host Indicator         */
0114     unsigned int LS:1;      /* 35 Limited Sampling       */
0115     unsigned int:12;
0116     unsigned int prim_asn:16;   /* primary ASN           */
0117     unsigned long long ia;      /* Instruction Address       */
0118     unsigned long long gpp;     /* Guest Program Parameter       */
0119     unsigned long long hpp;     /* Host Program Parameter        */
0120 } __packed;
0121 
0122 struct hws_diag_entry {
0123     unsigned int def:16;        /* 0-15  Data Entry Format       */
0124     unsigned int R:15;      /* 16-19 and 20-30 reserved      */
0125     unsigned int I:1;       /* 31 entry valid or invalid     */
0126     u8       data[];        /* Machine-dependent sample data     */
0127 } __packed;
0128 
0129 struct hws_combined_entry {
0130     struct hws_basic_entry  basic;  /* Basic-sampling data entry */
0131     struct hws_diag_entry   diag;   /* Diagnostic-sampling data entry */
0132 } __packed;
0133 
0134 struct hws_trailer_entry {
0135     union {
0136         struct {
0137             unsigned int f:1;   /* 0 - Block Full Indicator   */
0138             unsigned int a:1;   /* 1 - Alert request control  */
0139             unsigned int t:1;   /* 2 - Timestamp format       */
0140             unsigned int :29;   /* 3 - 31: Reserved       */
0141             unsigned int bsdes:16;  /* 32-47: size of basic SDE   */
0142             unsigned int dsdes:16;  /* 48-63: size of diagnostic SDE */
0143         };
0144         unsigned long long flags;   /* 0 - 63: All indicators     */
0145     };
0146     unsigned long long overflow;     /* 64 - sample Overflow count        */
0147     unsigned char timestamp[16];     /* 16 - 31 timestamp             */
0148     unsigned long long reserved1;    /* 32 -Reserved              */
0149     unsigned long long reserved2;    /*                   */
0150     union {              /* 48 - reserved for programming use */
0151         struct {
0152             unsigned int clock_base:1; /* in progusage2 */
0153             unsigned long long progusage1:63;
0154             unsigned long long progusage2;
0155         };
0156         unsigned long long progusage[2];
0157     };
0158 } __packed;
0159 
0160 /* Load program parameter */
0161 static inline void lpp(void *pp)
0162 {
0163     asm volatile("lpp 0(%0)\n" :: "a" (pp) : "memory");
0164 }
0165 
0166 /* Query counter information */
0167 static inline int qctri(struct cpumf_ctr_info *info)
0168 {
0169     int rc = -EINVAL;
0170 
0171     asm volatile (
0172         "0: qctri   %1\n"
0173         "1: lhi %0,0\n"
0174         "2:\n"
0175         EX_TABLE(1b, 2b)
0176         : "+d" (rc), "=Q" (*info));
0177     return rc;
0178 }
0179 
0180 /* Load CPU-counter-set controls */
0181 static inline int lcctl(u64 ctl)
0182 {
0183     int cc;
0184 
0185     asm volatile (
0186         "   lcctl   %1\n"
0187         "   ipm %0\n"
0188         "   srl %0,28\n"
0189         : "=d" (cc) : "Q" (ctl) : "cc");
0190     return cc;
0191 }
0192 
0193 /* Extract CPU counter */
0194 static inline int __ecctr(u64 ctr, u64 *content)
0195 {
0196     u64 _content;
0197     int cc;
0198 
0199     asm volatile (
0200         "   ecctr   %0,%2\n"
0201         "   ipm %1\n"
0202         "   srl %1,28\n"
0203         : "=d" (_content), "=d" (cc) : "d" (ctr) : "cc");
0204     *content = _content;
0205     return cc;
0206 }
0207 
0208 /* Extract CPU counter */
0209 static inline int ecctr(u64 ctr, u64 *val)
0210 {
0211     u64 content;
0212     int cc;
0213 
0214     cc = __ecctr(ctr, &content);
0215     if (!cc)
0216         *val = content;
0217     return cc;
0218 }
0219 
0220 /* Store CPU counter multiple for a particular counter set */
0221 enum stcctm_ctr_set {
0222     EXTENDED = 0,
0223     BASIC = 1,
0224     PROBLEM_STATE = 2,
0225     CRYPTO_ACTIVITY = 3,
0226     MT_DIAG = 5,
0227     MT_DIAG_CLEARING = 9,   /* clears loss-of-MT-ctr-data alert */
0228 };
0229 
0230 static __always_inline int stcctm(enum stcctm_ctr_set set, u64 range, u64 *dest)
0231 {
0232     int cc;
0233 
0234     asm volatile (
0235         "   STCCTM  %2,%3,%1\n"
0236         "   ipm %0\n"
0237         "   srl %0,28\n"
0238         : "=d" (cc)
0239         : "Q" (*dest), "d" (range), "i" (set)
0240         : "cc", "memory");
0241     return cc;
0242 }
0243 
0244 /* Query sampling information */
0245 static inline int qsi(struct hws_qsi_info_block *info)
0246 {
0247     int cc = 1;
0248 
0249     asm volatile(
0250         "0: qsi %1\n"
0251         "1: lhi %0,0\n"
0252         "2:\n"
0253         EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
0254         : "+d" (cc), "+Q" (*info));
0255     return cc ? -EINVAL : 0;
0256 }
0257 
0258 /* Load sampling controls */
0259 static inline int lsctl(struct hws_lsctl_request_block *req)
0260 {
0261     int cc;
0262 
0263     cc = 1;
0264     asm volatile(
0265         "0: lsctl   0(%1)\n"
0266         "1: ipm %0\n"
0267         "   srl %0,28\n"
0268         "2:\n"
0269         EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
0270         : "+d" (cc), "+a" (req)
0271         : "m" (*req)
0272         : "cc", "memory");
0273 
0274     return cc ? -EINVAL : 0;
0275 }
0276 
0277 /* Sampling control helper functions */
0278 
0279 #include <linux/time.h>
0280 
0281 static inline unsigned long freq_to_sample_rate(struct hws_qsi_info_block *qsi,
0282                         unsigned long freq)
0283 {
0284     return (USEC_PER_SEC / freq) * qsi->cpu_speed;
0285 }
0286 
0287 static inline unsigned long sample_rate_to_freq(struct hws_qsi_info_block *qsi,
0288                         unsigned long rate)
0289 {
0290     return USEC_PER_SEC * qsi->cpu_speed / rate;
0291 }
0292 
0293 #define SDB_TE_ALERT_REQ_MASK   0x4000000000000000UL
0294 #define SDB_TE_BUFFER_FULL_MASK 0x8000000000000000UL
0295 
0296 /* Return TOD timestamp contained in an trailer entry */
0297 static inline unsigned long long trailer_timestamp(struct hws_trailer_entry *te)
0298 {
0299     /* TOD in STCKE format */
0300     if (te->t)
0301         return *((unsigned long long *) &te->timestamp[1]);
0302 
0303     /* TOD in STCK format */
0304     return *((unsigned long long *) &te->timestamp[0]);
0305 }
0306 
0307 /* Return pointer to trailer entry of an sample data block */
0308 static inline unsigned long *trailer_entry_ptr(unsigned long v)
0309 {
0310     void *ret;
0311 
0312     ret = (void *) v;
0313     ret += PAGE_SIZE;
0314     ret -= sizeof(struct hws_trailer_entry);
0315 
0316     return (unsigned long *) ret;
0317 }
0318 
0319 /* Return true if the entry in the sample data block table (sdbt)
0320  * is a link to the next sdbt */
0321 static inline int is_link_entry(unsigned long *s)
0322 {
0323     return *s & 0x1ul ? 1 : 0;
0324 }
0325 
0326 /* Return pointer to the linked sdbt */
0327 static inline unsigned long *get_next_sdbt(unsigned long *s)
0328 {
0329     return (unsigned long *) (*s & ~0x1ul);
0330 }
0331 #endif /* _ASM_S390_CPU_MF_H */