[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230316090418.GA2665235@leoy-yangtze.lan>
Date: Thu, 16 Mar 2023 17:04:18 +0800
From: Leo Yan <leo.yan@...aro.org>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
John Garry <john.g.garry@...cle.com>,
James Clark <james.clark@....com>,
Adrian Hunter <adrian.hunter@...el.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v5 11/16] perf kvm: Use histograms list to replace cached
list
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.
Thanks,
Leo
Powered by blists - more mailing lists