Skip to content

Commit 74466e8

Browse files
Thomas Richterhcahca
authored andcommitted
s390/pai_crypto: Unify sample push logic and update context handling
Unify naming and logic for PAI PMU drivers to support both PMUs pai_crypto and pai_ext. Rename paicrypt_push_sample() to pai_push_sample() to reflect its common usage. Add detailed comments about invocation context and scheduler callbacks. Use struct pai_pmu to determine area_size instead of PAGE_SIZE for counter backup. Remove obsolete variable paicrypt_cnt. Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Jan Polensky <japo@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 0f1c0d7 commit 74466e8

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

arch/s390/kernel/perf_pai_crypto.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <asm/debug.h>
2121

2222
static debug_info_t *paidbg;
23-
static unsigned int paicrypt_cnt; /* Size of the mapped counter sets */
24-
/* extracted with QPACI instruction */
2523

2624
DEFINE_STATIC_KEY_FALSE(pai_key);
2725

@@ -486,9 +484,25 @@ static size_t paicrypt_copy(struct pai_userdata *userdata, unsigned long *page,
486484
return outidx * sizeof(*userdata);
487485
}
488486

489-
static int paicrypt_push_sample(size_t rawsize, struct pai_map *cpump,
490-
struct perf_event *event)
487+
/* Write sample when one or more counters values are nonzero.
488+
*
489+
* Note: The function paicrypt_sched_task() and pai_push_sample() are not
490+
* invoked after function paicrypt_del() has been called because of function
491+
* perf_sched_cb_dec(). Both functions are only
492+
* called when sampling is active. Function perf_sched_cb_inc()
493+
* has been invoked to install function paicrypt_sched_task() as call back
494+
* to run at context switch time.
495+
*
496+
* This causes function perf_event_context_sched_out() and
497+
* perf_event_context_sched_in() to check whether the PMU has installed an
498+
* sched_task() callback. That callback is not active after paicrypt_del()
499+
* returns and has deleted the event on that CPU.
500+
*/
501+
static int pai_push_sample(size_t rawsize, struct pai_map *cpump,
502+
struct perf_event *event)
491503
{
504+
int idx = PAI_PMU_IDX(event);
505+
struct pai_pmu *pp = &pai_pmu[idx];
492506
struct perf_sample_data data;
493507
struct perf_raw_record raw;
494508
struct pt_regs regs;
@@ -520,7 +534,7 @@ static int paicrypt_push_sample(size_t rawsize, struct pai_map *cpump,
520534
overflow = perf_event_overflow(event, &data, &regs);
521535
perf_event_update_userpage(event);
522536
/* Save crypto counter lowcore page after reading event data. */
523-
memcpy((void *)PAI_SAVE_AREA(event), cpump->area, PAGE_SIZE);
537+
memcpy((void *)PAI_SAVE_AREA(event), cpump->area, pp->area_size);
524538
return overflow;
525539
}
526540

@@ -538,7 +552,7 @@ static void pai_have_sample(struct perf_event *event, struct pai_map *cpump)
538552
event->attr.exclude_user,
539553
event->attr.exclude_kernel);
540554
if (rawsize) /* No incremented counters */
541-
paicrypt_push_sample(rawsize, cpump, event);
555+
pai_push_sample(rawsize, cpump, event);
542556
}
543557

544558
/* Check if there is data to be saved on schedule out of a task. */
@@ -920,7 +934,6 @@ static int __init paipmu_setup(void)
920934
switch (i) {
921935
case PAI_PMU_CRYPTO:
922936
p->num_avail = ib.num_cc;
923-
paicrypt_cnt = ib.num_cc;
924937
if (p->num_avail >= PAI_CRYPTO_MAXCTR) {
925938
pr_err("Too many PMU %s counters %d\n",
926939
p->pmuname, p->num_avail);

0 commit comments

Comments
 (0)