From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, will@kernel.org,
catalin.marinas@arm.com, mark.rutland@arm.com,
Mark Brown <broonie@kernel.org>,
James Clark <james.clark@arm.com>, Rob Herring <robh@kernel.org>,
Marc Zyngier <maz@kernel.org>,
Suzuki Poulose <suzuki.poulose@arm.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH V11 08/10] arm64/perf: Add struct brbe_regset helper functions
Date: Mon, 5 Jun 2023 08:44:50 +0530 [thread overview]
Message-ID: <a11beb49-7b4f-08f0-b1e2-782a0ba973ea@arm.com> (raw)
In-Reply-To: <CAM9d7cihqiUULBR7JoizDGySVYdOx3TH_CJV=QDpeck3p8z5wg@mail.gmail.com>
On 6/2/23 08:10, Namhyung Kim wrote:
> On Tue, May 30, 2023 at 9:15 PM Anshuman Khandual
> <anshuman.khandual@arm.com> wrote:
>>
>> The primary abstraction level for fetching branch records from BRBE HW has
>> been changed as 'struct brbe_regset', which contains storage for all three
>> BRBE registers i.e BRBSRC, BRBTGT, BRBINF. Whether branch record processing
>> happens in the task sched out path, or in the PMU IRQ handling path, these
>> registers need to be extracted from the HW. Afterwards both live and stored
>> sets need to be stitched together to create final branch records set. This
>> adds required helper functions for such operations.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>> Tested-by: James Clark <james.clark@arm.com>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>
> [SNIP]
>> +
>> +static inline void copy_brbe_regset(struct brbe_regset *src, int src_idx,
>> + struct brbe_regset *dst, int dst_idx)
>> +{
>> + dst[dst_idx].brbinf = src[src_idx].brbinf;
>> + dst[dst_idx].brbsrc = src[src_idx].brbsrc;
>> + dst[dst_idx].brbtgt = src[src_idx].brbtgt;
>> +}
>> +
>> +/*
>> + * This function concatenates branch records from stored and live buffer
>> + * up to maximum nr_max records and the stored buffer holds the resultant
>> + * buffer. The concatenated buffer contains all the branch records from
>> + * the live buffer but might contain some from stored buffer considering
>> + * the maximum combined length does not exceed 'nr_max'.
>> + *
>> + * Stored records Live records
>> + * ------------------------------------------------^
>> + * | S0 | L0 | Newest |
>> + * --------------------------------- |
>> + * | S1 | L1 | |
>> + * --------------------------------- |
>> + * | S2 | L2 | |
>> + * --------------------------------- |
>> + * | S3 | L3 | |
>> + * --------------------------------- |
>> + * | S4 | L4 | nr_max
>> + * --------------------------------- |
>> + * | | L5 | |
>> + * --------------------------------- |
>> + * | | L6 | |
>> + * --------------------------------- |
>> + * | | L7 | |
>> + * --------------------------------- |
>> + * | | | |
>> + * --------------------------------- |
>> + * | | | Oldest |
>> + * ------------------------------------------------V
>> + *
>> + *
>> + * S0 is the newest in the stored records, where as L7 is the oldest in
>> + * the live reocords. Unless the live buffer is detetcted as being full
>> + * thus potentially dropping off some older records, L7 and S0 records
>> + * are contiguous in time for a user task context. The stitched buffer
>> + * here represents maximum possible branch records, contiguous in time.
>> + *
>> + * Stored records Live records
>> + * ------------------------------------------------^
>> + * | L0 | L0 | Newest |
>> + * --------------------------------- |
>> + * | L0 | L1 | |
>> + * --------------------------------- |
>> + * | L2 | L2 | |
>> + * --------------------------------- |
>> + * | L3 | L3 | |
>> + * --------------------------------- |
>> + * | L4 | L4 | nr_max
>> + * --------------------------------- |
>> + * | L5 | L5 | |
>> + * --------------------------------- |
>> + * | L6 | L6 | |
>> + * --------------------------------- |
>> + * | L7 | L7 | |
>> + * --------------------------------- |
>> + * | S0 | | |
>> + * --------------------------------- |
>> + * | S1 | | Oldest |
>> + * ------------------------------------------------V
>> + * | S2 | <----|
>> + * ----------------- |
>> + * | S3 | <----| Dropped off after nr_max
>> + * ----------------- |
>> + * | S4 | <----|
>> + * -----------------
>> + */
>> +static int stitch_stored_live_entries(struct brbe_regset *stored,
>> + struct brbe_regset *live,
>> + int nr_stored, int nr_live,
>> + int nr_max)
>> +{
>> + int nr_total, nr_excess, nr_last, i;
>> +
>> + nr_total = nr_stored + nr_live;
>> + nr_excess = nr_total - nr_max;
>> +
>> + /* Stored branch records in stitched buffer */
>> + if (nr_live == nr_max)
>> + nr_stored = 0;
>> + else if (nr_excess > 0)
>> + nr_stored -= nr_excess;
>> +
>> + /* Stitched buffer branch records length */
>> + if (nr_total > nr_max)
>> + nr_last = nr_max;
>> + else
>> + nr_last = nr_total;
>> +
>> + /* Move stored branch records */
>> + for (i = 0; i < nr_stored; i++)
>> + copy_brbe_regset(stored, i, stored, nr_last - nr_stored - 1 + i);
>
> I'm afraid it can overwrite some entries if nr_live is small
> and nr_stored is big. Why not use memmove()?
nr_stored is first adjusted with nr_excess if both live and stored entries combined
exceed the maximum branch records in the HW. I am wondering how it can override ?
>
> Also I think it'd be simpler if you copy store to live.
> It'll save copying live in the IRQ but it will copy the
> whole content to store again for the sched switch.
But how that is better than the current scheme ?
next prev parent reply other threads:[~2023-06-05 3:15 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 4:04 [PATCH V11 00/10] arm64/perf: Enable branch stack sampling Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 01/10] drivers: perf: arm_pmu: Add new sched_task() callback Anshuman Khandual
2023-06-05 7:26 ` Mark Rutland
2023-05-31 4:04 ` [PATCH V11 02/10] arm64/perf: Add BRBE registers and fields Anshuman Khandual
2023-06-05 7:55 ` Mark Rutland
2023-06-06 4:27 ` Anshuman Khandual
2023-06-13 16:27 ` Mark Rutland
2023-06-14 2:59 ` Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 03/10] arm64/perf: Add branch stack support in struct arm_pmu Anshuman Khandual
2023-06-05 7:58 ` Mark Rutland
2023-06-06 4:47 ` Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 04/10] arm64/perf: Add branch stack support in struct pmu_hw_events Anshuman Khandual
2023-06-05 8:00 ` Mark Rutland
2023-05-31 4:04 ` [PATCH V11 05/10] arm64/perf: Add branch stack support in ARMV8 PMU Anshuman Khandual
2023-06-02 2:33 ` Namhyung Kim
2023-06-05 2:43 ` Anshuman Khandual
2023-06-05 12:05 ` Mark Rutland
2023-06-06 10:34 ` Anshuman Khandual
2023-06-06 10:41 ` Mark Rutland
2023-06-08 10:13 ` Suzuki K Poulose
2023-06-09 4:00 ` Anshuman Khandual
2023-06-09 9:54 ` Suzuki K Poulose
2023-06-09 7:14 ` Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 06/10] arm64/perf: Enable branch stack events via FEAT_BRBE Anshuman Khandual
2023-06-02 1:45 ` Namhyung Kim
2023-06-05 3:00 ` Anshuman Khandual
2023-06-05 13:43 ` Mark Rutland
2023-06-09 4:30 ` Anshuman Khandual
2023-06-09 12:37 ` Mark Rutland
2023-06-09 4:47 ` Anshuman Khandual
2023-06-09 12:42 ` Mark Rutland
2023-06-09 5:22 ` Anshuman Khandual
2023-06-09 12:47 ` Mark Rutland
2023-06-09 13:15 ` Mark Rutland
2023-06-12 8:35 ` Anshuman Khandual
2023-06-09 13:34 ` James Clark
2023-06-12 10:12 ` Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 07/10] arm64/perf: Add PERF_ATTACH_TASK_DATA to events with has_branch_stack() Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 08/10] arm64/perf: Add struct brbe_regset helper functions Anshuman Khandual
2023-06-02 2:40 ` Namhyung Kim
2023-06-05 3:14 ` Anshuman Khandual [this message]
2023-06-05 23:49 ` Namhyung Kim
2023-06-13 17:17 ` Mark Rutland
2023-06-14 5:14 ` Anshuman Khandual
2023-06-14 10:59 ` Mark Rutland
2023-05-31 4:04 ` [PATCH V11 09/10] arm64/perf: Implement branch records save on task sched out Anshuman Khandual
2023-05-31 4:04 ` [PATCH V11 10/10] arm64/perf: Implement branch records save on PMU IRQ Anshuman Khandual
2023-06-09 11:13 ` [PATCH V11 00/10] arm64/perf: Enable branch stack sampling Anshuman Khandual
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=a11beb49-7b4f-08f0-b1e2-782a0ba973ea@arm.com \
--to=anshuman.khandual@arm.com \
--cc=acme@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=james.clark@arm.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=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=robh@kernel.org \
--cc=suzuki.poulose@arm.com \
--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;
as well as URLs for NNTP newsgroup(s).