Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1283880rwd; Thu, 1 Jun 2023 13:11:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7kCEsCW7vXBxE2ugbuK0VTqxqN2ztTIhvQyig5LXEtYVuQfRed1MKV1mosbSM/4iuf1BDr X-Received: by 2002:a05:6a21:6d91:b0:f0:b6e3:90c9 with SMTP id wl17-20020a056a216d9100b000f0b6e390c9mr9074649pzb.4.1685650266383; Thu, 01 Jun 2023 13:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685650266; cv=none; d=google.com; s=arc-20160816; b=X/7ZHH3q0lMyfdWvHxSZ0CheD6NqSaC4jmnSQe0kAN8F8kHj3sZ/CBXlDgIN3tvE7W pmYFwuXKk1qHkA8JGR8U1BmwmI1rUWWs9D1smOji9caLw2Le8wXA5HdNdefKmsdSd3bz 0pBPa5H2P4aWYnbu8Q2SqAsgHDwJOdHXhD/bAAV4TsGTcMDPAX+9iGULLYmFI849Clfs P8evuazYIgq28yd0iC6h9gXt0PmbPlgixke7vlMCp3iGwopaNDP1tlV2aX2rbyqXm/Rg qLLF+T+/aJUYm8Gj0y7ipawoO2AwFhaWmb6kKWfEGqA21SZTIKpHQPFCzmt6UnYAuf5I 8uYw== 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; bh=Y34DRcR4oyrMrH8rCayEYkffVXLlvSWIWiRp10d7zbI=; b=HC2E8mD+MIWVCOpM+o66WPWblwf6dPsC3N1n+Ti7N/UfDM0ZLtRGqeJQqv161cr09z a8+qvTLvrJhXWWVHBtz5uVkKMoSGCe8GsQg8EVgZrYooEna+oAMeNpT+hVeVQfAhcqHg LgPRvqbFk5WRTfJatViB7+CmpwLc4SgyKxnECyeAdFIPmSqxVS1Ut1htBcoMZhJ2+/t9 mXkwzUHCsK/pzWnV/IBSTGoYpwxoRnX8GxorETRZvPC4sEyfYeRFLLb/itEsgWf/vgUC bO+WW9TqZg5MbXxYqe2xisqoauLrdFFBeLXXzszDM2ih6qXy0hAr3SfwsPgaFkMlrfeb ONwg== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a6566c6000000b0053fbb190cb9si886057pgw.572.2023.06.01.13.10.51; Thu, 01 Jun 2023 13:11:06 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbjFAUFX convert rfc822-to-8bit (ORCPT + 99 others); Thu, 1 Jun 2023 16:05:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjFAUFW (ORCPT ); Thu, 1 Jun 2023 16:05:22 -0400 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B86CA133; Thu, 1 Jun 2023 13:05:20 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-bad010e1e50so1337379276.1; Thu, 01 Jun 2023 13:05:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685649920; x=1688241920; 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=S7ybGJR51tiJdbi6kkpyvQG8Yr1ailpxWvd45KdWn10=; b=kPcWuflZSeaNcCwMXJKOn4Hq6t2mtf1iD9bFbf1iquT78prP2Mcz9IJj8DCliTcs6k 2qP70Xl0v+uufgCeLV2nTe2l7ZHqfX5tzWhxeAjRJDgIVKBT0y35bkHM+AgGRZFHzUAn NmUcPmXpchyFMLYIAvSMo5FBoyhVjxyJkuAvZJevKX4KQUJKdYfKB96f2sG5K3v9VC48 p0WPsBL7ZEYTxiIbLwGGjM0aMywofCu0Z1BstYaC6cl92VV3oHB3y804qFu3OGIfcXjn TrWtk7m05MfqOfo3pfSMlmWs5f8kFkqZrvdN9XjEEVC58575zahaqD7LEipQD3EfiIpA 4Xzg== X-Gm-Message-State: AC+VfDziEQLPzh/HFXTxNYnHvyJqNhtIh5X4fqg58TJk/VgTgmeIbW4K MrGioX1MY5PHkkjnNKp1fRNsMoVOfO8dJywwer4= X-Received: by 2002:a25:e312:0:b0:ba8:fe6:8e3f with SMTP id z18-20020a25e312000000b00ba80fe68e3fmr961071ybd.5.1685649919797; Thu, 01 Jun 2023 13:05:19 -0700 (PDT) MIME-Version: 1.0 References: <20230601023644.587584-1-irogers@google.com> <20230601023644.587584-2-irogers@google.com> In-Reply-To: <20230601023644.587584-2-irogers@google.com> From: Namhyung Kim Date: Thu, 1 Jun 2023 13:05:08 -0700 Message-ID: Subject: Re: [PATCH v1 2/2] perf pmu: Warn about invalid config for all PMUs and configs To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Rob Herring , Zhengjun Xing , James Clark , Suzuki Poulouse , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed, May 31, 2023 at 7:36 PM Ian Rogers wrote: > > Don't just check the raw PMU type, the only core PMU on homogeneous > x86, check raw and all dynamically added PMUs. Extend the > perf_pmu__warn_invalid_config to check all 4 config values. Rather > than process the format list once per event, store the computed masks > for each config value. Don't ignore the mask being zero, which is > likely for config2 and config3, add config_masks_present so config > values can be ignored only when no format information is present. > > Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Thanks, Namhyung > --- > tools/perf/util/parse-events.c | 13 +++++++++--- > tools/perf/util/pmu.c | 38 ++++++++++++++++++++++++---------- > tools/perf/util/pmu.h | 13 +++++++++++- > 3 files changed, 49 insertions(+), 15 deletions(-) > > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > index 7f047ac11168..9f60607b0d86 100644 > --- a/tools/perf/util/parse-events.c > +++ b/tools/perf/util/parse-events.c > @@ -245,9 +245,16 @@ __add_event(struct list_head *list, int *idx, > if (pmu) > perf_pmu__warn_invalid_formats(pmu); > > - if (pmu && attr->type == PERF_TYPE_RAW) > - perf_pmu__warn_invalid_config(pmu, attr->config, name); > - > + if (pmu && (attr->type == PERF_TYPE_RAW || attr->type >= PERF_TYPE_MAX)) { > + perf_pmu__warn_invalid_config(pmu, attr->config, name, > + PERF_PMU_FORMAT_VALUE_CONFIG, "config"); > + perf_pmu__warn_invalid_config(pmu, attr->config1, name, > + PERF_PMU_FORMAT_VALUE_CONFIG1, "config1"); > + perf_pmu__warn_invalid_config(pmu, attr->config2, name, > + PERF_PMU_FORMAT_VALUE_CONFIG2, "config2"); > + perf_pmu__warn_invalid_config(pmu, attr->config3, name, > + PERF_PMU_FORMAT_VALUE_CONFIG3, "config3"); > + } > if (init_attr) > event_attr_init(attr); > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 204ce3f02e63..b0443406fd57 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -1611,37 +1611,53 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) > return pmu->nr_caps; > } > > -void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, > - const char *name) > +static void perf_pmu__compute_config_masks(struct perf_pmu *pmu) > { > struct perf_pmu_format *format; > - __u64 masks = 0, bits; > - char buf[100]; > - unsigned int i; > + > + if (pmu->config_masks_computed) > + return; > > list_for_each_entry(format, &pmu->format, list) { > - if (format->value != PERF_PMU_FORMAT_VALUE_CONFIG) > + unsigned int i; > + __u64 *mask; > + > + if (format->value >= PERF_PMU_FORMAT_VALUE_CONFIG_END) > continue; > > + pmu->config_masks_present = true; > + mask = &pmu->config_masks[format->value]; > + > for_each_set_bit(i, format->bits, PERF_PMU_FORMAT_BITS) > - masks |= 1ULL << i; > + *mask |= 1ULL << i; > } > + pmu->config_masks_computed = true; > +} > + > +void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, > + const char *name, int config_num, > + const char *config_name) > +{ > + __u64 bits; > + char buf[100]; > + > + perf_pmu__compute_config_masks(pmu); > > /* > * Kernel doesn't export any valid format bits. > */ > - if (masks == 0) > + if (!pmu->config_masks_present) > return; > > - bits = config & ~masks; > + bits = config & ~pmu->config_masks[config_num]; > if (bits == 0) > return; > > bitmap_scnprintf((unsigned long *)&bits, sizeof(bits) * 8, buf, sizeof(buf)); > > - pr_warning("WARNING: event '%s' not valid (bits %s of config " > + pr_warning("WARNING: event '%s' not valid (bits %s of %s " > "'%llx' not supported by kernel)!\n", > - name ?: "N/A", buf, config); > + name ?: "N/A", buf, config_name, config); > } > > int perf_pmu__match(char *pattern, char *name, char *tok) > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h > index 7a1535dc1f12..d98b0feec022 100644 > --- a/tools/perf/util/pmu.h > +++ b/tools/perf/util/pmu.h > @@ -81,6 +81,10 @@ struct perf_pmu { > * perf_event_attr once. > */ > bool formats_checked; > + /** @config_masks_present: Are there config format values? */ > + bool config_masks_present; > + /** @config_masks_computed: Set when masks are lazily computed. */ > + bool config_masks_computed; > /** > * @max_precise: Number of levels of :ppp precision supported by the > * PMU, read from > @@ -125,6 +129,12 @@ struct perf_pmu { > /** @list: Element on pmus list in pmu.c. */ > struct list_head list; > > + /** > + * @config_masks: Derived from the PMU's format data, bits that are > + * valid within the config value. > + */ > + __u64 config_masks[PERF_PMU_FORMAT_VALUE_CONFIG_END]; > + > /** > * @missing_features: Features to inhibit when events on this PMU are > * opened. > @@ -255,7 +265,8 @@ int perf_pmu__convert_scale(const char *scale, char **end, double *sval); > int perf_pmu__caps_parse(struct perf_pmu *pmu); > > void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, > - const char *name); > + const char *name, int config_num, > + const char *config_name); > void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu); > > int perf_pmu__match(char *pattern, char *name, char *tok); > -- > 2.41.0.rc0.172.g3f132b7071-goog >