From patchwork Wed Feb 28 16:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Weilin" X-Patchwork-Id: 207919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3467030dyb; Wed, 28 Feb 2024 08:42:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+VruqveN9nBwD6BdNZ41k1Mb25feWPibSdVJQ1/Fr4n3LHPOVB9lUkZO6fMDmhKZEU7viI2nJkj+gxzr2IJvYIh8/Uw== X-Google-Smtp-Source: AGHT+IHaPmBs10+2IQtHQ4hpF5LAUS5OzIXL03k1KWl3wGjUS0xlBSr58De0js0+iSsCMWvcRdpK X-Received: by 2002:a05:6a21:1786:b0:19e:48b6:9c43 with SMTP id nx6-20020a056a21178600b0019e48b69c43mr5951821pzb.58.1709138540377; Wed, 28 Feb 2024 08:42:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709138540; cv=pass; d=google.com; s=arc-20160816; b=bEVp68KbaUd9wmggflCRGGP9ahAConohXwDAwhFEB25XA1obOb5jkl8PNXyexOKXDa Ml8ymxwz1r9JgOoFisbushGKKV89ZVHiAPrccaknFzWHb5Hly5pyAT2AI8EZw5PZ4U2r Hhkk0hyuInOhjph8agIjS9/l2zbf0py6VcFNMLB3lrxgrXHVxlFGEbewJvcsQudG2hN3 Cv542S511Evw2mcs0uL5kaPK9jcuCTvc6xkBJAVXZLX26+DhWVetyisa3I8AplGAVQRP KSStWO+frd8bgfITjjC+YVjDDOCFQmfAw+SdgNPeZWKftdIIMo2EOSTXqMG2loptHIZs JdBg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85337-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j73-20020a638b4c000000b00565db2812a0si7714143pge.60.2024.02.28.08.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 08:42:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85337-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85337-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6FFB3B29D4D for ; Wed, 28 Feb 2024 16:14:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A40B3FBA1; Wed, 28 Feb 2024 16:12:47 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792161654042722187 X-GMAIL-MSGID: 1792161654042722187 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)