Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4374362rdh; Tue, 28 Nov 2023 22:24:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoiYlR+hNyiaa0dux14WV4nYx3JqmbZ9L+D/YI9Hb4wW7nQYBMedF8x8MylXEY96guYtRS X-Received: by 2002:a17:90b:3b4e:b0:285:8cb1:7f52 with SMTP id ot14-20020a17090b3b4e00b002858cb17f52mr18341438pjb.18.1701239084238; Tue, 28 Nov 2023 22:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701239084; cv=none; d=google.com; s=arc-20160816; b=W86QAUKpsq7DsCHE2Xr29Qfhc1FPIBd+uH8fO43rukufz+5KhpyVDTMZL0eUoolX1c cO0QLB/8qoXKkOlkQH67t1IVJ12LTmDYKHXTKUt5dF1+N4gelXfTIznMBNi6Dt9Fyj+G 3k6ZBO5aQ9kipxiLq66JwbjZFxW1gRQd9l0u0AEG+q1LAISkZ2NLcQW+6KaY7vwPbJgW 3eLdBp6yZLTYaTMZEg+tGCkKY6ZhGvSTMS/I7VdrO9S8Xnbi4rfXpqo74ulRbTGo8wBQ d3/mAO15yYjF2ljnlsWqJxfKxXNIYtcGviYlHzl8CRaHHDSYIo2Svj35kCwaXz/dim1/ xGAQ== 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=RrR3MK1LW15VjpUrUw2X9mVPoBtBYztiwKpoFmC9scE=; fh=XHfxLTtgEgumfK/Ybw9ABXB8MwTUbUR72FKJvvM7MDU=; b=XKMlg0h9rhFUThQT2ccZoK5bD8hCvEEXkERehsX9VSDajM+CxEFT7wY+lx7V7kpbzN E2Myk4ybcGWFJT3lAr8k9m+94G1JBkA1oSp0djT8vvEwisSVuIBInB2zYi2IAL1/NDlI f0gj6Ji9QDnAkUGpXgbMF6gaGLmn6C/epngvZ2A08Rfg+tY1/rhURGDZF43RNWSrZwbh HMhTRlxm5H7nK8yCnqWrfbUOEUOHs12XonTHLGgLIYNWFAVqkU8GkA/i6lG9yq6GS/p5 WUDfNwXrYrcpu2RSpMmJRZodz5zHxw6Rh2kjjwdZMLlxcskJUch9coWawZIQS8LyPRBq zhXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pvnhHQKW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y21-20020a17090ad71500b00285a62cc148si678197pju.134.2023.11.28.22.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:24:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pvnhHQKW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4B5A1807A5BA; Tue, 28 Nov 2023 22:24:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjK2GYR (ORCPT + 99 others); Wed, 29 Nov 2023 01:24:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjK2GYP (ORCPT ); Wed, 29 Nov 2023 01:24:15 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B826110C0 for ; Tue, 28 Nov 2023 22:24:21 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b51e26a7aso25235e9.1 for ; Tue, 28 Nov 2023 22:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701239060; x=1701843860; darn=vger.kernel.org; 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=RrR3MK1LW15VjpUrUw2X9mVPoBtBYztiwKpoFmC9scE=; b=pvnhHQKWIRRGPVPJtxocxSZ5U5hYunLHyQCLjIaLr+nw1bU1q1xvRJQkfR9SmUS/TQ RrtD1Tyz7brtpsdHOMhI8QuIG49BPVbTyMytS4nrH0ML+Zfrmzy+k65nxd80dUYPqDRX c3KJwuvoTev+wTkBTO+x5HL4xcwtdcH65gONW9fLOSeaaPhd/ld/TDH2UqE1SfQCAA0V O26DXQrhF6RCARxgGv1Byka2+nmQ63n3yFHBVnenNvp70DG2Xfo1IUTcK0t1qUDuzWy/ YO26I2Gx757KD49BFN7/F77lyaBjcu9GeBo9bScoYSQMZAYT8xVr2AZvggZpSJ5BS9mL 6XGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701239060; x=1701843860; 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=RrR3MK1LW15VjpUrUw2X9mVPoBtBYztiwKpoFmC9scE=; b=h4vPIgzpvlYz270OFe8dA6TBWK8At9aU2MQBAeOZFPXVRfzVdpbe9m+6SL7bq7eD9o yfSCocy+3k9knwwlP6IXWIr+WyGsJxquj2MOzgR+S68cwKDIPtXj/GrSwAMZE74iMjZd FbdrMxxCgYVCPLlf59CUlItRzJoHDYCH27GS+I5Zr5dVEfuHIIRuvm9f0kxCrNeVhVbw maVpIVpeT22fFJpHCEq+NEvB+RG43aixJH/8RqgJ0jot3vpjGK5VOEQvB6NtvIx54LlH lHRVts1VjY4zdp+PaO8UVab8uv7oLOxq1bZneKK6M2BM809tOW3muO4cTmhb4choQwhU V5VA== X-Gm-Message-State: AOJu0YyxU6PjjsF36q7nE9/y5Kns3H8CsCNaqgwS1z0IFSK99Hb/KjKe 50nsDVtIykHx5roC9pQbrturvgXF+V9nB7gZx+vNZQ== X-Received: by 2002:a05:600c:3c83:b0:40b:2ec6:2a87 with SMTP id bg3-20020a05600c3c8300b0040b2ec62a87mr886505wmb.5.1701239059996; Tue, 28 Nov 2023 22:24:19 -0800 (PST) MIME-Version: 1.0 References: <20231128203940.3964287-1-kan.liang@linux.intel.com> In-Reply-To: <20231128203940.3964287-1-kan.liang@linux.intel.com> From: Ian Rogers Date: Tue, 28 Nov 2023 22:24:08 -0800 Message-ID: Subject: Re: [PATCH] perf mem: Fix perf mem error on hybrid To: kan.liang@linux.intel.com Cc: acme@kernel.org, mingo@redhat.com, peterz@infradead.org, mark.rutland@arm.com, namhyung@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, ravi.bangoria@amd.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ammy Yi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 22:24:41 -0800 (PST) On Tue, Nov 28, 2023 at 12:39=E2=80=AFPM wrote: > > From: Kan Liang > > The below error can be triggered on a hybrid machine. > > $ perf mem record -t load sleep 1 > event syntax error: 'breakpoint/mem-loads,ldlat=3D30/P' > \___ Bad event or PMU > > Unable to find PMU or event on a PMU of 'breakpoint' > > In the perf_mem_events__record_args(), the current perf never checks the > availability of a mem event on a given PMU. All the PMUs will be added > to the perf mem event list. Perf errors out for the unsupported PMU. > > Extend perf_mem_event__supported() and take a PMU into account. Check > the mem event for each PMU before adding it to the perf mem event list. > > Optimize the perf_mem_events__init() a little bit. The function is to > check whether the mem events are supported in the system. It doesn't > need to scan all PMUs. Just return with the first supported PMU is good > enough. > > Fixes: 5752c20f3787 ("perf mem: Scan all PMUs instead of just core ones") > Reported-by: Ammy Yi > Tested-by: Ammy Yi > Signed-off-by: Kan Liang > --- > tools/perf/util/mem-events.c | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) > > diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c > index 954b235e12e5..3a2e3687878c 100644 > --- a/tools/perf/util/mem-events.c > +++ b/tools/perf/util/mem-events.c > @@ -100,11 +100,14 @@ int perf_mem_events__parse(const char *str) > return -1; > } > > -static bool perf_mem_event__supported(const char *mnt, char *sysfs_name) > +static bool perf_mem_event__supported(const char *mnt, struct perf_pmu *= pmu, > + struct perf_mem_event *e) > { > + char sysfs_name[100]; > char path[PATH_MAX]; > struct stat st; > > + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->nam= e); Not sure if this is right. Looking at sysfs_name values: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tr= ee/tools/perf/util/mem-events.c?h=3Dperf-tools-next#n23 "cpu/events/mem-loads" and "cpu/events/mem-stores", so won't pmu->name never be used? Is there a missed change to change the cpu to %s? Thanks, Ian > scnprintf(path, PATH_MAX, "%s/devices/%s", mnt, sysfs_name); > return !stat(path, &st); > } > @@ -120,7 +123,6 @@ int perf_mem_events__init(void) > > for (j =3D 0; j < PERF_MEM_EVENTS__MAX; j++) { > struct perf_mem_event *e =3D perf_mem_events__ptr(j); > - char sysfs_name[100]; > struct perf_pmu *pmu =3D NULL; > > /* > @@ -136,12 +138,12 @@ int perf_mem_events__init(void) > * of core PMU. > */ > while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { > - scnprintf(sysfs_name, sizeof(sysfs_name), e->sysf= s_name, pmu->name); > - e->supported |=3D perf_mem_event__supported(mnt, = sysfs_name); > + e->supported |=3D perf_mem_event__supported(mnt, = pmu, e); > + if (e->supported) { > + found =3D true; > + break; > + } > } > - > - if (e->supported) > - found =3D true; > } > > return found ? 0 : -ENOENT; > @@ -167,13 +169,10 @@ static void perf_mem_events__print_unsupport_hybrid= (struct perf_mem_event *e, > int idx) > { > const char *mnt =3D sysfs__mount(); > - char sysfs_name[100]; > struct perf_pmu *pmu =3D NULL; > > while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { > - scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, > - pmu->name); > - if (!perf_mem_event__supported(mnt, sysfs_name)) { > + if (!perf_mem_event__supported(mnt, pmu, e)) { > pr_err("failed: event '%s' not supported\n", > perf_mem_events__name(idx, pmu->name)); > } > @@ -183,6 +182,7 @@ static void perf_mem_events__print_unsupport_hybrid(s= truct perf_mem_event *e, > int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, > char **rec_tmp, int *tmp_nr) > { > + const char *mnt =3D sysfs__mount(); > int i =3D *argv_nr, k =3D 0; > struct perf_mem_event *e; > > @@ -211,6 +211,9 @@ int perf_mem_events__record_args(const char **rec_arg= v, int *argv_nr, > while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) = { > const char *s =3D perf_mem_events__name(j= , pmu->name); > > + if (!perf_mem_event__supported(mnt, pmu, = e)) > + continue; > + > rec_argv[i++] =3D "-e"; > if (s) { > char *copy =3D strdup(s); > -- > 2.35.1 >