Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2030019ybh; Fri, 17 Jul 2020 07:40:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsDGBLpjQ2ZbljIBxUtnFKsVKb0JuCYD9Qurj/WAJDVTTwhMGuOWWS3ANSTZ4UWfC3iLP1 X-Received: by 2002:a17:906:455:: with SMTP id e21mr9181031eja.550.1594996819178; Fri, 17 Jul 2020 07:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594996819; cv=none; d=google.com; s=arc-20160816; b=Q1Zd1/rmEYMVjoO8QonvoYmBCFRfNPpXByXeBwwSKnMk0fDh9oICQn+CdNssMZxpfF FZW5LZjLB2nKKgBP94n9fCYj6aEPmkN30i5ocBhqnvg2mLvUCOEwljRHxcwO6j4gIhOB 0arZVpiefC//gmkFNF2bJhWEBz7CX4mFk/d4Z2yX5T6gjUPq4XJhWMWFfbxRGHG2drj1 6tGS9D6fZQsLajfk5MRm9MzVnB209VP4/mW8lKikH8j/wl7FmpZPkM5ON3WmBFIWNpTc icktS0dCYu8o1SyXaK+wKQ7bns/59l64XQwxVLorrnChWd7TcH9ayTvaHj9Gzk++TdOQ InFQ== 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=VYNmyfGkRtgT6M2/w1xCrXsfOtBriDc30SnQ3OQ81uc=; b=daG+gmEh5WWu7BlkFY9zDSTvjuy283qT9FWBGjsGEd6C+xBAuhVOlEFyHehGZcW3r/ rqKlLiBNaXWfNkOjmCNz3mR/tC5BRZOy1OD1SkoMMkbdAQeiZJX/iIFA3+s2dZySZ+nJ 6S/6qEyILhh50bT08zxcK0FyW+mb8e6bKtJ5oeKuBiKavqG8KEnd65s0E9gn192Yt0A2 1nK51xFKsUm3LaMC9r3KT+odEnvnySCmum9RYl4tVxxOkwcSdmYV3bk+KIkyDq/1n+z5 zBBz9ye2oykNZpriRwKim++Adxuafdxi21gt4eUok3ihl87gnNIL+rvWdttyowWEo+qu sDFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="J/7Su+Du"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s23si5080181eju.242.2020.07.17.07.39.56; Fri, 17 Jul 2020 07:40:19 -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=@gmail.com header.s=20161025 header.b="J/7Su+Du"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbgGQOhW (ORCPT + 99 others); Fri, 17 Jul 2020 10:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726891AbgGQOhW (ORCPT ); Fri, 17 Jul 2020 10:37:22 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70761C0619D2 for ; Fri, 17 Jul 2020 07:37:22 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id z3so5467669pfn.12 for ; Fri, 17 Jul 2020 07:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VYNmyfGkRtgT6M2/w1xCrXsfOtBriDc30SnQ3OQ81uc=; b=J/7Su+DuwOfqtbFPvFjjo7lqXVfjJdEELbjVM7qltE0EBnfgqu9t4Nkmhh8XHzJEim gkwcH8TrGBd1bnOz0FCX24zzD8g4yhlGWTdociUMf4LJzeMiK352ZduS9zKF39MgzpNz +cBXw4vOAJH1j/eWHrslMcwlAjFIUDM5ZZR6bYi0fVIFHqXJkggwJ/MzHjgQzgtUuI46 rXXsGBGR9yfTwjxY0B0y4+LkDS4kjbzHSqzrrp6ksV4BAGs0VvnQz33ayioi9m4W61f9 3juDZS/JtvUXNwMoqSc1JWqPB27DnuPVOU38bTd4j5zyumwYTOgpgu9WDVBo8DrEy0Q2 NgnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VYNmyfGkRtgT6M2/w1xCrXsfOtBriDc30SnQ3OQ81uc=; b=oakhzcYO3usS9PA8bQvpdUXqyscqbineL2wuyN5fchrVYWAHq9DdRcNEJwGu7Q+g/R Hf6dXT88VkwtI17kMkvbL+5wgFWhu0KvYoq8LboTxcjNN7yub6lMYOlYy3x6K1XKB/g3 BCtTsawsXgS5tKZpKibmn25AY7Efh0ez4Kosqz2bTQAP8JYDYXZwkXvKoaLVfn/wx63k R9oY++MlEOSoHwdCwAtJcYE/cmnm88UmIvOVk0/pJPRv43ostjbrPvHYQ0T17XT+WFN1 yYgyhDErQmwafknLmBw7chkuh7PimIm+n9k0erMr+NXkeTWIUboztHGeAQGS5y1nqu0a 30Dg== X-Gm-Message-State: AOAM531zHnxEJuQwO4K4Vkn19oZxIB4jLPhaz+UwdFFrevb6C2j6V7B8 cRmL6yWs6yjtOiOxb1At2BE= X-Received: by 2002:a62:3204:: with SMTP id y4mr8042194pfy.50.1594996642019; Fri, 17 Jul 2020 07:37:22 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id a68sm3214689pje.35.2020.07.17.07.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 07:37:21 -0700 (PDT) From: Changbin Du To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Namhyung Kim , Steven Rostedt , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v6 04/17] perf ftrace: add option '-m/--buffer-size' to set per-cpu buffer size Date: Fri, 17 Jul 2020 22:36:15 +0800 Message-Id: <20200717143628.47721-5-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717143628.47721-1-changbin.du@gmail.com> References: <20200717143628.47721-1-changbin.du@gmail.com> 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 This adds an option '-m/--buffer-size' to allow us set the size of per-cpu tracing buffer. Signed-off-by: Changbin Du --- v2: support units as a suffix. --- tools/perf/Documentation/perf-ftrace.txt | 5 +++ tools/perf/builtin-ftrace.c | 56 +++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt index d79560dea19f..dcac0d75a0e5 100644 --- a/tools/perf/Documentation/perf-ftrace.txt +++ b/tools/perf/Documentation/perf-ftrace.txt @@ -52,6 +52,11 @@ OPTIONS Ranges of CPUs are specified with -: 0-2. Default is to trace on all online CPUs. +-m:: +--buffer-size:: + Set the size of per-cpu tracing buffer, is expected to + be a number with appended unit character - B/K/M/G. + -T:: --trace-funcs=:: Only trace functions given by the argument. Multiple functions diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 9abf97c29cb6..3ea3aaa4650b 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -26,7 +26,7 @@ #include "thread_map.h" #include "util/cap.h" #include "util/config.h" - +#include "util/units.h" struct perf_ftrace { struct evlist *evlist; @@ -38,6 +38,7 @@ struct perf_ftrace { struct list_head graph_funcs; struct list_head nograph_funcs; int graph_depth; + unsigned long percpu_buffer_size; }; struct filter_entry { @@ -323,6 +324,21 @@ static int set_tracing_depth(struct perf_ftrace *ftrace) return 0; } +static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace) +{ + int ret; + + if (ftrace->percpu_buffer_size == 0) + return 0; + + ret = write_tracing_file_int("buffer_size_kb", + ftrace->percpu_buffer_size / 1024); + if (ret < 0) + return ret; + + return 0; +} + static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) { char *trace_file; @@ -387,6 +403,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) goto out_reset; } + if (set_tracing_percpu_buffer_size(ftrace) < 0) { + pr_err("failed to set tracing per-cpu buffer size\n"); + goto out_reset; + } + if (write_tracing_file("current_tracer", ftrace->tracer) < 0) { pr_err("failed to set current_tracer to %s\n", ftrace->tracer); goto out_reset; @@ -506,6 +527,37 @@ static void delete_filter_func(struct list_head *head) } } +static int parse_buffer_size(const struct option *opt, + const char *str, int unset) +{ + unsigned long *s = (unsigned long *)opt->value; + static struct parse_tag tags_size[] = { + { .tag = 'B', .mult = 1 }, + { .tag = 'K', .mult = 1 << 10 }, + { .tag = 'M', .mult = 1 << 20 }, + { .tag = 'G', .mult = 1 << 30 }, + { .tag = 0 }, + }; + unsigned long val; + + if (unset) { + *s = 0; + return 0; + } + + val = parse_tag_value(str, tags_size); + if (val != (unsigned long) -1) { + if (val < 1024) { + pr_err("buffer size too small, must larger than 1KB."); + return -1; + } + *s = val; + return 0; + } + + return -1; +} + int cmd_ftrace(int argc, const char **argv) { int ret; @@ -543,6 +595,8 @@ int cmd_ftrace(int argc, const char **argv) "Set nograph filter on given functions", parse_filter_func), OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth, "Max depth for function graph tracer"), + OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size", + "size of per cpu buffer", parse_buffer_size), OPT_END() }; -- 2.25.1