Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp175835ybh; Fri, 17 Jul 2020 23:50:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPNXKi/aLItIF4kE9BwWR6Z777tjSB0fqhUf8CoVFhbc8HdIK8WkC4wBuJexhfYLODrYhS X-Received: by 2002:a17:906:f20d:: with SMTP id gt13mr12058495ejb.117.1595055012440; Fri, 17 Jul 2020 23:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595055012; cv=none; d=google.com; s=arc-20160816; b=KOwDqf//cjCORXnv0SbKTcsLzLv8oEbH3j+a6+r6g6MtNyAbe5iQOIPIYzNIk5kV8Z iqh/RfW16QJmHEBhpOq5PHDLzw1h4+lY0bkdPo44jJlKboGVx+cavetgtlAexmTjyljQ T9fibJHOcbpELXeHeEmjpEjK3pt4dsDaL1Eh0+PAcluP/l7KxwaWATTo8t2MUCBqhjXn o8Ib3ZaGNDQHdLuX2E8oIZYWJVSVKELd/plWS0Dl8f/2xW4ib57anKGJ0xNV8TYAH03J m0qB4d7Wqv/xSETVJUp0rAQQzArbKIIaV0jelquLf2gBwjKzPNZDbD81WH86E8TRLnkc MWNA== 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=Harjrr7y6PUyK2mGrgedXG/2vDJx3FDLhTm2GoOMA36mjtSHch/0ETqpeKIf8nah6S fDWsto+nXj4CVXfCr214AARiWiW0GzSaeKM1yRCPTt+tX0tDmch/XvlUcbrvtrIxYhSQ xktUu/SL2FBe3ArfNJRpJFGhHerIvTKuqFhwaZlkutNUU23yzIWxXI/g4PrS9LI7IBTZ +hZFfuYEmzNjSP2Pm2Sdu7jFlRiJ/llA6PSiXOSIYjD7NKQvfMeC2wwxYGe/tOrchMwo PsjHHtkDaXk3atn8yJy36/AACuRpVAY0dE9vGQS6+tG4PFN4hFS1hi4Cim3pi4T/ck6/ OQgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CKW5yWTQ; 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 qt10si7182485ejb.196.2020.07.17.23.49.49; Fri, 17 Jul 2020 23:50:12 -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=CKW5yWTQ; 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 S1729004AbgGRGtM (ORCPT + 99 others); Sat, 18 Jul 2020 02:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbgGRGtL (ORCPT ); Sat, 18 Jul 2020 02:49:11 -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 BCF71C0619D2 for ; Fri, 17 Jul 2020 23:49:11 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id u185so6438438pfu.1 for ; Fri, 17 Jul 2020 23:49:11 -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=CKW5yWTQOlfqkQ5gjrsucLTdfEpiiE6Z5NPIPSpXoLsbQ+17RnDpp8D0nwLTU3v3YG qId72cNnwMxNo/+NXmYgVYXhZ+xDjjDlr2iyZ7fuji+6fDoxApfSytagLrANHYp/dxHT RbIdYqAOIX2868MTITCQw5J6XppHgBo+UB4ElU8+GpeHoFD7OlILgsOfSnhhCS2oRF7P itg6213PRfHqTSk4fjaJt57nCQZ0DJjbKWCT3C9Jjjv9Ef8oDAh4IL0Wgab28j31tDLk 18wmTg6ARx5YtiERP5VF5agpg2pmfS5j539VSZ8lTzE7PtJguE50XFHmTdKj0LRuop7u Bk3A== 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=ueYuuIBa+NCdHQVNnT3xUSLwqANpT83yxbX39ppnoXM1sZIBNjffPKCh+fXPdNrCXS FYuTnt96DmvIxGyOaNgwSmMPrIX4PqrC9U0dRAh6GTBX7yHb9g8keH82O37UMYI4gWnW i+g33Fb9+ZxR0gEKuKCKBvqHtacCOBTfMDcOqx687v3vELe/Hgir4FJ55NzustiRo/bP ZCsUzCkfa+4b37DbsaV2zfdzSFrG7PACndW2wpokY93oSHYtvUgyCCm1xYvYQTkRY8Mb oL70SjoBvrlV/4DCQEmGguEelexx2GJOyk/ZY2TJH24Da3GqpOglrr/dSINH8e1Q3rgP UNsA== X-Gm-Message-State: AOAM530xzi9j2Vy0LKi/H3uKrkuSmQQLhxbf6tOPyZIJgKnVZIWRMqCt o2FXO+mKQujLKXJG9vYPPm8= X-Received: by 2002:a63:d143:: with SMTP id c3mr11342422pgj.306.1595054951293; Fri, 17 Jul 2020 23:49:11 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id q10sm10422781pfk.86.2020.07.17.23.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 23:49:10 -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 v7 04/18] perf ftrace: add option '-m/--buffer-size' to set per-cpu buffer size Date: Sat, 18 Jul 2020 14:48:12 +0800 Message-Id: <20200718064826.9865-5-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200718064826.9865-1-changbin.du@gmail.com> References: <20200718064826.9865-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