Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5335005pxu; Wed, 21 Oct 2020 22:19:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxislpt5fYG3saY/5SX/Isz4XzLRwTfPKFEV0w2CTiyjZByEWMPBKEWCbG4p+Gi7yjeNpPn X-Received: by 2002:a17:906:7f8c:: with SMTP id f12mr745222ejr.8.1603343945091; Wed, 21 Oct 2020 22:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603343945; cv=none; d=google.com; s=arc-20160816; b=zPVu0TvDXcdGbsjzz0fWA2Y8xCbi3oDeezFUSCIv8hyJ0IPD/mRSwkN1rmn76qpf4i QNdfYwRydhxU/UJGrq8PnEBLwKZpvCom6VNtgeZwWbxfQ+TJenyzN+KP4Zva0gIOeuld 7lkoOUxI3Qrg9aFaB4Vgn438N2OM4XHzCmDNKY31803bsDxGKezWZo5XRJVGNUmjnI0C TMsFvymnuwtypXrsqP5kD6Ds7Q2Xb9raoZ/sdRWBTKAquVinbk6xpJg8YNmwh6BKYTds N/R3Ekffa9fJCezG7n+pmj0iFP0VX6dBLRMpSk8vX6hgT3nHXHPUgCyn/xzJP8GampEB OtUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :references:cc:to:from:subject:ironport-sdr:ironport-sdr; bh=9p/GjqG0Sa/SZKxUK35vhXBRrlXniZZ+cfqHJAmElI8=; b=zOr5LgNNbe9Gf8qJtv9z4HodyOh0UOtNNqDAPV4PxHhSQfJPxIu1FOsloQwBn0Zt3E +1nw1ge9Ejl6l7OHjxcqGyD2jl/+NbdjDf/leZRA5viKMJTmDQuPTF8CuklMMHzKWRjv e0KQKK8nZfKz1GNHjb8YvErZJAXbBqBawc6pTFeoX/PhDWaX+nCcPZUxQzyXYESKlupo U9eafXcA86OD4+t/SryzT2R3//ZuLXJu6WFiKyS03Gk3RLQ61thfwfc3AkNGbM8sboUs JBVtaEQBwKDXZK6ELL42PqDx5rOZnDjt05nM+UwG7a4RRl/PCtwlwMDiJc5lfYEyZ30b p0Ag== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qo14si208248ejb.663.2020.10.21.22.18.43; Wed, 21 Oct 2020 22:19: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2444362AbgJUQDB (ORCPT + 99 others); Wed, 21 Oct 2020 12:03:01 -0400 Received: from mga14.intel.com ([192.55.52.115]:7684 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408739AbgJUQDA (ORCPT ); Wed, 21 Oct 2020 12:03:00 -0400 IronPort-SDR: Ml9gP375kEsPgvqYZsDs67qHXUeo5x8AAJQlxGg15+9wIJXyeBfo+EKR4l+8lbwlc4hC3g0Gga HdqhWGu83L2w== X-IronPort-AV: E=McAfee;i="6000,8403,9780"; a="166614201" X-IronPort-AV: E=Sophos;i="5.77,401,1596524400"; d="scan'208";a="166614201" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2020 09:03:00 -0700 IronPort-SDR: WaldfLDHWitgtN45wRTUKDqDB22lZHf00xYz0hnKS3u7MyWBoL4/Hg2y2K2Q24R8Pk5RGd9i9e 8cyNNuh/HsOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,401,1596524400"; d="scan'208";a="533582048" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 21 Oct 2020 09:03:00 -0700 Received: from [10.249.231.46] (abudanko-mobl.ccr.corp.intel.com [10.249.231.46]) by linux.intel.com (Postfix) with ESMTP id C0FE4580107; Wed, 21 Oct 2020 09:02:57 -0700 (PDT) Subject: [PATCH v2 08/15] perf record: write trace data into mmap trace files From: Alexey Budankov To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Namhyung Kim , Alexander Shishkin , Adrian Hunter , Andi Kleen , Peter Zijlstra , Ingo Molnar , linux-kernel References: <1ec29ed6-0047-d22f-630b-a7f5ccee96b4@linux.intel.com> Organization: Intel Corp. Message-ID: <1202e665-6321-28d4-eca3-b21693364467@linux.intel.com> Date: Wed, 21 Oct 2020 19:02:56 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <1ec29ed6-0047-d22f-630b-a7f5ccee96b4@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Write trace buffer data into per mmap trace files located at data directory. Streaming thread adjusts its affinity according to mask of the buffer being processed. Signed-off-by: Alexey Budankov --- tools/perf/builtin-record.c | 44 ++++++++++++++++++++++++++++++++----- tools/perf/util/record.h | 1 + 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 619aaee11231..ba26d75c51d6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -120,6 +120,11 @@ static const char *affinity_tags[PERF_AFFINITY_MAX] = { "SYS", "NODE", "CPU" }; +static int record__threads_enabled(struct record *rec) +{ + return rec->opts.threads; +} + static bool switch_output_signal(struct record *rec) { return rec->switch_output.signal && @@ -894,6 +899,20 @@ static int record__mmap_evlist(struct record *rec, return -EINVAL; } } + + if (record__threads_enabled(rec)) { + int i, ret, nr = evlist->core.nr_mmaps; + struct mmap *mmaps = rec->opts.overwrite ? + evlist->overwrite_mmap : evlist->mmap; + + ret = perf_data__create_dir(&rec->data, evlist->core.nr_mmaps); + if (ret) + return ret; + + for (i = 0; i < nr; i++) + mmaps[i].file = &rec->data.dir.files[i]; + } + return 0; } @@ -1184,8 +1203,12 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist, /* * Mark the round finished in case we wrote * at least one event. + * + * No need for round events in directory mode, + * because per-cpu maps and files have data + * sorted by kernel. */ - if (bytes_written != rec->bytes_written) + if (!record__threads_enabled(rec) && bytes_written != rec->bytes_written) rc = record__write(rec, NULL, &finished_round_event, sizeof(finished_round_event)); if (overwrite) @@ -1231,7 +1254,9 @@ static void record__init_features(struct record *rec) if (!rec->opts.use_clockid) perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA); - perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); + if (!record__threads_enabled(rec)) + perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); + if (!record__comp_enabled(rec)) perf_header__clear_feat(&session->header, HEADER_COMPRESSED); @@ -1242,15 +1267,21 @@ static void record__finish_output(struct record *rec) { struct perf_data *data = &rec->data; - int fd = perf_data__fd(data); + int i, fd = perf_data__fd(data); if (data->is_pipe) return; rec->session->header.data_size += rec->bytes_written; data->file.size = lseek(perf_data__fd(data), 0, SEEK_CUR); + if (record__threads_enabled(rec)) { + for (i = 0; i < data->dir.nr; i++) + data->dir.files[i].size = lseek(data->dir.files[i].fd, 0, SEEK_CUR); + } if (!rec->no_buildid) { + /* this will be recalculated during process_buildids() */ + rec->samples = 0; process_buildids(rec); if (rec->buildid_all) @@ -2041,8 +2072,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) status = err; record__synthesize(rec, true); - /* this will be recalculated during process_buildids() */ - rec->samples = 0; if (!err) { if (!rec->timestamp_filename) { @@ -2680,9 +2709,12 @@ int cmd_record(int argc, const char **argv) } - if (rec->opts.kcore) + if (rec->opts.kcore || record__threads_enabled(rec)) rec->data.is_dir = true; + if (record__threads_enabled(rec)) + rec->opts.affinity = PERF_AFFINITY_CPU; + if (rec->opts.comp_level != 0) { pr_debug("Compression enabled, disabling build id collection at the end of the session.\n"); rec->no_buildid = true; diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h index 266760ac9143..aeda3cdaa3e9 100644 --- a/tools/perf/util/record.h +++ b/tools/perf/util/record.h @@ -74,6 +74,7 @@ struct record_opts { int ctl_fd; int ctl_fd_ack; bool ctl_fd_close; + bool threads; }; extern const char * const *record_usage; -- 2.24.1