Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp87416pxb; Mon, 8 Feb 2021 16:08:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxSZ7uQYP8HA1Mth10oaFLclTVONoJgnOELAdfIvoJp7JvQZh8jgS5GJ0ZMNHSY/frm5Zh X-Received: by 2002:a17:906:8252:: with SMTP id f18mr19627148ejx.418.1612829332798; Mon, 08 Feb 2021 16:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612829332; cv=none; d=google.com; s=arc-20160816; b=BtJ3o1c/OTYYywKXOR/Up7n5MVfV+N+MKTv29ZiMTjO8etIJRHHFnB8uo2NFJTA+pR jwRgg+InK4WsmL5aaKqdv2yQpTplaOCbqhOnVlsav2sY3Xn3o4YWN128dwVKiTVdcuZ4 Awmmh3qdddv+CAetMZ+4lcQz7QDl5s2EUqvDkkT1QOZ7ST6jCw12qCDx2m0hFgR0PF9M w0RY1eEVUaEc8B0c7CSTKoQI7Pt0Z+8QZnYJWHWCF/XwdFzeCLgDZN+eEv6DOrv3nCrK Wi/U5sEf/pA/unGHW2S7anCrTZ0Ho6zD80Q7TAHQcv6rHDDmvv0XMrId3u0kYiKp+NY6 zj5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=AyR5tYOGD0Ic7kF1GXDgdua8KaZMVHQPfBN9s6Ucs3k=; b=K1gunCCvxeWWRbz6NSKKgkHu7V+duKtPloryumZp3DkQoVb6kz1+Mw201+gC/7FTTR JRNyCAu77Vo43nMBjt0/mT+r0Lv5Z4EDBr/8Krh1cN1dQnQUneweOMlurrYz47D63t8w 5UYdjAsBRuB2QgS0pg4Yw5mkdFojlZ+ykGTdreMAo0JIx4ro7c2TIBuu+nOUnBPBjgIF ObKT8HgUbpz54PwlwBwhp0ZxQZiQ+0IpAQ1QYu2K/oSAPlbPP1aIWpgKsWxgUk5XJShk k0GViT3I6EdyBbBG+0WmJ8Nh0qNpKxMj/+GbsTc32Jp/DWMRMTAQZfRQlBvidpKx3RHN Ay9w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si14859228edc.395.2021.02.08.16.08.25; Mon, 08 Feb 2021 16:08:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbhBIAH0 (ORCPT + 99 others); Mon, 8 Feb 2021 19:07:26 -0500 Received: from mga09.intel.com ([134.134.136.24]:7333 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbhBIAHX (ORCPT ); Mon, 8 Feb 2021 19:07:23 -0500 IronPort-SDR: MMavFpwTpzov+IThVaqb5bgVwEAYmgFNwAIDcF7KBOdIEF4tEv2FHj+Wt5obDPf6tf4EkAQ/er +pEq1FsoQbDg== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="181947478" X-IronPort-AV: E=Sophos;i="5.81,163,1610438400"; d="scan'208";a="181947478" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 16:05:37 -0800 IronPort-SDR: Ws7yiCUCyLVZpOK7AE4z+08xRXUG7jwTpPtLtzv/cwqn3dFcS6+XLOWN5X0YM2QpGu3rj8zDaq U3twhIn85SCA== X-IronPort-AV: E=Sophos;i="5.81,163,1610438400"; d="scan'208";a="395793230" Received: from yjin15-mobl1.ccr.corp.intel.com (HELO [10.238.4.27]) ([10.238.4.27]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 16:05:34 -0800 Subject: Re: [PATCH 28/49] perf pmu: Save detected hybrid pmus to a global pmu list To: Arnaldo Carvalho de Melo , kan.liang@linux.intel.com Cc: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, namhyung@kernel.org, jolsa@redhat.com, ak@linux.intel.com, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, "Jin, Yao" References: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> <1612797946-18784-29-git-send-email-kan.liang@linux.intel.com> <20210208185521.GJ920417@kernel.org> From: "Jin, Yao" Message-ID: <36f679f5-30b9-cb2a-0373-2c9e05645750@linux.intel.com> Date: Tue, 9 Feb 2021 08:05:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210208185521.GJ920417@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnaldo, On 2/9/2021 2:55 AM, Arnaldo Carvalho de Melo wrote: > Em Mon, Feb 08, 2021 at 07:25:25AM -0800, kan.liang@linux.intel.com escreveu: >> From: Jin Yao >> >> We identify the cpu_core pmu and cpu_atom pmu by explicitly >> checking following files: >> >> For cpu_core, check: >> "/sys/bus/event_source/devices/cpu_core/cpus" >> >> For cpu_atom, check: >> "/sys/bus/event_source/devices/cpu_atom/cpus" >> >> If the 'cpus' file exists, the pmu exists. >> >> But in order not to hardcode the "cpu_core" and "cpu_atom", >> and make the code generic, if the path >> "/sys/bus/event_source/devices/cpu_xxx/cpus" exists, the hybrid >> pmu exists. All the detected hybrid pmus are linked to a >> global list 'perf_pmu__hybrid_pmus' and then next we just need >> to iterate the list by using perf_pmu__for_each_hybrid_pmus. >> >> Reviewed-by: Andi Kleen >> Signed-off-by: Jin Yao >> --- >> tools/perf/util/pmu.c | 21 +++++++++++++++++++++ >> tools/perf/util/pmu.h | 7 +++++++ >> 2 files changed, 28 insertions(+) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index 0c25457..e97b121 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -27,6 +27,7 @@ >> #include "fncache.h" >> >> struct perf_pmu perf_pmu__fake; >> +LIST_HEAD(perf_pmu__hybrid_pmus); >> >> struct perf_pmu_format { >> char *name; >> @@ -633,11 +634,27 @@ static struct perf_cpu_map *pmu_cpumask(const char *name) >> return NULL; >> } >> >> +static bool pmu_is_hybrid(const char *name) >> +{ >> + char path[PATH_MAX]; >> + const char *sysfs; >> + >> + if (strncmp(name, "cpu_", 4)) >> + return false; >> + >> + sysfs = sysfs__mountpoint(); > > Its extremely unlikely that sysfs isn't mounted, but if so, this will > NULL deref, so please do as other sysfs__mountpoint() uses in > tools/perf/util/pmu.c and check if sysfs is NULL, returning false, i.e. > file isn't available. > Yes, I need to check the return value of sysfs__mountpoint(), something like. sysfs = sysfs__mountpoint(); if (!sysfs) return false; >> + snprintf(path, PATH_MAX, CPUS_TEMPLATE_CPU, sysfs, name); >> + return file_available(path); >> +} >> + >> static bool pmu_is_uncore(const char *name) >> { >> char path[PATH_MAX]; >> const char *sysfs; >> >> + if (pmu_is_hybrid(name)) >> + return false; >> + >> sysfs = sysfs__mountpoint(); >> snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name); >> return file_available(path); >> @@ -951,6 +968,7 @@ static struct perf_pmu *pmu_lookup(const char *name) >> pmu->is_uncore = pmu_is_uncore(name); >> if (pmu->is_uncore) >> pmu->id = pmu_id(name); >> + pmu->is_hybrid = pmu_is_hybrid(name); >> pmu->max_precise = pmu_max_precise(name); >> pmu_add_cpu_aliases(&aliases, pmu); >> pmu_add_sys_aliases(&aliases, pmu); >> @@ -962,6 +980,9 @@ static struct perf_pmu *pmu_lookup(const char *name) >> list_splice(&aliases, &pmu->aliases); >> list_add_tail(&pmu->list, &pmus); >> >> + if (pmu->is_hybrid) >> + list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus); >> + >> pmu->default_config = perf_pmu__get_default_config(pmu); >> >> return pmu; >> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h >> index 0e724d5..99bdb5d 100644 >> --- a/tools/perf/util/pmu.h >> +++ b/tools/perf/util/pmu.h >> @@ -5,6 +5,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include "parse-events.h" >> #include "pmu-events/pmu-events.h" >> @@ -34,6 +35,7 @@ struct perf_pmu { >> __u32 type; >> bool selectable; >> bool is_uncore; >> + bool is_hybrid; >> bool auxtrace; >> int max_precise; >> struct perf_event_attr *default_config; >> @@ -42,9 +44,11 @@ struct perf_pmu { >> struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ >> struct list_head caps; /* HEAD struct perf_pmu_caps -> list */ >> struct list_head list; /* ELEM */ >> + struct list_head hybrid_list; >> }; >> >> extern struct perf_pmu perf_pmu__fake; >> +extern struct list_head perf_pmu__hybrid_pmus; >> >> struct perf_pmu_info { >> const char *unit; >> @@ -124,4 +128,7 @@ int perf_pmu__convert_scale(const char *scale, char **end, double *sval); >> >> int perf_pmu__caps_parse(struct perf_pmu *pmu); >> >> +#define perf_pmu__for_each_hybrid_pmus(pmu) \ > > singular, i.e. > > #define perf_pmu__for_each_hybrid_pmu(pmu) \ > Got it. Will use perf_pmu__for_each_hybrid_pmu in next version. Thanks Jin Yao >> + list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) >> + >> #endif /* __PMU_H */ >> -- >> 2.7.4 >> >