Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4223880pxf; Tue, 6 Apr 2021 10:47:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlfgMn5nwxinR8zZy6cI2EMVkKP5DgAmH5aiKgRZtHzTLbXJCR4Hb4F6L0acAX6wsUJB4W X-Received: by 2002:a17:906:168c:: with SMTP id s12mr7367173ejd.462.1617731266037; Tue, 06 Apr 2021 10:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617731266; cv=none; d=google.com; s=arc-20160816; b=jtrUYiiM1cJsXd8zNtKwMDp8fTQvQpYjbaZMmP74aSr4YJDYVRaB5Uwabb6M30F3gg 3+orljRDaC/RadDV1kf94qW9DfVbThfuR/w7F1Pg501PWADgrl0KCyxoiHhsGv6lqo2b Hz3TO1Tk2ERgxOHI0tHsa1lRFbmnhCa1em3z3q+GfmFXvgflLyo8C6r7kYi8IllletY7 UX0XbyKu0TQlOmIVmWyjWDxuLGYqt+uXz8tBgLnKKdsCcirymWkPAvOtRu9HZ20/CLlq hYavukLx8ALm9Jkui30Una2VwxjbI8LvP8YpjkygKcxAzyLKioM+Gn1s0kBk0U05k/Rn 3cQA== 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=fhauXe6H7946/FpsP0Z865zUcm94b1a4wfI+ckIBu7Q=; b=o4PM24JDG0taHcq9iF1K3yVZFbmET7DjX7Z7BXAIGExgiD17OjmLeKL3o/MVyDIpxU ssO//cw+U8FRpGXT9/me3fpaQC99HTTWkqadzoKhoxm2cOgu0uOlYkRb4pXFix5rwe9V prx09TQcgjn6s666h3fc2HAzgfMvk+oF7n1cD0HDYSla7EioRTuSCETJ4KT1ou9j2t+R K7XdpRMRNsk159klPBFX49kDLdhIiwV9+uZAL6DxoMRW8bI0az5EJCSLCUiVAA6Kl+RS f2PDjESXsZvd6T3SrJRW1vfowqw5ZP0p03aSlfWtsslIEhbmq2iTASB+j4i2WV0SxfnR 5XWQ== 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 ho20si17065155ejc.295.2021.04.06.10.47.20; Tue, 06 Apr 2021 10:47:46 -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 S244469AbhDFIpL (ORCPT + 99 others); Tue, 6 Apr 2021 04:45:11 -0400 Received: from mga02.intel.com ([134.134.136.20]:13152 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244417AbhDFIpK (ORCPT ); Tue, 6 Apr 2021 04:45:10 -0400 IronPort-SDR: lHG7cnUsRlPRyBca8alj83PDGKetGrNeb5HxMEHRYVO256dZBcZddIK1iXEtm+93ZMneF6okS/ GYnUHLWo48Iw== X-IronPort-AV: E=McAfee;i="6000,8403,9945"; a="180152156" X-IronPort-AV: E=Sophos;i="5.81,308,1610438400"; d="scan'208";a="180152156" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2021 01:45:03 -0700 IronPort-SDR: Dj6hVveqLK/PFJOSjVdTlEInJUKchM6ygtBa7FhhJ7pAH8Kx9OMRXXBIT0QrgLRHBn4r5KJgdE EoNAK+rDXz+w== X-IronPort-AV: E=Sophos;i="5.81,308,1610438400"; d="scan'208";a="421121773" Received: from abaydur-mobl1.ccr.corp.intel.com (HELO [10.249.228.164]) ([10.249.228.164]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2021 01:45:00 -0700 Subject: [PATCH v4 04/12] perf record: stop threads in the end of trace streaming From: "Bayduraev, Alexey V" To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexei Budankov , Alexander Antonov References: <6c15adcb-6a9d-320e-70b5-957c4c8b6ff2@linux.intel.com> Organization: Intel Corporation Message-ID: <3113338a-a17e-cc3e-2d1a-fb1b468d5dcd@linux.intel.com> Date: Tue, 6 Apr 2021 11:44:57 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <6c15adcb-6a9d-320e-70b5-957c4c8b6ff2@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB 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 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 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 ecb6bf33ed85..4612314853c1 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -110,6 +110,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; @@ -1820,6 +1830,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->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; @@ -1836,6 +1863,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