Commit d3db4ac3 authored by Thomas Richter's avatar Thomas Richter Committed by Vasily Gorbik

s390/pai: rework pai_crypto mapped buffer reference count

Rework the mapped buffer reference count in PMU pai_crypto
to match the same technique as in PMU pai_ext.
This simplifies the logic.
Do not count the individual number of counter and sampling
processes. Remember the type of access and the total number of
references to the buffer.
Signed-off-by: default avatarThomas Richter <tmricht@linux.ibm.com>
Acked-by: default avatarSumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent 4c787963
...@@ -36,8 +36,8 @@ struct paicrypt_map { ...@@ -36,8 +36,8 @@ struct paicrypt_map {
unsigned long *page; /* Page for CPU to store counters */ unsigned long *page; /* Page for CPU to store counters */
struct pai_userdata *save; /* Page to store no-zero counters */ struct pai_userdata *save; /* Page to store no-zero counters */
unsigned int users; /* # of PAI crypto users */ unsigned int users; /* # of PAI crypto users */
unsigned int sampler; /* # of PAI crypto samplers */ unsigned int refcnt; /* Reference count mapped buffers */
unsigned int counter; /* # of PAI crypto counters */ enum paievt_mode mode; /* Type of event */
struct perf_event *event; /* Perf event for sampling */ struct perf_event *event; /* Perf event for sampling */
}; };
...@@ -56,15 +56,11 @@ static void paicrypt_event_destroy(struct perf_event *event) ...@@ -56,15 +56,11 @@ static void paicrypt_event_destroy(struct perf_event *event)
cpump->event = NULL; cpump->event = NULL;
static_branch_dec(&pai_key); static_branch_dec(&pai_key);
mutex_lock(&pai_reserve_mutex); mutex_lock(&pai_reserve_mutex);
if (event->attr.sample_period) debug_sprintf_event(cfm_dbg, 5, "%s event %#llx cpu %d users %d"
cpump->sampler -= 1; " mode %d refcnt %d\n", __func__,
else event->attr.config, event->cpu, cpump->users,
cpump->counter -= 1; cpump->mode, cpump->refcnt);
debug_sprintf_event(cfm_dbg, 5, "%s event %#llx cpu %d" if (!--cpump->refcnt) {
" sampler %d counter %d\n", __func__,
event->attr.config, event->cpu, cpump->sampler,
cpump->counter);
if (!cpump->counter && !cpump->sampler) {
debug_sprintf_event(cfm_dbg, 4, "%s page %#lx save %p\n", debug_sprintf_event(cfm_dbg, 4, "%s page %#lx save %p\n",
__func__, (unsigned long)cpump->page, __func__, (unsigned long)cpump->page,
cpump->save); cpump->save);
...@@ -72,6 +68,7 @@ static void paicrypt_event_destroy(struct perf_event *event) ...@@ -72,6 +68,7 @@ static void paicrypt_event_destroy(struct perf_event *event)
cpump->page = NULL; cpump->page = NULL;
kvfree(cpump->save); kvfree(cpump->save);
cpump->save = NULL; cpump->save = NULL;
cpump->mode = PAI_MODE_NONE;
} }
mutex_unlock(&pai_reserve_mutex); mutex_unlock(&pai_reserve_mutex);
} }
...@@ -136,17 +133,14 @@ static u64 paicrypt_getall(struct perf_event *event) ...@@ -136,17 +133,14 @@ static u64 paicrypt_getall(struct perf_event *event)
*/ */
static int paicrypt_busy(struct perf_event_attr *a, struct paicrypt_map *cpump) static int paicrypt_busy(struct perf_event_attr *a, struct paicrypt_map *cpump)
{ {
unsigned int *use_ptr;
int rc = 0; int rc = 0;
mutex_lock(&pai_reserve_mutex); mutex_lock(&pai_reserve_mutex);
if (a->sample_period) { /* Sampling requested */ if (a->sample_period) { /* Sampling requested */
use_ptr = &cpump->sampler; if (cpump->mode != PAI_MODE_NONE)
if (cpump->counter || cpump->sampler)
rc = -EBUSY; /* ... sampling/counting active */ rc = -EBUSY; /* ... sampling/counting active */
} else { /* Counting requested */ } else { /* Counting requested */
use_ptr = &cpump->counter; if (cpump->mode == PAI_MODE_SAMPLING)
if (cpump->sampler)
rc = -EBUSY; /* ... and sampling active */ rc = -EBUSY; /* ... and sampling active */
} }
if (rc) if (rc)
...@@ -172,12 +166,16 @@ static int paicrypt_busy(struct perf_event_attr *a, struct paicrypt_map *cpump) ...@@ -172,12 +166,16 @@ static int paicrypt_busy(struct perf_event_attr *a, struct paicrypt_map *cpump)
rc = 0; rc = 0;
unlock: unlock:
/* If rc is non-zero, do not increment counter/sampler. */ /* If rc is non-zero, do not set mode and reference count */
if (!rc) if (!rc) {
*use_ptr += 1; cpump->refcnt++;
debug_sprintf_event(cfm_dbg, 5, "%s sample_period %#llx sampler %d" cpump->mode = a->sample_period ? PAI_MODE_SAMPLING
" counter %d page %#lx save %p rc %d\n", __func__, : PAI_MODE_COUNTING;
a->sample_period, cpump->sampler, cpump->counter, }
debug_sprintf_event(cfm_dbg, 5, "%s sample_period %#llx users %d"
" mode %d refcnt %d page %#lx save %p rc %d\n",
__func__, a->sample_period, cpump->users,
cpump->mode, cpump->refcnt,
(unsigned long)cpump->page, cpump->save, rc); (unsigned long)cpump->page, cpump->save, rc);
mutex_unlock(&pai_reserve_mutex); mutex_unlock(&pai_reserve_mutex);
return rc; return rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment