Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3374423pxy; Tue, 4 May 2021 00:06:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLl7JII2fNIA5ai3Lx+unhNkG0mSOknYlyrtDN3Q1QpFRibqXWlj3sVe3IVPPXRcj7XC7x X-Received: by 2002:a17:902:7b92:b029:eb:6fc0:39e6 with SMTP id w18-20020a1709027b92b02900eb6fc039e6mr24316262pll.83.1620111997718; Tue, 04 May 2021 00:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620111997; cv=none; d=google.com; s=arc-20160816; b=zKXh9TaD4Eyzzk5N9vOn44kOscRVo7F87lfWIcD6uzNn4WDkmSvKGCtBY1pq4bgccR XwYQ+2PkXDhNkLgszvw2bZzya9s1r6M13vEKEonHN6NY7ipqYWFFrXh4KRVWg93IgOv6 OIWQB1bWbRCsR7+cpchAv9ngpvUZSeT5PkevR06IRw33LBR3/ejL7lloJ8xaRIzkHhqm VWAeoYVfenAvSqtbpfB1mQT7HX4CfTn2buwZtFpdQ1+QIDWcIYNQd+HB7chAKjwwCs7l S+hIuaDgktJ4aeBZmI6rG6YNAAtVqUWi2rpJujQFaSLNH9HKoBUFd329mDkV33odrMBK i6Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=1S5GXcgN2Iw7kUfNwy4z1EBfNMbK64ITTvA4JzIeUP0=; b=K77j7bmMBC6dT/qyUfVoCkvnkVcr45gCh9Bb6QNNWIlme+PR1jYsjWD2V/7fepuGhR Pw/ZgO9sWi1YV+6CbRVN1xPZOARe1+7p10R/ocp+LeetJ9fhDRmH7TbWBuONcRUyR1tP ofq2jHK43zcL/3swb31hgliqv8izX48MRBSEtyr5ASWUdswpA4MAngnNgvFK8Xs6ySty SBbrKfx+aXwnVh+To8WbeCqBE6zfQ3HcX59jPfiZ9NBwuXJTgs4DUEJ7Daos8/f/X0xh X/vHwjAuwAdm+BaGfs0r5YNyTLhnFoSDUqrtSi4+Kq3lJ5Cs6xKp0ZNWHTcyz3LLAmQp uY2g== 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 ay20si2278846pjb.153.2021.05.04.00.06.12; Tue, 04 May 2021 00:06:37 -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 S229976AbhEDHGR (ORCPT + 99 others); Tue, 4 May 2021 03:06:17 -0400 Received: from mga11.intel.com ([192.55.52.93]:41320 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbhEDHGQ (ORCPT ); Tue, 4 May 2021 03:06:16 -0400 IronPort-SDR: /FXrErKyn0C9T1+rKy2aj28n2lhBC96AWLxvLoAIkvWtxXyGIZGOJ/UQDfg0ZC/zmPXAF7F7UG Q/p3S2xTfguA== X-IronPort-AV: E=McAfee;i="6200,9189,9973"; a="194779366" X-IronPort-AV: E=Sophos;i="5.82,271,1613462400"; d="scan'208";a="194779366" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 00:05:22 -0700 IronPort-SDR: NlUyyctx4TgWL5ZIiYUGyle3xkmBOkM05P2lonaz7jQzk/MQzrulMX5z2mD4QdgSJreZSG6iPm UOqrtPCqJYVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,271,1613462400"; d="scan'208";a="450895289" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga004.fm.intel.com with ESMTP; 04 May 2021 00:05:17 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov Subject: [PATCH v5 04/20] perf record: stop threads in the end of trace streaming Date: Tue, 4 May 2021 10:04:39 +0300 Message-Id: <4c4ae43379284208aaacd6dc1b7f166760cad740.1619781188.git.alexey.v.bayduraev@linux.intel.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signal thread to terminate by closing write fd of msg pipe. Receive THREAD_MSG__READY message as the confirmation of the thread's termination. Stop threads created for parallel trace streaming prior their stats processing. Acked-by: Andi Kleen Signed-off-by: Alexey Bayduraev --- tools/perf/builtin-record.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 2a3dac894aa3..52703eceb47f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -112,6 +112,16 @@ struct thread_data { static __thread struct thread_data *thread; +enum thread_msg { + THREAD_MSG__UNDEFINED = 0, + THREAD_MSG__READY, + THREAD_MSG__MAX, +}; + +static const char *thread_msg_tags[THREAD_MSG__MAX] = { + "UNDEFINED", "READY" +}; + struct record { struct perf_tool tool; struct record_opts opts; @@ -1851,6 +1861,23 @@ static void record__uniquify_name(struct record *rec) } } +static int record__terminate_thread(struct thread_data *thread_data) +{ + int res; + enum thread_msg ack = THREAD_MSG__UNDEFINED; + pid_t tid = thread_data->tid; + + close(thread_data->pipes.msg[1]); + res = read(thread_data->pipes.ack[0], &ack, sizeof(ack)); + if (res != -1) + pr_debug2("threads[%d]: sent %s\n", tid, thread_msg_tags[ack]); + else + pr_err("threads[%d]: failed to recv msg=%s from tid=%d\n", + thread->tid, thread_msg_tags[ack], tid); + + return 0; +} + static int record__start_threads(struct record *rec) { struct thread_data *thread_data = rec->thread_data; @@ -1867,6 +1894,9 @@ static int record__stop_threads(struct record *rec, unsigned long *waking) int t; struct thread_data *thread_data = rec->thread_data; + for (t = 1; t < rec->nr_threads; t++) + record__terminate_thread(&thread_data[t]); + for (t = 0; t < rec->nr_threads; t++) { rec->samples += thread_data[t].samples; *waking += thread_data[t].waking; -- 2.19.0