From: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-kernel@vger.kernel.org, hemant@linux.vnet.ibm.com,
naveen.n.rao@linux.vnet.ibm.com
Subject: Re: [RFC 1/4] perf kvm: Enable 'record' on powerpc
Date: Mon, 9 May 2016 20:28:18 +0530 [thread overview]
Message-ID: <5730A58A.5020908@linux.vnet.ibm.com> (raw)
In-Reply-To: <20160427214722.GU11033@kernel.org>
Hi Arnaldo,
Thanks for the review. Please find my comments below.
On Thursday 28 April 2016 03:17 AM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Apr 27, 2016 at 06:02:21PM +0530, Ravi Bangoria escreveu:
>> Hi Arnaldo,
>>
>> I've worked on your patch. I'm sending this patch(diff) to check if this
>> is the same idea you want to progress with. I cleanup your patch,
>> removed arch specific compile time directives and changed code to
>> enable cross arch reporting. I tested record on powerpc and report
>> on x86 and it's working.
>>
>> Please give suggestion about your approach. Let me know if you have
>> some other idea to progress with.
>>
>> Here is the diff w.r.t perf/cpumode branch:
>>
>> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
>> index bff6664..83ef6c6 100644
>> --- a/tools/perf/builtin-kvm.c
>> +++ b/tools/perf/builtin-kvm.c
>> @@ -1480,6 +1480,60 @@ perf_stat:
>> }
>> #endif /* HAVE_KVM_STAT_SUPPORT */
>>
>> +#define PPC_HV_DECREMENTER 2432
>> +#define PPC_HV_BIT 3
>> +#define PPC_PR_BIT 49
>> +#define PPC_MAX 63
>> +
>> +static bool perf_sample__is_hv_dec_trap(struct perf_sample *sample, struct
>> perf_evsel *evsel)
>> +{
>> + int trap = perf_evsel__intval(evsel, sample, "trap");
>> + return trap == PPC_HV_DECREMENTER;
>> +}
>> +
>> +static void perf_kvm__munge_ppc_guest_sample(struct perf_evsel *evsel,
>> struct perf_sample *sample)
>> +{
>> + unsigned long msr, hv, pr;
>> +
>> + if (!perf_sample__is_hv_dec_trap(sample, evsel))
>> + return;
>> +
>> + sample->ip = perf_evsel__intval(evsel, sample, "pc");
>> + sample->cpumode = PERF_RECORD_MISC_GUEST_KERNEL;
>> +
>> + msr = perf_evsel__intval(evsel, sample, "msr");
>> + hv = msr & ((unsigned long)1 << (PPC_MAX - PPC_HV_BIT));
>> + pr = msr & ((unsigned long)1 << (PPC_MAX - PPC_PR_BIT));
>> + if (!hv && pr)
>> + sample->cpumode = PERF_RECORD_MISC_GUEST_USER;
>> +}
>> +
>> +static bool perf_evlist__recorded_on_ppc(const struct perf_evlist *evlist)
>> +{
>> + if (evlist->env && evlist->env->arch) {
>> + return !strcmp(evlist->env->arch, "ppc64") ||
>> + !strcmp(evlist->env->arch, "ppc64le");
>> + }
>> + return false;
>> +}
>> +
>> +int perf_kvm__setup_munge_ppc_guest_event(struct perf_evlist *evlist)
>> +{
>> + struct perf_evsel *evsel;
>> + const char name[] = "kvm_hv:kvm_guest_exit";
>> +
>> + if (!perf_evlist__recorded_on_ppc(evlist))
>> + return 0;
>> +
>> + evsel = perf_evlist__find_tracepoint_by_name(evlist, name);
>> + if (evsel == NULL)
>> + return -1;
>> +
>> + evsel->munge_sample = perf_kvm__munge_ppc_guest_sample;
>> +
>> + return 0;
>> +}
>> +
>> static int __cmd_record(const char *file_name, int argc, const char **argv)
>> {
>> int rec_argc, i = 0, j;
>> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
>> index ab47273..7cb41f7 100644
>> --- a/tools/perf/builtin-report.c
>> +++ b/tools/perf/builtin-report.c
>> @@ -879,6 +879,12 @@ repeat:
>> if (session == NULL)
>> return -1;
>>
>> + if (perf_guest &&
>> + perf_kvm__setup_munge_ppc_guest_event(session->evlist)) {
>> + pr_err("PPC event not present in %s file\n", input_name);
>> + goto error;
>> + }
> This looks out of place, i.e. this reads: "For all cases where there is
> a guest and we can't setup the ppc KVM guest related stuff, its an
> error"
>
> I think this gets clearer as:
>
> if (perf_guest && perf_evlist__recorded_on_ppc(evlist) &&
> perf_kvm__setup_munge_ppc_guest_event(session->evlist)) {
> pr_err("PPC event not present in %s file\n", input_name);
> goto error;
> }
>
> Then we read this as "Hey, if this was recorded on ppc, try to set
> things up for ppc",
Yes I'll change this.
> but then again, what is this KVM stuff doing in the
> generic 'perf report' code?
Basically we are checking if data recorded on ppc in perf.data file. Which
can be done after opening a file and mapping header info in evlist. And
evlist is initialized in builtin-record.c only. So, I don't see any
possibility to
move this in builtin-kvm.c. Kindly guide how can we do it.
> What if this is a perf.data file generated on PPC but being read on PPC?
> This will not make sense to munge it, right?
If you are asking about normal(without kvm) perf record and report, it's
working with this patch. Otherwise can you please explain little bit more.
But yes, we can change this code like this:
if (perf_guest && perf_evlist__recorded_on_ppc(session->evlist))
perf_kvm__setup_munge_ppc_guest_event(session->evlist);
and change definition of perf_kvm__setup_munge_ppc_guest_event as:
void perf_kvm__setup_munge_ppc_guest_event(struct perf_evlist *evlist)
{
struct perf_evsel *evsel;
const char name[] = "kvm_hv:kvm_guest_exit";
evsel = perf_evlist__find_tracepoint_by_name(evlist, name);
if (evsel == NULL)
return;
evsel->munge_sample = perf_kvm__munge_ppc_guest_sample;
}
>
> This is with what I remember from this case, please bear with me.
Regards,
Ravi
next prev parent reply other threads:[~2016-05-09 14:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 9:07 [RFC 0/4] perf kvm: Guest Symbol Resolution for powerpc Ravi Bangoria
2016-02-24 9:07 ` [RFC 1/4] perf kvm: Enable 'record' on powerpc Ravi Bangoria
2016-03-22 19:12 ` Arnaldo Carvalho de Melo
2016-03-23 2:19 ` Arnaldo Carvalho de Melo
2016-03-24 21:15 ` Arnaldo Carvalho de Melo
2016-03-28 10:58 ` Ravi Bangoria
2016-03-28 12:28 ` Arnaldo Carvalho de Melo
2016-04-27 12:32 ` Ravi Bangoria
2016-04-27 21:47 ` Arnaldo Carvalho de Melo
2016-05-09 14:58 ` Ravi Bangoria [this message]
2016-02-24 9:07 ` [RFC 2/4] perf kvm: Introduce evsel as argument to perf_event__preprocess_sample Ravi Bangoria
2016-02-24 9:07 ` [RFC 3/4] perf kvm: Enable 'report' on powerpc Ravi Bangoria
2016-02-24 9:07 ` [RFC 4/4] perf kvm: Fix output fields instead of 'trace' for perf kvm report " Ravi Bangoria
2016-03-02 14:25 ` Arnaldo Carvalho de Melo
2016-03-02 15:46 ` Ravi Bangoria
2016-03-02 16:22 ` Arnaldo Carvalho de Melo
2016-03-03 1:19 ` Ravi Bangoria
2016-03-08 15:42 ` Ravi Bangoria
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=5730A58A.5020908@linux.vnet.ibm.com \
--to=ravi.bangoria@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=hemant@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
/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).