Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4207919pxb; Mon, 8 Feb 2021 10:22:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDynuFmu5mEQAJ2jhBg8yvh6T/fP5a35HrVUCm/SOjyNfuANqkPi2oJMQLfyIsFLkcm3NF X-Received: by 2002:aa7:dd57:: with SMTP id o23mr18448660edw.252.1612808577040; Mon, 08 Feb 2021 10:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612808577; cv=none; d=google.com; s=arc-20160816; b=ievsMmmPcrQ1zRuqWnBrsz0V2OgM646Dqw7VRNqMp8KxJxzP0pLEzhv5uQ9MIeQ0EN 0u2h3Aj4u/uE5FIcEY66PuS45z7auiWvWJOk0H+5i1/lhDWeoZe8n2gxlajeax9t3M8+ Vhz2EIzgBV7sauFmSxFp29fKYQujUGqNueGv8DI+T8J4taU5JLxVY+BYDDeO0Jx38c5u xeiuHk75rC0FKfOZk16rmEZMkprHm3i/b5QGfLexwH4MDjSth1edEl1T/BZfRT2NHRi7 dF3feqExX6I7VcuKwcm49RyG1h8rkjrjASee3UZR7p279K8uAz/xQ4pToeUPAWOjis2n fIhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=vXutTyZiGTfx7JO0aWCK8PheJruQ/GGZwwPGY/bkXzM=; b=Z+oqsktjBiYpKGkEpHqJ8Y/ZG5X3nKJcEpCPDKqUSbkrlyVbU03uoDFMlM9H4UDVNx iPFxhfhuhefzo4ZAUMyJy8tpYXioSTGsL5pz1tcMvdGyZqhqpT2DXdKTuaPtvUOmb2C/ zExt0TkvUw0lwWa2orcvDnZMRX95tsPXWYBjk/hW2755yJle6UtX2Yj0TG4CS01ESy4g fjv30u5uS6SdckWD0xNlA2dNPc5nKnPAKbCz5EAaalanwA/0YrmWoMzktUUzm8joUREj PftTK4JXbrNnr3r5Nu2kM3BfQLbx1iBjMVkbfFYXy62QuyfGfhhaiRBwCbxx2hiUOFZt QSrw== 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 d23si4588674eje.107.2021.02.08.10.22.33; Mon, 08 Feb 2021 10:22:57 -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 S234050AbhBHSVq (ORCPT + 99 others); Mon, 8 Feb 2021 13:21:46 -0500 Received: from mga14.intel.com ([192.55.52.115]:62838 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234118AbhBHPp2 (ORCPT ); Mon, 8 Feb 2021 10:45:28 -0500 IronPort-SDR: vfGEzhnnLCvX0J4uzU+nu+6y9TiyrAiQjwO3e7B8eqQQQ9yAwS6zhdMR7W6/vt9zCriaJggUAB jmHRB4MGMNUw== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="180952045" X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="180952045" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 07:30:36 -0800 IronPort-SDR: Ynh3p6Wg355GnbjZEodKzkDRNON3zNkG5/zADujRs6pcN1jN6VTdu4t8FQxHYpeTi1zzXyDKep V3jNfnD3/3yQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="358820873" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga003.jf.intel.com with ESMTP; 08 Feb 2021 07:30:36 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, acme@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, bp@alien8.de, namhyung@kernel.org, jolsa@redhat.com, ak@linux.intel.com, yao.jin@linux.intel.com, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com Subject: [PATCH 29/49] perf pmu: Add hybrid helper functions Date: Mon, 8 Feb 2021 07:25:26 -0800 Message-Id: <1612797946-18784-30-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> References: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jin Yao The functions perf_pmu__is_hybrid and perf_pmu__find_hybrid_pmu can be used to identify the hybrid platform and return the found hybrid cpu pmu. All the detected hybrid pmus have been saved in 'perf_pmu__hybrid_pmus' list. So we just need to search this list for a pmu name. perf_pmu__hybrid_type_to_pmu converts the user specified string to hybrid pmu name. This is used to support the '--cputype' option in next patches. perf_pmu__hybrid_exist checks if hybrid pmus exist. Reviewed-by: Andi Kleen Signed-off-by: Jin Yao --- tools/perf/util/pmu.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.h | 11 +++++++++++ 2 files changed, 51 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e97b121..04447f5 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1842,3 +1842,43 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) return nr_caps; } + +struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) +{ + struct perf_pmu *pmu; + + if (!name) + return NULL; + + perf_pmu__for_each_hybrid_pmus(pmu) { + if (!strcmp(name, pmu->name)) + return pmu; + } + + return NULL; +} + +bool perf_pmu__is_hybrid(const char *name) +{ + return perf_pmu__find_hybrid_pmu(name) != NULL; +} + +char *perf_pmu__hybrid_type_to_pmu(const char *type) +{ + char *pmu_name = NULL; + + if (asprintf(&pmu_name, "cpu_%s", type) < 0) + return NULL; + + if (perf_pmu__is_hybrid(pmu_name)) + return pmu_name; + + /* + * The pmus may be not scanned yet, so check the sysfs. + */ + if (pmu_is_hybrid(pmu_name)) + return pmu_name; + + free(pmu_name); + return NULL;; +} diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 99bdb5d..bb74595 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -131,4 +131,15 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu); #define perf_pmu__for_each_hybrid_pmus(pmu) \ list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) +struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); + +bool perf_pmu__is_hybrid(const char *name); + +char *perf_pmu__hybrid_type_to_pmu(const char *type); + +static inline bool perf_pmu__hybrid_exist(void) +{ + return !list_empty(&perf_pmu__hybrid_pmus); +} + #endif /* __PMU_H */ -- 2.7.4