Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5965007rwd; Mon, 5 Jun 2023 10:54:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SXNs+pdUjEzGnGgpMD7aVDbZ2vgObcH0lGZNiN5hM4gYr0IK1l4eV2+4rgwNHmD0IyKDz X-Received: by 2002:a05:6a20:144f:b0:10f:13bb:5d4f with SMTP id a15-20020a056a20144f00b0010f13bb5d4fmr3755093pzi.2.1685987686311; Mon, 05 Jun 2023 10:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685987686; cv=none; d=google.com; s=arc-20160816; b=q4G4E632e/5MAruKIlUgLkvKd5MjFkMeD6VHuj6zHJPOIgUgs+1VL/pw/jLtGTPb/Z fgZbhKy8vyDTX9E1ONej7sDTcYM7vCy1TK9n2InjOmtW8wCTk6EdW5osG3nUAegvmJ7v 69GxGkHDiwyfAp1xmd2alH5e2W2XlwXbigXUYtb6Zk8ETUA5jQTvP2CalP7pNgmGm3UU 6LLDeRAw+n2duBrgFrVc2hMaU46/JL1AshpwBfskH1kvT2UdLvelHVKVflpMvAB1l6m1 i8I7+XfeHb1CNMc1BygzoxSf+z4qlDkWHZMCVXmtdkHxwq7VX/iW13L0R//mdUyoCOhI p+CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZshFYyq0L62kSyIdVgRWRK042dyZJOn9HYiwHN6D3gw=; b=vzcNvFfnbieTsW3/o/jvKp0c4+67lcSaBqGhtzgkHpMZngFTOUz3SKTqqz285apoHy 5BTE/6GjJRc+x17G9uM7+S66ny8j2Zvetxye4OAXc4n35c9RtRABXeuVc7z0iEY0aIfE 13yO4UfZxq1LyDvjfRODYK5CTUugTlzvkWh4mzl522DKb0i8yySDGKjgt1s5cwr+hqiN Fwsd7+09PMMIp302ewlOO/su2RvY0j7NlmMGx5uR0mpD96jdFIxl9QvTsWQsjnVq442q 30ohQW2xgteJPad1+zRrODumbXWm++W9hrWm33xWU4Hd/5RNJfpf+J0O1Z6KjW2Hz4O5 S4nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=nETNHxZZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k64-20020a633d43000000b005347efdfecbsi5918500pga.111.2023.06.05.10.54.31; Mon, 05 Jun 2023 10:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=nETNHxZZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234624AbjFERce (ORCPT + 99 others); Mon, 5 Jun 2023 13:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234583AbjFERcb (ORCPT ); Mon, 5 Jun 2023 13:32:31 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3966798 for ; Mon, 5 Jun 2023 10:32:30 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-33d928a268eso14575ab.0 for ; Mon, 05 Jun 2023 10:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685986349; x=1688578349; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZshFYyq0L62kSyIdVgRWRK042dyZJOn9HYiwHN6D3gw=; b=nETNHxZZw+vTDFQ/qXc6wRhWJd2piX+BMCcp+PflMe6YRKr9vk1q3JiH0NFgSf9/7c PgSHAn/zC5hW9EuHiCGpOMyU6TJhkBw63kSKo7z8qQJ/yQAvxkLeuP8syKWu6iaZJeb+ /ggrs/Kd9nNpUfvyprfC2FnqLOsDxsIj0adw913vBKgBMw/ofeMCdEVOwc33DKuYR1wM KW1k1Za+oIxJVCHZ+qukzAZCJ1BjUmoLKBEqzr+5yegBvOIhynmhA5VQM8peptQ0wyuD xDSGlpjsqdW+7YroTc5pZYorhDSMgAO2+4A74XANA4Spkrm8yP6ujgRNs1n2wJ4aRSN1 KJUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685986349; x=1688578349; 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=ZshFYyq0L62kSyIdVgRWRK042dyZJOn9HYiwHN6D3gw=; b=d7iofOzUs1meFQwz/oRDBrD2aU93HKE4s54/Bf9c14FfeNOjn72JL/Ol5pOXt54/aw a0EaKhW7QDbrMowQSZ/PG5v8SBgnaQn8sOUIxgdtxEJhwSzG+7kMeH1ui9gNkEorSe+A bYJAfu1ZD2cQbfWbllV1EWBWPuNvCRjPh8RGyQ3JwW4bPba0E/QyAsJGEirziApFn894 3FJ7Cv3eIesAOT6h9kYh7qxIcub/2lKhLMPIXYTji7Z6QT0gXUQ+ePoruHObvvt35Eof mTIJwbsx5cSUAX1hI1uR+e3mSkhsqpUtDNYXRCIQaHyMUOI3ivuWDR4x1Uk/GrnhKRWN aLFw== X-Gm-Message-State: AC+VfDw7GmMYuTLuGCWKHxuh2GmlKhVKZ1z3hdezQs+AZCz2og5ihSwF D0DSLPx48Qb0DsIjGmj5RvBox+VM3mInyasEY5bnbQ== X-Received: by 2002:a05:6e02:1d82:b0:32a:f2a9:d1b7 with SMTP id h2-20020a056e021d8200b0032af2a9d1b7mr13562ila.10.1685986349429; Mon, 05 Jun 2023 10:32:29 -0700 (PDT) MIME-Version: 1.0 References: <20230504195803.3331775-1-irogers@google.com> <2abe618d-a2c4-3b22-ac9d-37bc91d05d41@linux.intel.com> In-Reply-To: <2abe618d-a2c4-3b22-ac9d-37bc91d05d41@linux.intel.com> From: Ian Rogers Date: Mon, 5 Jun 2023 10:32:18 -0700 Message-ID: Subject: Re: [PATCH v1 1/2] perf expr: Make the evaluation of & and | logical and lazy To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , James Clark , Andrii Nakryiko , Eduard Zingerman , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Ahmad Yasin , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , "Liang, Kan" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 18, 2023 at 12:47=E2=80=AFPM Liang, Kan wrote: > > > > On 2023-05-04 3:58 p.m., Ian Rogers wrote: > > Currently the & and | operators are only used in metric thresholds > > like (from the tma_retiring metric): > > tma_retiring > 0.7 | tma_heavy_operations > 0.1 > > > > Thresholds are always computed when present, but a lack events may > > mean the threshold can't be computed. This happens with the option > > --metric-no-threshold for say the metric tma_retiring on Tigerlake > > model CPUs. To fully compute the threshold tma_heavy_operations is > > needed and it needs the extra events of IDQ.MS_UOPS, > > UOPS_DECODED.DEC0, cpu/UOPS_DECODED.DEC0,cmask=3D1/ and > > IDQ.MITE_UOPS. So --metric-no-threshold is a useful option to reduce > > the number of events needed and potentially multiplexing of events. > > > > Rather than just fail threshold computations like this, we may know a > > result from just the left or right-hand side. So, for tma_retiring if > > its value is "> 0.7" we know it is over the threshold. This allows the > > metric to have the threshold coloring, when possible, without all the > > counters being programmed. > > > > Signed-off-by: Ian Rogers > > --- > > The patch works well on my machine. > > Tested-by: Kan Liang > > Thanks, > Kan Arnaldo, could we take this set? Thanks, Ian > > tools/perf/tests/expr.c | 40 +++++++++++++++++++ > > tools/perf/util/expr.y | 86 +++++++++++++++++++++++++++++++++-------- > > 2 files changed, 109 insertions(+), 17 deletions(-) > > > > diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c > > index cbf0e0c74906..45c7fedb797a 100644 > > --- a/tools/perf/tests/expr.c > > +++ b/tools/perf/tests/expr.c > > @@ -184,6 +184,46 @@ static int test__expr(struct test_suite *t __maybe= _unused, int subtest __maybe_u > > NULL, ctx) =3D=3D 0); > > TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); > > > > + /* The expression is a constant 0.0 without needing to evaluate E= VENT1. */ > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("0 & EVENT1 > 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("EVENT1 > 0 & 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("1 & EVENT1 > 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); > > + TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &va= l_ptr)); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("EVENT1 > 0 & 1", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); > > + TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &va= l_ptr)); > > + > > + /* The expression is a constant 1.0 without needing to evaluate E= VENT1. */ > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("1 | EVENT1 > 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("EVENT1 > 0 | 1", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("0 | EVENT1 > 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); > > + TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &va= l_ptr)); > > + expr__ctx_clear(ctx); > > + TEST_ASSERT_VAL("find ids", > > + expr__find_ids("EVENT1 > 0 | 0", NULL, ctx) =3D= =3D 0); > > + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); > > + TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &va= l_ptr)); > > + > > /* Test toplogy constants appear well ordered. */ > > expr__ctx_clear(ctx); > > TEST_ASSERT_VAL("#num_cpus", expr__parse(&num_cpus, ctx, "#num_cp= us") =3D=3D 0); > > diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y > > index 250e444bf032..6b110f9f95c9 100644 > > --- a/tools/perf/util/expr.y > > +++ b/tools/perf/util/expr.y > > @@ -123,20 +123,6 @@ static struct ids handle_id(struct expr_parse_ctx = *ctx, char *id, > > * constant value using OP. Its invariant that there are no ids. If c= omputing > > * ids for non-constants union the set of IDs that must be computed. > > */ > > -#define BINARY_LONG_OP(RESULT, OP, LHS, RHS) \ > > - if (!compute_ids || (is_const(LHS.val) && is_const(RHS.val))) { \ > > - assert(LHS.ids =3D=3D NULL); = \ > > - assert(RHS.ids =3D=3D NULL); = \ > > - if (isnan(LHS.val) || isnan(RHS.val)) { \ > > - RESULT.val =3D NAN; = \ > > - } else { \ > > - RESULT.val =3D (long)LHS.val OP (long)RHS.val; = \ > > - } \ > > - RESULT.ids =3D NULL; = \ > > - } else { \ > > - RESULT =3D union_expr(LHS, RHS); = \ > > - } > > - > > #define BINARY_OP(RESULT, OP, LHS, RHS) = \ > > if (!compute_ids || (is_const(LHS.val) && is_const(RHS.val))) { \ > > assert(LHS.ids =3D=3D NULL); = \ > > @@ -213,9 +199,75 @@ expr: NUMBER > > } > > | ID { $$ =3D handle_id(ctx, $1, compute_ids, = /*source_count=3D*/false); } > > | SOURCE_COUNT '(' ID ')' { $$ =3D handle_id(ctx, $3, compute_ids, = /*source_count=3D*/true); } > > -| expr '|' expr { BINARY_LONG_OP($$, |, $1, $3); } > > -| expr '&' expr { BINARY_LONG_OP($$, &, $1, $3); } > > -| expr '^' expr { BINARY_LONG_OP($$, ^, $1, $3); } > > +| expr '|' expr > > +{ > > + if (is_const($1.val) && is_const($3.val)) { > > + assert($1.ids =3D=3D NULL); > > + assert($3.ids =3D=3D NULL); > > + $$.ids =3D NULL; > > + $$.val =3D (fpclassify($1.val) =3D=3D FP_ZERO && fpclassi= fy($3.val) =3D=3D FP_ZERO) ? 0 : 1; > > + } else if (is_const($1.val)) { > > + assert($1.ids =3D=3D NULL); > > + if (fpclassify($1.val) =3D=3D FP_ZERO) { > > + $$ =3D $3; > > + } else { > > + $$.val =3D 1; > > + $$.ids =3D NULL; > > + ids__free($3.ids); > > + } > > + } else if (is_const($3.val)) { > > + assert($3.ids =3D=3D NULL); > > + if (fpclassify($3.val) =3D=3D FP_ZERO) { > > + $$ =3D $1; > > + } else { > > + $$.val =3D 1; > > + $$.ids =3D NULL; > > + ids__free($1.ids); > > + } > > + } else { > > + $$ =3D union_expr($1, $3); > > + } > > +} > > +| expr '&' expr > > +{ > > + if (is_const($1.val) && is_const($3.val)) { > > + assert($1.ids =3D=3D NULL); > > + assert($3.ids =3D=3D NULL); > > + $$.val =3D (fpclassify($1.val) !=3D FP_ZERO && fpclassify= ($3.val) !=3D FP_ZERO) ? 1 : 0; > > + $$.ids =3D NULL; > > + } else if (is_const($1.val)) { > > + assert($1.ids =3D=3D NULL); > > + if (fpclassify($1.val) !=3D FP_ZERO) { > > + $$ =3D $3; > > + } else { > > + $$.val =3D 0; > > + $$.ids =3D NULL; > > + ids__free($3.ids); > > + } > > + } else if (is_const($3.val)) { > > + assert($3.ids =3D=3D NULL); > > + if (fpclassify($3.val) !=3D FP_ZERO) { > > + $$ =3D $1; > > + } else { > > + $$.val =3D 0; > > + $$.ids =3D NULL; > > + ids__free($1.ids); > > + } > > + } else { > > + $$ =3D union_expr($1, $3); > > + } > > +} > > +| expr '^' expr > > +{ > > + if (is_const($1.val) && is_const($3.val)) { > > + assert($1.ids =3D=3D NULL); > > + assert($3.ids =3D=3D NULL); > > + $$.val =3D (fpclassify($1.val) =3D=3D FP_ZERO) !=3D (fpcl= assify($3.val) =3D=3D FP_ZERO) ? 1 : 0; > > + $$.ids =3D NULL; > > + } else { > > + $$ =3D union_expr($1, $3); > > + } > > +} > > | expr '<' expr { BINARY_OP($$, <, $1, $3); } > > | expr '>' expr { BINARY_OP($$, >, $1, $3); } > > | expr '+' expr { BINARY_OP($$, +, $1, $3); }