Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1505236pxv; Fri, 2 Jul 2021 05:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNmYfvaxO+wIXh0eUt+EgIl0dfT5NCL6iT3Ar2Q//ZULN9Da1ICkY4zUoP/IpacNm3bUb3 X-Received: by 2002:a17:906:4fc6:: with SMTP id i6mr5102649ejw.472.1625229284279; Fri, 02 Jul 2021 05:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625229284; cv=none; d=google.com; s=arc-20160816; b=uVlawggqHL5Gllg7wNq37Wi3jnG5/EURuUgLfrlycjYVlwyGHIy4zFPhqTX7K8Wobz hH4gtsBl3nsE/DKvZapS76yCO2CiDCFE8OhuhM3mZTaHD1yGwh9rpSsWDv155jGuDp1u xI+qFUU2MaYReniCMvgTvddqPam8yFllIfcFW0ndwdz247x7iV7W35V8FEBUlaBh6/Zx CSeLk/99ox4vTc6b9LJqNFmA9TC/0ZWzdAqrWHJ1g77z658MccAxiHJ9NjRL/O0YfICa ZSZsJ4MVQQ/67AUwCly23YSVMTcRYJhE5RcXA4qfOu3FQ/HyEqIyiFXoQIjNaIXKXgT6 Ln6g== 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; bh=0xUKK+WMo0xfjtuqDduhLw8lbEytnQtR81Hhk/c4CuU=; b=f0gAxjvupTuHyJdB3ijqF3pamqmHD5WRbNDua+5OGVOXpnLEZRFHvxaO3XBIws4oOv kvmmQBQ+BPK2aOi+iW3COH6Lu5lQpJHpPQ6nQYQt7chzsqzWrC5KdEBzug4GNucwxnzl b9bX2TcWr8UgnyDg+IjTTNUFibCSHwoWKGSSkXpjGpY+7ubPnzp4IqdvfD7yhYK7ZnkH 6gCoZvclNLKZlMn3dNJc0mpn45gX2kA1isHd7wQoJ9e4M88hJVyuLHpruRz2ikEpV+TC Cr31ZgKcb4ZOR9aDL1iBzdsgylExBjVYUvR4n1n4b+y/JJ+m7hI8Zhp91HtYXeba1Tpf PSXQ== 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 f22si3071893edf.183.2021.07.02.05.34.19; Fri, 02 Jul 2021 05:34:44 -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 S232305AbhGBMfe (ORCPT + 99 others); Fri, 2 Jul 2021 08:35:34 -0400 Received: from mga01.intel.com ([192.55.52.88]:3459 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232227AbhGBMfa (ORCPT ); Fri, 2 Jul 2021 08:35:30 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="230397106" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="230397106" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 05:32:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642660219" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2021 05:32:52 -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 , Riccardo Mancini Subject: [PATCH v9 06/24] perf record: Stop threads in the end of trace streaming Date: Fri, 2 Jul 2021 15:32:14 +0300 Message-Id: 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 Acked-by: Namhyung Kim Signed-off-by: Alexey Bayduraev --- tools/perf/builtin-record.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 95b6c1c0df44..62184af9ba62 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -112,6 +112,16 @@ struct record_thread { static __thread struct record_thread *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; @@ -1916,6 +1926,24 @@ static void record__uniquify_name(struct record *rec) } } +static int record__terminate_thread(struct record_thread *thread_data) +{ + int res; + enum thread_msg ack = THREAD_MSG__UNDEFINED; + pid_t tid = thread_data->tid; + + close(thread_data->pipes.msg[1]); + thread_data->pipes.msg[1] = -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 record_thread *thread_data = rec->thread_data; @@ -1932,6 +1960,9 @@ static int record__stop_threads(struct record *rec, unsigned long *waking) int t; struct record_thread *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