Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2831473pxv; Mon, 12 Jul 2021 03:02:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4u/w6DCLXBqdVoaYmqoXBvgqaGuyVpriixm36K5heCRYw8dvg1TOIRjPChIEgXSMFFl5L X-Received: by 2002:aa7:d353:: with SMTP id m19mr26697131edr.162.1626084151439; Mon, 12 Jul 2021 03:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084151; cv=none; d=google.com; s=arc-20160816; b=AwfFqRzDLTJf10HIjtdHV26F1iVbSiLrOdME8YIkblWWMdhCOvyj5HlUwawcxtLBS/ eGQUgI+9iTr1frn2TPLf44xzSrlknMA6ySdXu6rUvL+7KSgcWBisptpASqKuMmu4HZ// rtI4AOXW9xHHqbXTBn49VlW66NC66lJB6O2o/C/wA06mSdLINMEDxVVs/UZ2C3J7hepD tVGOFR9bDY7snrVlZsP0FDiWzS5ccb4AXwxPFrfbdNSzzBRoCpI1cveKYnW3/g9voY43 VR3O+gwq8iXI7MvtKFtwhItAKS43ESqVmydKiaM/s7e8IEtAWE4Mm2na+9v/qQJl1qpk GH+g== 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=88Pv1sj7hRKHmspKUFJI5+KEU9ibSGisAmik6VpEAWc=; b=qOJVeUk/XrPthzARt/pSfuvP3UHQd2f16ywEqDDWe8mwi6TcrwhfJWxBZCSJyieKdS VgPLWvkw7ncqkmit9JYxiF8yOqEcKVlVLyVtWGQUG0WHbLFTrBMHcY4uYXtEzuwbNSMV 8Bmrbpzk2dp+cZKI0jq3p1+KDA+fv84FUIctHCfk1ks3Sf4TEv6R6BvoAgkxiQcryOpj YTQEDEaVMyUPGddBiu3c0OK07RmPILNCE8UO4Z5H7V4GYjh34ebrTbSEwa04euyLEwdn si4flXsYZQZuONwsLeDKRlIbzGJc0Y2LZgZTuOcOZSL94tbbrx5F7o/aoEjqzBpOAsFR vc2g== 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 y12si1990582edt.124.2021.07.12.03.02.07; Mon, 12 Jul 2021 03:02:31 -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 S245338AbhGLHLi (ORCPT + 99 others); Mon, 12 Jul 2021 03:11:38 -0400 Received: from mga18.intel.com ([134.134.136.126]:45864 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239229AbhGLGtd (ORCPT ); Mon, 12 Jul 2021 02:49:33 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10042"; a="197204387" X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="197204387" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2021 23:46:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="491916152" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jul 2021 23:46:42 -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 v10 06/24] perf record: Stop threads in the end of trace streaming Date: Mon, 12 Jul 2021 09:46:06 +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 dfc5db24e037..2f907186468a 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; @@ -1918,6 +1928,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; @@ -1934,6 +1962,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