Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp437065pxv; Wed, 30 Jun 2021 08:57:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe25hAsgrwSQNVuS7c5G4zEEsHz53DWTOKXAivNVc4b8ycWpxol8HYFuvq8jukOpYhXaL+ X-Received: by 2002:a17:907:3f29:: with SMTP id hq41mr35937463ejc.101.1625068675627; Wed, 30 Jun 2021 08:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625068675; cv=none; d=google.com; s=arc-20160816; b=FOaeBoN/5WBa6RNRykPUAW1+s5MQoxcngkDqA00ELPBIBVpKWyNXmCln9lmJR4kgiA gA0235wkpntFJP028pHkcyGG/m5XlpwoA4865+S4702KBrWAdGDB9tit2PHencelKo6a 2IlHATABR15oBxlJ01zZnZJuWqbfa7AgmigLyrygvMZXlG14MbfsWpExiSwCJIkuwauQ fGJWzjmWONaBktR6FlgKJZ4DeTSBTz2lcbSLe1Ly+ywjV7q1DqFS56EpFmshQe0kaYXv sDUwASVjT+GgIy8c1hwhljPgdueAqXf6lnUNy05xzhpSMv/o3QPOCzWQRquu95MOikMH mxNw== 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=+7IWPzWG9AXHv888kq8rN6rhnTunRgnKOIzstfRXoxg=; b=TzZpBSEDKPvpyDeO1AADnerj11QL7JhTbBtbNWxcySYsu7htjvI0v2haCnS4CHFg7v YBjEK2TruGC/iKcqDVIxGj0+d1rZ6xUtBuXrvi7WOcbk2UhRuf0lqgoUD6JTIJG0qdE0 PanK9q7Qk2kFMmJJItQTpF1pbuKsThmiaom37xYd4TED94Xvk6rxoAGKdmAo1Ia8Hxop 03HOgbqYm8LmEOywX703uOYsp9YdytK7gHrUC19tGurH8YyoADESxUeolD/i9W9lDPn1 NiA8dCXWKRHPavhbLHt3+VBR+y6kgG1x3ZZwRdKLJJJf69RQp9kM0KF/flahI1bt8R62 vIxw== 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 bx11si20177799edb.263.2021.06.30.08.57.31; Wed, 30 Jun 2021 08:57:55 -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 S235962AbhF3P6C (ORCPT + 99 others); Wed, 30 Jun 2021 11:58:02 -0400 Received: from mga01.intel.com ([192.55.52.88]:3954 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235939AbhF3P6B (ORCPT ); Wed, 30 Jun 2021 11:58:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="230015588" X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="230015588" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 08:55:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="559099589" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga001.fm.intel.com with ESMTP; 30 Jun 2021 08:55:16 -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 v8 04/22] perf record: Stop threads in the end of trace streaming Date: Wed, 30 Jun 2021 18:54:43 +0300 Message-Id: <0140e468bf81b3c10f9780473a49804f820a7023.1625065643.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 Acked-by: Namhyung Kim 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 3935c0fabe01..82a21da2af16 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; @@ -1857,6 +1867,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; @@ -1873,6 +1900,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