s390/cpum_cf: rework PER_CPU_DEFINE of struct cpu_cf_events
authorThomas Richter <tmricht@linux.ibm.com>
Thu, 15 Jun 2023 11:31:58 +0000 (13:31 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Thu, 22 Jun 2023 12:37:30 +0000 (14:37 +0200)
commit9b9cf3c77e7e090b30657b3d2c288deb58dfb4f2
treedbddd01f7f04b153f8ba8aa9051a0460abc019b0
parentd0d3e218d50bc93282df7bded9193e6fc9ccda48
s390/cpum_cf: rework PER_CPU_DEFINE of struct cpu_cf_events

Struct cpu_cf_events is a large data structure and is statically defined
for each possible CPU. Rework this and replace it by dynamically
allocated data structures created when a perf_event_open() system call
is invoked or an access via character device /dev/hwctr takes place.

It is replaced by an array of pointers to all possible CPUs and
reference counting. The array of pointers is allocated when the first
event is created. For each online CPU an event is installed on, a struct
cpu_cf_events is allocated and a pointer to struct cpu_cf_events is
stored in the array:

                   CPU   0   1   2   3  ...  N
                       +---+---+---+---+---+---+
 cpu_cf_root::cpucf--> | * |   |   |   |...|   |
                       +-|-+---+---+---+---+---+
                         |
                         |
                        \|/
                     +-------------+
     |cpu_cf_events|
     |             |
                     +-------------+

With this approach the large data structure is only allocated when
an event is actually installed and used.
Also implement proper reference counting for allocation and removal.

During interrupt processing make sure the pointer to cpu_cf_events
is valid. The interrupt handler is shared and might be called when
no event is active.
This requires checking for a valid pointer to struct cpu_cf_events.
When the pointer to the per-cpu cpu_cf_events is NULL, simply return.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/kernel/perf_cpum_cf.c