From patchwork Wed May 20 18:20:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294556 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=VBmrZvCC; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1KH1SX5z9sT9 for ; Thu, 21 May 2020 04:21:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbgETSVG (ORCPT ); Wed, 20 May 2020 14:21:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726790AbgETSUV (ORCPT ); Wed, 20 May 2020 14:20:21 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FE3C05BD43 for ; Wed, 20 May 2020 11:20:21 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 5so2625105ybe.17 for ; Wed, 20 May 2020 11:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pg8X3zsQYx36UMQsRQzJQNRzKxV0haL9XJi6KY3pltg=; b=VBmrZvCCpRZVw1T00v/lESnT7gpttLx7jwELUa4fEJrn+8/2Qq2iBQEZgVtggT3VpY oZjN4qja7wDJO/zdNXgBwIUSdj1m+WWHmrOHth5G5BXVE7IIu83QLP7zROmuGAotOer+ qixha/bEOroun3NqM9wWI2EB94vwbuJ6tQdUC3py+QuhMajVTXUpxbfku/4qjJY5j6WM BteNzNNVPYViB4OGzMKxxlwXAWoaDLecZFdaHaj1DkWN0+62sXbuFUkhgJzey7XjgpoD 95R1tIP9t5kbtyo4sZfSJ7tfZAcunS0EXb7v3z4FXlXuWc5SQjl5og0y5tFfKRUxuJcw K4RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pg8X3zsQYx36UMQsRQzJQNRzKxV0haL9XJi6KY3pltg=; b=ZBDupxsKGoqIt+7bgnswTGGU0PVVf2yWuBM+RnXK9H7hUljzmh9KeHDdq3Lo/iPYM4 88blVxLmmohQNw02rUmOTrO+M9nfN8JplkK+cbwxyd/OXyWTPu4lbr0cMVTMsnRXnzSU VhwJdkHUHIO/7Ww5BaTPjuQ5fwmUazgIEv+fgdzJUqhHzXBWXIiMwKYtU3BNph4bZTHN E5Tq2nxalGsVbTx6hEEY6VcOSTCPaM5d1rPbKmBkrxNLHs15hqincKPehIzXbf67HVPc cYtbtb/m1B5hQooEC+fh6jRpsFO/AyQ/hQVw0bI+GLY14sVBA/1mQa9Dm+eX8vy9XiKG Vahw== X-Gm-Message-State: AOAM533zY+PL7gA8wtP2eEcuRDULXqY6gay+R62F1K2tYGOL6RJIwR8S LowPLqNu5VkFxRnzkKmSVHyXej7OxzwX X-Google-Smtp-Source: ABdhPJxXHOCLByEfiE0YgbrkzsO6F5SEvxAk7PYQaNFmnyIGcAQwXMWYQqMTZjQYQw78N+QHO0iimvN0QFh7 X-Received: by 2002:a25:9805:: with SMTP id a5mr3939790ybo.26.1589998820800; Wed, 20 May 2020 11:20:20 -0700 (PDT) Date: Wed, 20 May 2020 11:20:05 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-2-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 1/7] perf metricgroup: Always place duration_time last From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If a metric contains the duration_time event then the event is placed outside of the metric's group of events. Rather than split the group, make it so the duration_time is immediately after the group. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index a16f60da06ab..7a43ee0a2e40 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -410,8 +410,8 @@ static void metricgroup__add_metric_weak_group(struct strbuf *events, struct expr_parse_ctx *ctx) { struct hashmap_entry *cur; - size_t bkt, i = 0; - bool no_group = false; + size_t bkt; + bool no_group = true, has_duration = false; hashmap__for_each_entry((&ctx->ids), cur, bkt) { pr_debug("found event %s\n", (const char *)cur->key); @@ -421,20 +421,20 @@ static void metricgroup__add_metric_weak_group(struct strbuf *events, * group. */ if (!strcmp(cur->key, "duration_time")) { - if (i > 0) - strbuf_addf(events, "}:W,"); - strbuf_addf(events, "duration_time"); - no_group = true; + has_duration = true; continue; } strbuf_addf(events, "%s%s", - i == 0 || no_group ? "{" : ",", + no_group ? "{" : ",", (const char *)cur->key); no_group = false; - i++; } - if (!no_group) + if (!no_group) { strbuf_addf(events, "}:W"); + if (has_duration) + strbuf_addf(events, ",duration_time"); + } else if (has_duration) + strbuf_addf(events, "duration_time"); } static void metricgroup__add_metric_non_group(struct strbuf *events, From patchwork Wed May 20 18:20:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294555 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=ERNLTMCu; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1KD14L7z9sT9 for ; Thu, 21 May 2020 04:21:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726650AbgETSUZ (ORCPT ); Wed, 20 May 2020 14:20:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbgETSUY (ORCPT ); Wed, 20 May 2020 14:20:24 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB6EAC08C5C0 for ; Wed, 20 May 2020 11:20:23 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y8so2624424ybn.20 for ; Wed, 20 May 2020 11:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nbhZ9P8EBn/6lSfkuc6XkauJvve4e394c9GAeFVHVtc=; b=ERNLTMCuGSsUvR4ZHD8o4TPpu1gI33gfIaKtor2dYnBOBZxClZH50a1Bdpk2IPGVs+ tXlIA7jzmJxUzjgCheueIraN9TURLzov08p/k//zxiFAiNcQNa2vBYaAVUQ57lPwnO86 uwJZIah6SuXv499SbR3x/yw4rMGWJ54+gkDFogsSwsferCvHbgwr0c0cr0mdShlOhmhn DoAYOF2tMO/DNvBu3sXamvhLl6zt2csn2/j30OgADaKm6JUXRtXmMKhWUrjln4/sD0B5 s8RiDK9bgKHShpj7yQCV0SLqaCWKIe31nTnN6r7Cam5XIB49yU7x2BtjUw9q0cMOVr3D lhGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nbhZ9P8EBn/6lSfkuc6XkauJvve4e394c9GAeFVHVtc=; b=PD88A7Pgy3QTVuMElJNdk4g7gFAbIJOso6oAB0zu+q47doQBPzemCdx/XLWFo4IGW5 siRSnLroOjY/zduUEaPA45Mpj5AA6w2bK0wFdQ52N37I1Mw75XNIBdlhi050FlMYHtjY zIhZctT40XYHgLXDMfhI32CnAcXeEI2dxRWBnRo6kEFVP88RSGktRZb7vmgDdYeZX94X GGrBpmSKgW0rxdzgHNJGNFZdTEF2lflwKDaXz0xTztjwn+Q5jIwAz8JlDiHlpv7e8QAv bZeuXn2WEHn71qqKSzoAVwoD5361XeKDE4wew2uoUtyjEGhOLvpROB/qgB8sCw/5+44X 0YGQ== X-Gm-Message-State: AOAM533UhRSAIdJS6zwCRiHMG/T5Ek/Tze2nZ/Z6PDTNoW75oaqTViDZ jmW6ymGftJ7vuZkKARB4wgYdClVygzLl X-Google-Smtp-Source: ABdhPJxJE4GhVQOLdNOx5d0k2G1puroT5shTBCTJfE0J9SPJmLN+vC0wuoq8WE06pQt8OCaNfvDYhI4Ph2jk X-Received: by 2002:a25:3627:: with SMTP id d39mr5892945yba.278.1589998823002; Wed, 20 May 2020 11:20:23 -0700 (PDT) Date: Wed, 20 May 2020 11:20:06 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-3-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 2/7] perf metricgroup: Use early return in add_metric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Use early return in metricgroup__add_metric and try to make the intent of the returns more intention revealing. Suggested-by: Jiri Olsa Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 7a43ee0a2e40..5c0603ef4c75 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -524,7 +524,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, { struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_event *pe; - int i, ret = -EINVAL; + int i, ret; + bool has_match = false; if (!map) return 0; @@ -532,17 +533,23 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, for (i = 0; ; i++) { pe = &map->table[i]; - if (!pe->name && !pe->metric_group && !pe->metric_name) + if (!pe->name && !pe->metric_group && !pe->metric_name) { + /* End of pmu events. */ + if (!has_match) + return -EINVAL; break; + } if (!pe->metric_expr) continue; if (match_metric(pe->metric_group, metric) || match_metric(pe->metric_name, metric)) { - + has_match = true; pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); if (!strstr(pe->metric_expr, "?")) { ret = __metricgroup__add_metric(events, group_list, pe, 1); + if (ret) + return ret; } else { int j, count; @@ -553,14 +560,15 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, * those events to group_list. */ - for (j = 0; j < count; j++) + for (j = 0; j < count; j++) { ret = __metricgroup__add_metric(events, group_list, pe, j); + if (ret) + return ret; + } } - if (ret == -ENOMEM) - break; } } - return ret; + return 0; } static int metricgroup__add_metric_list(const char *list, struct strbuf *events, From patchwork Wed May 20 18:20:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294552 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=dzBNCrel; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1KB0c1rz9sT9 for ; Thu, 21 May 2020 04:21:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbgETSU2 (ORCPT ); Wed, 20 May 2020 14:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726898AbgETSU0 (ORCPT ); Wed, 20 May 2020 14:20:26 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70842C05BD43 for ; Wed, 20 May 2020 11:20:26 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id e43so4786043qtc.3 for ; Wed, 20 May 2020 11:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KKQUK0ht2kaKDrQ/rdrxhZMGnz6XCmJO5hA8GPHu2yA=; b=dzBNCrelUrT1JxAQv8vNvpOAWP6S6LumYmJircB+N3/gszxbhqSdn8q233fNWA60eX kg44zXMH51b77C43kXXKjg1IeO236183xY/tsmVczZ0ZFwxJoWGiEjG6vnU/U6yJyUvA Ec9aceakvgFlmtKypStS2qo0XIq51G/SfOw251x/GZFIuzIeckOvaDZUA890WzTuwn5U vxDzw2A8cnQNg6STnrQQcNDtUTtVJqdp113A3RnqOhCincW5i76Tb5GMQ0POIMKPVcCa tHGwpafAyhI/1EeRXorSP/bjo+8T81IX0KW0n4PZvL27oi6XAENG0QjZBR7xFUN8UnzY 8D0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KKQUK0ht2kaKDrQ/rdrxhZMGnz6XCmJO5hA8GPHu2yA=; b=op7SZ+sF1CQd757nkiIP7l63iwYVuqWfF0EAMukefLvkpte/fdjOP4inBEPNd9/9Lq 1785qBhbUchvQS6tYcdfDMtupnX0aH5mfo4ENZMXNAgr+So6jwvpy7sTrs1aeV+GzHGi DASNDPpI5+S0+Tm0ELLIu0YVWSpsfq3qevhy5BPDcaUmE2voLApEgFcr7ORPo3XePuyv u/Iv1cc7IlHkoooK797YcyVII4ocizuXq5VviBJTCVr1iPDxesPHNOLCCm4U4aVK8QKq pDOVt+AS+38urW1qWXkbV47rrWzlbQIbv9hbVnEId6BQmxwdeJ//+cv3SABcFCGcXcxP 9pEg== X-Gm-Message-State: AOAM533YfVV/wCmw0qh6tRzk9dB1pe4PwEGDBvckiGPwkQZpuQ11JKNL 3Nyc0pkuxO1B/D+JHwOLy55DNV/2HRPk X-Google-Smtp-Source: ABdhPJxs3av1fJD8WsF76BuWXwHu5sAYT+IWWJCwS+9YgSKfRnU38Sm2Lt9qWQzaPsCtKzaoQ1TjJ8FINtIE X-Received: by 2002:ad4:47c8:: with SMTP id p8mr6022353qvw.93.1589998825230; Wed, 20 May 2020 11:20:25 -0700 (PDT) Date: Wed, 20 May 2020 11:20:07 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-4-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 3/7] perf metricgroup: Delay events string creation From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently event groups are placed into groups_list at the same time as the events string containing the events is built. Separate these two operations and build the groups_list first, then the event string from the groups_list. This adds an ability to reorder the groups_list that will be used in a later patch. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 5c0603ef4c75..dca433520b92 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -90,6 +90,7 @@ struct egroup { const char *metric_expr; const char *metric_unit; int runtime; + bool has_constraint; }; static struct evsel *find_evsel_group(struct evlist *perf_evlist, @@ -485,8 +486,8 @@ int __weak arch_get_runtimeparam(void) return 1; } -static int __metricgroup__add_metric(struct strbuf *events, - struct list_head *group_list, struct pmu_event *pe, int runtime) +static int __metricgroup__add_metric(struct list_head *group_list, + struct pmu_event *pe, int runtime) { struct egroup *eg; @@ -499,6 +500,7 @@ static int __metricgroup__add_metric(struct strbuf *events, eg->metric_expr = pe->metric_expr; eg->metric_unit = pe->unit; eg->runtime = runtime; + eg->has_constraint = metricgroup__has_constraint(pe); if (expr__find_other(pe->metric_expr, NULL, &eg->pctx, runtime) < 0) { expr__ctx_clear(&eg->pctx); @@ -506,14 +508,6 @@ static int __metricgroup__add_metric(struct strbuf *events, return -EINVAL; } - if (events->len > 0) - strbuf_addf(events, ","); - - if (metricgroup__has_constraint(pe)) - metricgroup__add_metric_non_group(events, &eg->pctx); - else - metricgroup__add_metric_weak_group(events, &eg->pctx); - list_add_tail(&eg->nd, group_list); return 0; @@ -524,6 +518,7 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, { struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_event *pe; + struct egroup *eg; int i, ret; bool has_match = false; @@ -547,7 +542,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); if (!strstr(pe->metric_expr, "?")) { - ret = __metricgroup__add_metric(events, group_list, pe, 1); + ret = __metricgroup__add_metric(group_list, + pe, 1); if (ret) return ret; } else { @@ -561,13 +557,26 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, */ for (j = 0; j < count; j++) { - ret = __metricgroup__add_metric(events, group_list, pe, j); + ret = __metricgroup__add_metric( + group_list, pe, j); if (ret) return ret; } } } } + list_for_each_entry(eg, group_list, nd) { + if (events->len > 0) + strbuf_addf(events, ","); + + if (eg->has_constraint) { + metricgroup__add_metric_non_group(events, + &eg->pctx); + } else { + metricgroup__add_metric_weak_group(events, + &eg->pctx); + } + } return 0; } From patchwork Wed May 20 18:20:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294548 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=BqrxCMwi; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1Jr20WVz9sTS for ; Thu, 21 May 2020 04:20:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbgETSUe (ORCPT ); Wed, 20 May 2020 14:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbgETSUa (ORCPT ); Wed, 20 May 2020 14:20:30 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B51B5C061A0F for ; Wed, 20 May 2020 11:20:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 186so2634520ybq.1 for ; Wed, 20 May 2020 11:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wGTE29BsgrWmThr3Ae7vqwYEGfSpg6F0IAHZFs59Yr0=; b=BqrxCMwi98i1HwXU41vZdhF0qgF0kyjIMD1sY8wwJrYyMo2ScsVqgIB0vWqiuF6MA5 D+D5pBEyhD7bLaBZxA8uP24t3Q0a1x750RottBh2pRXHRyTWBkMcFAs2C9J/kBfEVdyu nAnGVC7ARuETDVU5oYIXtcrG03KZQIRFld/4Q3pBhaIL08ZE3xM7Xilce+S2e9T5RcYO SHq1ZR6LZr7vxenQOc9nVBL38Q3VyUm2fUUxudtUXdhcCd6yMZF8Y/OMUeA3kW6Bufyi QpgpYFmuU6X6z4UJ8+Lb/y1JH3zhPigjBqmuXFX8FM10d+fELo3MQIiyLl2k7b6jTU3H CoIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wGTE29BsgrWmThr3Ae7vqwYEGfSpg6F0IAHZFs59Yr0=; b=jDkuJ6gx9Pkqj7HtbW8Q4YVzC9s/r9jytVXdF6Bhx9MI5mCRPEI98LYABNW00t+IA2 13MVF2xvD+dDJyATyRn2cpW5rsBamvPXltFzdrb66a+Su6Kf7KB16u/Ol/E5JpQ8ZBPA cEOPFccxeziSuRfiifP9iZG+DzdSbQYUO1FQfv6ZPguNemVaae6h/gAhs4Bsu4/3V5Ud tGp1lbvCFETX9MwlEwvNg0hRPLm6BRzNZJwQp5z2wbv4lh5d7gtqIxXsJNtk4Q+ZlwCY lTLGFXDPOdhDQeJyVtY3gBg/ARCJBLK9l2opUgP5aAg2bfnDTy+APnoyq0QRVLKurnLY XWWA== X-Gm-Message-State: AOAM533R7ETmBhDbtR4L6Dp2Rotv+xryRhRIOeKYpSvUkJidrCyyYVk/ Qbm2Avdwa+QulaWD083+Ze9GB2SZCD38 X-Google-Smtp-Source: ABdhPJwzdQK/jWwCpO0ZVm1Kg2j9m8W4jwQAQLCGOfG7f3sAz59C9o8AjdQ1WP1XUcT7BdmkhPNemNU/qYOy X-Received: by 2002:a25:9709:: with SMTP id d9mr8866827ybo.85.1589998827956; Wed, 20 May 2020 11:20:27 -0700 (PDT) Date: Wed, 20 May 2020 11:20:08 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-5-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 4/7] perf metricgroup: Order event groups by size From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When adding event groups to the group list, insert them in size order. This performs an insertion sort on the group list. By placing the largest groups at the front of the group list it is possible to see if a larger group contains the same events as a later group. This can make the later group redundant - it can reuse the events from the large group. A later patch will add this sharing. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index dca433520b92..bac63524d12f 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -508,7 +508,21 @@ static int __metricgroup__add_metric(struct list_head *group_list, return -EINVAL; } - list_add_tail(&eg->nd, group_list); + if (list_empty(group_list)) + list_add(&eg->nd, group_list); + else { + struct list_head *pos; + + /* Place the largest groups at the front. */ + list_for_each_prev(pos, group_list) { + struct egroup *old = list_entry(pos, struct egroup, nd); + + if (hashmap__size(&eg->pctx.ids) <= + hashmap__size(&old->pctx.ids)) + break; + } + list_add(&eg->nd, pos); + } return 0; } From patchwork Wed May 20 18:20:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294545 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=VzeWl9pP; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1Jj4XBYz9sTR for ; Thu, 21 May 2020 04:20:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727035AbgETSUg (ORCPT ); Wed, 20 May 2020 14:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726898AbgETSUb (ORCPT ); Wed, 20 May 2020 14:20:31 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3168FC08C5C1 for ; Wed, 20 May 2020 11:20:31 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id q11so4466925qvu.13 for ; Wed, 20 May 2020 11:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dFH0bguyroAKGCbCOB64fKS92V92w36ZKjgGmubJCt4=; b=VzeWl9pPiBlDKyw7SWwTfrc5+kdhTEDrbh/k+YRyx/8Gw2AfSgHlWjCihzrAP+AT4+ AQLAXAPycwjJLYdC8lcTs+1YM33B0jdelE+SURetT2RC9w7hnSXCvia2Fm1mEv3yj/Ws 5AmvsxUZOf/0oWPrs+fZVWUMLZYaOcAPPF8JpwCbDpngErbjoTslNN/XGrIjgkw6L414 j1Y9vIW8US9Oe+7eFOVoJAiylfWoRYvghOt+oZ0tpRs/uZ9DLgRUy9eaL7VISXTHd8Hu KKJ5lW71Cmd7j5SM3sDuH3NbeJDhMcpBm0pkRocLPt78d6l+GNSqdbkjWMoj1/AdjEhy l3kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dFH0bguyroAKGCbCOB64fKS92V92w36ZKjgGmubJCt4=; b=it9usJIBdwARP/KrNim58y9HEc/znPlGdpxQ66LJOJzeRpCF0NUD7YJqMn44p0M6oo uLIpi7YdNYl/isGll5DoD2LzNJWC4VBI6zTipdx31A3tdRoRzzWOJvWe4lonVuH/ow6r XOa8m9EJ2TMRDNSglDIU+AeKQwdvSjvRWU8fOpXsX1ay3tdPEabl1Uj6EqwgtEz4kbpN X/znE8WA0lvM6m5gGoHPXZZshvPZb9E9O5/2nA0FYEoAOujLnWugoQ/qmvak8nJkFonW NuoevWZOoSvbLnyDbm8vJm8YzfTJ/Cb6p12paeUYws8Ai8ANddSGa9eQ8KI+mKIJmyeS yRdQ== X-Gm-Message-State: AOAM53068PxJP8Q0iu7u+3PvvzGrqnkXs16C+rq5nkKxWKebFjiUxYLw nvBBNZeBW4asDYhhnkj+prD6t3j5K3js X-Google-Smtp-Source: ABdhPJxKpQij+oI0JS1JuBQuuRDKCD0w/3pF9Nn2NSZesa6e4cNrvFPLZQnv3NF393SUvKIhCAWV0HcR2/3A X-Received: by 2002:a05:6214:1265:: with SMTP id r5mr5915593qvv.171.1589998830235; Wed, 20 May 2020 11:20:30 -0700 (PDT) Date: Wed, 20 May 2020 11:20:09 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-6-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 5/7] perf metricgroup: Remove duped metric group events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org A metric group contains multiple metrics. These metrics may use the same events. If metrics use separate events then it leads to more multiplexing and overall metric counts fail to sum to 100%. Modify how metrics are associated with events so that if the events in an earlier group satisfy the current metric, the same events are used. A record of used events is kept and at the end of processing unnecessary events are eliminated. Before: $ perf stat -a -M TopDownL1 sleep 1 Performance counter stats for 'system wide': 920,211,343 uops_issued.any # 0.5 Backend_Bound (16.56%) 1,977,733,128 idq_uops_not_delivered.core (16.56%) 51,668,510 int_misc.recovery_cycles (16.56%) 732,305,692 uops_retired.retire_slots (16.56%) 1,497,621,849 cycles (16.56%) 721,098,274 uops_issued.any # 0.1 Bad_Speculation (16.79%) 1,332,681,791 cycles (16.79%) 552,475,482 uops_retired.retire_slots (16.79%) 47,708,340 int_misc.recovery_cycles (16.79%) 1,383,713,292 cycles # 0.4 Frontend_Bound (16.76%) 2,013,757,701 idq_uops_not_delivered.core (16.76%) 1,373,363,790 cycles # 0.1 Retiring (33.54%) 577,302,589 uops_retired.retire_slots (33.54%) 392,766,987 inst_retired.any # 0.3 IPC (50.24%) 1,351,873,350 cpu_clk_unhalted.thread (50.24%) 1,332,510,318 cycles # 5330041272.0 SLOTS (49.90%) 1.006336145 seconds time elapsed After: $ perf stat -a -M TopDownL1 sleep 1 Performance counter stats for 'system wide': 765,949,145 uops_issued.any # 0.1 Bad_Speculation # 0.5 Backend_Bound (50.09%) 1,883,830,591 idq_uops_not_delivered.core # 0.3 Frontend_Bound (50.09%) 48,237,080 int_misc.recovery_cycles (50.09%) 581,798,385 uops_retired.retire_slots # 0.1 Retiring (50.09%) 1,361,628,527 cycles # 5446514108.0 SLOTS (50.09%) 391,415,714 inst_retired.any # 0.3 IPC (49.91%) 1,336,486,781 cpu_clk_unhalted.thread (49.91%) 1.005469298 seconds time elapsed Note: Bad_Speculation + Backend_Bound + Frontend_Bound + Retiring = 100% after, where as before it is 110%. After there are 2 groups, whereas before there are 6. After the cycles event appears once, before it appeared 5 times. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 91 ++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index bac63524d12f..dba19de2f9ea 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -93,36 +93,72 @@ struct egroup { bool has_constraint; }; +/** + * Find a group of events in perf_evlist that correpond to those from a parsed + * metric expression. + * @perf_evlist: a list of events something like: {metric1 leader, metric1 + * sibling, metric1 sibling}:W,duration_time,{metric2 leader, metric2 sibling, + * metric2 sibling}:W,duration_time + * @pctx: the parse context for the metric expression. + * @has_constraint: is there a contraint on the group of events? In which case + * the events won't be grouped. + * @metric_events: out argument, null terminated array of evsel's associated + * with the metric. + * @evlist_used: in/out argument, bitmap tracking which evlist events are used. + * @return the first metric event or NULL on failure. + */ static struct evsel *find_evsel_group(struct evlist *perf_evlist, struct expr_parse_ctx *pctx, + bool has_constraint, struct evsel **metric_events, unsigned long *evlist_used) { - struct evsel *ev; - bool leader_found; - const size_t idnum = hashmap__size(&pctx->ids); - size_t i = 0; - int j = 0; + struct evsel *ev, *current_leader = NULL; double *val_ptr; + int i = 0, matched_events = 0, events_to_match; + const int idnum = (int)hashmap__size(&pctx->ids); + + /* duration_time is grouped separately. */ + if (!has_constraint && + hashmap__find(&pctx->ids, "duration_time", (void **)&val_ptr)) + events_to_match = idnum - 1; + else + events_to_match = idnum; evlist__for_each_entry (perf_evlist, ev) { - if (test_bit(j++, evlist_used)) + /* + * Events with a constraint aren't grouped and match the first + * events available. + */ + if (has_constraint && ev->weak_group) continue; - if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) { - if (!metric_events[i]) - metric_events[i] = ev; - i++; - if (i == idnum) - break; - } else { - /* Discard the whole match and start again */ - i = 0; + if (!has_constraint && ev->leader != current_leader) { + /* + * Start of a new group, discard the whole match and + * start again. + */ + matched_events = 0; memset(metric_events, 0, sizeof(struct evsel *) * idnum); + current_leader = ev->leader; } + if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) + metric_events[matched_events++] = ev; + if (matched_events == events_to_match) + break; } - if (i != idnum) { + if (events_to_match != idnum) { + /* Add the first duration_time. */ + evlist__for_each_entry(perf_evlist, ev) { + if (!strcmp(ev->name, "duration_time")) { + metric_events[matched_events++] = ev; + break; + } + } + } + + if (matched_events != idnum) { /* Not whole match */ return NULL; } @@ -130,18 +166,8 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, metric_events[idnum] = NULL; for (i = 0; i < idnum; i++) { - leader_found = false; - evlist__for_each_entry(perf_evlist, ev) { - if (!leader_found && (ev == metric_events[i])) - leader_found = true; - - if (leader_found && - !strcmp(ev->name, metric_events[i]->name)) { - ev->metric_leader = metric_events[i]; - } - j++; - } ev = metric_events[i]; + ev->metric_leader = ev; set_bit(ev->idx, evlist_used); } @@ -157,7 +183,7 @@ static int metricgroup__setup_events(struct list_head *groups, int i = 0; int ret = 0; struct egroup *eg; - struct evsel *evsel; + struct evsel *evsel, *tmp; unsigned long *evlist_used; evlist_used = bitmap_alloc(perf_evlist->core.nr_entries); @@ -173,7 +199,8 @@ static int metricgroup__setup_events(struct list_head *groups, ret = -ENOMEM; break; } - evsel = find_evsel_group(perf_evlist, &eg->pctx, metric_events, + evsel = find_evsel_group(perf_evlist, &eg->pctx, + eg->has_constraint, metric_events, evlist_used); if (!evsel) { pr_debug("Cannot resolve %s: %s\n", @@ -200,6 +227,12 @@ static int metricgroup__setup_events(struct list_head *groups, list_add(&expr->nd, &me->head); } + evlist__for_each_entry_safe(perf_evlist, tmp, evsel) { + if (!test_bit(evsel->idx, evlist_used)) { + evlist__remove(perf_evlist, evsel); + evsel__delete(evsel); + } + } bitmap_free(evlist_used); return ret; From patchwork Wed May 20 18:20:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294549 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=ErejxLjT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1Js3Bmzz9sTR for ; Thu, 21 May 2020 04:20:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbgETSUo (ORCPT ); Wed, 20 May 2020 14:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727016AbgETSUe (ORCPT ); Wed, 20 May 2020 14:20:34 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5234FC05BD43 for ; Wed, 20 May 2020 11:20:33 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id s8so2602445ybj.9 for ; Wed, 20 May 2020 11:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=YC/vW0/Yyw2ws5i1r6FNrpfqqePjuSe7zIo6oeOBTx4=; b=ErejxLjTyZxjazrBjxnUrMyQVx8Ez8rBjkfrc/9uWS4ZxgknoQ6+kqP/ZFr1Npiopu RZXRXWnMcs5GQc7ltlRRSU5fTpgi+W/PgamTIOr+maIZpldFQjWoVw/CS00t1BPURFYQ VYtF9s7ODbq7lLg7Jmun2DOO5AuGE4k9uEky5JcnVKHyZvtuiAnBOs3gYzrceq1NlgF0 kx4bqrcDNBtjGfy3hYzeLWpz6aYYRaYTQ0I0yoiAfjbpP7cR9g1PFCzT8CYXFw13Oipw 1gDmgN4fyEPbWkcjCSyQOR4Fd/KLa27a32zE2/y430NzqC9Y6PkrXM1GgrOgwRzAzJ6/ JrXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YC/vW0/Yyw2ws5i1r6FNrpfqqePjuSe7zIo6oeOBTx4=; b=a+SuPcP/ue3um+xzVskiSscHFnHCp5CsssDtrw/hckrSIac5KgM8uh7/jWi//mN78J pdALRTZ+PD12wMpGgGigBz7870ZtTZQ7yI80gEwIVxcMFcqnj8hQKN7WBLeNAppNxuXC q2pnaZRy5O3Kc+RvnhATaTo1eYKImYn8XaZ7G9dc2ozvhHhCTDPZj7im5xglcRTuTQma fZfC8RM0kTWqVpH/UFUv9P4yUW9YrCBBZDJ+S1WgeLBKfE8BvKI7drwxsYUcX0RK96JA KUPADomZhrgU3Odj3DavpDedaEEVUMpTZDIjeFkUzGqNx2KYrCft2TGDb7ZylwXjFyzz mvtA== X-Gm-Message-State: AOAM531gmHjc+L/dkgQ41CbJQ8Ei9gkF0TMkyGG1ezsnc1DVMvNq7zQj kNxZ2qtXSG10jk4ZHWn9PtwnLjGRUgrP X-Google-Smtp-Source: ABdhPJyNb6kdICtGW5xwiDqUxmaFNzpoM9O4jHh4xJyqEmXuxnLSsOJpYRPsv2DNrXsKq7sC0hhLq7pPK55n X-Received: by 2002:a25:9c04:: with SMTP id c4mr9429482ybo.103.1589998832489; Wed, 20 May 2020 11:20:32 -0700 (PDT) Date: Wed, 20 May 2020 11:20:10 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-7-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 6/7] perf metricgroup: Add options to not group or merge From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add --metric-no-group that causes all events within metrics to not be grouped. This can allow the event to get more time when multiplexed, but may also lower accuracy. Add --metric-no-merge option. By default events in different metrics may be shared if the group of events for one metric is the same or larger than that of the second. Sharing may increase or lower accuracy and so is now configurable. Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-stat.txt | 19 +++++++ tools/perf/builtin-stat.c | 11 ++++- tools/perf/util/metricgroup.c | 68 ++++++++++++++++++++------ tools/perf/util/metricgroup.h | 6 ++- tools/perf/util/stat.h | 2 + 5 files changed, 87 insertions(+), 19 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 3fb5028aef08..cc1e4c62bc91 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -234,6 +234,25 @@ filter out the startup phase of the program, which is often very different. Print statistics of transactional execution if supported. +--metric-no-group:: +By default, events to compute a metric are placed in weak groups. The +group tries to enforce scheduling all or none of the events. The +--metric-no-group option places events outside of groups and may +increase the chance of the event being scheduled - leading to more +accuracy. However, as events may not be scheduled together accuracy +for metrics like instructions per cycle can be lower - as both metrics +may no longer be being measured at the same time. + +--metric-no-merge:: +By default metric events in different weak groups can be shared if one +group contains all the events needed by another. In such cases one +group will be eliminated reducing event multiplexing and making it so +that certain groups of metrics sum to 100%. A downside to sharing a +group is that the group may require multiplexing and so accuracy for a +small group that need not have multiplexing is lowered. This option +forbids the event merging logic from sharing events between groups and +may be used to increase accuracy in this case. + STAT RECORD ----------- Stores stat data into perf data file. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c43ba6080691..25aafbc13d17 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -904,7 +904,10 @@ static int parse_metric_groups(const struct option *opt, const char *str, int unset __maybe_unused) { - return metricgroup__parse_groups(opt, str, &stat_config.metric_events); + return metricgroup__parse_groups(opt, str, + stat_config.metric_no_group, + stat_config.metric_no_merge, + &stat_config.metric_events); } static struct option stat_options[] = { @@ -982,6 +985,10 @@ static struct option stat_options[] = { "ms to wait before starting measurement after program start"), OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL, "Only print computed metrics. No raw values", enable_metric_only), + OPT_BOOLEAN(0, "metric-no-group", &stat_config.metric_no_group, + "don't group metric events, impacts multiplexing"), + OPT_BOOLEAN(0, "metric-no-merge", &stat_config.metric_no_merge, + "don't try to share events between metrics in a group"), OPT_BOOLEAN(0, "topdown", &topdown_run, "measure topdown level 1 statistics"), OPT_BOOLEAN(0, "smi-cost", &smi_cost, @@ -1506,6 +1513,8 @@ static int add_default_attributes(void) struct option opt = { .value = &evsel_list }; return metricgroup__parse_groups(&opt, "transaction", + stat_config.metric_no_group, + stat_config.metric_no_merge, &stat_config.metric_events); } diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index dba19de2f9ea..50d22f6b60c0 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -95,11 +95,15 @@ struct egroup { /** * Find a group of events in perf_evlist that correpond to those from a parsed - * metric expression. + * metric expression. Note, as find_evsel_group is called in the same order as + * perf_evlist was constructed, metric_no_merge doesn't need to test for + * underfilling a group. * @perf_evlist: a list of events something like: {metric1 leader, metric1 * sibling, metric1 sibling}:W,duration_time,{metric2 leader, metric2 sibling, * metric2 sibling}:W,duration_time * @pctx: the parse context for the metric expression. + * @metric_no_merge: don't attempt to share events for the metric with other + * metrics. * @has_constraint: is there a contraint on the group of events? In which case * the events won't be grouped. * @metric_events: out argument, null terminated array of evsel's associated @@ -109,6 +113,7 @@ struct egroup { */ static struct evsel *find_evsel_group(struct evlist *perf_evlist, struct expr_parse_ctx *pctx, + bool metric_no_merge, bool has_constraint, struct evsel **metric_events, unsigned long *evlist_used) @@ -132,6 +137,9 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, */ if (has_constraint && ev->weak_group) continue; + /* Ignore event if already used and merging is disabled. */ + if (metric_no_merge && test_bit(ev->idx, evlist_used)) + continue; if (!has_constraint && ev->leader != current_leader) { /* * Start of a new group, discard the whole match and @@ -142,8 +150,23 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, sizeof(struct evsel *) * idnum); current_leader = ev->leader; } - if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) + if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) { + if (has_constraint) { + /* + * Events aren't grouped, ensure the same event + * isn't matched from two groups. + */ + for (i = 0; i < matched_events; i++) { + if (!strcmp(ev->name, + metric_events[i]->name)) { + break; + } + } + if (i != matched_events) + continue; + } metric_events[matched_events++] = ev; + } if (matched_events == events_to_match) break; } @@ -175,6 +198,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, } static int metricgroup__setup_events(struct list_head *groups, + bool metric_no_merge, struct evlist *perf_evlist, struct rblist *metric_events_list) { @@ -200,8 +224,9 @@ static int metricgroup__setup_events(struct list_head *groups, break; } evsel = find_evsel_group(perf_evlist, &eg->pctx, - eg->has_constraint, metric_events, - evlist_used); + metric_no_merge, + eg->has_constraint, metric_events, + evlist_used); if (!evsel) { pr_debug("Cannot resolve %s: %s\n", eg->metric_name, eg->metric_expr); @@ -520,7 +545,9 @@ int __weak arch_get_runtimeparam(void) } static int __metricgroup__add_metric(struct list_head *group_list, - struct pmu_event *pe, int runtime) + struct pmu_event *pe, + bool metric_no_group, + int runtime) { struct egroup *eg; @@ -533,7 +560,7 @@ static int __metricgroup__add_metric(struct list_head *group_list, eg->metric_expr = pe->metric_expr; eg->metric_unit = pe->unit; eg->runtime = runtime; - eg->has_constraint = metricgroup__has_constraint(pe); + eg->has_constraint = metric_no_group || metricgroup__has_constraint(pe); if (expr__find_other(pe->metric_expr, NULL, &eg->pctx, runtime) < 0) { expr__ctx_clear(&eg->pctx); @@ -560,7 +587,8 @@ static int __metricgroup__add_metric(struct list_head *group_list, return 0; } -static int metricgroup__add_metric(const char *metric, struct strbuf *events, +static int metricgroup__add_metric(const char *metric, bool metric_no_group, + struct strbuf *events, struct list_head *group_list) { struct pmu_events_map *map = perf_pmu__find_map(NULL); @@ -590,7 +618,9 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, if (!strstr(pe->metric_expr, "?")) { ret = __metricgroup__add_metric(group_list, - pe, 1); + pe, + metric_no_group, + 1); if (ret) return ret; } else { @@ -605,7 +635,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, for (j = 0; j < count; j++) { ret = __metricgroup__add_metric( - group_list, pe, j); + group_list, pe, + metric_no_group, j); if (ret) return ret; } @@ -627,7 +658,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, return 0; } -static int metricgroup__add_metric_list(const char *list, struct strbuf *events, +static int metricgroup__add_metric_list(const char *list, bool metric_no_group, + struct strbuf *events, struct list_head *group_list) { char *llist, *nlist, *p; @@ -642,7 +674,8 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events, strbuf_addf(events, "%s", ""); while ((p = strsep(&llist, ",")) != NULL) { - ret = metricgroup__add_metric(p, events, group_list); + ret = metricgroup__add_metric(p, metric_no_group, events, + group_list); if (ret == -EINVAL) { fprintf(stderr, "Cannot find metric or group `%s'\n", p); @@ -669,8 +702,10 @@ static void metricgroup__free_egroups(struct list_head *group_list) } int metricgroup__parse_groups(const struct option *opt, - const char *str, - struct rblist *metric_events) + const char *str, + bool metric_no_group, + bool metric_no_merge, + struct rblist *metric_events) { struct parse_events_error parse_error; struct evlist *perf_evlist = *(struct evlist **)opt->value; @@ -680,7 +715,8 @@ int metricgroup__parse_groups(const struct option *opt, if (metric_events->nr_entries == 0) metricgroup__rblist_init(metric_events); - ret = metricgroup__add_metric_list(str, &extra_events, &group_list); + ret = metricgroup__add_metric_list(str, metric_no_group, + &extra_events, &group_list); if (ret) return ret; pr_debug("adding %s\n", extra_events.buf); @@ -691,8 +727,8 @@ int metricgroup__parse_groups(const struct option *opt, goto out; } strbuf_release(&extra_events); - ret = metricgroup__setup_events(&group_list, perf_evlist, - metric_events); + ret = metricgroup__setup_events(&group_list, metric_no_merge, + perf_evlist, metric_events); out: metricgroup__free_egroups(&group_list); return ret; diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 6b09eb30b4ec..287850bcdeca 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -29,8 +29,10 @@ struct metric_event *metricgroup__lookup(struct rblist *metric_events, struct evsel *evsel, bool create); int metricgroup__parse_groups(const struct option *opt, - const char *str, - struct rblist *metric_events); + const char *str, + bool metric_no_group, + bool metric_no_merge, + struct rblist *metric_events); void metricgroup__print(bool metrics, bool groups, char *filter, bool raw, bool details); diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index a5604a20bdca..5322339d889c 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -111,6 +111,8 @@ struct perf_stat_config { bool all_user; bool percore_show_thread; bool summary; + bool metric_no_group; + bool metric_no_merge; FILE *output; unsigned int interval; unsigned int timeout; From patchwork Wed May 20 18:20:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1294546 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=eVokqwG3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49S1Jp3dJGz9sTR for ; Thu, 21 May 2020 04:20:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727045AbgETSUl (ORCPT ); Wed, 20 May 2020 14:20:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbgETSUg (ORCPT ); Wed, 20 May 2020 14:20:36 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89C32C08C5C0 for ; Wed, 20 May 2020 11:20:35 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 207so2644764ybl.2 for ; Wed, 20 May 2020 11:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qEvd4x8iUsR7kfWiuh/jmJJHKtjhzJyBE+y8nt3gTxE=; b=eVokqwG3f1DWq3B2VU75ImzZJZ87g4smfOOCsLyMgXVgInjD2jU69dwde+ItcqJCoJ CNyunHXm6dMA3c9XZOdci2HOwhzsz/8sZSgHtx3RHEgonCETRLDDrzDPiiGzgrztPbmF Ug5byOB2TfNbnnl0cmLQ/v50g27rDmPAN+ajcNGGk6MpKt6naNcWkHu/mD0yvPYwHliV VscfqS5NAPHHzNdc+ctVoX859ZoeTq3nXyGi2XgmER9idZLk1PnhljYrqBslz49+Uf1A ZM2POxrcKFzPCleuLmPa21gczdL8oLT+njyEU7hezS7DaAHxXyP7mns9wT9LjOkb6Bk4 eNfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qEvd4x8iUsR7kfWiuh/jmJJHKtjhzJyBE+y8nt3gTxE=; b=kADQ5RFsH4IOagRuis/oCaGJ/E/R3u7q2QGLOYytAfsujABhGwCBvKzr54o+SAhzwO pT85sb+P4EPmJ0d46XWoOQ4Esg8BPtk4lulVYvy4hRjObTWE7i33h3hk8IrLqpLBvACJ RJnA/BEfVuQAZUWebRKJSqW0UijqumOWeATF8yLV1bLSpTg/97eZDZXXtkTNPj9Fpmcy y9FlwBPbXdn9NU+CEZs2AjQmZr3eicxP3fex2zFIawBORgej1QRD33ShrAEmViFQTL8l FOp0ydofFkODOmnxG3056t0r0+KueA12MbDrlAar58Y6frHZUXJ0jQDXbZTeGy649NK1 GYwA== X-Gm-Message-State: AOAM532hQeRba9WC0YK9gvgn2Z4GJYXPDeGOXFjzfRDy72TH/RIibKso 6NmGryAtDqBPd+ubdiDvEn9RBvamHX6A X-Google-Smtp-Source: ABdhPJyHN+0rbcjsE/V1xWdrFn3brQHIAZ0/P+ok6EF+o35T6o8TF2+dmB6jytrwLcuIYo7jKTFV1BeJId9P X-Received: by 2002:a25:3610:: with SMTP id d16mr9112137yba.222.1589998834804; Wed, 20 May 2020 11:20:34 -0700 (PDT) Date: Wed, 20 May 2020 11:20:11 -0700 In-Reply-To: <20200520182011.32236-1-irogers@google.com> Message-Id: <20200520182011.32236-8-irogers@google.com> Mime-Version: 1.0 References: <20200520182011.32236-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v2 7/7] perf metricgroup: Remove unnecessary ',' from events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Song Liu , Andrii Nakryiko , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , Paul Clarke , Srikar Dronamraju , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Remove unnecessary commas from events before they are parsed. This avoids ',' being echoed by parse-events.l. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 50d22f6b60c0..f787161e54ba 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -501,9 +501,14 @@ static void metricgroup__add_metric_non_group(struct strbuf *events, { struct hashmap_entry *cur; size_t bkt; + bool first = true; - hashmap__for_each_entry((&ctx->ids), cur, bkt) - strbuf_addf(events, ",%s", (const char *)cur->key); + hashmap__for_each_entry((&ctx->ids), cur, bkt) { + if (!first) + strbuf_addf(events, ","); + strbuf_addf(events, "%s", (const char *)cur->key); + first = false; + } } static void metricgroup___watchdog_constraint_hint(const char *name, bool foot)