Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp902533lqh; Thu, 28 Mar 2024 23:50:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUasVXXJpsTFfVgDl8Rnq0TF0PjFdC2936tnJC90AlqsLTKea4etwvPJna72j7fYTXMAEXES1/DE+nBsQBLqnGbQ1NNRZDAdFgT0mkarw== X-Google-Smtp-Source: AGHT+IHCedlHvVP13YM4zyqUWuULsTqS8pPkPFDxtp3f6lJhKnkke4q5of8jV21Pr2xyI23sLxS4 X-Received: by 2002:a05:6a00:1790:b0:6e6:f9b8:38eb with SMTP id s16-20020a056a00179000b006e6f9b838ebmr1613915pfg.21.1711695045081; Thu, 28 Mar 2024 23:50:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711695045; cv=pass; d=google.com; s=arc-20160816; b=eAxm1rwML2cIWLsb1FSZ4hPdVV/CnhfT2rhj+Sd45OQbhojkSB393wuXtiFRdDmsY6 HPKsW3AnfNQyu2d/x2xzEHA3Jp9JZi5MpHL754oy7pqLAZuwmJN1ljAvla3DKTjRUpWp WKwASfDawgTB0FeS3SUXVuj1wFTmVekVE3TwlXSbii74ILbFUXgbYorw5YIsUm8gmyR4 aYTNmwFeaxzh0vFgV34saP2xNUJna4y75B1znkPKLtpvPe+6Q6S9DaH5GTgbII1Ar6pG 302c8hEzsL2r5PXDi/0LhAjja1utyMkbGW80OF9hkPBgezEExIuZFhcfy1Dprm+gMjzw ijHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=hKxkF5DycsiIenidpZ8HuGYDWfU4JArm5xr/R0Y9MYk=; fh=1Bs2MINNIDaeZJC/Y3jlJRYEPLWNdG5vqeN7Ckm8zs4=; b=j1YjR8TAlG5gFLpqUu7nUSg0gInC7FCshtg57pjbRFfW0lJsJ3dtFEzkPJKUt5AZyH P2XkBm9f5Oe8Yf3zeOwGnFMgJf8Kzic666C9JZlqujNpskC1lMLH7gSvdaGceBc6aKRW IF5u9J1rrVo2Qz4eN4fi8SLwc5HJRV7+z+7mMkk8MTodDkM2L5nc23BDO1t26nOMxsET v8XZ3NeZDpIGtUXBswRw4kCLVLfY5AxzEfFH/7fc3+JYuZF0jCoCGf1dZJ4TiihIhJBr +vpRiQ5yk+XKYoA6/GsjoXTiEW6r6JSfa8z6tMffTbpgTQEcnPgQrcjwQzD7R2HdQ8n0 yP8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-124209-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124209-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gx3-20020a056a001e0300b006e6f6dd1735si2999725pfb.371.2024.03.28.23.50.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 23:50:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124209-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-124209-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124209-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 BD33EB23B7A for ; Fri, 29 Mar 2024 06:47:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E7063C48D; Fri, 29 Mar 2024 06:47:43 +0000 (UTC) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2954D3BB20; Fri, 29 Mar 2024 06:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711694862; cv=none; b=kCgRRfEYkeO5Jcz4bQFmG6coSJ+T3dvsOruQx2C61Nb1HWhBk6KKnOueuAGwJPInPpr//qj/QkOadIzwSj5qbPwOQSP3g77HW+qgGbBlYgXhGlqfOhmEeo9nyWUKOgMWDW9xpONe0FANc7U8o4MejdAM2yNNGWLvkR3yCB2pA3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711694862; c=relaxed/simple; bh=izFK5XYkRZKa9ZCzV4opit9b3Ca7NJrbNYZctJIiawE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=L/V5qsvmBHO714hayP3bpRRQO+jJ/WKd0Oe0ioIryxMpHILRkwFQ8nUap1fSd9rUIpy4s+QoZ8DHtK9vXbT+0gmOT0NML/BkZB1kPxwUNMTy/gCd66ViP3Po9vySnxzWfUK4N24t1HjHYwPqWaMOutshTowBooHPmR8TBVW8hKI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e6fb9a494aso1506054b3a.0; Thu, 28 Mar 2024 23:47:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711694860; x=1712299660; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hKxkF5DycsiIenidpZ8HuGYDWfU4JArm5xr/R0Y9MYk=; b=nYeXxpeOq1Z3V52j3IuiKwntoEUicTrr+gE2eNuXzrKxf1y57z5kIQlep2jMJtcpwz bQd9JtcH80EoAGI4Y+hjAZcVook27uKudE0Pr18u5tvUemyNdG4FkHTvtouafnj2OFtr XRJR2KCZG7Vco4rNfdrT3LLrvkjKpsQ6P/MJGvgJ1mUHWcJTKClrbdGa6l/6uASxlnoS quo3x749yQ79NXe/TYvNq74DxwOOX9jmkAs7cAOwR9CktX0h9YSvFAYtTMR5xUFCyNDD TorPSuaepzZvTiIzsoB8vJDorW/Buuk3lxQ5MXBPTtvL+RgNcwg7bsuk6yMVcyULKalI UU9Q== X-Forwarded-Encrypted: i=1; AJvYcCUxUITKU8BcwPM8kjxcyaebYEqqAUpPRwlFUxXj0hkAflT3PtuR/QiEnrI7hQHFd5ClgWBTKyGgLQOubMkgNGEV20ndxHwgpEvgzn7qrIFBskVA4AWd1qpmL9u/XbJSjMPc7yX7oC4onpIHT76eRQ== X-Gm-Message-State: AOJu0YyQdl56a8wSBCwrveRzXlX4YTPLUNUs/EmdMHWlUVQg+6WpZ51C 8EAfJOq9Yk6G58wxc2L73+5ijr5oXytShrSdPZt4pbeFEVLrSIf4Ox1GHFE7SnZTO9KIeeZikq0 N50BLxdymt0K25FAY0AvGSdLk4C4= X-Received: by 2002:a05:6a20:958b:b0:1a1:776d:15c with SMTP id iu11-20020a056a20958b00b001a1776d015cmr1470917pzb.21.1711694860427; Thu, 28 Mar 2024 23:47:40 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240326202859.960577-1-weilin.wang@intel.com> <20240326202859.960577-5-weilin.wang@intel.com> In-Reply-To: <20240326202859.960577-5-weilin.wang@intel.com> From: Namhyung Kim Date: Thu, 28 Mar 2024 23:47:29 -0700 Message-ID: Subject: Re: [RFC PATCH v5 4/6] perf stat: Create another thread for sample data processing To: weilin.wang@intel.com Cc: Ian Rogers , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 26, 2024 at 1:29=E2=80=AFPM wrote: > > From: Weilin Wang > > Another thread is required to synchronize between perf stat and perf reco= rd > when we pass data through pipe. It seems better if you can squash this commit to the patch 2/6. Thanks, Namhyung > > Signed-off-by: Weilin Wang > Reviewed-by: Ian Rogers > --- > tools/perf/builtin-stat.c | 51 +++++++++++++++++++++-------------- > tools/perf/util/stat-shadow.c | 4 +-- > 2 files changed, 33 insertions(+), 22 deletions(-) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index fc887d9aaa66..14488cb0cfc8 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -802,9 +802,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 =3D 0; > + struct child_process *cmd =3D arg; > struct perf_session *session; > struct perf_data data =3D { > .mode =3D PERF_DATA_MODE_READ, > @@ -819,29 +819,15 @@ static int __cmd_script(struct child_process *cmd _= _maybe_unused) > .attr =3D perf_event__process_attr, > }, > }; > - struct tpebs_event *e; > - > - list_for_each_entry(e, &stat_config.tpebs_events, nd) { > - struct tpebs_retire_lat *new =3D malloc(sizeof(struct tpe= bs_retire_lat)); > > - if (!new) > - return -1; > - new->event.name =3D strdup(e->name); > - new->event.tpebs_name =3D strdup(e->tpebs_name); > - new->count =3D 0; > - new->sum =3D 0; > - list_add_tail(&new->event.nd, &stat_config.tpebs_results)= ; > - } > - > - kill(cmd->pid, SIGTERM); > session =3D perf_session__new(&data, &script.tool); > if (IS_ERR(session)) > - return PTR_ERR(session); > + return NULL; > script.session =3D session; > - err =3D 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) > @@ -861,16 +847,37 @@ static int __run_perf_stat(int argc, const char **a= rgv, int run_idx) > int err; > bool second_pass =3D false; > struct child_process cmd; > + pthread_t thread_script; > > /* Prepare perf record for sampling event retire_latency before f= ork and > * prepare workload */ > if (stat_config.tpebs_event_size > 0) { > int ret; > + struct tpebs_event *e; > > pr_debug("perf stat pid =3D %d\n", getpid()); > + list_for_each_entry(e, &stat_config.tpebs_events, nd) { > + struct tpebs_retire_lat *new =3D malloc(sizeof(st= ruct tpebs_retire_lat)); > + > + if (!new) > + return -1; > + new->event.name =3D strdup(e->name); > + new->event.tpebs_name =3D strdup(e->tpebs_name); > + new->count =3D 0; > + new->sum =3D 0; > + list_add_tail(&new->event.nd, &stat_config.tpebs_= results); > + } > ret =3D prepare_perf_record(&cmd); > if (ret) > return ret; > + if (pthread_create(&thread_script, NULL, __cmd_script, &c= md)) { > + kill(cmd.pid, SIGTERM); > + close(cmd.out); > + pr_err("Could not create thread to process sample= data.\n"); > + return -1; > + } > + /* Wait for perf record initialization a little bit.*/ > + sleep(2); > } > > if (forks) { > @@ -1081,8 +1088,12 @@ static int __run_perf_stat(int argc, const char **= argv, int run_idx) > if (stat_config.tpebs_event_size > 0) { > int ret; > > - ret =3D __cmd_script(&cmd); > + kill(cmd.pid, SIGTERM); > + pthread_join(thread_script, NULL); > close(cmd.out); > + ret =3D finish_command(&cmd); > + if (ret !=3D -ERR_RUN_COMMAND_WAITPID_SIGNAL) > + return ret; > } > > if (stat_config.walltime_run_table) > diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.= c > index 8fc3415de106..bc77e9e02892 100644 > --- a/tools/perf/util/stat-shadow.c > +++ b/tools/perf/util/stat-shadow.c > @@ -361,8 +361,8 @@ static int prepare_retire_lat(struct expr_parse_ctx *= pctx, > int ret =3D 0; > struct tpebs_retire_lat *t; > > - list_for_each_entry(t, retire_lats, nd) { > - ret =3D expr__add_id_val(pctx, strdup(t->tpebs_name), t->= val); > + list_for_each_entry(t, retire_lats, event.nd) { > + ret =3D expr__add_id_val(pctx, strdup(t->event.tpebs_name= ), t->val); > if (ret < 0) > return ret; > } > -- > 2.43.0 >