From: Peter Zijlstra <peterz@infradead.org>
To: kan.liang@intel.com
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, acme@kernel.org,
jolsa@redhat.com, tglx@linutronix.de, eranian@google.com,
ak@linux.intel.com
Subject: Re: [PATCH V5] perf: Add PERF_SAMPLE_PHYS_ADDR
Date: Tue, 22 Aug 2017 19:07:36 +0200 [thread overview]
Message-ID: <20170822170736.GI32112@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <1502993843-6837-1-git-send-email-kan.liang@intel.com>
On Thu, Aug 17, 2017 at 02:17:23PM -0400, kan.liang@intel.com wrote:
> diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
> index a322fed..f0e8d9c 100644
> --- a/arch/x86/events/intel/ds.c
> +++ b/arch/x86/events/intel/ds.c
> @@ -1065,6 +1065,35 @@ static inline u64 intel_hsw_transaction(struct pebs_record_skl *pebs)
> return txn;
> }
>
> +static u64 dla_to_phys(u64 dla)
> +{
> + u64 phys_addr = 0;
> + struct page *p = NULL;
> +
> + if (dla >= TASK_SIZE) {
> + /* If it's vmalloc()d memory, leave phys_addr as 0 */
> + if (virt_addr_valid(dla) &&
> + !(dla >= VMALLOC_START && dla < VMALLOC_END))
> + phys_addr = (u64)virt_to_phys((void *)(uintptr_t)dla);
> + } else {
> + /*
> + * Walking the pages tables for user address.
> + * Interrupts are disabled, so it prevents any tear down
> + * of the page tables.
> + * Try IRQ-safe __get_user_pages_fast first.
> + * If failed, leave phys_addr as 0.
> + */
> + if ((current->mm != NULL) &&
> + (__get_user_pages_fast(dla, 1, 0, &p) == 1))
> + phys_addr = page_to_phys(p) + dla % PAGE_SIZE;
> +
> + if (p)
> + put_page(p);
> + }
> +
> + return phys_addr;
> +}
Is this in any way x86 specific? AFAICT this should work in generic code
as long as data->addr is provided.
> static void setup_pebs_sample_data(struct perf_event *event,
> struct pt_regs *iregs, void *__pebs,
> struct perf_sample_data *data,
> @@ -1179,6 +1208,9 @@ static void setup_pebs_sample_data(struct perf_event *event,
> x86_pmu.intel_cap.pebs_format >= 1)
> data->addr = pebs->dla;
>
> + if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0))
> + data->phys_addr = dla_to_phys(data->addr);
> +
> if (x86_pmu.intel_cap.pebs_format >= 2) {
> /* Only set the TSX weight when no memory weight. */
> if ((sample_type & PERF_SAMPLE_WEIGHT) && !fll)
next prev parent reply other threads:[~2017-08-22 17:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-17 18:17 [PATCH V5] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
2017-08-22 16:56 ` Peter Zijlstra
2017-08-22 17:58 ` Liang, Kan
2017-08-22 18:21 ` Peter Zijlstra
2017-08-22 17:07 ` Peter Zijlstra [this message]
2017-08-22 17:15 ` Liang, Kan
2017-08-22 17:31 ` Andi Kleen
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=20170822170736.GI32112@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/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