diff options
-rw-r--r-- | arch/s390/include/asm/cpu_mf.h | 40 | ||||
-rw-r--r-- | arch/s390/include/asm/perf_event.h | 28 | ||||
-rw-r--r-- | arch/s390/kernel/perf_cpum_sf.c | 380 | ||||
-rw-r--r-- | arch/s390/kernel/perf_event.c | 21 | ||||
-rw-r--r-- | arch/s390/oprofile/hwsampler.c | 4 |
5 files changed, 377 insertions, 96 deletions
diff --git a/arch/s390/include/asm/cpu_mf.h b/arch/s390/include/asm/cpu_mf.h index 09dc5facc0bc..cb700d54bd83 100644 --- a/arch/s390/include/asm/cpu_mf.h +++ b/arch/s390/include/asm/cpu_mf.h | |||
@@ -59,13 +59,15 @@ struct cpumf_ctr_info { | |||
59 | /* QUERY SAMPLING INFORMATION block */ | 59 | /* QUERY SAMPLING INFORMATION block */ |
60 | struct hws_qsi_info_block { /* Bit(s) */ | 60 | struct hws_qsi_info_block { /* Bit(s) */ |
61 | unsigned int b0_13:14; /* 0-13: zeros */ | 61 | unsigned int b0_13:14; /* 0-13: zeros */ |
62 | unsigned int as:1; /* 14: sampling authorisation control*/ | 62 | unsigned int as:1; /* 14: basic-sampling authorization */ |
63 | unsigned int b15_21:7; /* 15-21: zeros */ | 63 | unsigned int ad:1; /* 15: diag-sampling authorization */ |
64 | unsigned int es:1; /* 22: sampling enable control */ | 64 | unsigned int b16_21:6; /* 16-21: zeros */ |
65 | unsigned int b23_29:7; /* 23-29: zeros */ | 65 | unsigned int es:1; /* 22: basic-sampling enable control */ |
66 | unsigned int cs:1; /* 30: sampling activation control */ | 66 | unsigned int ed:1; /* 23: diag-sampling enable control */ |
67 | unsigned int:1; /* 31: reserved */ | 67 | unsigned int b24_29:6; /* 24-29: zeros */ |
68 | unsigned int bsdes:16; /* 4-5: size of basic sampling entry */ | 68 | unsigned int cs:1; /* 30: basic-sampling activation control */ |
69 | unsigned int cd:1; /* 31: diag-sampling activation control */ | ||
70 | unsigned int bsdes:16; /* 4-5: size of basic sampling entry */ | ||
69 | unsigned int dsdes:16; /* 6-7: size of diagnostic sampling entry */ | 71 | unsigned int dsdes:16; /* 6-7: size of diagnostic sampling entry */ |
70 | unsigned long min_sampl_rate; /* 8-15: minimum sampling interval */ | 72 | unsigned long min_sampl_rate; /* 8-15: minimum sampling interval */ |
71 | unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/ | 73 | unsigned long max_sampl_rate; /* 16-23: maximum sampling interval*/ |
@@ -82,10 +84,11 @@ struct hws_lsctl_request_block { | |||
82 | unsigned int s:1; /* 0: maximum buffer indicator */ | 84 | unsigned int s:1; /* 0: maximum buffer indicator */ |
83 | unsigned int h:1; /* 1: part. level reserved for VM use*/ | 85 | unsigned int h:1; /* 1: part. level reserved for VM use*/ |
84 | unsigned long long b2_53:52;/* 2-53: zeros */ | 86 | unsigned long long b2_53:52;/* 2-53: zeros */ |
85 | unsigned int es:1; /* 54: sampling enable control */ | 87 | unsigned int es:1; /* 54: basic-sampling enable control */ |
86 | unsigned int b55_61:7; /* 55-61: - zeros */ | 88 | unsigned int ed:1; /* 55: diag-sampling enable control */ |
87 | unsigned int cs:1; /* 62: sampling activation control */ | 89 | unsigned int b56_61:6; /* 56-61: - zeros */ |
88 | unsigned int b63:1; /* 63: zero */ | 90 | unsigned int cs:1; /* 62: basic-sampling activation control */ |
91 | unsigned int cd:1; /* 63: diag-sampling activation control */ | ||
89 | unsigned long interval; /* 8-15: sampling interval */ | 92 | unsigned long interval; /* 8-15: sampling interval */ |
90 | unsigned long tear; /* 16-23: TEAR contents */ | 93 | unsigned long tear; /* 16-23: TEAR contents */ |
91 | unsigned long dear; /* 24-31: DEAR contents */ | 94 | unsigned long dear; /* 24-31: DEAR contents */ |
@@ -96,8 +99,7 @@ struct hws_lsctl_request_block { | |||
96 | unsigned long rsvrd4; /* reserved */ | 99 | unsigned long rsvrd4; /* reserved */ |
97 | } __packed; | 100 | } __packed; |
98 | 101 | ||
99 | 102 | struct hws_basic_entry { | |
100 | struct hws_data_entry { | ||
101 | unsigned int def:16; /* 0-15 Data Entry Format */ | 103 | unsigned int def:16; /* 0-15 Data Entry Format */ |
102 | unsigned int R:4; /* 16-19 reserved */ | 104 | unsigned int R:4; /* 16-19 reserved */ |
103 | unsigned int U:4; /* 20-23 Number of unique instruct. */ | 105 | unsigned int U:4; /* 20-23 Number of unique instruct. */ |
@@ -114,6 +116,18 @@ struct hws_data_entry { | |||
114 | unsigned long long hpp; /* Host Program Parameter */ | 116 | unsigned long long hpp; /* Host Program Parameter */ |
115 | } __packed; | 117 | } __packed; |
116 | 118 | ||
119 | struct hws_diag_entry { | ||
120 | unsigned int def:16; /* 0-15 Data Entry Format */ | ||
121 | unsigned int R:14; /* 16-19 and 20-30 reserved */ | ||
122 | unsigned int I:1; /* 31 entry valid or invalid */ | ||
123 | u8 data[]; /* Machine-dependent sample data */ | ||
124 | } __packed; | ||
125 | |||
126 | struct hws_combined_entry { | ||
127 | struct hws_basic_entry basic; /* Basic-sampling data entry */ | ||
128 | struct hws_diag_entry diag; /* Diagnostic-sampling data entry */ | ||
129 | } __packed; | ||
130 | |||
117 | struct hws_trailer_entry { | 131 | struct hws_trailer_entry { |
118 | union { | 132 | union { |
119 | struct { | 133 | struct { |
diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/perf_event.h index 7667bde37dcb..bd4573f1d65c 100644 --- a/arch/s390/include/asm/perf_event.h +++ b/arch/s390/include/asm/perf_event.h | |||
@@ -52,15 +52,39 @@ struct perf_sf_sde_regs { | |||
52 | #define PERF_CPUM_CF_MAX_CTR 256 | 52 | #define PERF_CPUM_CF_MAX_CTR 256 |
53 | 53 | ||
54 | /* Perf PMU definitions for the sampling facility */ | 54 | /* Perf PMU definitions for the sampling facility */ |
55 | #define PERF_CPUM_SF_MAX_CTR 1 | 55 | #define PERF_CPUM_SF_MAX_CTR 2 |
56 | #define PERF_EVENT_CPUM_SF 0xB0000UL /* Raw event ID */ | 56 | #define PERF_EVENT_CPUM_SF 0xB0000UL /* Event: Basic-sampling */ |
57 | #define PERF_EVENT_CPUM_SF_DIAG 0xBD000UL /* Event: Combined-sampling */ | ||
58 | #define PERF_CPUM_SF_BASIC_MODE 0x0001 /* Basic-sampling flag */ | ||
59 | #define PERF_CPUM_SF_DIAG_MODE 0x0002 /* Diagnostic-sampling flag */ | ||
60 | #define PERF_CPUM_SF_MODE_MASK (PERF_CPUM_SF_BASIC_MODE| \ | ||
61 | PERF_CPUM_SF_DIAG_MODE) | ||
57 | 62 | ||
58 | #define REG_NONE 0 | 63 | #define REG_NONE 0 |
59 | #define REG_OVERFLOW 1 | 64 | #define REG_OVERFLOW 1 |
60 | #define OVERFLOW_REG(hwc) ((hwc)->extra_reg.config) | 65 | #define OVERFLOW_REG(hwc) ((hwc)->extra_reg.config) |
61 | #define SFB_ALLOC_REG(hwc) ((hwc)->extra_reg.alloc) | 66 | #define SFB_ALLOC_REG(hwc) ((hwc)->extra_reg.alloc) |
67 | #define RAWSAMPLE_REG(hwc) ((hwc)->config) | ||
62 | #define TEAR_REG(hwc) ((hwc)->last_tag) | 68 | #define TEAR_REG(hwc) ((hwc)->last_tag) |
63 | #define SAMPL_RATE(hwc) ((hwc)->event_base) | 69 | #define SAMPL_RATE(hwc) ((hwc)->event_base) |
70 | #define SAMPL_FLAGS(hwc) ((hwc)->config_base) | ||
71 | #define SAMPL_DIAG_MODE(hwc) (SAMPL_FLAGS(hwc) & PERF_CPUM_SF_DIAG_MODE) | ||
72 | |||
73 | /* Structure for sampling data entries to be passed as perf raw sample data | ||
74 | * to user space. Note that raw sample data must be aligned and, thus, might | ||
75 | * be padded with zeros. | ||
76 | */ | ||
77 | struct sf_raw_sample { | ||
78 | #define SF_RAW_SAMPLE_BASIC PERF_CPUM_SF_BASIC_MODE | ||
79 | #define SF_RAW_SAMPLE_DIAG PERF_CPUM_SF_DIAG_MODE | ||
80 | u64 format; | ||
81 | u32 size; /* Size of sf_raw_sample */ | ||
82 | u16 bsdes; /* Basic-sampling data entry size */ | ||
83 | u16 dsdes; /* Diagnostic-sampling data entry size */ | ||
84 | struct hws_basic_entry basic; /* Basic-sampling data entry */ | ||
85 | struct hws_diag_entry diag; /* Diagnostic-sampling data entry */ | ||
86 | u8 padding[]; /* Padding to next multiple of 8 */ | ||
87 | } __packed; | ||
64 | 88 | ||
65 | /* Perf hardware reserve and release functions */ | 89 | /* Perf hardware reserve and release functions */ |
66 | int perf_reserve_sampling(void); | 90 | int perf_reserve_sampling(void); |
diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c index 28fa2f235158..b4ec058c4f10 100644 --- a/arch/s390/kernel/perf_cpum_sf.c +++ b/arch/s390/kernel/perf_cpum_sf.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/percpu.h> | 17 | #include <linux/percpu.h> |
18 | #include <linux/notifier.h> | 18 | #include <linux/notifier.h> |
19 | #include <linux/export.h> | 19 | #include <linux/export.h> |
20 | #include <linux/slab.h> | ||
20 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
21 | #include <linux/moduleparam.h> | 22 | #include <linux/moduleparam.h> |
22 | #include <asm/cpu_mf.h> | 23 | #include <asm/cpu_mf.h> |
@@ -31,8 +32,8 @@ | |||
31 | #define CPUM_SF_MIN_SDBT 1 | 32 | #define CPUM_SF_MIN_SDBT 1 |
32 | 33 | ||
33 | /* Number of sample-data-blocks per sample-data-block-table (SDBT): | 34 | /* Number of sample-data-blocks per sample-data-block-table (SDBT): |
34 | * The table contains SDB origin (8 bytes) and one SDBT origin that | 35 | * A table contains SDB pointers (8 bytes) and one table-link entry |
35 | * points to the next table. | 36 | * that points to the origin of the next SDBT. |
36 | */ | 37 | */ |
37 | #define CPUM_SF_SDB_PER_TABLE ((PAGE_SIZE - 8) / 8) | 38 | #define CPUM_SF_SDB_PER_TABLE ((PAGE_SIZE - 8) / 8) |
38 | 39 | ||
@@ -48,8 +49,11 @@ static inline int require_table_link(const void *sdbt) | |||
48 | 49 | ||
49 | /* Minimum and maximum sampling buffer sizes: | 50 | /* Minimum and maximum sampling buffer sizes: |
50 | * | 51 | * |
51 | * This number represents the maximum size of the sampling buffer | 52 | * This number represents the maximum size of the sampling buffer taking |
52 | * taking the number of sample-data-block-tables into account. | 53 | * the number of sample-data-block-tables into account. Note that these |
54 | * numbers apply to the basic-sampling function only. | ||
55 | * The maximum number of SDBs is increased by CPUM_SF_SDB_DIAG_FACTOR if | ||
56 | * the diagnostic-sampling function is active. | ||
53 | * | 57 | * |
54 | * Sampling buffer size Buffer characteristics | 58 | * Sampling buffer size Buffer characteristics |
55 | * --------------------------------------------------- | 59 | * --------------------------------------------------- |
@@ -63,6 +67,7 @@ static inline int require_table_link(const void *sdbt) | |||
63 | */ | 67 | */ |
64 | static unsigned long __read_mostly CPUM_SF_MIN_SDB = 15; | 68 | static unsigned long __read_mostly CPUM_SF_MIN_SDB = 15; |
65 | static unsigned long __read_mostly CPUM_SF_MAX_SDB = 8176; | 69 | static unsigned long __read_mostly CPUM_SF_MAX_SDB = 8176; |
70 | static unsigned long __read_mostly CPUM_SF_SDB_DIAG_FACTOR = 1; | ||
66 | 71 | ||
67 | struct sf_buffer { | 72 | struct sf_buffer { |
68 | unsigned long *sdbt; /* Sample-data-block-table origin */ | 73 | unsigned long *sdbt; /* Sample-data-block-table origin */ |
@@ -290,8 +295,20 @@ static int alloc_sampling_buffer(struct sf_buffer *sfb, unsigned long num_sdb) | |||
290 | 295 | ||
291 | static void sfb_set_limits(unsigned long min, unsigned long max) | 296 | static void sfb_set_limits(unsigned long min, unsigned long max) |
292 | { | 297 | { |
298 | struct hws_qsi_info_block si; | ||
299 | |||
293 | CPUM_SF_MIN_SDB = min; | 300 | CPUM_SF_MIN_SDB = min; |
294 | CPUM_SF_MAX_SDB = max; | 301 | CPUM_SF_MAX_SDB = max; |
302 | |||
303 | memset(&si, 0, sizeof(si)); | ||
304 | if (!qsi(&si)) | ||
305 | CPUM_SF_SDB_DIAG_FACTOR = DIV_ROUND_UP(si.dsdes, si.bsdes); | ||
306 | } | ||
307 | |||
308 | static unsigned long sfb_max_limit(struct hw_perf_event *hwc) | ||
309 | { | ||
310 | return SAMPL_DIAG_MODE(hwc) ? CPUM_SF_MAX_SDB * CPUM_SF_SDB_DIAG_FACTOR | ||
311 | : CPUM_SF_MAX_SDB; | ||
295 | } | 312 | } |
296 | 313 | ||
297 | static unsigned long sfb_pending_allocs(struct sf_buffer *sfb, | 314 | static unsigned long sfb_pending_allocs(struct sf_buffer *sfb, |
@@ -312,8 +329,8 @@ static int sfb_has_pending_allocs(struct sf_buffer *sfb, | |||
312 | 329 | ||
313 | static void sfb_account_allocs(unsigned long num, struct hw_perf_event *hwc) | 330 | static void sfb_account_allocs(unsigned long num, struct hw_perf_event *hwc) |
314 | { | 331 | { |
315 | /* Limit the number SDBs to not exceed the maximum */ | 332 | /* Limit the number of SDBs to not exceed the maximum */ |
316 | num = min_t(unsigned long, num, CPUM_SF_MAX_SDB - SFB_ALLOC_REG(hwc)); | 333 | num = min_t(unsigned long, num, sfb_max_limit(hwc) - SFB_ALLOC_REG(hwc)); |
317 | if (num) | 334 | if (num) |
318 | SFB_ALLOC_REG(hwc) += num; | 335 | SFB_ALLOC_REG(hwc) += num; |
319 | } | 336 | } |
@@ -324,32 +341,89 @@ static void sfb_init_allocs(unsigned long num, struct hw_perf_event *hwc) | |||
324 | sfb_account_allocs(num, hwc); | 341 | sfb_account_allocs(num, hwc); |
325 | } | 342 | } |
326 | 343 | ||
327 | static int allocate_sdbt(struct cpu_hw_sf *cpuhw, struct hw_perf_event *hwc) | 344 | static size_t event_sample_size(struct hw_perf_event *hwc) |
345 | { | ||
346 | struct sf_raw_sample *sfr = (struct sf_raw_sample *) RAWSAMPLE_REG(hwc); | ||
347 | size_t sample_size; | ||
348 | |||
349 | /* The sample size depends on the sampling function: The basic-sampling | ||
350 | * function must be always enabled, diagnostic-sampling function is | ||
351 | * optional. | ||
352 | */ | ||
353 | sample_size = sfr->bsdes; | ||
354 | if (SAMPL_DIAG_MODE(hwc)) | ||
355 | sample_size += sfr->dsdes; | ||
356 | |||
357 | return sample_size; | ||
358 | } | ||
359 | |||
360 | static void deallocate_buffers(struct cpu_hw_sf *cpuhw) | ||
361 | { | ||
362 | if (cpuhw->sfb.sdbt) | ||
363 | free_sampling_buffer(&cpuhw->sfb); | ||
364 | } | ||
365 | |||
366 | static int allocate_buffers(struct cpu_hw_sf *cpuhw, struct hw_perf_event *hwc) | ||
328 | { | 367 | { |
329 | unsigned long n_sdb, freq; | 368 | unsigned long n_sdb, freq, factor; |
330 | unsigned long factor; | 369 | size_t sfr_size, sample_size; |
370 | struct sf_raw_sample *sfr; | ||
371 | |||
372 | /* Allocate raw sample buffer | ||
373 | * | ||
374 | * The raw sample buffer is used to temporarily store sampling data | ||
375 | * entries for perf raw sample processing. The buffer size mainly | ||
376 | * depends on the size of diagnostic-sampling data entries which is | ||
377 | * machine-specific. The exact size calculation includes: | ||
378 | * 1. The first 4 bytes of diagnostic-sampling data entries are | ||
379 | * already reflected in the sf_raw_sample structure. Subtract | ||
380 | * these bytes. | ||
381 | * 2. The perf raw sample data must be 8-byte aligned (u64) and | ||
382 | * perf's internal data size must be considered too. So add | ||
383 | * an additional u32 for correct alignment and subtract before | ||
384 | * allocating the buffer. | ||
385 | * 3. Store the raw sample buffer pointer in the perf event | ||
386 | * hardware structure. | ||
387 | */ | ||
388 | sfr_size = ALIGN((sizeof(*sfr) - sizeof(sfr->diag) + cpuhw->qsi.dsdes) + | ||
389 | sizeof(u32), sizeof(u64)); | ||
390 | sfr_size -= sizeof(u32); | ||
391 | sfr = kzalloc(sfr_size, GFP_KERNEL); | ||
392 | if (!sfr) | ||
393 | return -ENOMEM; | ||
394 | sfr->size = sfr_size; | ||
395 | sfr->bsdes = cpuhw->qsi.bsdes; | ||
396 | sfr->dsdes = cpuhw->qsi.dsdes; | ||
397 | RAWSAMPLE_REG(hwc) = (unsigned long) sfr; | ||
331 | 398 | ||
332 | /* Calculate sampling buffers using 4K pages | 399 | /* Calculate sampling buffers using 4K pages |
333 | * | 400 | * |
334 | * 1. Use frequency as input. The samping buffer is designed for | 401 | * 1. Determine the sample data size which depends on the used |
335 | * a complete second. This can be adjusted through the "factor" | 402 | * sampling functions, for example, basic-sampling or |
336 | * variable. | 403 | * basic-sampling with diagnostic-sampling. |
404 | * | ||
405 | * 2. Use the sampling frequency as input. The sampling buffer is | ||
406 | * designed for almost one second. This can be adjusted through | ||
407 | * the "factor" variable. | ||
337 | * In any case, alloc_sampling_buffer() sets the Alert Request | 408 | * In any case, alloc_sampling_buffer() sets the Alert Request |
338 | * Control indicator to trigger measurement-alert to harvest | 409 | * Control indicator to trigger a measurement-alert to harvest |
339 | * sample-data-blocks (sdb). | 410 | * sample-data-blocks (sdb). |
340 | * | 411 | * |
341 | * 2. Compute the number of sample-data-blocks and ensure a minimum | 412 | * 3. Compute the number of sample-data-blocks and ensure a minimum |
342 | * of CPUM_SF_MIN_SDB. Also ensure the upper limit does not | 413 | * of CPUM_SF_MIN_SDB. Also ensure the upper limit does not |
343 | * exceed CPUM_SF_MAX_SDB. See also the remarks for these | 414 | * exceed a "calculated" maximum. The symbolic maximum is |
344 | * symbolic constants. | 415 | * designed for basic-sampling only and needs to be increased if |
416 | * diagnostic-sampling is active. | ||
417 | * See also the remarks for these symbolic constants. | ||
345 | * | 418 | * |
346 | * 3. Compute number of pages used for the sample-data-block-table | 419 | * 4. Compute the number of sample-data-block-tables (SDBT) and |
347 | * and ensure a minimum of CPUM_SF_MIN_SDBT (at minimum one table | 420 | * ensure a minimum of CPUM_SF_MIN_SDBT (one table can manage up |
348 | * to manage up to 511 sample-data-blocks). | 421 | * to 511 SDBs). |
349 | */ | 422 | */ |
423 | sample_size = event_sample_size(hwc); | ||
350 | freq = sample_rate_to_freq(&cpuhw->qsi, SAMPL_RATE(hwc)); | 424 | freq = sample_rate_to_freq(&cpuhw->qsi, SAMPL_RATE(hwc)); |
351 | factor = 1; | 425 | factor = 1; |
352 | n_sdb = DIV_ROUND_UP(freq, factor * ((PAGE_SIZE-64) / cpuhw->qsi.bsdes)); | 426 | n_sdb = DIV_ROUND_UP(freq, factor * ((PAGE_SIZE-64) / sample_size)); |
353 | if (n_sdb < CPUM_SF_MIN_SDB) | 427 | if (n_sdb < CPUM_SF_MIN_SDB) |
354 | n_sdb = CPUM_SF_MIN_SDB; | 428 | n_sdb = CPUM_SF_MIN_SDB; |
355 | 429 | ||
@@ -366,8 +440,10 @@ static int allocate_sdbt(struct cpu_hw_sf *cpuhw, struct hw_perf_event *hwc) | |||
366 | return 0; | 440 | return 0; |
367 | 441 | ||
368 | debug_sprintf_event(sfdbg, 3, | 442 | debug_sprintf_event(sfdbg, 3, |
369 | "allocate_sdbt: rate=%lu f=%lu sdb=%lu/%lu cpuhw=%p\n", | 443 | "allocate_buffers: rate=%lu f=%lu sdb=%lu/%lu" |
370 | SAMPL_RATE(hwc), freq, n_sdb, CPUM_SF_MAX_SDB, cpuhw); | 444 | " sample_size=%lu cpuhw=%p\n", |
445 | SAMPL_RATE(hwc), freq, n_sdb, sfb_max_limit(hwc), | ||
446 | sample_size, cpuhw); | ||
371 | 447 | ||
372 | return alloc_sampling_buffer(&cpuhw->sfb, | 448 | return alloc_sampling_buffer(&cpuhw->sfb, |
373 | sfb_pending_allocs(&cpuhw->sfb, hwc)); | 449 | sfb_pending_allocs(&cpuhw->sfb, hwc)); |
@@ -509,10 +585,8 @@ static void setup_pmc_cpu(void *flags) | |||
509 | if (err) { | 585 | if (err) { |
510 | pr_err("Switching off the sampling facility failed " | 586 | pr_err("Switching off the sampling facility failed " |
511 | "with rc=%i\n", err); | 587 | "with rc=%i\n", err); |
512 | } else { | 588 | } else |
513 | if (cpusf->sfb.sdbt) | 589 | deallocate_buffers(cpusf); |
514 | free_sampling_buffer(&cpusf->sfb); | ||
515 | } | ||
516 | debug_sprintf_event(sfdbg, 5, | 590 | debug_sprintf_event(sfdbg, 5, |
517 | "setup_pmc_cpu: released: cpuhw=%p\n", cpusf); | 591 | "setup_pmc_cpu: released: cpuhw=%p\n", cpusf); |
518 | break; | 592 | break; |
@@ -550,6 +624,10 @@ static int reserve_pmc_hardware(void) | |||
550 | 624 | ||
551 | static void hw_perf_event_destroy(struct perf_event *event) | 625 | static void hw_perf_event_destroy(struct perf_event *event) |
552 | { | 626 | { |
627 | /* Free raw sample buffer */ | ||
628 | if (RAWSAMPLE_REG(&event->hw)) | ||
629 | kfree((void *) RAWSAMPLE_REG(&event->hw)); | ||
630 | |||
553 | /* Release PMC if this is the last perf event */ | 631 | /* Release PMC if this is the last perf event */ |
554 | if (!atomic_add_unless(&num_events, -1, 1)) { | 632 | if (!atomic_add_unless(&num_events, -1, 1)) { |
555 | mutex_lock(&pmc_reserve_mutex); | 633 | mutex_lock(&pmc_reserve_mutex); |
@@ -569,8 +647,15 @@ static void hw_init_period(struct hw_perf_event *hwc, u64 period) | |||
569 | static void hw_reset_registers(struct hw_perf_event *hwc, | 647 | static void hw_reset_registers(struct hw_perf_event *hwc, |
570 | unsigned long *sdbt_origin) | 648 | unsigned long *sdbt_origin) |
571 | { | 649 | { |
650 | struct sf_raw_sample *sfr; | ||
651 | |||
572 | /* (Re)set to first sample-data-block-table */ | 652 | /* (Re)set to first sample-data-block-table */ |
573 | TEAR_REG(hwc) = (unsigned long) sdbt_origin; | 653 | TEAR_REG(hwc) = (unsigned long) sdbt_origin; |
654 | |||
655 | /* (Re)set raw sampling buffer register */ | ||
656 | sfr = (struct sf_raw_sample *) RAWSAMPLE_REG(hwc); | ||
657 | memset(&sfr->basic, 0, sizeof(sfr->basic)); | ||
658 | memset(&sfr->diag, 0, sfr->dsdes); | ||
574 | } | 659 | } |
575 | 660 | ||
576 | static unsigned long hw_limit_rate(const struct hws_qsi_info_block *si, | 661 | static unsigned long hw_limit_rate(const struct hws_qsi_info_block *si, |
@@ -634,6 +719,20 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
634 | goto out; | 719 | goto out; |
635 | } | 720 | } |
636 | 721 | ||
722 | /* Always enable basic sampling */ | ||
723 | SAMPL_FLAGS(hwc) = PERF_CPUM_SF_BASIC_MODE; | ||
724 | |||
725 | /* Check if diagnostic sampling is requested. Deny if the required | ||
726 | * sampling authorization is missing. | ||
727 | */ | ||
728 | if (attr->config == PERF_EVENT_CPUM_SF_DIAG) { | ||
729 | if (!si.ad) { | ||
730 | err = -EPERM; | ||
731 | goto out; | ||
732 | } | ||
733 | SAMPL_FLAGS(hwc) |= PERF_CPUM_SF_DIAG_MODE; | ||
734 | } | ||
735 | |||
637 | /* The sampling information (si) contains information about the | 736 | /* The sampling information (si) contains information about the |
638 | * min/max sampling intervals and the CPU speed. So calculate the | 737 | * min/max sampling intervals and the CPU speed. So calculate the |
639 | * correct sampling interval and avoid the whole period adjust | 738 | * correct sampling interval and avoid the whole period adjust |
@@ -679,14 +778,14 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
679 | */ | 778 | */ |
680 | if (cpuhw) | 779 | if (cpuhw) |
681 | /* Event is pinned to a particular CPU */ | 780 | /* Event is pinned to a particular CPU */ |
682 | err = allocate_sdbt(cpuhw, hwc); | 781 | err = allocate_buffers(cpuhw, hwc); |
683 | else { | 782 | else { |
684 | /* Event is not pinned, allocate sampling buffer on | 783 | /* Event is not pinned, allocate sampling buffer on |
685 | * each online CPU | 784 | * each online CPU |
686 | */ | 785 | */ |
687 | for_each_online_cpu(cpu) { | 786 | for_each_online_cpu(cpu) { |
688 | cpuhw = &per_cpu(cpu_hw_sf, cpu); | 787 | cpuhw = &per_cpu(cpu_hw_sf, cpu); |
689 | err = allocate_sdbt(cpuhw, hwc); | 788 | err = allocate_buffers(cpuhw, hwc); |
690 | if (err) | 789 | if (err) |
691 | break; | 790 | break; |
692 | } | 791 | } |
@@ -705,7 +804,8 @@ static int cpumsf_pmu_event_init(struct perf_event *event) | |||
705 | 804 | ||
706 | switch (event->attr.type) { | 805 | switch (event->attr.type) { |
707 | case PERF_TYPE_RAW: | 806 | case PERF_TYPE_RAW: |
708 | if (event->attr.config != PERF_EVENT_CPUM_SF) | 807 | if ((event->attr.config != PERF_EVENT_CPUM_SF) && |
808 | (event->attr.config != PERF_EVENT_CPUM_SF_DIAG)) | ||
709 | return -ENOENT; | 809 | return -ENOENT; |
710 | break; | 810 | break; |
711 | case PERF_TYPE_HARDWARE: | 811 | case PERF_TYPE_HARDWARE: |
@@ -786,8 +886,9 @@ static void cpumsf_pmu_enable(struct pmu *pmu) | |||
786 | return; | 886 | return; |
787 | } | 887 | } |
788 | 888 | ||
789 | debug_sprintf_event(sfdbg, 6, "pmu_enable: es=%i cs=%i tear=%p dear=%p\n", | 889 | debug_sprintf_event(sfdbg, 6, "pmu_enable: es=%i cs=%i ed=%i cd=%i " |
790 | cpuhw->lsctl.es, cpuhw->lsctl.cs, | 890 | "tear=%p dear=%p\n", cpuhw->lsctl.es, cpuhw->lsctl.cs, |
891 | cpuhw->lsctl.ed, cpuhw->lsctl.cd, | ||
791 | (void *) cpuhw->lsctl.tear, (void *) cpuhw->lsctl.dear); | 892 | (void *) cpuhw->lsctl.tear, (void *) cpuhw->lsctl.dear); |
792 | } | 893 | } |
793 | 894 | ||
@@ -807,6 +908,7 @@ static void cpumsf_pmu_disable(struct pmu *pmu) | |||
807 | /* Switch off sampling activation control */ | 908 | /* Switch off sampling activation control */ |
808 | inactive = cpuhw->lsctl; | 909 | inactive = cpuhw->lsctl; |
809 | inactive.cs = 0; | 910 | inactive.cs = 0; |
911 | inactive.cd = 0; | ||
810 | 912 | ||
811 | err = lsctl(&inactive); | 913 | err = lsctl(&inactive); |
812 | if (err) { | 914 | if (err) { |
@@ -867,21 +969,19 @@ static int perf_exclude_event(struct perf_event *event, struct pt_regs *regs, | |||
867 | * | 969 | * |
868 | * Return non-zero if an event overflow occurred. | 970 | * Return non-zero if an event overflow occurred. |
869 | */ | 971 | */ |
870 | static int perf_push_sample(struct perf_event *event, | 972 | static int perf_push_sample(struct perf_event *event, struct sf_raw_sample *sfr) |
871 | struct hws_data_entry *sample) | ||
872 | { | 973 | { |
873 | int overflow; | 974 | int overflow; |
874 | struct pt_regs regs; | 975 | struct pt_regs regs; |
875 | struct perf_sf_sde_regs *sde_regs; | 976 | struct perf_sf_sde_regs *sde_regs; |
876 | struct perf_sample_data data; | 977 | struct perf_sample_data data; |
978 | struct perf_raw_record raw; | ||
877 | 979 | ||
878 | /* Skip samples that are invalid or for which the instruction address | 980 | /* Setup perf sample */ |
879 | * is not predictable. For the latter, the wait-state bit is set. | ||
880 | */ | ||
881 | if (sample->I || sample->W) | ||
882 | return 0; | ||
883 | |||
884 | perf_sample_data_init(&data, 0, event->hw.last_period); | 981 | perf_sample_data_init(&data, 0, event->hw.last_period); |
982 | raw.size = sfr->size; | ||
983 | raw.data = sfr; | ||
984 | data.raw = &raw; | ||
885 | 985 | ||
886 | /* Setup pt_regs to look like an CPU-measurement external interrupt | 986 | /* Setup pt_regs to look like an CPU-measurement external interrupt |
887 | * using the Program Request Alert code. The regs.int_parm_long | 987 | * using the Program Request Alert code. The regs.int_parm_long |
@@ -893,14 +993,14 @@ static int perf_push_sample(struct perf_event *event, | |||
893 | regs.int_parm = CPU_MF_INT_SF_PRA; | 993 | regs.int_parm = CPU_MF_INT_SF_PRA; |
894 | sde_regs = (struct perf_sf_sde_regs *) ®s.int_parm_long; | 994 | sde_regs = (struct perf_sf_sde_regs *) ®s.int_parm_long; |
895 | 995 | ||
896 | regs.psw.addr = sample->ia; | 996 | regs.psw.addr = sfr->basic.ia; |
897 | if (sample->T) | 997 | if (sfr->basic.T) |
898 | regs.psw.mask |= PSW_MASK_DAT; | 998 | regs.psw.mask |= PSW_MASK_DAT; |
899 | if (sample->W) | 999 | if (sfr->basic.W) |
900 | regs.psw.mask |= PSW_MASK_WAIT; | 1000 | regs.psw.mask |= PSW_MASK_WAIT; |
901 | if (sample->P) | 1001 | if (sfr->basic.P) |
902 | regs.psw.mask |= PSW_MASK_PSTATE; | 1002 | regs.psw.mask |= PSW_MASK_PSTATE; |
903 | switch (sample->AS) { | 1003 | switch (sfr->basic.AS) { |
904 | case 0x0: | 1004 | case 0x0: |
905 | regs.psw.mask |= PSW_ASC_PRIMARY; | 1005 | regs.psw.mask |= PSW_ASC_PRIMARY; |
906 | break; | 1006 | break; |
@@ -922,7 +1022,7 @@ static int perf_push_sample(struct perf_event *event, | |||
922 | * purposes too. | 1022 | * purposes too. |
923 | * For now, simply use a non-zero value as guest indicator. | 1023 | * For now, simply use a non-zero value as guest indicator. |
924 | */ | 1024 | */ |
925 | if (sample->hpp) | 1025 | if (sfr->basic.hpp) |
926 | sde_regs->in_guest = 1; | 1026 | sde_regs->in_guest = 1; |
927 | 1027 | ||
928 | overflow = 0; | 1028 | overflow = 0; |
@@ -942,51 +1042,155 @@ static void perf_event_count_update(struct perf_event *event, u64 count) | |||
942 | local64_add(count, &event->count); | 1042 | local64_add(count, &event->count); |
943 | } | 1043 | } |
944 | 1044 | ||
1045 | static int sample_format_is_valid(struct hws_combined_entry *sample, | ||
1046 | unsigned int flags) | ||
1047 | { | ||
1048 | if (likely(flags & PERF_CPUM_SF_BASIC_MODE)) | ||
1049 | /* Only basic-sampling data entries with data-entry-format | ||
1050 | * version of 0x0001 can be processed. | ||
1051 | */ | ||
1052 | if (sample->basic.def != 0x0001) | ||
1053 | return 0; | ||
1054 | if (flags & PERF_CPUM_SF_DIAG_MODE) | ||
1055 | /* The data-entry-format number of diagnostic-sampling data | ||
1056 | * entries can vary. Because diagnostic data is just passed | ||
1057 | * through, do only a sanity check on the DEF. | ||
1058 | */ | ||
1059 | if (sample->diag.def < 0x8001) | ||
1060 | return 0; | ||
1061 | return 1; | ||
1062 | } | ||
1063 | |||
1064 | static int sample_is_consistent(struct hws_combined_entry *sample, | ||
1065 | unsigned long flags) | ||
1066 | { | ||
1067 | /* This check applies only to basic-sampling data entries of potentially | ||
1068 | * combined-sampling data entries. Invalid entries cannot be processed | ||
1069 | * by the PMU and, thus, do not deliver an associated | ||
1070 | * diagnostic-sampling data entry. | ||
1071 | */ | ||
1072 | if (unlikely(!(flags & PERF_CPUM_SF_BASIC_MODE))) | ||
1073 | return 0; | ||
1074 | /* | ||
1075 | * Samples are skipped, if they are invalid or for which the | ||
1076 | * instruction address is not predictable, i.e., the wait-state bit is | ||
1077 | * set. | ||
1078 | */ | ||
1079 | if (sample->basic.I || sample->basic.W) | ||
1080 | return 0; | ||
1081 | return 1; | ||
1082 | } | ||
1083 | |||
1084 | static void reset_sample_slot(struct hws_combined_entry *sample, | ||
1085 | unsigned long flags) | ||
1086 | { | ||
1087 | if (likely(flags & PERF_CPUM_SF_BASIC_MODE)) | ||
1088 | sample->basic.def = 0; | ||
1089 | if (flags & PERF_CPUM_SF_DIAG_MODE) | ||
1090 | sample->diag.def = 0; | ||
1091 | } | ||
1092 | |||
1093 | static void sfr_store_sample(struct sf_raw_sample *sfr, | ||
1094 | struct hws_combined_entry *sample) | ||
1095 | { | ||
1096 | if (likely(sfr->format & PERF_CPUM_SF_BASIC_MODE)) | ||
1097 | sfr->basic = sample->basic; | ||
1098 | if (sfr->format & PERF_CPUM_SF_DIAG_MODE) | ||
1099 | memcpy(&sfr->diag, &sample->diag, sfr->dsdes); | ||
1100 | } | ||
1101 | |||
1102 | static void debug_sample_entry(struct hws_combined_entry *sample, | ||
1103 | struct hws_trailer_entry *te, | ||
1104 | unsigned long flags) | ||
1105 | { | ||
1106 | debug_sprintf_event(sfdbg, 4, "hw_collect_samples: Found unknown " | ||
1107 | "sampling data entry: te->f=%i basic.def=%04x (%p)" | ||
1108 | " diag.def=%04x (%p)\n", te->f, | ||
1109 | sample->basic.def, &sample->basic, | ||
1110 | (flags & PERF_CPUM_SF_DIAG_MODE) | ||
1111 | ? sample->diag.def : 0xFFFF, | ||
1112 | (flags & PERF_CPUM_SF_DIAG_MODE) | ||
1113 | ? &sample->diag : NULL); | ||
1114 | } | ||
1115 | |||
945 | /* hw_collect_samples() - Walk through a sample-data-block and collect samples | 1116 | /* hw_collect_samples() - Walk through a sample-data-block and collect samples |
946 | * @event: The perf event | 1117 | * @event: The perf event |
947 | * @sdbt: Sample-data-block table | 1118 | * @sdbt: Sample-data-block table |
948 | * @overflow: Event overflow counter | 1119 | * @overflow: Event overflow counter |
949 | * | 1120 | * |
950 | * Walks through a sample-data-block and collects hardware sample-data that is | 1121 | * Walks through a sample-data-block and collects sampling data entries that are |
951 | * pushed to the perf event subsystem. The overflow reports the number of | 1122 | * then pushed to the perf event subsystem. Depending on the sampling function, |
952 | * samples that has been discarded due to an event overflow. | 1123 | * there can be either basic-sampling or combined-sampling data entries. A |
1124 | * combined-sampling data entry consists of a basic- and a diagnostic-sampling | ||
1125 | * data entry. The sampling function is determined by the flags in the perf | ||
1126 | * event hardware structure. The function always works with a combined-sampling | ||
1127 | * data entry but ignores the the diagnostic portion if it is not available. | ||
1128 | * | ||
1129 | * Note that the implementation focuses on basic-sampling data entries and, if | ||
1130 | * such an entry is not valid, the entire combined-sampling data entry is | ||
1131 | * ignored. | ||
1132 | * | ||
1133 | * The overflow variables counts the number of samples that has been discarded | ||
1134 | * due to a perf event overflow. | ||
953 | */ | 1135 | */ |
954 | static void hw_collect_samples(struct perf_event *event, unsigned long *sdbt, | 1136 | static void hw_collect_samples(struct perf_event *event, unsigned long *sdbt, |
955 | unsigned long long *overflow) | 1137 | unsigned long long *overflow) |
956 | { | 1138 | { |
957 | struct hws_data_entry *sample; | 1139 | unsigned long flags = SAMPL_FLAGS(&event->hw); |
958 | unsigned long *trailer; | 1140 | struct hws_combined_entry *sample; |
1141 | struct hws_trailer_entry *te; | ||
1142 | struct sf_raw_sample *sfr; | ||
1143 | size_t sample_size; | ||
1144 | |||
1145 | /* Prepare and initialize raw sample data */ | ||
1146 | sfr = (struct sf_raw_sample *) RAWSAMPLE_REG(&event->hw); | ||
1147 | sfr->format = flags & PERF_CPUM_SF_MODE_MASK; | ||
959 | 1148 | ||
960 | trailer = trailer_entry_ptr(*sdbt); | 1149 | sample_size = event_sample_size(&event->hw); |
961 | sample = (struct hws_data_entry *) *sdbt; | 1150 | te = (struct hws_trailer_entry *) trailer_entry_ptr(*sdbt); |
962 | while ((unsigned long *) sample < trailer) { | 1151 | sample = (struct hws_combined_entry *) *sdbt; |
1152 | while ((unsigned long *) sample < (unsigned long *) te) { | ||
963 | /* Check for an empty sample */ | 1153 | /* Check for an empty sample */ |
964 | if (!sample->def) | 1154 | if (!sample->basic.def) |
965 | break; | 1155 | break; |
966 | 1156 | ||
967 | /* Update perf event period */ | 1157 | /* Update perf event period */ |
968 | perf_event_count_update(event, SAMPL_RATE(&event->hw)); | 1158 | perf_event_count_update(event, SAMPL_RATE(&event->hw)); |
969 | 1159 | ||
970 | /* Check for basic sampling mode */ | 1160 | /* Check sampling data entry */ |
971 | if (sample->def == 0x0001) { | 1161 | if (sample_format_is_valid(sample, flags)) { |
972 | /* If an event overflow occurred, the PMU is stopped to | 1162 | /* If an event overflow occurred, the PMU is stopped to |
973 | * throttle event delivery. Remaining sample data is | 1163 | * throttle event delivery. Remaining sample data is |
974 | * discarded. | 1164 | * discarded. |
975 | */ | 1165 | */ |
976 | if (!*overflow) | 1166 | if (!*overflow) { |
977 | *overflow = perf_push_sample(event, sample); | 1167 | if (sample_is_consistent(sample, flags)) { |
978 | else | 1168 | /* Deliver sample data to perf */ |
1169 | sfr_store_sample(sfr, sample); | ||
1170 | *overflow = perf_push_sample(event, sfr); | ||
1171 | } | ||
1172 | } else | ||
979 | /* Count discarded samples */ | 1173 | /* Count discarded samples */ |
980 | *overflow += 1; | 1174 | *overflow += 1; |
981 | } else | 1175 | } else { |
982 | /* Sample slot is not yet written or other record */ | 1176 | debug_sample_entry(sample, te, flags); |
983 | debug_sprintf_event(sfdbg, 5, "hw_collect_samples: " | 1177 | /* Sample slot is not yet written or other record. |
984 | "Unknown sample data entry format:" | 1178 | * |
985 | " %i\n", sample->def); | 1179 | * This condition can occur if the buffer was reused |
1180 | * from a combined basic- and diagnostic-sampling. | ||
1181 | * If only basic-sampling is then active, entries are | ||
1182 | * written into the larger diagnostic entries. | ||
1183 | * This is typically the case for sample-data-blocks | ||
1184 | * that are not full. Stop processing if the first | ||
1185 | * invalid format was detected. | ||
1186 | */ | ||
1187 | if (!te->f) | ||
1188 | break; | ||
1189 | } | ||
986 | 1190 | ||
987 | /* Reset sample slot and advance to next sample */ | 1191 | /* Reset sample slot and advance to next sample */ |
988 | sample->def = 0; | 1192 | reset_sample_slot(sample, flags); |
989 | sample++; | 1193 | sample += sample_size; |
990 | } | 1194 | } |
991 | } | 1195 | } |
992 | 1196 | ||
@@ -1104,6 +1308,8 @@ static void cpumsf_pmu_start(struct perf_event *event, int flags) | |||
1104 | perf_pmu_disable(event->pmu); | 1308 | perf_pmu_disable(event->pmu); |
1105 | event->hw.state = 0; | 1309 | event->hw.state = 0; |
1106 | cpuhw->lsctl.cs = 1; | 1310 | cpuhw->lsctl.cs = 1; |
1311 | if (SAMPL_DIAG_MODE(&event->hw)) | ||
1312 | cpuhw->lsctl.cd = 1; | ||
1107 | perf_pmu_enable(event->pmu); | 1313 | perf_pmu_enable(event->pmu); |
1108 | } | 1314 | } |
1109 | 1315 | ||
@@ -1119,6 +1325,7 @@ static void cpumsf_pmu_stop(struct perf_event *event, int flags) | |||
1119 | 1325 | ||
1120 | perf_pmu_disable(event->pmu); | 1326 | perf_pmu_disable(event->pmu); |
1121 | cpuhw->lsctl.cs = 0; | 1327 | cpuhw->lsctl.cs = 0; |
1328 | cpuhw->lsctl.cd = 0; | ||
1122 | event->hw.state |= PERF_HES_STOPPED; | 1329 | event->hw.state |= PERF_HES_STOPPED; |
1123 | 1330 | ||
1124 | if ((flags & PERF_EF_UPDATE) && !(event->hw.state & PERF_HES_UPTODATE)) { | 1331 | if ((flags & PERF_EF_UPDATE) && !(event->hw.state & PERF_HES_UPTODATE)) { |
@@ -1158,11 +1365,13 @@ static int cpumsf_pmu_add(struct perf_event *event, int flags) | |||
1158 | 1365 | ||
1159 | /* Ensure sampling functions are in the disabled state. If disabled, | 1366 | /* Ensure sampling functions are in the disabled state. If disabled, |
1160 | * switch on sampling enable control. */ | 1367 | * switch on sampling enable control. */ |
1161 | if (WARN_ON_ONCE(cpuhw->lsctl.es == 1)) { | 1368 | if (WARN_ON_ONCE(cpuhw->lsctl.es == 1 || cpuhw->lsctl.ed == 1)) { |
1162 | err = -EAGAIN; | 1369 | err = -EAGAIN; |
1163 | goto out; | 1370 | goto out; |
1164 | } | 1371 | } |
1165 | cpuhw->lsctl.es = 1; | 1372 | cpuhw->lsctl.es = 1; |
1373 | if (SAMPL_DIAG_MODE(&event->hw)) | ||
1374 | cpuhw->lsctl.ed = 1; | ||
1166 | 1375 | ||
1167 | /* Set in_use flag and store event */ | 1376 | /* Set in_use flag and store event */ |
1168 | event->hw.idx = 0; /* only one sampling event per CPU supported */ | 1377 | event->hw.idx = 0; /* only one sampling event per CPU supported */ |
@@ -1185,6 +1394,7 @@ static void cpumsf_pmu_del(struct perf_event *event, int flags) | |||
1185 | cpumsf_pmu_stop(event, PERF_EF_UPDATE); | 1394 | cpumsf_pmu_stop(event, PERF_EF_UPDATE); |
1186 | 1395 | ||
1187 | cpuhw->lsctl.es = 0; | 1396 | cpuhw->lsctl.es = 0; |
1397 | cpuhw->lsctl.ed = 0; | ||
1188 | cpuhw->flags &= ~PMU_F_IN_USE; | 1398 | cpuhw->flags &= ~PMU_F_IN_USE; |
1189 | cpuhw->event = NULL; | 1399 | cpuhw->event = NULL; |
1190 | 1400 | ||
@@ -1198,9 +1408,11 @@ static int cpumsf_pmu_event_idx(struct perf_event *event) | |||
1198 | } | 1408 | } |
1199 | 1409 | ||
1200 | CPUMF_EVENT_ATTR(SF, SF_CYCLES_BASIC, PERF_EVENT_CPUM_SF); | 1410 | CPUMF_EVENT_ATTR(SF, SF_CYCLES_BASIC, PERF_EVENT_CPUM_SF); |
1411 | CPUMF_EVENT_ATTR(SF, SF_CYCLES_BASIC_DIAG, PERF_EVENT_CPUM_SF_DIAG); | ||
1201 | 1412 | ||
1202 | static struct attribute *cpumsf_pmu_events_attr[] = { | 1413 | static struct attribute *cpumsf_pmu_events_attr[] = { |
1203 | CPUMF_EVENT_PTR(SF, SF_CYCLES_BASIC), | 1414 | CPUMF_EVENT_PTR(SF, SF_CYCLES_BASIC), |
1415 | CPUMF_EVENT_PTR(SF, SF_CYCLES_BASIC_DIAG), | ||
1204 | NULL, | 1416 | NULL, |
1205 | }; | 1417 | }; |
1206 | 1418 | ||
@@ -1351,8 +1563,9 @@ static int param_set_sfb_size(const char *val, const struct kernel_param *kp) | |||
1351 | return rc; | 1563 | return rc; |
1352 | 1564 | ||
1353 | sfb_set_limits(min, max); | 1565 | sfb_set_limits(min, max); |
1354 | pr_info("Changed sampling buffer settings: min=%lu max=%lu\n", | 1566 | pr_info("The sampling buffer limits have changed to: " |
1355 | CPUM_SF_MIN_SDB, CPUM_SF_MAX_SDB); | 1567 | "min=%lu max=%lu (diag=x%lu)\n", |
1568 | CPUM_SF_MIN_SDB, CPUM_SF_MAX_SDB, CPUM_SF_SDB_DIAG_FACTOR); | ||
1356 | return 0; | 1569 | return 0; |
1357 | } | 1570 | } |
1358 | 1571 | ||
@@ -1362,13 +1575,38 @@ static struct kernel_param_ops param_ops_sfb_size = { | |||
1362 | .get = param_get_sfb_size, | 1575 | .get = param_get_sfb_size, |
1363 | }; | 1576 | }; |
1364 | 1577 | ||
1578 | #define RS_INIT_FAILURE_QSI 0x0001 | ||
1579 | #define RS_INIT_FAILURE_BSDES 0x0002 | ||
1580 | #define RS_INIT_FAILURE_ALRT 0x0003 | ||
1581 | #define RS_INIT_FAILURE_PERF 0x0004 | ||
1582 | static void __init pr_cpumsf_err(unsigned int reason) | ||
1583 | { | ||
1584 | pr_err("Sampling facility support for perf is not available: " | ||
1585 | "reason=%04x\n", reason); | ||
1586 | } | ||
1587 | |||
1365 | static int __init init_cpum_sampling_pmu(void) | 1588 | static int __init init_cpum_sampling_pmu(void) |
1366 | { | 1589 | { |
1590 | struct hws_qsi_info_block si; | ||
1367 | int err; | 1591 | int err; |
1368 | 1592 | ||
1369 | if (!cpum_sf_avail()) | 1593 | if (!cpum_sf_avail()) |
1370 | return -ENODEV; | 1594 | return -ENODEV; |
1371 | 1595 | ||
1596 | memset(&si, 0, sizeof(si)); | ||
1597 | if (qsi(&si)) { | ||
1598 | pr_cpumsf_err(RS_INIT_FAILURE_QSI); | ||
1599 | return -ENODEV; | ||
1600 | } | ||
1601 | |||
1602 | if (si.bsdes != sizeof(struct hws_basic_entry)) { | ||
1603 | pr_cpumsf_err(RS_INIT_FAILURE_BSDES); | ||
1604 | return -EINVAL; | ||
1605 | } | ||
1606 | |||
1607 | if (si.ad) | ||
1608 | sfb_set_limits(CPUM_SF_MIN_SDB, CPUM_SF_MAX_SDB); | ||
1609 | |||
1372 | sfdbg = debug_register(KMSG_COMPONENT, 2, 1, 80); | 1610 | sfdbg = debug_register(KMSG_COMPONENT, 2, 1, 80); |
1373 | if (!sfdbg) | 1611 | if (!sfdbg) |
1374 | pr_err("Registering for s390dbf failed\n"); | 1612 | pr_err("Registering for s390dbf failed\n"); |
@@ -1376,13 +1614,13 @@ static int __init init_cpum_sampling_pmu(void) | |||
1376 | 1614 | ||
1377 | err = register_external_interrupt(0x1407, cpumf_measurement_alert); | 1615 | err = register_external_interrupt(0x1407, cpumf_measurement_alert); |
1378 | if (err) { | 1616 | if (err) { |
1379 | pr_err("Failed to register for CPU-measurement alerts\n"); | 1617 | pr_cpumsf_err(RS_INIT_FAILURE_ALRT); |
1380 | goto out; | 1618 | goto out; |
1381 | } | 1619 | } |
1382 | 1620 | ||
1383 | err = perf_pmu_register(&cpumf_sampling, "cpum_sf", PERF_TYPE_RAW); | 1621 | err = perf_pmu_register(&cpumf_sampling, "cpum_sf", PERF_TYPE_RAW); |
1384 | if (err) { | 1622 | if (err) { |
1385 | pr_err("Failed to register cpum_sf pmu\n"); | 1623 | pr_cpumsf_err(RS_INIT_FAILURE_PERF); |
1386 | unregister_external_interrupt(0x1407, cpumf_measurement_alert); | 1624 | unregister_external_interrupt(0x1407, cpumf_measurement_alert); |
1387 | goto out; | 1625 | goto out; |
1388 | } | 1626 | } |
diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c index 60a68261d091..91aa215f947f 100644 --- a/arch/s390/kernel/perf_event.c +++ b/arch/s390/kernel/perf_event.c | |||
@@ -139,16 +139,21 @@ static void print_debug_sf(void) | |||
139 | int cpu = smp_processor_id(); | 139 | int cpu = smp_processor_id(); |
140 | 140 | ||
141 | memset(&si, 0, sizeof(si)); | 141 | memset(&si, 0, sizeof(si)); |
142 | if (qsi(&si)) { | 142 | if (qsi(&si)) |
143 | pr_err("CPU[%i]: CPM_SF: qsi failed\n"); | ||
144 | return; | 143 | return; |
145 | } | ||
146 | 144 | ||
147 | pr_info("CPU[%i]: CPM_SF: as=%i es=%i cs=%i bsdes=%i dsdes=%i" | 145 | pr_info("CPU[%i] CPUM_SF: basic=%i diag=%i min=%i max=%i cpu_speed=%i\n", |
148 | " min=%i max=%i cpu_speed=%i tear=%p dear=%p\n", | 146 | cpu, si.as, si.ad, si.min_sampl_rate, si.max_sampl_rate, |
149 | cpu, si.as, si.es, si.cs, si.bsdes, si.dsdes, | 147 | si.cpu_speed); |
150 | si.min_sampl_rate, si.max_sampl_rate, si.cpu_speed, | 148 | |
151 | si.tear, si.dear); | 149 | if (si.as) |
150 | pr_info("CPU[%i] CPUM_SF: Basic-sampling: a=%i e=%i c=%i" | ||
151 | " bsdes=%i tear=%p dear=%p\n", cpu, | ||
152 | si.as, si.es, si.cs, si.bsdes, si.tear, si.dear); | ||
153 | if (si.ad) | ||
154 | pr_info("CPU[%i] CPUM_SF: Diagnostic-sampling: a=%i e=%i c=%i" | ||
155 | " dsdes=%i tear=%p dear=%p\n", cpu, | ||
156 | si.ad, si.ed, si.cd, si.dsdes, si.tear, si.dear); | ||
152 | } | 157 | } |
153 | 158 | ||
154 | void perf_event_print_debug(void) | 159 | void perf_event_print_debug(void) |
diff --git a/arch/s390/oprofile/hwsampler.c b/arch/s390/oprofile/hwsampler.c index eb095874540d..a32c96761eab 100644 --- a/arch/s390/oprofile/hwsampler.c +++ b/arch/s390/oprofile/hwsampler.c | |||
@@ -799,7 +799,7 @@ static void worker_on_interrupt(unsigned int cpu) | |||
799 | static void add_samples_to_oprofile(unsigned int cpu, unsigned long *sdbt, | 799 | static void add_samples_to_oprofile(unsigned int cpu, unsigned long *sdbt, |
800 | unsigned long *dear) | 800 | unsigned long *dear) |
801 | { | 801 | { |
802 | struct hws_data_entry *sample_data_ptr; | 802 | struct hws_basic_entry *sample_data_ptr; |
803 | unsigned long *trailer; | 803 | unsigned long *trailer; |
804 | 804 | ||
805 | trailer = trailer_entry_ptr(*sdbt); | 805 | trailer = trailer_entry_ptr(*sdbt); |
@@ -809,7 +809,7 @@ static void add_samples_to_oprofile(unsigned int cpu, unsigned long *sdbt, | |||
809 | trailer = dear; | 809 | trailer = dear; |
810 | } | 810 | } |
811 | 811 | ||
812 | sample_data_ptr = (struct hws_data_entry *)(*sdbt); | 812 | sample_data_ptr = (struct hws_basic_entry *)(*sdbt); |
813 | 813 | ||
814 | while ((unsigned long *)sample_data_ptr < trailer) { | 814 | while ((unsigned long *)sample_data_ptr < trailer) { |
815 | struct pt_regs *regs = NULL; | 815 | struct pt_regs *regs = NULL; |