Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19716860rwd; Wed, 28 Jun 2023 13:13:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62Hq6d2htgLaCj/7S2nCIQNGtE/endxSdqiDsofR/RUGBQJjL9Ap4pJ3CdNgt0jXJYfiH5 X-Received: by 2002:a05:6a20:9382:b0:10c:4e7f:1a5a with SMTP id x2-20020a056a20938200b0010c4e7f1a5amr44836174pzh.49.1687983225258; Wed, 28 Jun 2023 13:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687983225; cv=none; d=google.com; s=arc-20160816; b=nPNFgsYQFK93GxpDUAzj4zgh+GXpULsUTE2oHHhxl82+mAmwJwY/Drh0VEtEHavHsO Db0eYAl/sxvmwf6tz0/gcYW2C/EckEOsf6tfvP7Pr/4yJGPXnAYryOR90rFztFTlEJkG 6K1rIPhBibqSDEy97I+YRCe14i/uI+EP52P0v4XB99exkaQ4TSbgbAraOoL0winq2xuB UufXiyagQNi8CwB71VzdpNhszixKhJlXhdIQhHonncF2BreI86+Qslx3Sjf2ndthnvgU 0OIzuJ5+q7eBydJbjQMlv6hyAt8B+wSf7mAalESbZgaUkOr24l0bYmmWQDBae3poyNns NJVg== 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=lbsV2takt+6NbUDnzvhhdbv2Ajwck67ixYf0MCeDajM=; fh=skDcguSCfN5XlR6DUEww5Hto0QbTke94/Jy+xxdyfbY=; b=xdV1VUh40f4rUKwHkA1LWmGSGI94R0oK9Nfw3tq/04/2D632MASIkv0P2URFP9ng2t mdZzUB8Oq0/OYkmvrxtGChuMMzPRsF37qJ0YIBF5UGBf2dvSRZDNcGUT8jOpnxioAILL GFKiNKedF3JgJkrDYeocOVWydfvuWLqMbiJJfstkTUjSMLxOTUuxkyePphkL4y2tTDmg aTMffG0QP+BoKveFw2uMVYG8dYXbauTq19c+TQ+BkjGlbH3aKxM+KY+qFwrdlhYuNMFg Cx9wJoBANw/Mh52yLz3IAwijVyLL3wCmfPlaYEUis+V+1Zd43RQbwaGrW1N72fSIGqMs 5qLA== 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 f28-20020a631f1c000000b005578a320ea6si9298285pgf.872.2023.06.28.13.13.32; Wed, 28 Jun 2023 13:13:45 -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 S231359AbjF1UFe convert rfc822-to-8bit (ORCPT + 99 others); Wed, 28 Jun 2023 16:05:34 -0400 Received: from mail-yb1-f172.google.com ([209.85.219.172]:59665 "EHLO mail-yb1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbjF1UFa (ORCPT ); Wed, 28 Jun 2023 16:05:30 -0400 Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-bd0a359ca35so121688276.3; Wed, 28 Jun 2023 13:05:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687982729; x=1690574729; 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=wTmpyVSMLrIk0QN7D+5i/fdXLo6g3GMR/467HY8B59c=; b=T4Hff1Fk03Bp3B0AkaOi9eYnl8ayYRfBGZKFg1Ly4lQqfCyzc/OpWg8Ebgcxzcr7j+ lfX7ZRm0gTTHOGj5kpVhpsWYeSGcmRRNGgKilxwUV2nqcGb0BHUUWnffIVAh4+7eKP1q s/gPMj2dAImgVPOu1Wme21eTIGI8gW4TPSFKxy2mt+ZUNfOV9VYj50cV2iAolb9vsDFU UNj72J1Iw2aybP0QL0Zvp20xVGXdwV/UTzXyD2+PeBzzcxHlDpqC8SmMIoEao/V8gRFF wr3HEOSws1oAOHwT43sxrLk4SR5hNXQwuIZEYWLzeQelntL0UhyqBqyHz6dirHnx5TZR pahw== X-Gm-Message-State: AC+VfDzzBtgNbdcyduYDB0Q5Tu8nS9SmNiNRJxeRYoZRzC6Rjp1Hecd0 G53xrdzjPL1k4EjaJcHGIHbSA279r8A8DHkwudo= X-Received: by 2002:a25:cf91:0:b0:c14:3d56:bf65 with SMTP id f139-20020a25cf91000000b00c143d56bf65mr9889094ybg.4.1687982729154; Wed, 28 Jun 2023 13:05:29 -0700 (PDT) MIME-Version: 1.0 References: <20230627182834.117565-1-irogers@google.com> <344a8de1-469d-a8f9-100e-9a67e562939b@huawei.com> In-Reply-To: <344a8de1-469d-a8f9-100e-9a67e562939b@huawei.com> From: Namhyung Kim Date: Wed, 28 Jun 2023 13:05:17 -0700 Message-ID: Subject: Re: [PATCH v1] perf pmus: Add placeholder core PMU To: Yang Jihong Cc: Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , James Clark , Suzuki Poulouse , Rob Herring , Ravi Bangoria , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 8:01 PM Yang Jihong wrote: > > Hello, > > On 2023/6/28 2:28, Ian Rogers wrote: > > If loading a core PMU fails, legacy hardware/cache events may segv due > > to there being no PMU. Create a placeholder empty PMU for this > > case. This was discussed in: > > https://lore.kernel.org/lkml/20230614151625.2077-1-yangjihong1@huawei.com/ > > > > Reported-by: Yang Jihong > > Signed-off-by: Ian Rogers > > --- > > tools/perf/util/pmu.c | 25 +++++++++++++++++++++++++ > > tools/perf/util/pmu.h | 1 + > > tools/perf/util/pmus.c | 7 ++++++- > > 3 files changed, 32 insertions(+), 1 deletion(-) > > > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > > index 8d5ecd4ff1a9..7f984a7f16ca 100644 > > --- a/tools/perf/util/pmu.c > > +++ b/tools/perf/util/pmu.c > > @@ -928,6 +928,31 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char > > return NULL; > > } > > > > +/* Creates the PMU when sysfs scanning fails. */ > > +struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus) > > +{ > > + struct perf_pmu *pmu = zalloc(sizeof(*pmu)); > > + > > + if (!pmu) > > + return NULL; > > + > > + pmu->name = strdup("cpu"); > > + if (!pmu->name) { > > + free(pmu); > > + return NULL; > > + } > > + > > + pmu->is_core = true; > > + pmu->type = PERF_TYPE_RAW; > > + pmu->cpus = cpu_map__online(); > > + > > + INIT_LIST_HEAD(&pmu->format); > > + INIT_LIST_HEAD(&pmu->aliases); > > + INIT_LIST_HEAD(&pmu->caps); > > + list_add_tail(&pmu->list, core_pmus); > > + return pmu; > > +} > > + > > void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) > > { > > struct perf_pmu_format *format; > > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h > > index 8807a624e918..203b92860e3c 100644 > > --- a/tools/perf/util/pmu.h > > +++ b/tools/perf/util/pmu.h > > @@ -286,6 +286,7 @@ int perf_pmu__event_source_devices_fd(void); > > int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags); > > > > struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name); > > +struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus); > > void perf_pmu__delete(struct perf_pmu *pmu); > > > > #endif /* __PMU_H */ > > diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c > > index 0866dee3fc62..3cd9de42139e 100644 > > --- a/tools/perf/util/pmus.c > > +++ b/tools/perf/util/pmus.c > > @@ -153,7 +153,12 @@ static void pmu_read_sysfs(bool core_only) > > > > closedir(dir); > > if (core_only) { > > - read_sysfs_core_pmus = true; > > + if (!list_empty(&core_pmus)) > > + read_sysfs_core_pmus = true; > > + else { > > + if (perf_pmu__create_placeholder_core_pmu(&core_pmus)) > > + read_sysfs_core_pmus = true; > > + } > > } else { > > read_sysfs_core_pmus = true; > > read_sysfs_all_pmus = true; > > > Great. This patch solves the problem, the test results are shown in [1]. > > Tested-by: Yang Jihong Applied to perf-tools-next, thanks!