public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: German Gomez <german.gomez@arm.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-perf-users <linux-perf-users@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, John Garry <john.garry@huawei.com>,
	Will Deacon <will@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 4/4] perf arm-spe: Support hardware-based PID tracing
Date: Thu, 11 Nov 2021 16:30:02 +0800	[thread overview]
Message-ID: <20211111083002.GA106401@leoy-ThinkPad-X240s> (raw)
In-Reply-To: <CAM9d7cjW_=hDkHVWchNFDyqZXbbBwMb224hbZTMsCe34MLL-4Q@mail.gmail.com>

Hi Namhyung,

On Wed, Nov 10, 2021 at 11:59:05PM -0800, Namhyung Kim wrote:

[...]

> > > > +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)
> > > > +{
> > > > +       struct arm_spe *spe = speq->spe;
> > > > +       int err = machine__set_current_tid(spe->machine, speq->cpu, tid, tid);
> > >
> > > I think we should pass -1 as pid as we don't know the real pid.
> >
> > AFAICT, I observe one case for machine__set_current_tid() returning error
> > is 'speq->cpu' is -1 (this is the case for per-thread tracing).  In
> > this case, if pass '-1' for pid/tid, it still will return failure.
> >
> > So here should return the error as it is.  Am I missing anything?
> 
> I'm not saying about the error.  It's about thread status.
> In the machine__set_current_tid(), it calls
> machine__findnew_thread() with given pid and tid.
> 
> I suspect it can set pid to a wrong value if the thread has
> no pid value at the moment.

Here we should avoid to write pid '-1' with
machine__set_current_tid().

The function arm_spe_set_tid() is invoked when SPE trace data contains
context packet and it passes pid coming from the context packet.  On
the other hand, when SPE trace data doesn't contain context packet, we
relies on context switch event to set pid value.  So if we pass pid
'-1' in arm_spe_set_tid(), it will overwrite the pid value which has
been set by context switch event.

Simply say, if SPE trace data contains context packet with valid pid,
perf invokes arm_spe_set_tid() to set the pid value.  Otherwise, it
should skip this operation and roll back to use the pid value from
the context switch event.

Thanks,
Leo

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-11-11  8:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-09 11:50 [PATCH v2 0/4] perf arm-spe: Track pid/tid for Arm SPE samples German Gomez
2021-11-09 11:50 ` [PATCH v2 1/4] perf arm-spe: Track task context switch for cpu-mode events German Gomez
2021-11-09 11:50 ` [PATCH v2 2/4] perf arm-spe: Update --switch-events docs in perf-record German Gomez
2021-11-11  7:18   ` Leo Yan
2021-11-11  7:29     ` Namhyung Kim
2021-11-09 11:50 ` [PATCH v2 3/4] perf arm-spe: Save context ID in record German Gomez
2021-11-11  7:25   ` Namhyung Kim
2021-11-09 11:50 ` [PATCH v2 4/4] perf arm-spe: Support hardware-based PID tracing German Gomez
2021-11-11  7:28   ` Namhyung Kim
2021-11-11  7:41     ` Leo Yan
2021-11-11  7:59       ` Namhyung Kim
2021-11-11  8:30         ` Leo Yan [this message]
2021-11-11 12:23           ` German Gomez
2021-11-11 12:42             ` Leo Yan
2021-11-11 13:10               ` German Gomez
2021-11-11  7:27 ` [PATCH v2 0/4] perf arm-spe: Track pid/tid for Arm SPE samples Leo Yan
2021-11-11 13:26   ` Leo Yan
2021-11-11 14:49     ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211111083002.GA106401@leoy-ThinkPad-X240s \
    --to=leo.yan@linaro.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=german.gomez@arm.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=namhyung@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox