Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3039655pxb; Mon, 16 Nov 2020 04:19:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBNpAGtsdZ0KLewza+hmP6M4wOCt3GxunkMaBxTG/bb+rZeJ8WXKwEDjzHobAu+6CUccy5 X-Received: by 2002:a17:906:7698:: with SMTP id o24mr13699733ejm.447.1605529197401; Mon, 16 Nov 2020 04:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605529197; cv=none; d=google.com; s=arc-20160816; b=BXENrjHjAUVXXmaa1FkdpfvKzCze+6sxdIWTHoK8DfNXx7GdHEuYwNkHSZxyZSBfjY lTivUo0pvO0DO3NmdA3GjnljKuC5yv7Ubxc9msxBjLgJmUB1hSH9NKh7lk1A5Eownpb+ m7uul+0exO7PQQugcz9cKWNXcTAt3D5PCpJP5s+39aO5LQP8YfkbSa/BYweiGjSHDYC0 0V0qJwzZaYasaE26MfVMXBudrW35tJUQFuUYrb9xbzEBXUSFO8L0z9/s7r3B9LWpL0DR P9XrYSG5VuxP38nYsgp7wMOuqJRIeXFJv8whc3/NYw1BHDOg1Wy4o/xn+TAgGufuxzuC gzoQ== 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=2Uqw5HEQQwSq1E6+tl9L8UeT1SIva5N2XnDWnLjxVhQ=; b=gdw8sxiDOQlnX915emXjojBVIt9gS1reG/NlAosLZt0CzT9ubcnK/MJ/LB/uMdY/us Z3kcUhkm1Bq+20DgZzEdV3jlavo6tOrEvAHvxx6hfNfEN3XL9eT+FmptMhMyCWI3f1wH XjFpJzE7OQ54CPzla3thvNMJyHlRVUYsBierhL61LBLmZUcVBncmmzG3GM+ryVgTGrch YgxaN57O33yP3E8AdOSHNLr6qALjRHeONLdJABUc1FUeI5PvexsaNDkIw1Qh5TGTSvRE vU9ovuvb1QqmsihM8lOtuZEGl0E+6hL8Szzeo4zblQdHWsUwTEnB8qSxNsAsndDcSsj1 jS0w== 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 r9si11931767edy.536.2020.11.16.04.19.32; Mon, 16 Nov 2020 04:19:57 -0800 (PST) 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 S1729963AbgKPMRU (ORCPT + 99 others); Mon, 16 Nov 2020 07:17:20 -0500 Received: from mga01.intel.com ([192.55.52.88]:15646 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727895AbgKPMRU (ORCPT ); Mon, 16 Nov 2020 07:17:20 -0500 IronPort-SDR: 6oq0t1bYNpKeW4lYCS5jkv7/YPgOOgOyDiG9F5pLuje8mK619CwZgVAaVW81RbqMn1K5TeYgeR MWpQI4UpZsrw== X-IronPort-AV: E=McAfee;i="6000,8403,9806"; a="188780176" X-IronPort-AV: E=Sophos;i="5.77,482,1596524400"; d="scan'208";a="188780176" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2020 04:17:19 -0800 IronPort-SDR: Whyn+cS//VO3c5R3MkkCVwvD9BJU6Z2pjXR3H+zOz3Q+y1CEPpLJHO42XMlzRklf5COYntBYYC ZrhjaeCNWDsg== X-IronPort-AV: E=Sophos;i="5.77,482,1596524400"; d="scan'208";a="543582898" Received: from abudanko-mobl.ccr.corp.intel.com (HELO [10.249.228.209]) ([10.249.228.209]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2020 04:17:16 -0800 Subject: [PATCH v3 04/12] perf record: stop threads in the end of trace streaming From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexey Bayduraev , Alexander Antonov References: <7d197a2d-56e2-896d-bf96-6de0a4db1fb8@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Mon, 16 Nov 2020 15:17:14 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <7d197a2d-56e2-896d-bf96-6de0a4db1fb8@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 Signal thread to terminate by closing write fd of comm.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. Signed-off-by: Alexey Budankov --- 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 e41e1cd90168..d0b528cde68b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -111,6 +111,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; @@ -1818,6 +1828,23 @@ 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__UNDEFINED; + 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]: 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; @@ -1834,6 +1861,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.24.1