Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1753321pxb; Fri, 20 Nov 2020 19:14:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzC7+6GsAdXbGaPqqL7NP5gahn336i5n4uxA6G/9uo8/9yOG032VAXRhlfjAjRSOgiyC62 X-Received: by 2002:a05:6402:3089:: with SMTP id de9mr39308225edb.100.1605928451662; Fri, 20 Nov 2020 19:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605928451; cv=none; d=google.com; s=arc-20160816; b=Uv9tAMThcXG6ANBrYrLCXN9vfvetJzk+i0Mj6nRyiveuNRFJufts4PRur75H0BUFyW P0PeS6j7jBr6ylcCOvPO7mj5gNAzSNyMqIVU25xoFUaCXvUt0xVQDFoK24saoMplhoYw ZQrcLlFblkX0GnaFuHEl9a0f8Bz1Vgnw7oyaP03aT3Yb8F59ea2UCfLd4Y+JEwAYIQLg +ID6YbvW/BqgzPUdGthHoVnz9C0taScOWUbHfwGoi+o59PRqTzlet/l7JAFMsqdt7vxw hV20fdE/wEvEUppcv/2C/oSUpFg1ieQkhsCIkXiXErbWG+UQgqqv6J5Yf+bkVxH2LR7z iRZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=Y9nCqzUR00s397XbJ4MbVQrXlMlJKCQR9tfy/2YBpDw=; b=FWxiixn0/rcYNmG3KkrvAUrw7JuY8CL/ZdWeNApJuT6afJsIx1DfdOkixQdqKm5V52 D1DvabGSEO0L22QHRphxIaI8TI7Tl+DXyNE9h09I9TzOpo6wQIcRWNUT0786cFydaCDT W3TbjJUEl7u6xSH5vj63rCw4JRc0BEImqKlUhBFb6NuRFIKw+r12lrbKPThuBqyCw5XO lfeZOLkLzjx+kaCRdvpv5otzNK/l/cAP6EzjajDFust8gyiyCBthzfROS9jVQSFo9wjq su4/lZfHSikKJPAAkxq8v1med1tMGopprI/gX4HF6SEfQD+t9dFUeNdXn8BnMLvgI655 Ydpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G+10cZhZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si3059519edk.386.2020.11.20.19.13.49; Fri, 20 Nov 2020 19:14:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=G+10cZhZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727232AbgKUDLY (ORCPT + 99 others); Fri, 20 Nov 2020 22:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgKUDLX (ORCPT ); Fri, 20 Nov 2020 22:11:23 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69ADCC061A47 for ; Fri, 20 Nov 2020 19:11:23 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id x3so7794936plr.23 for ; Fri, 20 Nov 2020 19:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=Y9nCqzUR00s397XbJ4MbVQrXlMlJKCQR9tfy/2YBpDw=; b=G+10cZhZBNjcNDMYayyrBcwRdjmzCDoI5BfPvWKZLsKDq8xkqAmgkMLRX9A3cN9Vht zFE3C8AFGvZE7F4VlKu8YOLDGjReIHdDv/qzJQM0TC4LXQnHWiR/GtaJx5Jh6bRB8CEb Q8MIMXJciGLHBvy9KH7MTInktArucVOAIcgqfB4r+fBqH6OS1iuloNzmHm1+zBy+g8NK 5KUKPi6+YzlkUrihuXK4DALsltvekLGRQLbz0HMZCxTcxfyz6uAIhH6VAZQ7uv9qphPx jqpkBlrnHzqk96egvIuQFHlQV86NnlzdzZ1YzldbyK/JDTGZfRadYh32xiyUAXMVJ5o/ DPCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=Y9nCqzUR00s397XbJ4MbVQrXlMlJKCQR9tfy/2YBpDw=; b=ZXN7YTJVi1U/8qN4zbjcVj+H+Dy8dqvxO5el1WExZW3yiKsNpZQfHEE0fwmhs+p3B5 YjXtSl6x833drxCOK1p1NZoj/aOfP+frSuQd2Rbix6q3i110B6u0J6W/w7a2E/Fpyr/o ZhLidlEx+oKrXsVBYfx4fjKJ5cFJxdYgmZHJt/HYRTAz/0z02j9TH+iuBb5Zq9DEuCj2 Xj33t8kP5VBrqpaVAe+j7V49xw2Zw4bmc3feQJcxm5UC15IWgzW7hyB3I3zouH7PNoex n+qJqqvc0Xhe9O2APMiXnPmdYOge5AlLI8UDvZKJ2Rcfnk0687KdX0mJMtLnSoZM5q+h ntrQ== X-Gm-Message-State: AOAM533/W33SYqL5AUt0KJ6htrs80KR3DbvqfKnHONMG52+jIg6sYOT6 XsAEp4hjtU/gS2AmuGTGo0mZXIJPZZzg Sender: "irogers via sendgmr" X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:2:f693:9fff:fef4:4583]) (user=irogers job=sendgmr) by 2002:a17:902:ba8b:b029:d7:e6da:cd21 with SMTP id k11-20020a170902ba8bb02900d7e6dacd21mr16233793pls.38.1605928282856; Fri, 20 Nov 2020 19:11:22 -0800 (PST) Date: Fri, 20 Nov 2020 19:11:14 -0800 Message-Id: <20201121031119.3554769-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v3 0/5] Don't compute events that won't be used in a metric. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org, Andi Kleen , Jin Yao , John Garry , Paul Clarke , kajoljain Cc: Stephane Eranian , Sandeep Dasgupta , linux-perf-users@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For a metric like: EVENT1 if #smt_on else EVENT2 currently EVENT1 and EVENT2 will be measured and then when the metric is reported EVENT1 or EVENT2 will be printed depending on the value from smt_on() during the expr parsing. Computing both events is unnecessary and can lead to multiplexing as discussed in this thread: https://lore.kernel.org/lkml/20201110100346.2527031-1-irogers@google.com/ This change modifies expression parsing so that constants are considered when building the set of ids (events) and only events not contributing to a constant value are measured. v3. fixes an assignment in patch 2/5. In patch 5/5 additional comments are added and useless frees are replaced by asserts. A new peephole optimization is added for the case CONST IF expr ELSE CONST, where the the constants are identical, as we don't need to evaluate the IF condition. v2. is a rebase. Ian Rogers (5): perf metric: Restructure struct expr_parse_ctx. perf metric: Use NAN for missing event IDs. perf metric: Rename expr__find_other. perf metric: Add utilities to work on ids map. perf metric: Don't compute unused events. tools/perf/tests/expr.c | 159 +++++++++----- tools/perf/tests/pmu-events.c | 42 ++-- tools/perf/util/expr.c | 136 ++++++++++-- tools/perf/util/expr.h | 17 +- tools/perf/util/expr.l | 9 - tools/perf/util/expr.y | 376 +++++++++++++++++++++++++++------- tools/perf/util/metricgroup.c | 44 ++-- tools/perf/util/stat-shadow.c | 54 +++-- 8 files changed, 623 insertions(+), 214 deletions(-) -- 2.29.2.454.gaff20da3a2-goog