s390/pai_ext: split function paiext_push_sample
authorThomas Richter <tmricht@linux.ibm.com>
Thu, 16 Nov 2023 11:12:12 +0000 (12:12 +0100)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Fri, 12 Jan 2024 13:23:27 +0000 (14:23 +0100)
Split function paiext_push_sample() into two parts. The first part
determines the number of bytes to store as raw data in the perf sample
record. This is now function paiext_have_sample().
The second part stores the raw data in the perf event's ring buffer.
No functional change.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Mete Durlu <meted@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/kernel/perf_pai_ext.c

index e2e1ce2de695fe9e9112b237bd1287fd1749c8de..af7f2b538c8fd47a19f73029264462bd6c4fdcbd 100644 (file)
@@ -415,21 +415,14 @@ static size_t paiext_copy(struct pai_userdata *userdata, unsigned long *area)
  * sched_task() callback. That callback is not active after paiext_del()
  * returns and has deleted the event on that CPU.
  */
-static int paiext_push_sample(void)
+static int paiext_push_sample(size_t rawsize, struct paiext_map *cpump,
+                             struct perf_event *event)
 {
-       struct paiext_mapptr *mp = this_cpu_ptr(paiext_root.mapptr);
-       struct paiext_map *cpump = mp->mapptr;
-       struct perf_event *event = cpump->event;
        struct perf_sample_data data;
        struct perf_raw_record raw;
        struct pt_regs regs;
-       size_t rawsize;
        int overflow;
 
-       rawsize = paiext_copy(cpump->save, cpump->area);
-       if (!rawsize)                   /* No incremented counters */
-               return 0;
-
        /* Setup perf sample */
        memset(&regs, 0, sizeof(regs));
        memset(&raw, 0, sizeof(raw));
@@ -458,6 +451,23 @@ static int paiext_push_sample(void)
        return overflow;
 }
 
+/* Check if there is data to be saved on schedule out of a task. */
+static int paiext_have_sample(void)
+{
+       struct paiext_mapptr *mp = this_cpu_ptr(paiext_root.mapptr);
+       struct paiext_map *cpump = mp->mapptr;
+       struct perf_event *event = cpump->event;
+       size_t rawsize;
+       int rc = 0;
+
+       if (!event)
+               return 0;
+       rawsize = paiext_copy(cpump->save, cpump->area);
+       if (rawsize)                    /* Incremented counters */
+               rc = paiext_push_sample(rawsize, cpump, event);
+       return rc;
+}
+
 /* Called on schedule-in and schedule-out. No access to event structure,
  * but for sampling only event NNPA_ALL is allowed.
  */
@@ -467,7 +477,7 @@ static void paiext_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched
         * results on schedule_out and if page was dirty, clear values.
         */
        if (!sched_in)
-               paiext_push_sample();
+               paiext_have_sample();
 }
 
 /* Attribute definitions for pai extension1 interface. As with other CPU