All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Kao <alankao@andestech.com>
To: "Wladimir J. van der Laan" <laanwj@gmail.com>
Cc: linux-riscv@lists.infradead.org,
	Palmer Dabbelt <palmer@sifive.com>,
	nickhu@andestech.com
Subject: Re: Perf counters on SiFive FU540-C000
Date: Wed, 3 Apr 2019 17:27:58 +0800	[thread overview]
Message-ID: <20190403092758.GA26612@andestech.com> (raw)
In-Reply-To: <20190403084237.qygtfnefppdr3vtj@aurora.visucore.com>

Hi Wladimir,

On Wed, Apr 03, 2019 at 10:42:37AM +0200, Wladimir J. van der Laan wrote:
> Hello,
> 
> Thanks Alan and Palmer for the input!
> 
> On Wed, Apr 03, 2019 at 09:04:26AM +0800, Alan Kao wrote:
> 
> > > >These are very basic: CSRs mhpmevent3 and mhpmevent4 can be used to choose a category
> > > >(Instruction Commit Events, Microarchitectural Events, Memory System Events), then
> > > >from these categories a bitmask of events can be set that will increase the associated
> > > >counter when they happen. I don't understand the rationale for counting multiple
> > > >kinds of events in one register, so from what I understand, two counters can be
> > > >supported at once in the perf interface.
> > > 
> > > The idea here is to allow users to have different performance counter
> > > granularities.  For example, users might want to count all pipeline flushes
> > > (maybe their framework defines that as a possible counter type) or may want
> > > to specifically indicate which sort of pipeline flush should be counted.
> 
> I didn't realize some of them were conceptually hierarchical, seen in that light
> it makes a lot of sense and it's a good way of being able to count at various levels.
> 
> > > >I found some documentation about platform specfic counters in Documentation/riscv/pmu.txt,
> > > >hopefully this is enough to get me started.
> > > >(If someone started work on this, please let me know)
> > > 
> > > Someone from Andes had patches out to add support for their performance
> > > counters a while ago.  The issue there was that the performance counter
> > > implementation was chosen at compile time, but it should really be detected
> > > at run time via some platform-specific mechanism (ie, device tree).
> > 
> > PMU detection was one of the problems, and should have been solved in previous
> > patches.  For the rest of the problems, Documentation/riscv/pmu.txt should
> > serve as a good guide.
> 
> Looking at the device tree (for 'sifive,fu540g' compatibility?) seems, to me,
> to be the right answer here.

Ideally there should be a PMU node in the DTS.  I don't have the DTS for FU540
so you have to check if something alike exists.

> 
> It'd be possible to really-detect by configuring a specific event type then
> running that instruction and looking at the counters, but that seems
> unnecessary.
> 

Sure.  beleiving-reading-parsing the DTS you got is the norm.

> > > Aside from that I think the only issue was how to expose these to userspace
> > > in a sane fashion, which is something I thought would be quite tricky.  IIRC
> > > someone managed to convince me that there was a really simple scheme for
> > > doing this, but I don't remember what it was.
> > 
> > The corresponding userspace tool is in tools/perf.  Once one finishes the kernel
> > part, the work left for userspace perf will be the symbolization of PMU raw
> > events.  The preliminary patch supports common counters only, so I believe this
> > will be the first platform-specific PMU in RISC-V.
> 
> Right-the user-space interface would be 'perf', the idea would be to make that
> work for all the counters so that 'perf top' and profiling work for them.
> 

Oops ... current spec gives you no interrupt when a counter overflows, so
basically you cannot do the profiling by perf even if you finish the event
mapping.  The best you can get is "perf stat" to work.

> So it seems to me that on the kernel side, apart from the setup and allocation
> logic, that these platform-specific counters can be handled in the same way as
> `mcycle` and `minstret` are, they're also simple counters without overrun
> notification logic or other fancy features.
> 
> Also with the same limitation that they cannot be written to from the kernel
> in S-mode, so need to keep track of deltas.
> 
> Speaking of which, can the kernel write to the selectors? Oh crap I guess not.

Unfortunately you are right.  You have to manually hack some SBIs for writing
event masks.

> 
> Wladimir

Alan

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

  reply	other threads:[~2019-04-03  9:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-31 14:37 Perf counters on SiFive FU540-C000 Wladimir J. van der Laan
2019-04-02 17:57 ` Palmer Dabbelt
2019-04-03  1:04   ` Alan Kao
2019-04-03  8:42     ` Wladimir J. van der Laan
2019-04-03  9:27       ` Alan Kao [this message]
2019-04-03  9:58         ` Wladimir J. van der Laan
2019-04-03 22:15       ` Palmer Dabbelt

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=20190403092758.GA26612@andestech.com \
    --to=alankao@andestech.com \
    --cc=laanwj@gmail.com \
    --cc=linux-riscv@lists.infradead.org \
    --cc=nickhu@andestech.com \
    --cc=palmer@sifive.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.