[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210119144658.793-8-james.clark@arm.com>
Date: Tue, 19 Jan 2021 16:46:58 +0200
From: James Clark <james.clark@....com>
To: linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org
Cc: Leo Yan <leo.yan@...aro.org>, James Clark <james.clark@....com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
John Garry <john.garry@...wei.com>,
Will Deacon <will@...nel.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Al Grant <al.grant@....com>,
Andre Przywara <andre.przywara@....com>,
Wei Li <liwei391@...wei.com>,
Tan Xiaojun <tanxiaojun@...wei.com>,
Adrian Hunter <adrian.hunter@...el.com>
Subject: [PATCH 8/8] perf arm-spe: Set thread TID
From: Leo Yan <leo.yan@...aro.org>
Set thread TID for SPE samples. Now that the context ID is saved
in each record it can be used to set the TID for a sample.
The context ID is only present in SPE data if the kernel is
compiled with CONFIG_PID_IN_CONTEXTIDR and perf record is
run as root. Otherwise the PID of the first process is assigned
to each SPE sample.
Signed-off-by: Leo Yan <leo.yan@...aro.org>
Signed-off-by: James Clark <james.clark@....com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Mark Rutland <mark.rutland@....com>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: John Garry <john.garry@...wei.com>
Cc: Will Deacon <will@...nel.org>
Cc: Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: Al Grant <al.grant@....com>
Cc: Andre Przywara <andre.przywara@....com>
Cc: Wei Li <liwei391@...wei.com>
Cc: Tan Xiaojun <tanxiaojun@...wei.com>
Cc: Adrian Hunter <adrian.hunter@...el.com>
---
tools/perf/util/arm-spe.c | 75 ++++++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 25 deletions(-)
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 27a0b9dfe22d..9828fad7e516 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -223,6 +223,46 @@ static inline u8 arm_spe_cpumode(struct arm_spe *spe, u64 ip)
PERF_RECORD_MISC_USER;
}
+static void arm_spe_set_pid_tid_cpu(struct arm_spe *spe,
+ struct auxtrace_queue *queue)
+{
+ struct arm_spe_queue *speq = queue->priv;
+ pid_t tid;
+
+ tid = machine__get_current_tid(spe->machine, speq->cpu);
+ if (tid != -1) {
+ speq->tid = tid;
+ thread__zput(speq->thread);
+ } else
+ speq->tid = queue->tid;
+
+ if ((!speq->thread) && (speq->tid != -1)) {
+ speq->thread = machine__find_thread(spe->machine, -1,
+ speq->tid);
+ }
+
+ if (speq->thread) {
+ speq->pid = speq->thread->pid_;
+ if (queue->cpu == -1)
+ speq->cpu = speq->thread->cpu;
+ }
+}
+
+static int arm_spe_set_tid(struct arm_spe_queue *speq, pid_t tid)
+{
+ int err;
+ struct arm_spe *spe = speq->spe;
+ struct auxtrace_queue *queue;
+
+ err = machine__set_current_tid(spe->machine, speq->cpu, tid, tid);
+ if (err)
+ return err;
+
+ queue = &speq->spe->queues.queue_array[speq->queue_nr];
+ arm_spe_set_pid_tid_cpu(speq->spe, queue);
+ return 0;
+}
+
static void arm_spe_prep_sample(struct arm_spe *spe,
struct arm_spe_queue *speq,
union perf_event *event,
@@ -431,6 +471,7 @@ static int arm_spe_sample(struct arm_spe_queue *speq)
static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
{
struct arm_spe *spe = speq->spe;
+ const struct arm_spe_record *record;
int ret;
if (!spe->kernel_start)
@@ -450,6 +491,11 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
if (ret < 0)
continue;
+ record = &speq->decoder->record;
+ ret = arm_spe_set_tid(speq, record->context_id);
+ if (ret)
+ return ret;
+
ret = arm_spe_sample(speq);
if (ret)
return ret;
@@ -500,6 +546,10 @@ static int arm_spe__setup_queue(struct arm_spe *spe,
record = &speq->decoder->record;
+ ret = arm_spe_set_tid(speq, record->context_id);
+ if (ret)
+ return ret;
+
speq->timestamp = record->timestamp;
ret = auxtrace_heap__add(&spe->heap, queue_nr, speq->timestamp);
if (ret)
@@ -552,31 +602,6 @@ static bool arm_spe__is_timeless_decoding(struct arm_spe *spe)
return timeless_decoding;
}
-static void arm_spe_set_pid_tid_cpu(struct arm_spe *spe,
- struct auxtrace_queue *queue)
-{
- struct arm_spe_queue *speq = queue->priv;
- pid_t tid;
-
- tid = machine__get_current_tid(spe->machine, speq->cpu);
- if (tid != -1) {
- speq->tid = tid;
- thread__zput(speq->thread);
- } else
- speq->tid = queue->tid;
-
- if ((!speq->thread) && (speq->tid != -1)) {
- speq->thread = machine__find_thread(spe->machine, -1,
- speq->tid);
- }
-
- if (speq->thread) {
- speq->pid = speq->thread->pid_;
- if (queue->cpu == -1)
- speq->cpu = speq->thread->cpu;
- }
-}
-
static int arm_spe_process_queues(struct arm_spe *spe, u64 timestamp)
{
unsigned int queue_nr;
--
2.28.0
Powered by blists - more mailing lists