Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1218291imm; Tue, 5 Jun 2018 10:51:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJG6cmNdbAl5ys7EbCk6kqeifLr9XfO5JuWA9V8T2P3uKLQ2uLfiY9T8ZgN+F6VAuRLUlYx X-Received: by 2002:a65:6007:: with SMTP id m7-v6mr20994841pgu.92.1528221103986; Tue, 05 Jun 2018 10:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528221103; cv=none; d=google.com; s=arc-20160816; b=szmhYBcz4I4yyh6k8tX+eZrrCvGCXjQSNfrNauYuKhyFeMbnwbENlqNZHGEtjabBHi 75DNq5Op9cNkqPmCO3mNaCfMX2vVrx58iKCNo/51yRaFYdbH1pk2KXkNq2oo5xVPRLk2 +qHm73fLjPHTqjCyVOYqTUHF9trPaximZ5MecABPfDjj+yZ3XvhBPDFkVzpaZQ0BS6fA 3ek5bS3eATcdzUQOWJBCvyaYvQGWy49W78ETN6bu2ATD9z1er5THY2wWZnl95H25qVom jVGenVQr4bKyAFJZlir9hmwvwwwY98FtmhRCYag5VBEfDzAbWgZX0fyu93p7cOdBVE9j SB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=udGTw8ZP5FUKgnJ/n0+hRBG7y8k7kzP3ADiCUN/M6w8=; b=vrBkIzN7ihQ+dn7HiW1RhNYCGRmN7r7L6PWE3TrLRR0ym2J81zQ5AdAp0p0nQvjO6S qy5IJQcHmE5OzrTCsuIR5g6UGmohsZ5SKeUVujFwz8UujQObKbZUz1K/8PJameSQiuQn wrk8arAageuqu7+GyVL6yuxEq701vtGHVIQuzPP7OgE+qr3B8k70EY8ssTzCpaPcy9e8 cgufu8nMZDFyPI01ZjCgEIRd0AKxbmNNrxKr/omtvhasiaT5zCOrEBMZvzq2wBiXa3sy sLhQ7TVX9ffB2sju+JWxXfPbRuw0dff/WX8rhDcBthTRi2HjRZmGXh3fEHDy2678pwZO U+jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ruEYL8Z1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69-v6si50527435pla.548.2018.06.05.10.51.29; Tue, 05 Jun 2018 10:51:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ruEYL8Z1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752136AbeFERvI (ORCPT + 99 others); Tue, 5 Jun 2018 13:51:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:45566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751852AbeFERvD (ORCPT ); Tue, 5 Jun 2018 13:51:03 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 544662075B; Tue, 5 Jun 2018 17:51:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528221062; bh=M/nafprX4yS9gfgx/vmkBV3yJqiXEQJQ+xBscrLx2Ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ruEYL8Z1oPQpsWFLBXk5236jaxH1463spx+vRNX/sHi8wPTPCA40+LlQNWMmafFVZ CKlvQRg7+F8ZQt27mji3U5vjZPp8oAuNmdNvnV0LQGOJ6LLDgmmPOZgqyY4jMOMttv OexPQTpzE/9vc2nIrni5202TOMaW0yvCqd2S50RE= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 07/46] perf annotate: Split allocation of annotated_source struct Date: Tue, 5 Jun 2018 14:49:51 -0300 Message-Id: <20180605175030.32549-8-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605175030.32549-1-acme@kernel.org> References: <20180605175030.32549-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo So that we can allocate just the notes->src->cyc_hist, that, unlike notes->src->histograms, is not per event, and in paths where we need to lazily allocate notes->src->cyc_hist we don't have the number of events handy to also allocate ->histograms. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-tsx7dhxzpi0criyx0sio3pz3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 10 +++++++--- tools/perf/util/annotate.h | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index a7221f9fa504..f0c6941bca6c 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -701,13 +701,17 @@ int symbol__alloc_hist(struct symbol *sym) sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(struct sym_hist_entry)); /* Check for overflow in zalloc argument */ - if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src)) - / symbol_conf.nr_events) + if (sizeof_sym_hist > SIZE_MAX / symbol_conf.nr_events) return -1; - notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); + notes->src = zalloc(sizeof(*notes->src)); if (notes->src == NULL) return -1; + notes->src->histograms = calloc(symbol_conf.nr_events, sizeof_sym_hist); + if (notes->src->histograms == NULL) { + zfree(¬es->src); + return -1; + } notes->src->sizeof_sym_hist = sizeof_sym_hist; notes->src->nr_histograms = symbol_conf.nr_events; INIT_LIST_HEAD(¬es->src->source); diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index aef9eae4f125..94b60e34c3a7 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -201,7 +201,7 @@ struct cyc_hist { /** struct annotated_source - symbols with hits have this attached as in sannotation * - * @histogram: Array of addr hit histograms per event being monitored + * @histograms: Array of addr hit histograms per event being monitored * @lines: If 'print_lines' is specified, per source code line percentages * @source: source parsed from a disassembler like objdump -dS * @cyc_hist: Average cycles per basic block @@ -217,7 +217,7 @@ struct annotated_source { int nr_histograms; size_t sizeof_sym_hist; struct cyc_hist *cycles_hist; - struct sym_hist histograms[0]; + struct sym_hist *histograms; }; struct annotation { @@ -269,7 +269,7 @@ void annotation__init_column_widths(struct annotation *notes, struct symbol *sym static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx) { - return (((void *)¬es->src->histograms) + + return (((void *)notes->src->histograms) + (notes->src->sizeof_sym_hist * idx)); } -- 2.14.3