Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3538851ybz; Mon, 20 Apr 2020 04:57:05 -0700 (PDT) X-Google-Smtp-Source: APiQypI06OJBPZQtLM5r2F4Yqxsy6L9xvMLHyHdMIgQPfGnLH8PH536IVXsJ4sGgYBOgyu0Iyd1L X-Received: by 2002:a17:906:af6f:: with SMTP id os15mr15995715ejb.78.1587383825274; Mon, 20 Apr 2020 04:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383825; cv=none; d=google.com; s=arc-20160816; b=TZzNnTiXwVxoxVmg6rWVg2SGtHdzAoi+BAUdVc15QcziNbzPnqJlgpoHEv/c/M+ZRZ fPO1N2BcTn2l8JKXHxamQLa9rzr6/IoloCNPybPwOkDURiSbXS+CZEGiCG816nmwll6B 1QtCeeAvLjSVUwfX3uyOqJO1g4/6wK50NvTsSrURKZB4/GYjXI7x0aC4R57yo4n54BJx 7UW7lcKHJz/F+vh737KRe1inRATIH68bD+bUsD/pCvG9+HcpHX4UuspzaefY35+fetnE rl9yQL4GojNLoQlKp6yMKjgNmgNwqNnCVEfFUaDn31PAPvrN9RkH/3ZLr3luU8IHWXUt xjmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yzkfHdskBFw1S21M3Ei6KN/tT6jlW5sKfWegNL7RxkI=; b=mBPDAuniR8KV7VFeMhHTZtr0r2fIetu3mCQ6lmCwpZ6ZF/xC8eyEZaCCPklzZHy/ZU GHiyqljcAjFmzyTjh/4nOeQ6X5tM75dviWah0e9X7gr/TWS7Pdg7njYEomye51DIvBzp MUij2V1jytccLm9a7Q7QouUqxDOXFoeJE3pecl+uW4LJUaCAVCigTgUVPfEJ15I9fBw2 i3toQ2XFVkSFM08kmOcigKOQwAT6uNhxzGN51Eq5QWRpE3NX2gl9KnQ00OpEH5jpuBsG xHJEQ2Nyb273FoZbTGjTb65LA92PBgAxcgTU1EQLs3kuBrZMLz77+uZ770CENy31qT4Y s7rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V2o6zqAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id cm21si394989edb.275.2020.04.20.04.56.42; Mon, 20 Apr 2020 04:57:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V2o6zqAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726895AbgDTLzJ (ORCPT + 99 others); Mon, 20 Apr 2020 07:55:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbgDTLzH (ORCPT ); Mon, 20 Apr 2020 07:55:07 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (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 1F7AA21927; Mon, 20 Apr 2020 11:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383707; bh=voRofBWt3Bg02puMqNN0CEnYZL5K/hkfznKgWIjtDkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V2o6zqAwxTrlao7X1XEHuokGQYcJdudb8S8d9awyMwyoRwbX/eSdMWtyH217zTx7Q K+bXCAS0jUrs5GMED+O8nlJ2j1/0FWXdaNI+OM/ExOWJMB6Vukvrf+dUH53ck4mZdR Aq6aGEBSQgQnalM7WQUyeTyBU5soucS+N0IwAC1o= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ian Rogers , Alexander Shishkin , Andrey Zhizhikin , Jiri Olsa , Kan Liang , Kefeng Wang , Mark Rutland , Peter Zijlstra , Petr Mladek , Stephane Eranian , Arnaldo Carvalho de Melo Subject: [PATCH 20/60] perf synthetic-events: save 4kb from 2 stack frames Date: Mon, 20 Apr 2020 08:52:36 -0300 Message-Id: <20200420115316.18781-21-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ian Rogers Reuse an existing char buffer to avoid two PATH_MAX sized char buffers. Reduces stack frame sizes by 4kb. perf_event__synthesize_mmap_events before 'sub $0x45b8,%rsp' after 'sub $0x35b8,%rsp'. perf_event__get_comm_ids before 'sub $0x2028,%rsp' after 'sub $0x1028,%rsp'. The performance impact of this change is negligible. Signed-off-by: Ian Rogers Cc: Alexander Shishkin Cc: Andrey Zhizhikin Cc: Jiri Olsa Cc: Kan Liang Cc: Kefeng Wang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Petr Mladek Cc: Stephane Eranian Cc: Thomas Gleixner Link: http://lore.kernel.org/lkml/20200402154357.107873-4-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/synthetic-events.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index a661b122d9d8..9d4aa951eaa6 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -71,7 +71,6 @@ int perf_tool__process_synth_event(struct perf_tool *tool, static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len, pid_t *tgid, pid_t *ppid) { - char filename[PATH_MAX]; char bf[4096]; int fd; size_t size = 0; @@ -81,11 +80,11 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len, *tgid = -1; *ppid = -1; - snprintf(filename, sizeof(filename), "/proc/%d/status", pid); + snprintf(bf, sizeof(bf), "/proc/%d/status", pid); - fd = open(filename, O_RDONLY); + fd = open(bf, O_RDONLY); if (fd < 0) { - pr_debug("couldn't open %s\n", filename); + pr_debug("couldn't open %s\n", bf); return -1; } @@ -281,9 +280,9 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, struct machine *machine, bool mmap_data) { - char filename[PATH_MAX]; FILE *fp; unsigned long long t; + char bf[BUFSIZ]; bool truncation = false; unsigned long long timeout = proc_map_timeout * 1000000ULL; int rc = 0; @@ -293,15 +292,15 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, if (machine__is_default_guest(machine)) return 0; - snprintf(filename, sizeof(filename), "%s/proc/%d/task/%d/maps", - machine->root_dir, pid, pid); + snprintf(bf, sizeof(bf), "%s/proc/%d/task/%d/maps", + machine->root_dir, pid, pid); - fp = fopen(filename, "r"); + fp = fopen(bf, "r"); if (fp == NULL) { /* * We raced with a task exiting - just return: */ - pr_debug("couldn't open %s\n", filename); + pr_debug("couldn't open %s\n", bf); return -1; } @@ -309,7 +308,6 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, t = rdclock(); while (1) { - char bf[BUFSIZ]; char prot[5]; char execname[PATH_MAX]; char anonstr[] = "//anon"; @@ -321,10 +319,10 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, break; if ((rdclock() - t) > timeout) { - pr_warning("Reading %s time out. " + pr_warning("Reading %s/proc/%d/task/%d/maps time out. " "You may want to increase " "the time limit by --proc-map-timeout\n", - filename); + machine->root_dir, pid, pid); truncation = true; goto out; } -- 2.21.1