From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752056AbbFZOGY (ORCPT ); Fri, 26 Jun 2015 10:06:24 -0400 Received: from mail.kernel.org ([198.145.29.136]:41629 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751680AbbFZOGS (ORCPT ); Fri, 26 Jun 2015 10:06:18 -0400 Date: Fri, 26 Jun 2015 11:06:04 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Adrian Hunter , Andi Kleen , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra , Stephane Eranian Subject: Re: [PATCH 01/22] perf thread_map: Introduce thread_map__reset function Message-ID: <20150626140604.GB3265@kernel.org> References: <1435310967-14570-1-git-send-email-jolsa@kernel.org> <1435310967-14570-2-git-send-email-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1435310967-14570-2-git-send-email-jolsa@kernel.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Jun 26, 2015 at 11:29:06AM +0200, Jiri Olsa escreveu: > We need to reset newly allocated 'struct thread_map_data' entries, > because we will introduce new comm memeber, which will get set > later or not at all. And this is an array that never shrinks, right? At least current usage just makes it grow, ok. - Arnaldo > Link: http://lkml.kernel.org/n/tip-hg8xtux446qyjqkkcezwkg0v@git.kernel.org > Signed-off-by: Jiri Olsa > --- > tools/perf/util/thread_map.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c > index 368cc58c6892..562e5e2c571c 100644 > --- a/tools/perf/util/thread_map.c > +++ b/tools/perf/util/thread_map.c > @@ -21,11 +21,26 @@ static int filter(const struct dirent *dir) > return 1; > } > > +static void thread_map__reset(struct thread_map *map, int start, int nr) > +{ > + size_t size = (nr - start) * sizeof(struct thread_map_data); > + > + memset(&map->map[start], 0, size); > +} > + > static struct thread_map *thread_map__realloc(struct thread_map *map, int nr) > { > size_t size = sizeof(*map) + sizeof(map->map[0]) * nr; > + int start = map ? map->nr : 0; > > - return realloc(map, size); > + map = realloc(map, size); > + /* > + * We only realloc to add more items, let's reset new items. > + */ > + if (map) > + thread_map__reset(map, start, nr); > + > + return map; > } > > #define thread_map__alloc(__nr) thread_map__realloc(NULL, __nr) > -- > 1.9.3