Re: [PATCH v2 2/6] perf test: Handle metric reuse in pmu-events parsing test

Jiri Olsa
2021-04-06T13:34:38Z

On Tue, Apr 06, 2021 at 02:21:11PM +0100, John Garry wrote:
> On 06/04/2021 13:55, Jiri Olsa wrote:
> > > > > So expr__find_other() may add a new item to pctx->ids, and we always iterate
> > > > > again, and try to lookup any pmu_events, *, above. If none exist, then we
> > > > hm, I don't see that.. so, what you do is:
> > > >
> > > > hashmap__for_each_entry_safe((&pctx->ids) ....) {
> > > >
> > > > rc = expr__find_other(pe->metric_expr, NULL, pctx, 0);
> > > > }
> > > >
> > > > and what I think we need to do is:
> > > >
> > > > hashmap__for_each_entry_safe((&pctx->ids) ....) {
> > > >
> > > > rc = expr__find_other(pe->metric_expr, NULL, pctx, 0);
> > > >
> > > > break;
> > > > }
> > > >
> > > > each time you resolve another metric, you need to restart
> > > > the pctx->ids iteration, because there will be new items,
> > > > and we are in the middle of it
> > > Sure, but we will restart anyway.
> > hum, where? you call expr__find_other and continue to next
> > pctx->ids item
>
> We have:
>
> resolve_metric_simple()
> {
> bool all;
>
> do {
> all = true;
>
> hashmap__for_each_entry_safe(&pctx->ids, ...) {
>
> pe = metricgroup_find_metric(cur->key, map);
> if (!pe)
> continue;
>
> ...
> all = false;
>
> expr_del_id(pctx, cur->key);
>
> ...
> rc = expr__find_other(pe->metric_expr, pctx);
> if (rc)
> goto out_err;
> }
>
> } while (!all);
>
> }
>
> So once we evaluate a pmu_event in pctx->ids in @pe, @all is set false, and
> we would loop again in the do-while loop, regardless of what
> expr__find_other() does (apart from erroring), and so call
> hashmap__for_each_entry_safe(&pctx->ids, ) again.

ah ok, so it finishes the hash iteration first and
then restarts it.. ok, I missed that, then it's fine

>
> This is really what is done in __resolve_metric() - indeed, I would use that
> function directly, but it looks hard to extract that from metricgroup.c .

yea, it's another world ;-) it's better to keep it separated

thanks,
jirka

>
> Thanks,
> John
>
> >
> > > Regardless of this, I don't think what I am doing is safe, i.e. adding new
> > > items in the middle of the iter, so I will change in the way you suggest.
> > it'll always add items in the middle of the iteration
>