Re: [PATCH v5 11/16] perf kvm: Use histograms list to replace cached list

Arnaldo Carvalho de Melo
2023-03-16T10:14:03Z

Em Thu, Mar 16, 2023 at 05:04:18PM +0800, Leo Yan escreveu:
> On Thu, Mar 16, 2023 at 12:42:53AM -0700, Namhyung Kim wrote:
>
> [...]
>
> > > static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm,
> > > struct event_key *key,
> > > struct perf_sample *sample)
> > > {
> > > struct kvm_event *event;
> > > - struct list_head *head;
> > > + struct hist_entry *he;
> > > + struct kvm_info *ki;
> > >
> > > BUG_ON(key->key == INVALID_KEY);
> > >
> > > - head = &kvm->kvm_events_cache[kvm_events_hash_fn(key->key)];
> > > - list_for_each_entry(event, head, hash_entry) {
> > > - if (event->key.key == key->key && event->key.info == key->info)
> > > - return event;
> > > + ki = zalloc(sizeof(*ki));
> > > + if (!ki) {
> > > + pr_err("Failed to allocate kvm info\n");
> > > + return NULL;
> > > }
> > >
> > > - event = kvm_alloc_init_event(kvm, key, sample);
> > > - if (!event)
> > > + kvm->events_ops->decode_key(kvm, key, ki->name);
> > > + he = hists__add_entry_ops(&kvm_hists.hists, &kvm_ev_entry_ops,
> > > + &kvm->al, NULL, NULL, NULL, ki, sample, true);
> >
> > The hists__add_entry{,_ops} can return either a new entry
> > or an existing one. I think it'd leak the 'ki' when it returns
> > the existing one. You may deep-copy it in hist_entry__init()
> > and always free the 'ki' here.
>
> Thanks for pointing out this, Namhyung. I will fix it.
>
> @Arnaldo, do you want me to send an appending patch, or will you drop
> this patch series from your branch so I send a new patch set?
>
> > Another thought on this. Lots of fields in the hist_entry are
> > not used for kvm. We might split the hist_entry somehow
> > so that we can use unnecessary parts only. But that could
> > be a future project. :)
>
> Yeah, I found now hist_entry contains many fields
> (branch_info/mem_info/kvm_info/block_info); we can consider to
> refactor the struct hist_entry to use an abstract pointer to refer
> tool's specific data, this could be easily extend hist_entry to
> support more tools.

Since I build tested this already and had the other fixes, I'm pushing
this out to perf-tools-next (and perf/core for a while, for people not
knowing about the new nbranch names) and you can continue from there,
ok?

- Arnaldo