Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2647564rbb; Wed, 28 Feb 2024 08:14:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUf1AOVHaJgKO3wUMfMBGtVja8hjna81f4ICMoVbM8E2WBg9mH4MsM+zvYsZwlmi9b4kos1ESrp12DKZxL3kxXLTY8veJgqvT4J+9m4fA== X-Google-Smtp-Source: AGHT+IG3pT142ls2yROZMAjFpFzV29qvexsea2hn5wvLo9spunQLcGTuGXwJCBzQQYSJcup0ySX/ X-Received: by 2002:a05:6871:522a:b0:21e:b7cc:5728 with SMTP id ht42-20020a056871522a00b0021eb7cc5728mr151388oac.30.1709136844015; Wed, 28 Feb 2024 08:14:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709136843; cv=pass; d=google.com; s=arc-20160816; b=QAm9qt+3VycyPbrWWXuTDJxHPSAWlvTA8Sb3F8vs8Sk2mjoNRPG6DmZFXSx44vjSf6 APyxWoFPL0I4mBnu8YDvOtwWoBJTqVyrEQwHvG/aDwaIDcunMu/ltxhpHr3M0+6Mfia1 i9NGYVqMSKaZbMwXdXTNuMRIdvJrpYUXv/i1RWtGwcYD0SaqiKtaeAzUhcz1sHOjFgbj OzzuUZHK6JwZ9/p1SeSKJlYXusO3mAZaNuTY0OurfNnnoY3B+vxaXXFlr9ssNhSXiepF DofSEZNcM+zzXKKV60LGV8ZgJi+jtWg6qKW5xSsAsl6LtQx4zQKUQm2tW029bnS/ZfO4 C6mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dWSbAfzmU6bQNmMufNiNY+/WoAM+WeQxF9zZJsC7byI=; fh=D8N1uhCLBRzbbRgEj9aMJ2/kVuNqnMf8W9VxSJOfqPA=; b=C9wuBafbBnLuwFm+zAE7EgD0iYWO8GA7xS0Byc/wY4SwNeT7xXQV1ySjQ3ZPYXMl/4 PFJiZf628Z3y+78egzQAtEFOPV2f6Q1CXlnnhCI1ZdWu1kbNtHbU+wztNvBuWauy/iYP hkMHa6php8x89yVc3xoGFcbUGn5nO1y+HwbW6YgDzoqJmJUkJvn78mASymCm+RlWq8MS WR4xX9yshFYAsIoswbkSrRr8h4U2S69Ibkl7YdBHg+ggNhL1DlPILs4TjvQLiSyN6eix +3gH21U03QZf9lcejTjO0/xfPhTa9g4B4n3/ufx3Ig42wjaD5kXAbLTVt6Yn1D+LSqVw ye8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OTzuCS1v; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85337-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e18-20020ac84912000000b0042e6182df5fsi9478283qtq.586.2024.02.28.08.14.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 08:14:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OTzuCS1v; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85337-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B19BE1C215E1 for ; Wed, 28 Feb 2024 16:14:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 436D115F323; Wed, 28 Feb 2024 16:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OTzuCS1v" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A409D15D5CF; Wed, 28 Feb 2024 16:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709136764; cv=none; b=NwxmKzYSh7TC7BChMNKW/q7BDjhBTyifLWWVf/1Fd4qARbmEsVjUCRad/DX8HXOsmYl1THVOFlgwDtW8jfFkn8NSfBRZ9EHGujVn+w1jSLMtn7iYYe3C/nWnUTUnAUyE/gArKuQtgzCWVAwy6Y9kwgk4y1d2wnrlbG1tUQq4Y5k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709136764; c=relaxed/simple; bh=WvnrJC58zvSrxJ8X4Aj5CwSK0eSjYIRrEgdXF3P5wG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kBuOy2WSZnzN/ba2xGx1te7XLZnkSd/oNMblxSTlMq0vJ57steFmF1EVUlXRBqexohZdJEwEFDm61HxIlwcCw5aoQJl1am7KOYGPDOqF0rUEfkKH+u70F5mqxEMRA2A/bZJx66LT2F9uRzKBCsiWsZBb6YABIB5R8Xwc2jQa0lg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OTzuCS1v; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709136762; x=1740672762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WvnrJC58zvSrxJ8X4Aj5CwSK0eSjYIRrEgdXF3P5wG4=; b=OTzuCS1vASo1Ri5cT4PvjoHYWnday7PhiJCE+QdKM/yV0kUXxeH5xorf BCLXZKVtQh3IqQsVRP/hJgqJUvuduKfkJvOi8q/4rgbNUXr3fJTy+BWbP AHj2ViOaN5OdJ158iAAhS5xpEUSZpp0aEeI3s3/XqAryCe9xNZM7egkvB R0GBTOVjGW6P8OB3fKpNZ6WTpIq9swBKE9VY7tAn6ScJ9CQlV/xMvmA+Q tYdF0DYu9zg9fpxy5Rn/Q+bOtayWioU0KE3DuAef5U1oipiX4UuZgXDbW Tus665eOQTEQsTidQezdRiRPg28qwoRVbmnZfZVE6Hr6sxQtyMyIgYxRu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="14185460" X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="14185460" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 08:12:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,190,1705392000"; d="scan'208";a="7418101" Received: from fl31ca102ks0602.deacluster.intel.com (HELO gnr-bkc.deacluster.intel.com) ([10.75.133.163]) by orviesa010.jf.intel.com with ESMTP; 28 Feb 2024 08:12:37 -0800 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers Subject: [RFC PATCH v2 4/6] perf stat: Create another thread for sample data processing Date: Wed, 28 Feb 2024 11:12:25 -0500 Message-ID: <20240228161227.484886-5-weilin.wang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240228161227.484886-1-weilin.wang@intel.com> References: <20240228161227.484886-1-weilin.wang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Weilin Wang Another thread is required to synchronize between perf stat and perf record when we pass data through pipe. Signed-off-by: Weilin Wang --- tools/perf/builtin-stat.c | 58 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 3e5865572266..2372175d3408 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -777,7 +777,6 @@ static int process_sample_event(struct perf_tool *tool, const char *evname; struct tpebs_retire_lat *t; - pr_debug("entering function %s\n ", __func__); evname = evsel__name(evsel); pr_debug("[%03d] ", sample->cpu); @@ -808,9 +807,9 @@ static int process_feature_event(struct perf_session *session, return 0; } -static int __cmd_script(struct child_process *cmd __maybe_unused) +static void *__cmd_script(void *arg __maybe_unused) { - int err = 0; + struct child_process *cmd = arg; struct perf_session *session; struct perf_data data = { .mode = PERF_DATA_MODE_READ, @@ -826,29 +825,15 @@ static int __cmd_script(struct child_process *cmd __maybe_unused) .attr = perf_event__process_attr, }, }; - struct tpebs_event *e; - - list_for_each_entry(e, &stat_config.tpebs_events, nd) { - struct tpebs_retire_lat *new = malloc(sizeof(struct tpebs_retire_lat)); - - if (!new) - return -1; - new->name = strdup(e->name); - new->tpebs_name = strdup(e->tpebs_name); - new->count = 0; - new->sum = 0; - list_add_tail(&new->nd, &stat_config.tpebs_results); - } - kill(cmd->pid, SIGTERM); session = perf_session__new(&data, &script.tool); if (IS_ERR(session)) - return PTR_ERR(session); + return NULL; script.session = session; - err = perf_session__process_events(session); + perf_session__process_events(session); perf_session__delete(session); - return err; + return NULL; } static int __run_perf_stat(int argc, const char **argv, int run_idx) @@ -868,15 +853,37 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) int err; bool second_pass = false; struct child_process cmd; + pthread_t thread_script; //Prepare perf record for sampling event retire_latency before fork and prepare workload if (stat_config.tpebs_event_size > 0) { int ret; + struct tpebs_event *e; pr_debug("perf stat pid = %d\n", getpid()); ret = prepare_perf_record(&cmd); if (ret) return ret; + + list_for_each_entry(e, &stat_config.tpebs_events, nd) { + struct tpebs_retire_lat *new = malloc(sizeof(struct tpebs_retire_lat)); + + if (!new) + return -1; + new->name = strdup(e->name); + new->tpebs_name = strdup(e->tpebs_name); + new->count = 0; + new->sum = 0; + list_add_tail(&new->nd, &stat_config.tpebs_results); + } + + if (pthread_create(&thread_script, NULL, __cmd_script, &cmd)) { + kill(cmd.pid, SIGTERM); + close(cmd.out); + pr_err("Could not create thread to process sample data.\n"); + return -1; + } + sleep(2); } if (forks) { @@ -1087,12 +1094,15 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) if (stat_config.tpebs_event_size > 0) { int ret; - pr_debug("pid = %d\n", getpid()); - pr_debug("cmd.pid = %d\n", cmd.pid); + pr_debug("Workload finished, finishing record\n"); + pr_debug("Perf stat pid = %d, Perf record pid = %d\n", getpid(), cmd.pid); - ret = __cmd_script(&cmd); + kill(cmd.pid, SIGTERM); + pthread_join(thread_script, NULL); close(cmd.out); - pr_debug("%d\n", ret); + ret = finish_command(&cmd); + if (ret != -ERR_RUN_COMMAND_WAITPID_SIGNAL) + return ret; } if (stat_config.walltime_run_table) -- 2.43.0