Re: [PATCH v2 2/2] perf lock: Don't free "lock_seq_stat" if read_count isn't zero
From: Leo Yan
Date: Mon Nov 02 2020 - 21:30:02 EST
On Mon, Nov 02, 2020 at 05:56:26PM +0100, Jiri Olsa wrote:
> On Wed, Oct 21, 2020 at 08:39:48AM +0800, Leo Yan wrote:
> > When execute command "perf lock report", it hits failure and outputs log
> > as follows:
> >
> > perf: builtin-lock.c:623: report_lock_release_event: Assertion `!(seq->read_count < 0)' failed.
> > Aborted
> >
> > This is an imbalance issue. The locking sequence structure
> > "lock_seq_stat" contains the reader counter and it is used to check if
> > the locking sequence is balance or not between acquiring and releasing.
> >
> > If the tool wrongly frees "lock_seq_stat" when "read_count" isn't zero,
> > the "read_count" will be reset to zero when allocate a new structure at
> > the next time; thus it causes the wrong counting for reader and finally
> > results in imbalance issue.
> >
> > To fix this issue, if detects "read_count" is not zero (means still
> > have read user in the locking sequence), goto the "end" tag to skip
> > freeing structure "lock_seq_stat".
> >
> > Fixes: e4cef1f65061 ("perf lock: Fix state machine to recognize lock sequence")
> > Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
> > ---
> > tools/perf/builtin-lock.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> > index 5cecc1ad78e1..a2f1e53f37a7 100644
> > --- a/tools/perf/builtin-lock.c
> > +++ b/tools/perf/builtin-lock.c
> > @@ -621,7 +621,7 @@ static int report_lock_release_event(struct evsel *evsel,
> > case SEQ_STATE_READ_ACQUIRED:
> > seq->read_count--;
> > BUG_ON(seq->read_count < 0);
> > - if (!seq->read_count) {
> > + if (seq->read_count) {
> > ls->nr_release++;
>
> it seems ok, but I fail to see what's nr_release for
> the point is just to skip the removal of seq right?
To be honest, I'm not sure if I understand your question :)
Either remove "seq" or not, "nr_release" will be increased. When remove
"seq", the code line [1] will increase '1' for "nr_release"; when skip
to remove "seq", "nr_release" is also increased 1 [2]. So I don't see
the logic issue for "nr_release", do I miss anything?
Another side topic is the four metrics "nr_acquire", "nr_release",
"nr_readlock", "nr_trylock" have been accounted, but they are not really
used for output final result. I'd like to defer this later as a task
for refine the output metrics.
Thanks,
Leo
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/builtin-lock.c#n641
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/builtin-lock.c#n625