From patchwork Tue Nov 29 19:10:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 27414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp521315wrr; Tue, 29 Nov 2022 11:14:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Hu4giRMy9xs1XXc6wZG4eJvzC8EuCRsib1DOvhspyyRwsMJpVykT4+C1Gs3eO5wyXPX4N X-Received: by 2002:a65:63d8:0:b0:477:172b:c350 with SMTP id n24-20020a6563d8000000b00477172bc350mr35493935pgv.313.1669749272947; Tue, 29 Nov 2022 11:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749272; cv=none; d=google.com; s=arc-20160816; b=FdJyMElRTlhr5D8pkk/i9Nmbl3Vbe/EMjwY1CftH2NxrlqSuqqwM01WW9im3Rhp2xs pb+aDvkeIbiDDnYl7NdS/X4XlLRJJWmrt0vLVEITf+SH2kXAR7lVfP+wXlBZQZu0PNni 4LzsX+Yze8p6LykE3T0j+Jdtep+OVczu0pcpcpi5ZtN+0hauWz+hS5iQp4VzzVYghz+y vEUqfT4wuUa2juRQcmA4VSI2PuXWa99J11jlZV/wiOBsTXezf7V3IMs+QnND6mAd3Z/C 3LVjwNUnySrkY2s4NwRkB5hbA5+mlg2ubHE/F+SwZHxR1egAVU+I2wFOw7EtOtToZGx2 1ZHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LWauFrTKFora3ZH0Jo4MEah4Z0NNZSk4ApzOJgiGBSA=; b=WbhRlfyR8TVVA0BToK4KbTCZrfjIGZV2NNPdOf82CReP6hgruHRyYWAKAsWx17IBTH ky/SC5v2voUS8trZ6xK3/0QBzq13c2XKTAHI0Bi9I+LPmFsz1YjPZ+crjxgs2jU9p2Qh 3BBVIyJdscRz7/ENeO7yMalp87A0VmDMemnI0v5r0M+EsApFMjqfJ9eLTSLl+MLdIboC BwRGeYkUxRX5dI8oECTMrrMd0SdG+27eBRpmT5XfXOuuckPtz0OYYdESUTDXjnc8pbiQ Kx5TnIr/Eo8VF99sEI2OLGdce7QKOIqnaan8HFXSZC0PpDlzzoaoqHxQyXbX56XML6zi uHww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bh56K2WB; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s30-20020a63ff5e000000b00476ff5e43d6si15423841pgk.319.2022.11.29.11.14.19; Tue, 29 Nov 2022 11:14:32 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=bh56K2WB; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236597AbiK2TKu (ORCPT + 99 others); Tue, 29 Nov 2022 14:10:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236435AbiK2TKq (ORCPT ); Tue, 29 Nov 2022 14:10:46 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB7357B5B for ; Tue, 29 Nov 2022 11:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669749045; x=1701285045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0LysSy+o68gZus5CsHds3iLhv9K3aJ1XZA9pHukedQ=; b=bh56K2WBV1+vSnm7F6pJ57im2zbjdENd4DULmpkQN8oZSGJ4o1JXtKPx 3HEZ5iG5bpqb7z1T7TAsrYknGKP3j5wL6XxoF0//IpQYt1es5r9hrK4l/ tVwrqG2JdDhsveLTcFJT4Y1hNJ3HOa9BoOZNXnKEIMme7C/ic3bVKvFMh /a0RIoriLTvfvufmdp82xuFeT39fnMMlp80z7SGTVktfF2nfSPt4ZQMmk IhfUYm2b+1ByVs7bTkEF4HOZazU7mwXSUVC7wipOeq5EdcrrT5v2itr9B HTKYCK57EAh+8iseOVGA9iZJHutf1DVUud4TzTkJf9r69kfLO9/s5Pzf4 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="379490763" X-IronPort-AV: E=Sophos;i="5.96,204,1665471600"; d="scan'208";a="379490763" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2022 11:10:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="749991992" X-IronPort-AV: E=Sophos;i="5.96,204,1665471600"; d="scan'208";a="749991992" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga002.fm.intel.com with ESMTP; 29 Nov 2022 11:10:33 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: steve.wahl@hpe.com, alexander.antonov@linux.intel.com, ak@linux.intel.com, eranian@google.com, namhyung@kernel.org, Kan Liang Subject: [PATCH 1/5] perf/x86/uncore: Factor out uncore_device_to_die() Date: Tue, 29 Nov 2022 11:10:19 -0800 Message-Id: <20221129191023.936738-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221129191023.936738-1-kan.liang@linux.intel.com> References: <20221129191023.936738-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859013414452336?= X-GMAIL-MSGID: =?utf-8?q?1750859013414452336?= From: Kan Liang The same code is used to retrieve the logical die ID with a given PCI device in both the discovery code and the code that supports a system with > 8 nodes. Factor out uncore_device_to_die() to replace the duplicate code. No functional change. Signed-off-by: Kan Liang --- arch/x86/events/intel/uncore.c | 15 +++++++++++++++ arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_discovery.c | 16 ++-------------- arch/x86/events/intel/uncore_snbep.c | 12 +----------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 6f1ccc57a692..8caf253be1de 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -65,6 +65,21 @@ int uncore_die_to_segment(int die) return bus ? pci_domain_nr(bus) : -EINVAL; } +int uncore_device_to_die(struct pci_dev *dev) +{ + int node = pcibus_to_node(dev->bus); + int cpu; + + for_each_cpu(cpu, cpumask_of_pcibus(dev->bus)) { + struct cpuinfo_x86 *c = &cpu_data(cpu); + + if (c->initialized && cpu_to_node(cpu) == node) + return c->logical_die_id; + } + + return -1; +} + static void uncore_free_pcibus_map(void) { struct pci2phy_map *map, *tmp; diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index e278e2e7c051..8d493bea9eb6 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -208,6 +208,7 @@ struct pci2phy_map { struct pci2phy_map *__find_pci2phy_map(int segment); int uncore_pcibus_to_dieid(struct pci_bus *bus); int uncore_die_to_segment(int die); +int uncore_device_to_die(struct pci_dev *dev); ssize_t uncore_event_show(struct device *dev, struct device_attribute *attr, char *buf); diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/intel/uncore_discovery.c index 5fd72d4b8bbb..08af92af2be2 100644 --- a/arch/x86/events/intel/uncore_discovery.c +++ b/arch/x86/events/intel/uncore_discovery.c @@ -33,7 +33,7 @@ static int logical_die_id; static int get_device_die_id(struct pci_dev *dev) { - int cpu, node = pcibus_to_node(dev->bus); + int node = pcibus_to_node(dev->bus); /* * If the NUMA info is not available, assume that the logical die id is @@ -43,19 +43,7 @@ static int get_device_die_id(struct pci_dev *dev) if (node < 0) return logical_die_id++; - for_each_cpu(cpu, cpumask_of_node(node)) { - struct cpuinfo_x86 *c = &cpu_data(cpu); - - if (c->initialized && cpu_to_node(cpu) == node) - return c->logical_die_id; - } - - /* - * All CPUs of a node may be offlined. For this case, - * the PCI and MMIO type of uncore blocks which are - * enumerated by the device will be unavailable. - */ - return -1; + return uncore_device_to_die(dev); } #define __node_2_type(cur) \ diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c index 44c2f879f708..31acc96ccb69 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1453,9 +1453,6 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool } raw_spin_unlock(&pci2phy_map_lock); } else { - int node = pcibus_to_node(ubox_dev->bus); - int cpu; - segment = pci_domain_nr(ubox_dev->bus); raw_spin_lock(&pci2phy_map_lock); map = __find_pci2phy_map(segment); @@ -1465,15 +1462,8 @@ static int snbep_pci2phy_map_init(int devid, int nodeid_loc, int idmap_loc, bool break; } - die_id = -1; - for_each_cpu(cpu, cpumask_of_pcibus(ubox_dev->bus)) { - struct cpuinfo_x86 *c = &cpu_data(cpu); + map->pbus_to_dieid[bus] = die_id = uncore_device_to_die(ubox_dev); - if (c->initialized && cpu_to_node(cpu) == node) { - map->pbus_to_dieid[bus] = die_id = c->logical_die_id; - break; - } - } raw_spin_unlock(&pci2phy_map_lock); if (WARN_ON_ONCE(die_id == -1)) {