From patchwork Thu Nov 7 07:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C7B4D5AE6E for ; Thu, 7 Nov 2024 07:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=d5CBVRj+oeokqCZ8tX2zkzcVhcgEep+JK2ByfRR+yWc=; b=A8l179LPM8Wr3B1BDklGlYzuC1 u0JTBdDbiQJlhL0+y0/4d67Dm+eX/HKd3frxozyB4Iprsp5PrQadD7gaYiMZHLjh/bZ4N/BdEsIq1 aPsmxPpuXRenK27T3hEaaVlin46aZfeQcRZ/5N0O+lKAmOWuhN8+eptFYOOnVMz7+DcXY1KcNF4Mo pt5Hh2hNKhk2JYttCAOiVx+nZLcvqevuq2UCrdcWuULoLsU1u94eix55m2wwkU+wJh05CA45o3ewC JKqiDq1ihoyFdmPMcdb7mnkNYZdbGpa8NOAxYYB19JXxxwqGf61doD8+xbNLPZLqitAw6UOPkT3sl 5m8bG2Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wo3-00000005xx6-1F9W; Thu, 07 Nov 2024 07:19:51 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkR-00000005wod-1F1X for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:10 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e30cf121024so1063296276.1 for ; Wed, 06 Nov 2024 23:16:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963766; x=1731568566; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d5CBVRj+oeokqCZ8tX2zkzcVhcgEep+JK2ByfRR+yWc=; b=XRF+EqaVKWEuj3L/jF8qdQnyf6lBCLV5EkplIDGNGeLo3dfC9X1cv0Z+eVTES2jcZW FpwQNWHmQbalnkiTk+UbYp+e/PZ8pq8Vc1ZyT7icleUBYoF0Y03rZq9RktbVKeft2gyr yISZFJkQsDl31SbxWpmYQkotYAK/VlbTenvwAU3WrSCI410WG7f41cBr/R2h5Re5VDJi K1svfH/2EgipOX/Y5wcxKEdMfWdL8y7DOHLN4RNXrSxNJKTS+jGhy/AMT2k2Ygcgo1YE LsoO4RUV6GPAUU6ApTHLf0ggPb3jbLgSgKYHZv0arxa9+d1vpW+ybo0SnrE/U7+MIjOM IDyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963766; x=1731568566; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d5CBVRj+oeokqCZ8tX2zkzcVhcgEep+JK2ByfRR+yWc=; b=CDAYzLMryWB0PbDokrXwUe1i8743ODNM/7Xu0u37Xzn0MkNRagEetl0TXFZ7iHC4J1 hbPIJvhPFIIcKS2Kom4IMbQxxQL0h3x2R5ZAXkvllH+F9LbWhdCYcbNeLeRWYQx8dpCb 6La9McEpD4ojcJ9IROVHIbMiIN85ryGXAFE/eY0IwObjqNjFk0bWxzHzpWOVr8ZehDMd K6Mu56iVCFUffBZhPseN1ZMulPjNaPg+5QdXtYwpd+XReWzqD7HCn725ylQ1QpR77Fir VcC5jmTzvj+rPo/QKx8wTBmn1VxOI+QhYojgIjpT7HRCBfGVigSLdNXqh6yugfulqwgi svGA== X-Forwarded-Encrypted: i=1; AJvYcCVf+HwvpRCVmvuiB5S+YPwON26n97kV4YWxiHqp3Z5t5izzoGQNTYmRDv3StPnVuPDGetik93RTFaCU9MWQhwL1@lists.infradead.org X-Gm-Message-State: AOJu0Yyj7XTjij8OpKxWc11GycRBUZHFnZH6f3d1CzJw+4J2wmsgq5Ry NRjbMw860rKDNBmKwc/1ZiyzWm/asgtVjQBVw2I4gom7+TT12nSQ+N2O+F2w+F9W2ICSnyLjHp2 WO44Jig== X-Google-Smtp-Source: AGHT+IEd0XW+XP13/lIdiLfA1JS+O6Mq9dYjD7PUyhpWzqvtXDfGa/+OwNkNynbL8Jl1y47mBuEBrXARi0WE X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:a305:0:b0:e11:639b:6428 with SMTP id 3f1490d57ef6-e3087722c24mr85002276.0.1730963765469; Wed, 06 Nov 2024 23:16:05 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:54 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-2-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 1/7] perf header: Move is_cpu_online to numa bench From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231607_361536_FA3931C8 X-CRM114-Status: GOOD ( 18.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The helper function is only used in the NUMA benchmark as typically online CPUs are determined through perf_cpu_map__new_online_cpus(). Reduce the scope of the function for now. Signed-off-by: Ian Rogers --- tools/perf/bench/numa.c | 51 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/header.c | 51 ---------------------------------------- tools/perf/util/header.h | 1 - 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 1fbd7c947abc..611451dbc234 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -533,6 +533,57 @@ static int parse_cpu_list(const char *arg) return 0; } +/* + * Check whether a CPU is online + * + * Returns: + * 1 -> if CPU is online + * 0 -> if CPU is offline + * -1 -> error case + */ +static int is_cpu_online(unsigned int cpu) +{ + char *str; + size_t strlen; + char buf[256]; + int status = -1; + struct stat statbuf; + + snprintf(buf, sizeof(buf), + "/sys/devices/system/cpu/cpu%d", cpu); + if (stat(buf, &statbuf) != 0) + return 0; + + /* + * Check if /sys/devices/system/cpu/cpux/online file + * exists. Some cases cpu0 won't have online file since + * it is not expected to be turned off generally. + * In kernels without CONFIG_HOTPLUG_CPU, this + * file won't exist + */ + snprintf(buf, sizeof(buf), + "/sys/devices/system/cpu/cpu%d/online", cpu); + if (stat(buf, &statbuf) != 0) + return 1; + + /* + * Read online file using sysfs__read_str. + * If read or open fails, return -1. + * If read succeeds, return value from file + * which gets stored in "str" + */ + snprintf(buf, sizeof(buf), + "devices/system/cpu/cpu%d/online", cpu); + + if (sysfs__read_str(buf, &str, &strlen) < 0) + return status; + + status = atoi(str); + + free(str); + return status; +} + static int parse_setup_cpu_list(void) { struct thread_data *td; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index a6386d12afd7..55c28e4377ec 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -987,57 +987,6 @@ static int write_dir_format(struct feat_fd *ff, return do_write(ff, &data->dir.version, sizeof(data->dir.version)); } -/* - * Check whether a CPU is online - * - * Returns: - * 1 -> if CPU is online - * 0 -> if CPU is offline - * -1 -> error case - */ -int is_cpu_online(unsigned int cpu) -{ - char *str; - size_t strlen; - char buf[256]; - int status = -1; - struct stat statbuf; - - snprintf(buf, sizeof(buf), - "/sys/devices/system/cpu/cpu%d", cpu); - if (stat(buf, &statbuf) != 0) - return 0; - - /* - * Check if /sys/devices/system/cpu/cpux/online file - * exists. Some cases cpu0 won't have online file since - * it is not expected to be turned off generally. - * In kernels without CONFIG_HOTPLUG_CPU, this - * file won't exist - */ - snprintf(buf, sizeof(buf), - "/sys/devices/system/cpu/cpu%d/online", cpu); - if (stat(buf, &statbuf) != 0) - return 1; - - /* - * Read online file using sysfs__read_str. - * If read or open fails, return -1. - * If read succeeds, return value from file - * which gets stored in "str" - */ - snprintf(buf, sizeof(buf), - "devices/system/cpu/cpu%d/online", cpu); - - if (sysfs__read_str(buf, &str, &strlen) < 0) - return status; - - status = atoi(str); - - free(str); - return status; -} - #ifdef HAVE_LIBBPF_SUPPORT static int write_bpf_prog_info(struct feat_fd *ff, struct evlist *evlist __maybe_unused) diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index a63a361f20f4..e91e89d22537 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -196,7 +196,6 @@ int write_padded(struct feat_fd *fd, const void *bf, #define MAX_CACHE_LVL 4 -int is_cpu_online(unsigned int cpu); int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cntp); /* From patchwork Thu Nov 7 07:15:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 346BED5AE6B for ; Thu, 7 Nov 2024 07:21:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QeV5H6hULi4PmNWhXYnKicIpV1Vf/5KV4yP0bFilR2g=; b=N8plGnt87PdKyb+nmxPI/uQx01 CzTL/M4SXZ7LyNQ+PM2wEPQIeqD0K0ihw7hYKYPk8JCilBwMGm7DqjPv1USTclAtn1o7ZgoRSQ8Go 1WyZApv+BB/3nw7b9xO2goepjfVOgoZ9fFwVWfchh2fwYj6aNh7IC96tUHBFA7kZwn9yl97lihNnX s/AVEb1F1O8Y6PwWi54v7ONAFNHILbRgyxRUMU+Yj/ktHY3tabSvsiTmYQ8591VRsKfH8ENtRBQ7C dPYXgtzEHG0Nqb5hvJWFMx0SZO490tvG/uitvyR+b8VC+i5nFEZUCTnGtkWAFhVFdLgu6n7aQQUUk Oy0WMLew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wpo-00000005yLt-1tWL; Thu, 07 Nov 2024 07:21:40 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkT-00000005wqB-1gj2 for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:13 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e30ceaa5feeso1271368276.2 for ; Wed, 06 Nov 2024 23:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963768; x=1731568568; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=QeV5H6hULi4PmNWhXYnKicIpV1Vf/5KV4yP0bFilR2g=; b=Lk5d+2a6Sx2xON4kl20ourDqXngv55aqtr2NTj6UzD2nmuiEWP/LNzRbEKuu9KYYLK +lYpMkBfv7qmViSntplAEEr4Frlt+nFckgbBX8lU3gQn0cppV6Ya8pNkfrYPb3ooc9Uu OAYjO1e4/iOQjJctZWpMqK/tmxyhx1py2pDPX3ujkPQN2NvaEuS0ozFL4J0Q7QGvwS2W Ll5eJrBqE2Y6u6xmwlZS+Vv639BuzFVg1UgshbMXZcD2GwYiurxlv3wyZwBjAXtaG/HD DXiXCzrVSHCsV5DH2/lMDpSCC57J3x9USYRw8paHVXLqYOdJZkRL9Y1o485ZlNeg8n3n wvTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963768; x=1731568568; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QeV5H6hULi4PmNWhXYnKicIpV1Vf/5KV4yP0bFilR2g=; b=vYGBR7WaUl1a8jjsShXSgKivDfiCb9X1CrK+S0wdj20GhUGT+GNucW+Ccx3Juov8ZZ oHlczRdKbc7jGwP5nNisaTlGO13h2PX/VrtiA8HLPfwqLfc6RaGKsDBwU/iSTz2S9AKw LEn8HhRuXpBqywceAAHsTsgIKB2Nh40F54ZDF8QjpTB+tYlL3d6Q/QJiK8xwIcEoFilT sJK/auUe+MNHO04J6/mXCB7PPGf6PJ7fiwu4GkhC22U+964fbqA/3lBBUiYbx2dvSMub ZDReqk7KU0WrY1AnAq6dDEul6k49lJ0vp9slyxwB5uIbGElAeEb8eR1/if1fKqkZE+8S kWow== X-Forwarded-Encrypted: i=1; AJvYcCUlsX5zT99pJh6nertw8dnngAov+DwFe0lxtQq7+YdNyTL/iMuoSwCX637s4IghhxEgVEUYuzPMM9S6IGUjjOBI@lists.infradead.org X-Gm-Message-State: AOJu0YxM07BJ8F41OPH7gBWxcn0FRi352pEf/qojBazz4U/q0FEn7Auu QqWoPrvu3o/BdLcpffzEavA1lWxOduuT+19wiqNrO3jT1gz4X5oQw4rfXeja8bZGODIoFICwkRL cqDmUbg== X-Google-Smtp-Source: AGHT+IE/ABVQ+QoaXLev0j3L1bcYVcVKTmJ8bev+UrY6tq85vQOpw2ZTVBgndT6AQUc++Em5ZIlqp477wVKR X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:d695:0:b0:e2b:d28f:bf28 with SMTP id 3f1490d57ef6-e3302537c7dmr36619276.2.1730963768215; Wed, 06 Nov 2024 23:16:08 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:55 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-3-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 2/7] perf header: Refactor get_cpuid to take a CPU for ARM From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231609_477777_6E631C26 X-CRM114-Status: GOOD ( 19.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org ARM BIG.little has no notion of a constant CPUID for both core types. To reflect this reality, change the get_cpuid function to also pass in a possibly unused logical cpu. If the dummy value (-1) is passed in then ARM can, as currently happens, select the first logical CPU's "CPUID". The changes to ARM getcpuid happen in a follow up change. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/header.c | 2 +- tools/perf/arch/loongarch/util/header.c | 2 +- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/arch/riscv/util/header.c | 2 +- tools/perf/arch/s390/util/header.c | 2 +- tools/perf/arch/x86/util/auxtrace.c | 3 ++- tools/perf/arch/x86/util/header.c | 2 +- tools/perf/builtin-kvm.c | 4 +++- tools/perf/util/env.c | 3 ++- tools/perf/util/header.c | 9 +++++---- tools/perf/util/header.h | 2 +- 11 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index 741df3614a09..760c21784713 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -50,7 +50,7 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) return ret; } -int get_cpuid(char *buf, size_t sz) +int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused) { struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); int ret; diff --git a/tools/perf/arch/loongarch/util/header.c b/tools/perf/arch/loongarch/util/header.c index d962dff55512..f1f0b116962d 100644 --- a/tools/perf/arch/loongarch/util/header.c +++ b/tools/perf/arch/loongarch/util/header.c @@ -70,7 +70,7 @@ static char *_get_cpuid(void) return cpuid; } -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { int ret = 0; char *cpuid = _get_cpuid(); diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c index 251cdbf58a4d..6d1a63a2922f 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -24,7 +24,7 @@ static bool is_compat_mode(void) } int -get_cpuid(char *buffer, size_t sz) +get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { unsigned long pvr; int nb; diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c index 1b29030021ee..ebac294c877f 100644 --- a/tools/perf/arch/riscv/util/header.c +++ b/tools/perf/arch/riscv/util/header.c @@ -81,7 +81,7 @@ static char *_get_cpuid(void) return cpuid; } -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { char *cpuid = _get_cpuid(); int ret = 0; diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c index 7933f6871c81..2add1a561242 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -27,7 +27,7 @@ #define SYSINFO "/proc/sysinfo" #define SRVLVL "/proc/service_levels" -int get_cpuid(char *buffer, size_t sz) +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { char *cp, *line = NULL, *line2; char type[8], model[33], version[8], manufacturer[32], authorization[8]; diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util/auxtrace.c index 354780ff1605..ecbf61a7eb3a 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -55,11 +55,12 @@ struct auxtrace_record *auxtrace_record__init(struct evlist *evlist, int *err) { char buffer[64]; + struct perf_cpu cpu = perf_cpu_map__min(evlist->core.all_cpus); int ret; *err = 0; - ret = get_cpuid(buffer, sizeof(buffer)); + ret = get_cpuid(buffer, sizeof(buffer), cpu); if (ret) { *err = ret; return NULL; diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c index a51444a77a5f..690f86cbbb1c 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -58,7 +58,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt) } int -get_cpuid(char *buffer, size_t sz) +get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) { return __get_cpuid(buffer, sz, "%s,%u,%u,%u$"); } diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 099ce3ebf67c..274568d712d1 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1226,7 +1226,9 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm) int err; if (kvm->live) { - err = get_cpuid(buf, sizeof(buf)); + struct perf_cpu cpu = {-1}; + + err = get_cpuid(buf, sizeof(buf), cpu); if (err != 0) { pr_err("Failed to look up CPU type: %s\n", str_error_r(err, buf, sizeof(buf))); diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ccb464026642..93cabdd7ff43 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -373,7 +373,8 @@ int perf_env__read_pmu_mappings(struct perf_env *env) int perf_env__read_cpuid(struct perf_env *env) { char cpuid[128]; - int err = get_cpuid(cpuid, sizeof(cpuid)); + struct perf_cpu cpu = {-1}; + int err = get_cpuid(cpuid, sizeof(cpuid), cpu); if (err) return err; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 55c28e4377ec..60b42ddc3dac 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -856,18 +856,19 @@ int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) * default get_cpuid(): nothing gets recorded * actual implementation must be in arch/$(SRCARCH)/util/header.c */ -int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused) +int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused, + struct perf_cpu cpu __maybe_unused) { return ENOSYS; /* Not implemented */ } -static int write_cpuid(struct feat_fd *ff, - struct evlist *evlist __maybe_unused) +static int write_cpuid(struct feat_fd *ff, struct evlist *evlist) { + struct perf_cpu cpu = perf_cpu_map__min(evlist->core.all_cpus); char buffer[64]; int ret; - ret = get_cpuid(buffer, sizeof(buffer)); + ret = get_cpuid(buffer, sizeof(buffer), cpu); if (ret) return -1; diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index e91e89d22537..b77f89de12dd 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -201,7 +201,7 @@ int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cntp); /* * arch specific callback */ -int get_cpuid(char *buffer, size_t sz); +int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu); char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); int strcmp_cpuid_str(const char *s1, const char *s2); From patchwork Thu Nov 7 07:15:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A954ED5AE6B for ; Thu, 7 Nov 2024 07:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cITlh9ATOoPVTRO1t6obQAYHyRTBK7FrpPuOEFqdekQ=; b=OS9IKaPWO1dzahM275NpuKQEqF KpAGhV+FBNV8FaRoePejp+8fPQhlTLYndzFtCsrMtYNG5hLUTdiZVReqWk0zlGqYHNdK0NoveDRza UvURF2gkiwZF0NeBFULx7fUHVf1t8y5eaqt2kcqXNU/iUWeYeK3QDYSsgg2ZZiCeOG5euQObdDsz2 VKA+jP+UyxmzCBscv4mptwkmbZqx4uuEwpehf+U/LkQ4Yux0KDELvCjtez6YEzjLe7d6hAtSfTIBJ XP0K1NVw0yD7U++WHLtrXph0W+2uJ2+K1/QnbrOGFELhbu3sNbkqqPXAhA1CkQ4OdAaUDUhyBs/N8 uxLiVP4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wrT-00000005yUT-43W0; Thu, 07 Nov 2024 07:23:23 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkV-00000005wrd-2YOe for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:13 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6ea33aad097so20159767b3.0 for ; Wed, 06 Nov 2024 23:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963770; x=1731568570; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cITlh9ATOoPVTRO1t6obQAYHyRTBK7FrpPuOEFqdekQ=; b=FHyPx+WjPGxzpvM91TEcf9/jNxK2u/GxZla4YKjoRdAbOqiVT1kFt0HeFWZQ4GSsal AXez4VPU9An85rvt+KxIMrSxuLhjKZoqsmKyUu0wI5ombB1MTYPYux/3ZXKkmoGjiO+z 3j6c/03J7RLwfNmkPNDXs3Ioi8CGi2i4icnwFKteVnBsAgtKMn8Hra4oLBWQJtKnaUze mvloDJq9ViYPYILG3b3UsqN83d39+CeVTzm94GeWWCosQkHem0wD8kELSV//UFc0UpEn 0QRQSbCNJJl5NSuAQdL67OzDb6qoFA+Fj0XfY+OF70B8TEHeu2ssfKX9cUPDvkKslzsz dGZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963770; x=1731568570; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cITlh9ATOoPVTRO1t6obQAYHyRTBK7FrpPuOEFqdekQ=; b=kh4Jrnv0pSv3wmxFUXQL/chxmZtEw4TYVMX4muDZp6KSa0eEGzcnMA+TIsT5vL4pSt KROJMAPQ5wZUwcGgIC6kXnhFiwva6v04iMHkZg/WGPQ6Egtmuqk/tUF9uqeNjT+F/f6n 2NMpgy3dLuE7el+yKBrorKjx5Ep7FUGqfc62NAoLZXgNmm2m3f7I6Mh8ksqewW3loGfD w4MZWenHA0bRJUlZ2x8NuHJrl8yPb4zrPv57mWsGX4Ig1XzDa5hf52QpUu5kBu+bLYwm rohQaYwrp7lUWNWdlPtweMpH9/T0sqVjKQ5rZ+eOKojS6pATjyCsx2tG2A5x1hwHNotf attA== X-Forwarded-Encrypted: i=1; AJvYcCX2CgrpCPDrhh4quhGE75FoHsXS7QT3Gv3RxSm1yTqBkupvTE7dwSeUyjqrNuM5D1OVYyoGkY1WHqTcNxjO4zRG@lists.infradead.org X-Gm-Message-State: AOJu0Yxg8p6UmK/DttjVc8fy/yfCPOrWPLPvxj7+uh+cR/yg4fCK4Vmz 6f8BhjwGulYDwfUStVONZgFl/pgZ9qaa6RiKEZdZHFOMqHtGyQZIMbX7VEKdjJmJWkTThN+lsTX R+HolOA== X-Google-Smtp-Source: AGHT+IG3hd8yCeGAX7h4k6RVex8boUD3HvG3dEWbSWvGpSoN2fs9Bh/9yh9W9X2pTJW73xmM0xEe1Jlq71HY X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:901:0:b0:e2e:2c2e:277b with SMTP id 3f1490d57ef6-e33691e2433mr5319276.3.1730963770308; Wed, 06 Nov 2024 23:16:10 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:56 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-4-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 3/7] perf arm64 header: Use cpu argument in get_cpuid From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231611_860355_AB8E08E2 X-CRM114-Status: GOOD ( 20.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use the cpu to read the MIDR file requested. If the "any" value (-1) is passed that keep the behavior of returning the first MIDR file that can be read. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/header.c | 63 ++++++++++++++--------------- tools/perf/util/header.h | 1 + 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index 760c21784713..f0907daad3ae 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -14,55 +14,52 @@ #define MIDR_REVISION_MASK GENMASK(3, 0) #define MIDR_VARIANT_MASK GENMASK(23, 20) -static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) +static int _get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) { + char path[PATH_MAX]; + FILE *file; const char *sysfs = sysfs__mountpoint(); - struct perf_cpu cpu; - int idx, ret = EINVAL; + assert(cpu.cpu != -1); if (!sysfs || sz < MIDR_SIZE) return EINVAL; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - char path[PATH_MAX]; - FILE *file; - - scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, - sysfs, cpu.cpu); - - file = fopen(path, "r"); - if (!file) { - pr_debug("fopen failed for file %s\n", path); - continue; - } - - if (!fgets(buf, MIDR_SIZE, file)) { - fclose(file); - continue; - } - fclose(file); + scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, sysfs, cpu.cpu); - /* got midr break loop */ - ret = 0; - break; + file = fopen(path, "r"); + if (!file) { + pr_debug("fopen failed for file %s\n", path); + return EINVAL; } - return ret; + if (!fgets(buf, MIDR_SIZE, file)) { + pr_debug("Failed to read file %s\n", path); + fclose(file); + return EINVAL; + } + fclose(file); + return 0; } -int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused) +int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) { - struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); - int ret; + struct perf_cpu_map *cpus; + int idx; + + if (cpu.cpu != -1) + return _get_cpuid(buf, sz, cpu); + cpus = perf_cpu_map__new_online_cpus(); if (!cpus) return EINVAL; - ret = _get_cpuid(buf, sz, cpus); - - perf_cpu_map__put(cpus); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + int ret = _get_cpuid(buf, sz, cpu); - return ret; + if (ret == 0) + return 0; + } + return EINVAL; } char *get_cpuid_str(struct perf_pmu *pmu) @@ -78,7 +75,7 @@ char *get_cpuid_str(struct perf_pmu *pmu) return NULL; /* read midr from list of cpus mapped to this pmu */ - res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus); + res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus)); if (res) { pr_err("failed to get cpuid string for PMU %s\n", pmu->name); free(buf); diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index b77f89de12dd..3bb768455a60 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -11,6 +11,7 @@ #include #include "env.h" #include "pmu.h" +#include enum { HEADER_RESERVED = 0, /* always cleared */ From patchwork Thu Nov 7 07:15:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED6E5D5AE6B for ; Thu, 7 Nov 2024 07:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0JtSX1ivElzP67Gy896L9Ack6oYznxDX7izzc96bZIU=; b=KASOLv+hF4qpQZEvDnFHJYZW9X AGfqZ+52HfSRHLwhn/swp6l+EJdQ+aixT9W7KRjQLeSvY3/Ku/MbikuCJjuwwuhrwzKGBWi70Z5AW xwLYlV6w62hcD4FydWzbkxPeAi/jKLLD/kTC6Ke5JsI+BaAYZLMOhROWO4tQpIHlTkNMLl9c3JbYt sgsH4CUHF52yVwLiHvdaiih6NXenOFet1vnjgThRZXXybFejb2vDuPKPSArDSjz180EW+L5Y0pPpB GVyp66seQfaEf5c3qD82mWzptJ2s7Z9VnZwm0Fj5G+pztEqDkU9vH5yuQmu46cJMOC+Eh8y+QBv4a TSLm3piA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wtM-00000005yu7-02Gq; Thu, 07 Nov 2024 07:25:20 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkX-00000005wtQ-35MC for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:15 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6eaae8b12bfso12308107b3.3 for ; Wed, 06 Nov 2024 23:16:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963772; x=1731568572; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=0JtSX1ivElzP67Gy896L9Ack6oYznxDX7izzc96bZIU=; b=M6Mwkd+VahDYznbfuGc4G9oIQrtPLHuoF/ZS1jqX/Fj6BXwL+bsqv/bs+Ix7H3VCtQ uLPBXdpUqCA3iBAzaf9LxkKuu+tjmHl7o/iGDBxSZy4K544yor+djJhF4DLJQS0l9RYJ 3T5wnyrm4gYtl+b0JgNdZ7bzzQewPrz/TPmxO+DP2TvVc601cpRNm4JEFSxXG6clWnMJ BdXgY3WNdlbhpChYKOKUFwIWU2WvyGQ8OL26jlbZMWcDI3ht9+aGZRwhNp9MNydrTzcu EOtMfW9HOfMm5fcPPbzUkLtlAeF3+OI4U4sT9U70gU1fOed3/VdQVwOOsUkJbXbYy76F rmKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963772; x=1731568572; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0JtSX1ivElzP67Gy896L9Ack6oYznxDX7izzc96bZIU=; b=UJdDct7Vo9nRuVyjwVpGT9r3w9nHHG5/ttLkedPUEWxCOZYgVSf453Pb3C2tDHvWJD Q0pgvSDg3ZEpxkZUP1IqrCHwmeHDSWNpSPtyLCaQdQ0cIf+GL8G2IjaeKNpbOaUmvOw3 0in+qZQOjEYyhMBDXSjxATawlgJwG4YGK+rbKGrakrKY/gOjWcQO6ZxPf4qts3GUgemG lvHoepx66HQHnRAAnhs6fIoDO/wpFx5dc9qfjxb/uDbHfYxtRRNT5KtIAKJ0AQzIh/72 CqFRfK8fxSBhitMXtj965f2DcFZ4yE2iEEYgBq5r/LeiCUPhwk9KE61wjnU1FTYSvbgl qv4w== X-Forwarded-Encrypted: i=1; AJvYcCUkdwRqyOVVSo4U630OjtWGUOGlHmldOTcn/EOHPuh688ZBIjVHutJUOFB4ZrzVrZUcKp2kF4zJpjfLshga4xY1@lists.infradead.org X-Gm-Message-State: AOJu0Yxju7bgII+aMLIJ5OjkuAj1jnzACZhIcklhQn+xleWyoN7IbfVa joc15l7KKuufWPPtn/r4dJUeppap8cWElLQK/5RPbtvBZbewBOiZe2ywUBSEJs2u+YwQ43yPvgF 14/8mPg== X-Google-Smtp-Source: AGHT+IHo4j7jX9RyogLzkobNcoqsPX4PHdOeTPc0u8XD0m/LH7jjhm2PFEQw7af1FfiKXF3NPlnJLAyyNQZP X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a05:690c:60c6:b0:6ea:71c3:6cc3 with SMTP id 00721157ae682-6ead60ddc27mr1107b3.8.1730963772515; Wed, 06 Nov 2024 23:16:12 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:57 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-5-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 4/7] perf header: Avoid transitive PMU includes From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231613_940210_2D3E5EF1 X-CRM114-Status: GOOD ( 11.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently satisfied via header.h. Note, pmu.h includes parse-events.h. Signed-off-by: Ian Rogers --- tools/perf/tests/expr.c | 2 ++ tools/perf/util/env.c | 1 + tools/perf/util/probe-event.c | 1 + 3 files changed, 4 insertions(+) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index e3aa9d4fcf3a..d60f1ac1d720 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -4,6 +4,8 @@ #include "util/expr.h" #include "util/hashmap.h" #include "util/header.h" +#include "util/pmu.h" +#include "util/pmus.h" #include "util/smt.h" #include "tests.h" #include diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 93cabdd7ff43..e2843ca2edd9 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -12,6 +12,7 @@ #include #include #include +#include "pmu.h" #include "pmus.h" #include "strbuf.h" #include "trace/beauty/beauty.h" diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index a580aa2cd512..d399c7e03341 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -40,6 +40,7 @@ #include "session.h" #include "string2.h" #include "strbuf.h" +#include "parse-events.h" #include #include From patchwork Thu Nov 7 07:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13866000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5A2DD5AE72 for ; Thu, 7 Nov 2024 08:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xNlMMjciLevQNjZxyRD3U9zk6KPHdhrwCerUrHCtyJU=; b=LDlBh2Gp9gJchDlaUjTIYrPpVo Hzh3tN2h6D77V4/FWu01mZBUT/DPS69jE4du1O57a/tsIE/ae6EpaNnmvgZUZA+BDWHxstmVJkOEu 27kFcIwhQEzEnPTtMikkioYtC84XaqvbJM8+gygMZdzdIJ7v35JpqjsU1IQTwGvXF876vGNwoCgPZ laGCO277M8z/1xw0gS9mF0I0aL6NsExj+ngrIEvIR3v/R4D6ZBJ/TZq+MtfJ1kJaIRaSMPvUvjuLI atzpf/vYwSd0ZlKz13dI1/WnDjIXDBEF7s4ME/Xd1KiKN7cqHg0KTeJlaOtK8BosoY9/5ZvmkjZKo FUAi3n9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8xvV-000000067i1-0cbY; Thu, 07 Nov 2024 08:31:37 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkZ-00000005wvM-4AIs for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:18 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6ea863ecfe9so12794287b3.3 for ; Wed, 06 Nov 2024 23:16:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963774; x=1731568574; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xNlMMjciLevQNjZxyRD3U9zk6KPHdhrwCerUrHCtyJU=; b=M6XV/8nKtkc2KRllya0vZhixhP0yO4+SPmgdJb/Nx9Ca+MzcWcn/EfffsfF5AQkabW OfO0o+eGn15DHYrTQC37tzViHLTN5Z8NXTSV9ZqvaNkCmWsMYJZO4/904SK08TKQYlgK GiWvgFkwvsgVfmhocERlFv/Nz72xOVkMs7WrXSiAXSc4jhVC6RK/iwOlDzaHgzgleZ34 0chbxya93dfxsSqHCSzbGVDV3d75wHHkdUlaGadM4yP05DG2xLZsskSnlG4ThoEP+DFP FC9kQUP9skFQaPKalYQdDzrS4r+6HZI0WlpoX//Strh3QiFjRqvQhjYtWh9ZDR74/pIc CPQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963774; x=1731568574; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xNlMMjciLevQNjZxyRD3U9zk6KPHdhrwCerUrHCtyJU=; b=B0U1tBizyg+vU4v20WSSyz58JSTe82/8YinxAhNkvLN1eL+fuZw4SsGzhsl95vckSv KSyGGL6xqSGjmFXJCGV48A+bjUtKvgVBxMvUUSHP8xmWb3BNBq1RgwsgiiSDACDXBWnO fV1VPOn4ArgOAvZ3NKIkm18VqQFTW3M7Qk3cwtbLdmevQhs5ftA99HG9MThDX44M134r djIVkqY4zWgnfLzqYMv6T8xvTGtDxpub1pjmjSe6T7f1CEXCS0fZICCrAYyCDoMtMaKS WbS/RhFOYG6oP2tQeX4vGago02LdmVVS0DIFWeb65H4dV/dJeP4aVy1+rWFTlzQG6m6w bHWg== X-Forwarded-Encrypted: i=1; AJvYcCVusuZMKt44yqTbOviQ/m9w5vS2nu2bsrAu+8QIZ/QjmYdMET03Ixnjw8hsKZjBeMhndD1/wlxedvhunAc0Z1dg@lists.infradead.org X-Gm-Message-State: AOJu0YzavYQKiUdjv6CFpS09QhmjXPE2PvyUV9Vz2WXZDSrFlrl0gP3u U09me7x/p4RGJoj419lc4jci2GLl2v6YcrCf2v2zpzc4RMHbJZnjHta+VlrOl/iXSjpn1opwIM5 1NehzVg== X-Google-Smtp-Source: AGHT+IG/7XhxHMGfAm7DZPUmoPIpXEULkLsWBXpgZNT6RrqUGymhXMvB92mJcPp186PEHd4y9zeHZVV5R7g4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a05:690c:4484:b0:6dd:bf69:7e06 with SMTP id 00721157ae682-6e9d8b2173amr9142837b3.7.1730963774596; Wed, 06 Nov 2024 23:16:14 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:58 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-6-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 5/7] perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231616_090827_C2358693 X-CRM114-Status: GOOD ( 26.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On ARM the cpuid is dependent on the core type of the CPU in question. The PMU was passed for the sake of the CPU map but this means in places a temporary PMU is created just to pass a CPU value. Just pass the CPU and fix up the callers. As there are no longer PMU users in header.h, shuffle forward declarations earlier to work around build failures. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/arm-spe.c | 14 ++------------ tools/perf/arch/arm64/util/header.c | 12 ++++-------- tools/perf/arch/loongarch/util/header.c | 2 +- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/arch/riscv/util/header.c | 2 +- tools/perf/arch/s390/util/header.c | 4 ++-- tools/perf/arch/x86/util/header.c | 3 +-- tools/perf/pmu-events/empty-pmu-events.c | 5 ++++- tools/perf/pmu-events/jevents.py | 5 ++++- tools/perf/tests/expr.c | 7 +++---- tools/perf/util/expr.c | 6 +++--- tools/perf/util/header.c | 22 +++++++++++++++++++++- tools/perf/util/header.h | 19 ++++++++++--------- tools/perf/util/pmu.c | 20 -------------------- tools/perf/util/pmu.h | 1 - 15 files changed, 57 insertions(+), 67 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 7ccdea3cd461..22b19dcc6beb 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -23,6 +23,7 @@ #include "../../../util/debug.h" #include "../../../util/auxtrace.h" #include "../../../util/record.h" +#include "../../../util/header.h" #include "../../../util/arm-spe.h" #include // reallocarray @@ -85,22 +86,11 @@ static int arm_spe_save_cpu_header(struct auxtrace_record *itr, struct arm_spe_recording *sper = container_of(itr, struct arm_spe_recording, itr); struct perf_pmu *pmu = NULL; - struct perf_pmu tmp_pmu; - char cpu_id_str[16]; char *cpuid = NULL; u64 val; - snprintf(cpu_id_str, sizeof(cpu_id_str), "%d", cpu.cpu); - tmp_pmu.cpus = perf_cpu_map__new(cpu_id_str); - if (!tmp_pmu.cpus) - return -ENOMEM; - /* Read CPU MIDR */ - cpuid = perf_pmu__getcpuid(&tmp_pmu); - - /* The CPU map will not be used anymore, release it */ - perf_cpu_map__put(tmp_pmu.cpus); - + cpuid = get_cpuid_allow_env_override(cpu); if (!cpuid) return -ENOMEM; val = strtol(cpuid, NULL, 16); diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index f0907daad3ae..f445a2dd6293 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -62,22 +62,18 @@ int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu) return EINVAL; } -char *get_cpuid_str(struct perf_pmu *pmu) +char *get_cpuid_str(struct perf_cpu cpu) { - char *buf = NULL; + char *buf = malloc(MIDR_SIZE); int res; - if (!pmu || !pmu->cpus) - return NULL; - - buf = malloc(MIDR_SIZE); if (!buf) return NULL; /* read midr from list of cpus mapped to this pmu */ - res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus)); + res = get_cpuid(buf, MIDR_SIZE, cpu); if (res) { - pr_err("failed to get cpuid string for PMU %s\n", pmu->name); + pr_err("failed to get cpuid string for CPU %d\n", cpu.cpu); free(buf); buf = NULL; } diff --git a/tools/perf/arch/loongarch/util/header.c b/tools/perf/arch/loongarch/util/header.c index f1f0b116962d..0c6d823334a2 100644 --- a/tools/perf/arch/loongarch/util/header.c +++ b/tools/perf/arch/loongarch/util/header.c @@ -90,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) return ret; } -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return _get_cpuid(); } diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c index 6d1a63a2922f..c7df534dbf8f 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -42,7 +42,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) } char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +get_cpuid_str(struct perf_cpu cpu __maybe_unused) { char *bufp; unsigned long pvr; diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c index ebac294c877f..4b839203d4a5 100644 --- a/tools/perf/arch/riscv/util/header.c +++ b/tools/perf/arch/riscv/util/header.c @@ -98,7 +98,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) } char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return _get_cpuid(); } diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c index 2add1a561242..db54677a17d2 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -137,11 +137,11 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) return (nbytes >= sz) ? ENOBUFS : 0; } -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu) { char *buf = malloc(128); - if (buf && get_cpuid(buf, 128)) + if (buf && get_cpuid(buf, 128, cpu)) zfree(&buf); return buf; } diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c index 690f86cbbb1c..412977f8aa83 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -63,8 +63,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused) return __get_cpuid(buffer, sz, "%s,%u,%u,%u$"); } -char * -get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char *get_cpuid_str(struct perf_cpu cpu __maybe_unused) { char *buf = malloc(128); diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 2b7516946ded..1f7f39a89ffd 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -515,13 +515,16 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map = NULL; + struct perf_cpu cpu = {-1}; char *cpuid = NULL; size_t i; if (has_last_result && last_result.pmu == pmu) return last_result.map; - cpuid = perf_pmu__getcpuid(pmu); + if (pmu) + cpu = perf_cpu_map__min(pmu->cpus); + cpuid = get_cpuid_allow_env_override(cpu); /* * On some platforms which uses cpus map, cpuid can be NULL for diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 6e71b09dbc2a..17cd1b1c6b66 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1031,13 +1031,16 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map = NULL; + struct perf_cpu cpu = {-1}; char *cpuid = NULL; size_t i; if (has_last_result && last_result.pmu == pmu) return last_result.map; - cpuid = perf_pmu__getcpuid(pmu); + if (pmu) + cpu = perf_cpu_map__min(pmu->cpus); + cpuid = get_cpuid_allow_env_override(cpu); /* * On some platforms which uses cpus map, cpuid can be NULL for diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index d60f1ac1d720..41ff1affdfcd 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -4,10 +4,9 @@ #include "util/expr.h" #include "util/hashmap.h" #include "util/header.h" -#include "util/pmu.h" -#include "util/pmus.h" #include "util/smt.h" #include "tests.h" +#include #include #include #include @@ -78,8 +77,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u struct expr_parse_ctx *ctx; bool is_intel = false; char strcmp_cpuid_buf[256]; - struct perf_pmu *pmu = perf_pmus__find_core_pmu(); - char *cpuid = perf_pmu__getcpuid(pmu); + struct perf_cpu cpu = {-1}; + char *cpuid = get_cpuid_allow_env_override(cpu); char *escaped_cpuid1, *escaped_cpuid2; TEST_ASSERT_VAL("get_cpuid", cpuid); diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 5e3732bc2fa5..f289044a1f7c 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -8,7 +8,6 @@ #include "debug.h" #include "evlist.h" #include "expr.h" -#include "pmu.h" #include "smt.h" #include "tool_pmu.h" #include @@ -16,6 +15,7 @@ #include "util/hashmap.h" #include "util/header.h" #include "util/pmu.h" +#include #include #include #include @@ -456,8 +456,8 @@ double expr__strcmp_cpuid_str(const struct expr_parse_ctx *ctx __maybe_unused, bool compute_ids __maybe_unused, const char *test_id) { double ret; - struct perf_pmu *pmu = perf_pmus__find_core_pmu(); - char *cpuid = perf_pmu__getcpuid(pmu); + struct perf_cpu cpu = {-1}; + char *cpuid = get_cpuid_allow_env_override(cpu); if (!cpuid) return NAN; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 60b42ddc3dac..06ca5762f61f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -819,11 +819,31 @@ static int write_group_desc(struct feat_fd *ff, * Each architecture should provide a more precise id string that * can be use to match the architecture's "mapfile". */ -char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +char * __weak get_cpuid_str(struct perf_cpu cpu __maybe_unused) { return NULL; } +char *get_cpuid_allow_env_override(struct perf_cpu cpu) +{ + char *cpuid; + static bool printed; + + cpuid = getenv("PERF_CPUID"); + if (cpuid) + cpuid = strdup(cpuid); + if (!cpuid) + cpuid = get_cpuid_str(cpu); + if (!cpuid) + return NULL; + + if (!printed) { + pr_debug("Using CPUID %s\n", cpuid); + printed = true; + } + return cpuid; +} + /* Return zero when the cpuid from the mapfile.csv matches the * cpuid string generated on this platform. * Otherwise return non-zero. diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 3bb768455a60..5201af6305f4 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -10,9 +10,14 @@ #include #include #include "env.h" -#include "pmu.h" #include +struct evlist; +union perf_event; +struct perf_header; +struct perf_session; +struct perf_tool; + enum { HEADER_RESERVED = 0, /* always cleared */ HEADER_FIRST_FEATURE = 1, @@ -92,8 +97,6 @@ struct perf_pipe_file_header { u64 size; }; -struct perf_header; - int perf_file_header__read(struct perf_file_header *header, struct perf_header *ph, int fd); @@ -125,11 +128,6 @@ struct perf_header_feature_ops { bool synthesize; }; -struct evlist; -struct perf_session; -struct perf_tool; -union perf_event; - extern const char perf_version_string[]; int perf_session__read_header(struct perf_session *session); @@ -204,6 +202,9 @@ int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cntp); */ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu); -char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); +char *get_cpuid_str(struct perf_cpu cpu); + +char *get_cpuid_allow_env_override(struct perf_cpu cpu); + int strcmp_cpuid_str(const char *s1, const char *s2); #endif /* __PERF_HEADER_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0789758598c0..514cb865f57b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -818,26 +818,6 @@ static int is_sysfs_pmu_core(const char *name) return file_available(path); } -char *perf_pmu__getcpuid(struct perf_pmu *pmu) -{ - char *cpuid; - static bool printed; - - cpuid = getenv("PERF_CPUID"); - if (cpuid) - cpuid = strdup(cpuid); - if (!cpuid) - cpuid = get_cpuid_str(pmu); - if (!cpuid) - return NULL; - - if (!printed) { - pr_debug("Using CPUID %s\n", cpuid); - printed = true; - } - return cpuid; -} - __weak const struct pmu_metrics_table *pmu_metrics_table__find(void) { return perf_pmu__find_metrics_table(NULL); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b86b3c3685a2..fba3fc608b64 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -260,7 +260,6 @@ void perf_pmu__arch_init(struct perf_pmu *pmu); void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table); -char *perf_pmu__getcpuid(struct perf_pmu *pmu); const struct pmu_metrics_table *pmu_metrics_table__find(void); bool pmu_uncore_identifier_match(const char *compat, const char *id); From patchwork Thu Nov 7 07:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865954 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6EB5D5AE6F for ; Thu, 7 Nov 2024 07:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KYK64IbVI+oTr67YzD9eKbuyvUN57DhW3er38c63SVk=; b=ny8zSVcmmYCc8k/XqtNDP6UjqG 4p+z/sDbl0KWL72RF5Oi22suxGLTpue5OOh4PIksQQB7Cmr4yv4y3YcwBkZ/QB3aSkdj2OVFySVZx YsFnHnxcltdjCCT0TeB0ACQQQdQK4qshbI7+dCKTiYINc/Z7Tyiq9xz/SLQfUKy4+bB49326FqmZr 7vhv7hECS9RtZ99OhNehytjtvb5kKyQeWTOaocGV4/hpxMguSG21CJnG1M+/M11fHXwVnE+MDDyqA Dlmjm5qsPNh3hTDr8+W5468oz7fWRhX03v9sz7Nc/lnUmpbO9QAkPTJlnLmHlWfG13XbPPYpRlQru rxQtbSaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wwk-00000005zRR-3NAH; Thu, 07 Nov 2024 07:28:50 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wkc-00000005wxN-32uJ for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:20 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e59dc7df64so8863647b3.1 for ; Wed, 06 Nov 2024 23:16:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963777; x=1731568577; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KYK64IbVI+oTr67YzD9eKbuyvUN57DhW3er38c63SVk=; b=koEUr6a+f4byEreO1i4FBx/whHynuFNhr9G2pATpG7V+Fwbk4alBETsdr9eobMLCQw KM2MgxWdNu8tFjuoyaiCsKm43vSgbSqpLoZ8XVE+Is1tFfkuo4ZBs5kMfvSZtR9deOJG DEFO0CP7gFri3/PjMpw5YVw9Qn5TziuLzTxlTZDel4rbTwMXOtgII7Emqu6TvPeQX6Nq n0p8ZhMnCvKXS95aK/4P3Exl+OyQ8DfCxy0JrIXK2lRkgOMum7ssKcKcCHpND3eWH9oU DJVMxQlmQ0Tw2kBFZet8AD09d77NwC8cAU2Xkp6AjkfrdTUaIskmiJESwT1ztR4oyojd o+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963777; x=1731568577; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KYK64IbVI+oTr67YzD9eKbuyvUN57DhW3er38c63SVk=; b=T33GZAvClYS/OKV+pbvb8UKARN5ZHTi1SuSKMoFIi0kgofKPkk/2TfGXJPywJhTrT/ yFyseNYMleRRylcvmQKwvle36Opps7HJDr6nKx1z64j4xYKbkshHj6wXvCBNTTP1+LBk PdBZwow4mwr2+E6xTAvD/JeaWGL5u1x1Z3HfP5e5TsUu8A4Vo5oNZfBkBewz/Ntj4TA/ D5ZidcVQqmvXaVowHeE8QQVdBDE24gDs2It/bmNNouB3Nnot+KPRY1TvraX6Ri/1EER1 Oi2UOlZ2DPBb8NNusCT/ojMuonR2CkRC462pvhP0plt94iHPc9BT8gfZe8ONPqLZUwp5 941Q== X-Forwarded-Encrypted: i=1; AJvYcCUUNwtZc7NhIMvmS8d2uLmpwrcHMlkCKXEwuqzM7OkGO9/539h3In7lDjoMeqfbUcpx15qk/Mo7TTNE5URjfHex@lists.infradead.org X-Gm-Message-State: AOJu0YycLkQXQVvPk8QCtXgtxN5IvyUS7G65uoeoeFqYS7FPfCUTiOKN ahg51j+XX+1KODaNTQdoUKZ9Pi7hb8vv0k1L0xa36Tk02kZjwEHy/6kG14nqFRPQ1OXox37Wh9W BV5dU4w== X-Google-Smtp-Source: AGHT+IEE1yqKHgqlv5intPfLwYeQKNT3vieLxoXotrZ7qIt8KVtU6GVAtqxkz210BAUWXZlbW1ErAef+mNNv X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a81:b512:0:b0:6ea:881b:b545 with SMTP id 00721157ae682-6ead646907emr707b3.4.1730963776837; Wed, 06 Nov 2024 23:16:16 -0800 (PST) Date: Wed, 6 Nov 2024 23:15:59 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-7-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 6/7] perf jevents: Add map_for_cpu From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231618_903890_B7B075C3 X-CRM114-Status: GOOD ( 14.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The PMU is no longer part of the map finding process and for metrics doesn't make sense as they lack a PMU. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 20 +++++++++++++------- tools/perf/pmu-events/jevents.py | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 1f7f39a89ffd..2151e8a43f16 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -503,11 +503,11 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, return 0; } -static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +static const struct pmu_events_map *map_for_cpu(struct perf_cpu cpu) { static struct { const struct pmu_events_map *map; - struct perf_pmu *pmu; + struct perf_cpu cpu; } last_result; static struct { const struct pmu_events_map *map; @@ -515,15 +515,12 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map = NULL; - struct perf_cpu cpu = {-1}; char *cpuid = NULL; size_t i; - if (has_last_result && last_result.pmu == pmu) + if (has_last_result && last_result.cpu.cpu == cpu.cpu) return last_result.map; - if (pmu) - cpu = perf_cpu_map__min(pmu->cpus); cpuid = get_cpuid_allow_env_override(cpu); /* @@ -555,12 +552,21 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) has_last_map_search = true; } out_update_last_result: - last_result.pmu = pmu; + last_result.cpu = cpu; last_result.map = map; has_last_result = true; return map; } +static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +{ + struct perf_cpu cpu = {-1}; + + if (pmu) + cpu = perf_cpu_map__min(pmu->cpus); + return map_for_cpu(cpu); +} + const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) { const struct pmu_events_map *map = map_for_pmu(pmu); diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 17cd1b1c6b66..6d6780ca0889 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1019,11 +1019,11 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, return 0; } -static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +static const struct pmu_events_map *map_for_cpu(struct perf_cpu cpu) { static struct { const struct pmu_events_map *map; - struct perf_pmu *pmu; + struct perf_cpu cpu; } last_result; static struct { const struct pmu_events_map *map; @@ -1031,15 +1031,12 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) } last_map_search; static bool has_last_result, has_last_map_search; const struct pmu_events_map *map = NULL; - struct perf_cpu cpu = {-1}; char *cpuid = NULL; size_t i; - if (has_last_result && last_result.pmu == pmu) + if (has_last_result && last_result.cpu.cpu == cpu.cpu) return last_result.map; - if (pmu) - cpu = perf_cpu_map__min(pmu->cpus); cpuid = get_cpuid_allow_env_override(cpu); /* @@ -1071,12 +1068,21 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) has_last_map_search = true; } out_update_last_result: - last_result.pmu = pmu; + last_result.cpu = cpu; last_result.map = map; has_last_result = true; return map; } +static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) +{ + struct perf_cpu cpu = {-1}; + + if (pmu) + cpu = perf_cpu_map__min(pmu->cpus); + return map_for_cpu(cpu); +} + const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) { const struct pmu_events_map *map = map_for_pmu(pmu); From patchwork Thu Nov 7 07:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13865955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3854D5AE6F for ; Thu, 7 Nov 2024 07:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Jp6Q6rsYTy2pkFfmFp9hLJ/9ui9ITiVOsHTsdSSP0vY=; b=fyyIsy7ItHFd8DKOpbdtqlnmRM Kh32TtJdHV5j7EQt0XINm8j/f2qMgZIa1sYed3M6X6rBn/6jeuU1IKsTPUPq26+ayZ24Vw5AFk+8s kYrDI3+I/EKnPkcHzXylPCcan8oWu2vlTKxj1CDMDdmDvGsAl45Cl9749Y5USuk/rCcpMD3pnVKVI plYmaMNySQ0xOfKCCfFzwUwFkZos9vjAJyAXr1EEwfeJUDgUiRtWQEfIyTpJYgzRcXLU837Zy2S7T vPh8ktyzf/kTROTQwUe4GxcDSLyDYkGTB/cOTJV2R8bVm3EqC7lWnD0S9vwf29wlyEsJiRG+eW05m w9O1tfqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8wyR-00000005ziq-2vsq; Thu, 07 Nov 2024 07:30:35 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8wke-00000005wys-1wfq for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 07:16:21 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6ea86f1df79so12648987b3.1 for ; Wed, 06 Nov 2024 23:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730963779; x=1731568579; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Jp6Q6rsYTy2pkFfmFp9hLJ/9ui9ITiVOsHTsdSSP0vY=; b=TMmn2JQlw9NzMgGl+QhfxA/tenhHU9eh0kfRvYojnNCqNtgX35CcXOR1xMjrSlRAE8 5hJmds9meckXF8Gbc6lyhAt1uZOg17PqCFtDttpv1W6nFfyegUOcTzZfuR7MjgLkEghw zqC2NdnMQeKaeXGRNyUiOnO10FMS/dLQXRd8e6Kw1I5Itt38XlfYKzVQt+Qx8ADDm0jA tfOfDTk6txV6S32yC5SXpgXAYCOfEzhNpSlD/nJJWkfSmQ4tiSLtcR+u1NtoSOr3FTwn 6ljoY+qoDnLeKfXguCQAiEzrwgxoAZFcskfB7iLfQHL1CMOWHoW2RkvhqUq0f8gKqHoD mb9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963779; x=1731568579; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jp6Q6rsYTy2pkFfmFp9hLJ/9ui9ITiVOsHTsdSSP0vY=; b=o8zcQI4i5OV67T4lGbQOnmKYHbzpiaq7l+wkYyxydNcQILPL2PhNmuG7AIiO7sZ6vC bw/7/GwHYGndx49+vSNaPS6gYgpouKqmqyVauIyutr6LdJK6UzVNIbEz/PBwdoQwytbk hZj5hdQ/eUNl7ocenjrXVpPYs0DPZRu+gU8QNcsAIwqgOSR6hSNT/CjG5Kp6inooEUak Hm48BwQagnbEYvCF2e5CogoXAEjgR3/qN0jDYOVMVLD80Syo3ipBo06KmemIjLems75z THoU7GlIak69tIvppCvwG5nc72m0gl06hHpX02bfd38jaHArMrlZRR83iGd1p9AlBsq/ mWfw== X-Forwarded-Encrypted: i=1; AJvYcCUzIafWdkO9z4nkQUlbhw0YGqew0jnAbyRrlFz8uTHnyIVZvBVs4as0ApoV7DnHBTEeZrmfFuNqELyM5Wc6CjX7@lists.infradead.org X-Gm-Message-State: AOJu0Yy1wVNnXXiFdLC/RGxMoCfW+v2LcasntyzfC7oklpEF8aFMOsD6 XePZzEapZWNKFf7esrYZl9tE0gcbzMEUCsECce30sBN2O81vbOmApVMense4wARbg4mJ0hCQXrt 4QZqE9A== X-Google-Smtp-Source: AGHT+IFjJTkBX3Ww5U3GdP9ImzIAFri1PsUtkuPx9cggbPAOvXg0q9D0jMn+HqGO7HRg6a+gW1C87/H1x3x6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a81:a8c3:0:b0:6e3:d670:f603 with SMTP id 00721157ae682-6e9d8aada53mr4568187b3.3.1730963779222; Wed, 06 Nov 2024 23:16:19 -0800 (PST) Date: Wed, 6 Nov 2024 23:16:00 -0800 In-Reply-To: <20241107071600.9082-1-irogers@google.com> Message-Id: <20241107071600.9082-8-irogers@google.com> Mime-Version: 1.0 References: <20241107071600.9082-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v1 7/7] perf pmu: Move pmu_metrics_table__find and remove ARM override From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_231620_608488_36868D87 X-CRM114-Status: GOOD ( 18.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move pmu_metrics_table__find to the jevents.py generated pmu-events.c and remove indirection override for ARM. The movement removes perf_pmu__find_metrics_table that exists to enable the ARM override. The ARM override isn't necessary as just the CPUID, not PMU, is used in the metric table lookup. On non-ARM the CPU argument is just ignored for the CPUID, for ARM -1 is passed so that the CPUID for the first logical CPU is read. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 20 -------------------- tools/perf/pmu-events/empty-pmu-events.c | 20 ++++---------------- tools/perf/pmu-events/jevents.py | 20 ++++---------------- tools/perf/pmu-events/pmu-events.h | 2 +- tools/perf/util/pmu.c | 5 ----- tools/perf/util/pmu.h | 1 - 6 files changed, 9 insertions(+), 59 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c index a0964b191fcb..895fb0d0610c 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -1,29 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include "../../../util/cpumap.h" -#include "../../../util/header.h" #include "../../../util/pmu.h" #include "../../../util/pmus.h" #include "../../../util/tool_pmu.h" #include -#include - -const struct pmu_metrics_table *pmu_metrics_table__find(void) -{ - struct perf_pmu *pmu; - - /* Metrics aren't currently supported on heterogeneous Arm systems */ - if (perf_pmus__num_core_pmus() > 1) - return NULL; - - /* Doesn't matter which one here because they'll all be the same */ - pmu = perf_pmus__find_core_pmu(); - if (pmu) - return perf_pmu__find_metrics_table(pmu); - - return NULL; -} u64 tool_pmu__cpu_slots_per_cycle(void) { diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 2151e8a43f16..1c7a2cfa321f 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -587,24 +587,12 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) return NULL; } -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) +const struct pmu_metrics_table *pmu_metrics_table__find(void) { - const struct pmu_events_map *map = map_for_pmu(pmu); - - if (!map) - return NULL; - - if (!pmu) - return &map->metric_table; - - for (size_t i = 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu = &map->metric_table.pmus[i]; - const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset]; + struct perf_cpu cpu = {-1}; + const struct pmu_events_map *map = map_for_cpu(cpu); - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return map ? &map->metric_table : NULL; } const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 6d6780ca0889..d781a377757a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1103,24 +1103,12 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) return NULL; } -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) +const struct pmu_metrics_table *pmu_metrics_table__find(void) { - const struct pmu_events_map *map = map_for_pmu(pmu); - - if (!map) - return NULL; - - if (!pmu) - return &map->metric_table; - - for (size_t i = 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu = &map->metric_table.pmus[i]; - const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset]; + struct perf_cpu cpu = {-1}; + const struct pmu_events_map *map = map_for_cpu(cpu); - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return map ? &map->metric_table : NULL; } const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 5435ad92180c..675562e6f770 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -103,7 +103,7 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pm void *data); const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); -const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); +const struct pmu_metrics_table *pmu_metrics_table__find(void); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 514cb865f57b..45838651b361 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -818,11 +818,6 @@ static int is_sysfs_pmu_core(const char *name) return file_available(path); } -__weak const struct pmu_metrics_table *pmu_metrics_table__find(void) -{ - return perf_pmu__find_metrics_table(NULL); -} - /** * Return the length of the PMU name not including the suffix for uncore PMUs. * diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index fba3fc608b64..7b3e71194e49 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -260,7 +260,6 @@ void perf_pmu__arch_init(struct perf_pmu *pmu); void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table); -const struct pmu_metrics_table *pmu_metrics_table__find(void); bool pmu_uncore_identifier_match(const char *compat, const char *id); int perf_pmu__convert_scale(const char *scale, char **end, double *sval);