Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1212961lqo; Fri, 17 May 2024 14:43:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBqwxDvctoTX+yW7fLS/rIdrItjAvtf+vcYxxnP0sJvyEmaexC0oXyzSdfJmhjxbJIx0Lj8AT1+gNghS/F+3/N1jAL/BevFhCWtto9iA== X-Google-Smtp-Source: AGHT+IH1fbwnM0Z3NijSi1gCbiCef4+MZlwrqMCdkolp+fGWn6D+ZxgOkbvV74Wv1XNO8xhvcqgM X-Received: by 2002:a05:620a:22f3:b0:790:6619:aa50 with SMTP id af79cd13be357-792c76104e2mr2164594185a.64.1715982218384; Fri, 17 May 2024 14:43:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715982218; cv=pass; d=google.com; s=arc-20160816; b=0Lp+HHmKmj71/H3PhgLFDWfwNh9daKC0EFi53GP+IGwei7kNnYqWWC0Am+/w/JaFLE 3Wshfubdpxle07v8WpvTxr5/vIatKVcFe2N5R9noGhft7K8vF7h9fiansguNpcDOLhwy 3zoiXvQe/ZoNbACML/swYSxRrdHEBn8qaNDhcxDaqfL6juqqXeyDow/U+dFf/DDO62mI W6CcWhZLtMkGAsU79YpmyjnT+7hb3JFOpOZfxTdJibbZd5MO16xx00GpmET5Uoa5nqfD j8bitYTy2jLyCVb7XZLNBMzUics9HFahJUODRdxDNr2JsMU5SruRkfPgwzQ+ayeacKLq BPmA== 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=IDCtfy/Bp0EaDflNWvcEH2uJMngajJPoBsVPh87Br9Q=; fh=dOnNn2JduCVl0SKrBi7xEVlEng+mZBPq7uvEgDpqh6M=; b=r0er+l7i39bBnRg8oo8EAla5WIkdHcYyfjTd0X062SX8YPLRdVG2B/lHRxjW7QTuWo rESDO4jyNPL/NtRpmEprX3r1qCKrcx9WbM8JS7Hm4o6IotUMLhdpm0q/IV5Kf60JdfTt xGtqeSj5ygMZUD5eL2UZOwrHvNtiFlOm3qfc/enJNqOX3HfBUgGPZP44ADFuHXvneWCE 2K+0cvH9VISOc3Is8HWOvKLCEbVQ+O8YE9NVrrtFPGsCKr557F/bMcQdMgpkWKaSzGgB Cl14BNZ06cwBz/Hr1sskKkNz9yAxcdHg8hgFL9k9pUeqwfsOblGTiSz4Po5kROTmm1Xp GuhA==; 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-182656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792cfb85317si902302185a.42.2024.05.17.14.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 14:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182656-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182656-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1160D1C21DDF for ; Fri, 17 May 2024 21:43:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A2771411DD; Fri, 17 May 2024 21:43:23 +0000 (UTC) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 1B76F141981; Fri, 17 May 2024 21:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715982202; cv=none; b=A+bmXojuvDdj+jimSiQjYgzETBUY5Z1XkqcBMEkEeeeAmmkgFRyIndbeX6aZ3Uu7xkt/L2NpbJ0RvV4n0JZjFRIqBsQt2WZkwUuMnwV0sqjFY/O/3Nlu9KAo8yy4Uv2c/EPePd5krMTB5dw7Qi52HHkXu3IN/aBGSjUcKWy+nDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715982202; c=relaxed/simple; bh=TOQR4C7aJOSef0guoBb210jKTjOGMJ9RgirLaoUIQwc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=czATfmRl9a/pCEr3VfUbNxA+LxKoM5dtIKbuNX/hLdZ/PHJ7TdFyygy4c1xtoYyJ4C76vEKX4LWydoereW261vcF92QWTcjMzdWapAAIWA1G6rMt5G39Zx/W7FDLAia0+/7XyMAGmMxSpOo9NaB2cm/A4bzoWbq39N5buObfJps= 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.214.169 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-pl1-f169.google.com with SMTP id d9443c01a7336-1ec4dc64c6cso21410845ad.0; Fri, 17 May 2024 14:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715982200; x=1716587000; 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=IDCtfy/Bp0EaDflNWvcEH2uJMngajJPoBsVPh87Br9Q=; b=HzQvNswhF1bv6klLwyhfaLWgirrAMQiQauH3egU3WLlj3DfNLYd4x01k6zihV6rekp 24dDhKbF9TmPxOH0K0wEC316cHeXNd9FKtyqTGpa3m4/8MVAQWNVyDVwxxluBrOzWDkS +RwQs2FFOeSrpJ1Lcu4eIi3VoOJynknfr5QGIubrjnbG62/cpARdMcted1HghMn8jXvr p//YoYbzuSGVn9paVXrnv46JvbHZePglb9O6Djb9h2k+7RzdYKFz1NgVRHC2yb7XKeMD 68aNAUf9gT1H9cPvlm1M+GK4gU5g1irOiOLZRd0/8hs/EHtwq4MZnHofKNwcjU6E7F4P nxzw== X-Forwarded-Encrypted: i=1; AJvYcCUeAejqh+zZaGa0y3ObhKt/69Xsg5VMEZLF8AgX2J8Y8A/+oMsTaTf57ahCuocNMxnvPlUyIFq0Yw03dmVycJvA/94eGkClCd8l5x5HatoYxoCtVuRqRzFedROqIJMM/ueYdWe6PIPOGUpKnUKq7Q== X-Gm-Message-State: AOJu0YyQl1dVmsyfuwbpzOcSmvMcl/C+VfTvKMv7N3zN/XrsPBnPfN+F Ky+s12jJFEU1O25vuyWM8yTv7M60wguJgOyxpri2PAKCH3K3v1aAEnVmcP//wBWbTHhNwWUBoCt iCMTtBBxfZwdPAAHXZb3dM53NVSk= X-Received: by 2002:a17:903:1d2:b0:1eb:2ee2:43bd with SMTP id d9443c01a7336-1ef43d0acc1mr286452235ad.7.1715982200271; Fri, 17 May 2024 14:43:20 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240515054443.2824147-1-weilin.wang@intel.com> <20240515054443.2824147-4-weilin.wang@intel.com> In-Reply-To: <20240515054443.2824147-4-weilin.wang@intel.com> From: Namhyung Kim Date: Fri, 17 May 2024 14:43:08 -0700 Message-ID: Subject: Re: [RFC PATCH v8 3/7] perf stat: Fork and launch perf record when perf stat needs to get retire latency value for a metric. 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, May 14, 2024 at 10:44=E2=80=AFPM wrote: > > From: Weilin Wang > > When retire_latency value is used in a metric formula, perf stat would fo= rk a > perf record process with "-e" and "-W" options. Perf record will collect > required retire_latency values in parallel while perf stat is collecting > counting values. > > At the point of time that perf stat stops counting, it would send sigterm= signal > to perf record process and receiving sampling data back from perf record = from a > pipe. Perf stat will then process the received data to get retire latency= data > and calculate metric result. > > Another thread is required to synchronize between perf stat and perf reco= rd > when we pass data through pipe. > > Signed-off-by: Weilin Wang > Reviewed-by: Ian Rogers > --- [SNIP] > diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.= c > new file mode 100644 > index 000000000000..4b7a98794fae > --- /dev/null > +++ b/tools/perf/util/intel-tpebs.c > @@ -0,0 +1,285 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * intel_pt.c: Intel Processor Trace support > + * Copyright (c) 2013-2015, Intel Corporation. This needs some updates. :) > + */ > + > + > +#include > +#include > +#include > +#include "intel-tpebs.h" > +#include > +#include > +#include > +#include "sample.h" > +#include "debug.h" > +#include "evlist.h" > +#include "evsel.h" > +#include "session.h" > +#include "tool.h" > +#include "metricgroup.h" > +#include > +#include > + > + > + > +#define PERF_DATA "-" > +#define CONTROL "/tmp/control" > +#define ACK "/tmp/ack" > +pthread_t reader_thread; > +struct child_process *cmd; > +struct perf_stat_config *stat_config; static ? > + > +static int get_perf_record_args(const char **record_argv) > +{ > + int i =3D 0; > + struct tpebs_retire_lat *e; > + > + pr_debug("Prepare perf record for retire_latency\n"); > + > + record_argv[i++] =3D "perf"; > + record_argv[i++] =3D "record"; > + record_argv[i++] =3D "-W"; > + record_argv[i++] =3D "--synth=3Dno"; Unfortunately this still synthesizes MMAP records for the kernel and modules. As we don't care about them and just want to minimize the overhead at the beginning, we can add "--tail-synthesize" too. > + record_argv[i++] =3D "--control=3Dfifo:/tmp/control,/tmp/ack"; This hard-coded path won't work well when more than one users want to run the perf command at the same time. Thanks, Namhyung > + > + if (stat_config->user_requested_cpu_list) { > + record_argv[i++] =3D "-C"; > + record_argv[i++] =3D stat_config->user_requested_cpu_list= ; > + } > + > + if (stat_config->system_wide) > + record_argv[i++] =3D "-a"; > + > + if (!stat_config->system_wide && !stat_config->user_requested_cpu= _list) { > + pr_err("Require -a or -C option to run sampling.\n"); > + return -ECANCELED; > + } > + > + list_for_each_entry(e, &stat_config->tpebs_results, nd) { > + record_argv[i++] =3D "-e"; > + record_argv[i++] =3D e->name; > + } > + > + record_argv[i++] =3D "-o"; > + record_argv[i++] =3D PERF_DATA; > + > + return 0; > +} > + >