Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5413128pxj; Wed, 26 May 2021 09:55:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1xC1BgLVDBuofHD4Y1mXFtwHjgdM2d7HhuMMTdD7csZTzCoPAW1SM0QmpkHo9kHDMmHaH X-Received: by 2002:a17:907:961e:: with SMTP id gb30mr35933851ejc.58.1622048136720; Wed, 26 May 2021 09:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622048136; cv=none; d=google.com; s=arc-20160816; b=V2PqnxjP3pME/d9IjVZ9fH+dWXXbDbOD1pRudZO38qJBvPzrXaRndlwvIV71p0WIuW YVT/qdKbhBy0wkKBAAct3T6TUOnFl9tI5LNSnljhwNfZkY/HP/PN9Sd6biYT9/9BqVi9 2PT/9eIzba25KBA8U+o1QsqPUuMUdelIu76OJZixmt1YAcV7r3OxJsziB8kHcYNcey6S 6css1lZz1CoQC72iE6ZLGeCRukIVzVLKIJay9Sa/0cw7k86eLumatXJLvmlcTBm4d4uq cXkRWS0sRrRBOtmYTX1yTl7tzLbwOKI3XbFT4iyWNAt1uizUjg+iaT9f4JEq9AaCmJYX mVfQ== 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 :ironport-sdr:ironport-sdr; bh=ZFMGPQbfXd7RjzV5f7JW/uGItmoMoH36/au0VS2E/Kg=; b=kCLcBozTTdI5+/DGp7QO7FtA4Rs+K8hwq/yHRG2n84z6aEWnVCN8hcB5CcIfX6xVqN kuGElfyhZiYl7S7hNgbmODkFBjgfo8ksu+6NQUtAH36sfOYXrTk038hn0W79AeObgRaB Iv0B7G5V24TVYyOt5g/xca0bbc9nAaqicyJhI61M69r9MNyGWmeV85oC47nejJG8SOOx sunCVrxzoTRBYbNjCORFQ5owfhl5qyg2wKuE1olanavJh6B3G03UC3sgGq5dEOuhWE2Q 0D4mhqyKpaVm89L10hXKfCiFcEj268DCrd4b2Bn9vQLKrzrLMdI0EEraDjRGZ+DfRksQ 0enA== 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 m23si7854059ejr.199.2021.05.26.09.55.00; Wed, 26 May 2021 09:55:36 -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 S234304AbhEZKzQ (ORCPT + 99 others); Wed, 26 May 2021 06:55:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:1593 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234273AbhEZKzB (ORCPT ); Wed, 26 May 2021 06:55:01 -0400 IronPort-SDR: nu8TuupwOdLqFpZKLh3lc0d2pffiGwxAX26jjdguagknYrdFVBtXZVWvt5Zmxveg7NIRY5g0RB G1GaFoMq8Y8A== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="189556414" X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="189556414" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 03:53:29 -0700 IronPort-SDR: 0XYFYr3CVloHG9r2cwknKWt6yjhugJqDcGEqqY0noM/m8X19N83TbBzPWlC9y4qcOtNGT+K8Kb dA8nu8Lijgvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="436079167" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga007.jf.intel.com with ESMTP; 26 May 2021 03:53:27 -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 Subject: [PATCH v6 04/20] perf record: Stop threads in the end of trace streaming Date: Wed, 26 May 2021 13:52:57 +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 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 2027334d70bc..838c1f779849 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