Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5338548pxu; Wed, 21 Oct 2020 22:28:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5fRPqtQ9+PGpPzpaY3IaTdMJxLKG6Du//l6Up+8OwwiPTSDjVQrUugHvMHZ92/+Gk4Nt6 X-Received: by 2002:a05:6402:293:: with SMTP id l19mr701495edv.227.1603344514481; Wed, 21 Oct 2020 22:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603344514; cv=none; d=google.com; s=arc-20160816; b=sopElQkkgbEoaSYrshiIH88pfKeKM/QEUqmumN30OAqn1muTPATrnxIpO4G7/wsRxk zrohi35NV1pDYUbODLEqRiWIFDUrbAdtorNB25hn18fxyPdrCXACjFyyO+9ZFDgNQivK 8f4xzxPo3GQu+m1OS1y4jqErZNFKUMOPBP3qgXNS6h8UylU7sboUSysim6IEch1ntnum OOkJhjTl2Wk1mUwuMEy142WoUcO7Vj++E0jLxyEqo7E5CeFw+3KllBzxU1+vULaC7/JH r5QpSyUA0ogB0EhPgzP5XJdhq66rc4Nc5bjf9plfZLEkDi8JehmlnocIQR0yneJe9uBU L0RA== 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=GIHCOWDMh9bnUFM+iLxR5Nc4GtciFqa45uZzs0OFQpA=; b=SUlNN6SGtsdCzjXZQML+1IsdwrwMrUmzM51SCtrgnIQcGb+7NCvAd65rnFk6Lka/93 /di5SlB2cqCMtLj5btToCzvlBltCYg88P8K077CQqfkhw3u0lygRtMc2xsA4Rh3HwkAm oci3d2myDFtxMoS0Ohj4RA+9iRQogSqN4o2AnJNvVELkGwH0RfSNuzjHIfYnX+0N4LAw k4FRfuy09tv6nCAZXN085YmtGIO9i5EU4LAxDUUK/D6D021gS80YDEP3Hl4sVyHLSpTU gmgAU49CYU7nCb+Z1I9NE9PIet2v3IWuzv7F4Y13Rqjvzu64foHseSi3ZQKC5MxnMjeU mBhg== 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 c14si295362edw.305.2020.10.21.22.28.11; Wed, 21 Oct 2020 22:28:34 -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 S2502803AbgJUQIw (ORCPT + 99 others); Wed, 21 Oct 2020 12:08:52 -0400 Received: from mga14.intel.com ([192.55.52.115]:8295 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502799AbgJUQIv (ORCPT ); Wed, 21 Oct 2020 12:08:51 -0400 IronPort-SDR: Rv74zu4G7mmjRrv9AZr9sklUqbXYeBMCxuxvyvfWW8sofUiS9cz6QYXK/UEFlBN+srnU4iucOO vzVXTKjD0gew== X-IronPort-AV: E=McAfee;i="6000,8403,9780"; a="166615350" X-IronPort-AV: E=Sophos;i="5.77,401,1596524400"; d="scan'208";a="166615350" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2020 09:08:50 -0700 IronPort-SDR: 5FcaEDjs9+1cG767U5gSLlizsH8fyLquw9xuXG+POVFcZnjuTFasFEpl5AmO1Tw7QKGEh0QnwL ZheqI+NfCQlg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,401,1596524400"; d="scan'208";a="359545450" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP; 21 Oct 2020 09:08:50 -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 602B5580720; Wed, 21 Oct 2020 09:08:48 -0700 (PDT) Subject: [PATCH v2 13/15] perf record: stop threads in the end of trace streaming 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: <76431e0e-a758-a262-61ea-97e05f433f44@linux.intel.com> Date: Wed, 21 Oct 2020 19:08:47 +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 Close write fd of comm.msg pipe to signal thread to terminate and receive THREAD_MSG__READY confirmation on termination. Accumulate thread stats into global stats to be correctly calculated and displayed in perf tool output. Signed-off-by: Alexey Budankov --- tools/perf/builtin-record.c | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3b7e9026f25b..a15642656066 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -85,6 +85,16 @@ struct switch_output { int cur_file; }; +enum thread_msg { + THREAD_MSG__UNSUPPORTED = 0, + THREAD_MSG__READY, + THREAD_MSG__MAX, +}; + +static const char *thread_msg_tags[THREAD_MSG__MAX] = { + "UNSUPPORTED", "READY" +}; + struct thread_data { pid_t tid; struct { @@ -1796,6 +1806,50 @@ static void hit_auxtrace_snapshot_trigger(struct record *rec) } } +static int record__terminate_thread(struct thread_data *thread_data) +{ + int res; + enum thread_msg ack = THREAD_MSG__UNSUPPORTED; + pid_t tid = thread_data->tid; + + close(thread_data->comm.msg[1]); + res = read(thread_data->comm.ack[0], &ack, sizeof(ack)); + if (res != -1) + pr_debug("threads: %d -> %s\n", tid, thread_msg_tags[ack]); + else + pr_err("threads: failed to recv msg=%s from %d\n", + thread_msg_tags[ack], tid); + + return 0; +} + +static int record__stop_threads(struct record *rec, unsigned long *waking) +{ + int i, j, nr_thread_data = rec->nr_thread_data; + struct thread_data *thread_data = rec->thread_data; + + if (!record__threads_enabled(rec)) + return 0; + + for (i = 1; i < nr_thread_data; i++) + record__terminate_thread(&thread_data[i]); + + for (i = 0; i < nr_thread_data; i++) { + pr_debug("threads: %d : samples %lld, wakes %ld\n", + thread_data[i].tid, thread_data[i].samples, + thread_data[i].waking); + + rec->samples += thread_data[i].samples; + *waking += thread_data[i].waking; + for (j = 0; j < thread_data[i].nr_mmaps; j++) { + rec->session->bytes_transferred += thread_data[i].maps[j].bytes_transferred; + rec->session->bytes_compressed += thread_data[i].maps[j].bytes_compressed; + } + } + + return 0; +} + static int __cmd_record(struct record *rec, int argc, const char **argv) { int err; @@ -1903,7 +1957,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) if (record__open(rec) != 0) { err = -1; - goto out_child; + goto out_free_threads; } session->header.env.comp_mmap_len = session->evlist->core.mmap_len; @@ -2203,18 +2257,20 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } - if (!quiet) - fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); - if (target__none(&rec->opts.target)) record__synthesize_workload(rec, true); out_child: + record__stop_threads(rec, &waking); +out_free_threads: record__free_thread_data(rec); evlist__finalize_ctlfd(rec->evlist); record__mmap_read_all(rec, true); record__aio_mmap_read_sync(rec); + if (!quiet) + fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); + if (rec->session->bytes_transferred && rec->session->bytes_compressed) { ratio = (float)rec->session->bytes_transferred/(float)rec->session->bytes_compressed; session->header.env.comp_ratio = ratio + 0.5; -- 2.24.1