Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3373497pxb; Mon, 17 Jan 2022 18:56:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhQo6MIjBaN4r1zXYm2KoWZRbllc7tDkO9WrbNz/0DGO9qPiWjVoRen0/zbUb4UNKxdORP X-Received: by 2002:a17:902:b7c6:b0:14a:b17e:4088 with SMTP id v6-20020a170902b7c600b0014ab17e4088mr9698763plz.24.1642474618443; Mon, 17 Jan 2022 18:56:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642474618; cv=none; d=google.com; s=arc-20160816; b=H+YUXTIusKhpgfEH0CJT6Ice/oH2CZ5tr8EUrNjzZIq5qNex2LDLIrbUkjPAZwKTks JRyNK1ZwNCR17tOTQ0mvKkrXPI38FpMwx2k8Rn+p5zbBjptKjeub3QDHm9j7sHB2+Y23 9SJGO7j2wufjlaCeZ8qIbbXq2oqvxh/C7vTyJID4Ebk2enbxVJJkceeyyUYSzsyuRhX8 jT1Vj19tye7d6e/jrYxqe4RcDiQLWj8S3DfQpvPXJg9nDQQakvY6vbXbIlbckXx7WfiW tvXvJwTYpoz+te80XJ09PGgGBP+GhVtKDYmupr0YFTQyMoU4xYcg07pbKrvd+s9mB3f7 MYgg== 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 :dkim-signature; bh=Ma9YmXGygPID+wIH3FoWKAMJ7wM4il5cAH/w2GVA99U=; b=kL4FzNvgkYxAyTUVZRS8iFA90rrvWdm3ZY0hryWcPAGhdp/0h19Jb/1BovAMPWRXQI KR1C3tiJS8OSou0bs4+fbPKRO05Vbl7oNgYbgRCL1y2mcxcvClM1Z/Srd2fX+cGpx4xV eOxk7N3GQqZt3e5vdlmmcp2gFMPTPZMTUtfdG4rskbQijMtoeLXsb2CsjQUk9Oo50tU8 9Q4zyR2ug1iIflmzMI7NBrUfiN17NGKTAYrNTCsguIpvkV4z8yHlJLzmsFPcA8vWhiGX hyO8RskySumx7EcjxmgBEWf3Ej5PP18CqtYpVUCG3Dy2BBIKHzyEHjY5c6yPO7g3wPon pG0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QUaQ9daO; 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=pass (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 v4si14921050pfu.21.2022.01.17.18.56.44; Mon, 17 Jan 2022 18:56:58 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=QUaQ9daO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242735AbiAQSfH (ORCPT + 99 others); Mon, 17 Jan 2022 13:35:07 -0500 Received: from mga12.intel.com ([192.55.52.136]:48606 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242714AbiAQSfB (ORCPT ); Mon, 17 Jan 2022 13:35:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642444501; x=1673980501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0aHYD73piCArIhy7L3X52iWfwqLV+CmuHF+Tctl2QoI=; b=QUaQ9daO8cJsEgvUfNHYCVRrB/9zwgNLD8B16sgkkYsPf2psVTPBhl4n 1H0rdojQk6q4GAAVXneBYfZWyELqal4ZgvwoyBBGxKBtEXksHhq1QF6Ys QpsKq3GNyH1PIAJiNGHUTkPd0pbSWcjBqWLjAc61J0VYdB2oTxK+N6xWq S9Ry+UVjS3ZUGT29QGu5bBZ6Am59a2LM5pEohkBWKCg/lO/T3nuePnddC E7u522wRsmX2ZJKPdHifEAaaP9jR51f7rxa0/UNHUXvBVL+Cwajm6C6LI qp+TCH3bFPTzqF1S4lF3t+U9b73uveL5t+OqcdmJdFwxSbahnymGDKJQe w==; X-IronPort-AV: E=McAfee;i="6200,9189,10229"; a="224656000" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="224656000" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 10:35:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="492434227" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga002.jf.intel.com with ESMTP; 17 Jan 2022 10:34:57 -0800 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 v13 06/16] perf record: Stop threads in the end of trace streaming Date: Mon, 17 Jan 2022 21:34:26 +0300 Message-Id: <55ef8cc5ec3a96360660d9dc1763573225325f8c.1642440724.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 Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini 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 163d261dd293..0e65b80927b7 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -114,6 +114,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; @@ -1886,6 +1896,24 @@ static void record__uniquify_name(struct record *rec) } } +static int record__terminate_thread(struct record_thread *thread_data) +{ + int err; + 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; + err = read(thread_data->pipes.ack[0], &ack, sizeof(ack)); + if (err > 0) + pr_debug2("threads[%d]: sent %s\n", tid, thread_msg_tags[ack]); + else + pr_warning("threads[%d]: failed to receive termination notification from %d\n", + thread->tid, tid); + + return 0; +} + static int record__start_threads(struct record *rec) { struct record_thread *thread_data = rec->thread_data; @@ -1902,6 +1930,9 @@ static int record__stop_threads(struct record *rec) 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; -- 2.19.0