Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp811175rwb; Thu, 12 Jan 2023 12:40:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXuY19khZ9rY8u3SuRz+N6I3GrlSpZ/wqkQvP5JQsZXoHDqQ4h1OuABDpU9st1GdHTFkRMCH X-Received: by 2002:a05:6a00:4149:b0:576:5a71:454a with SMTP id bv9-20020a056a00414900b005765a71454amr8176305pfb.2.1673556044410; Thu, 12 Jan 2023 12:40:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673556044; cv=none; d=google.com; s=arc-20160816; b=jZoBWVjT78vHzayxkfPOKNtpxYdjZFh4FSMZD93F76Cs3LooPe5PlMCyfS31cZ3TP2 tYULb9ue72ljT6Jwiq8TqZPntqACu1y0d1m9ngVSeE+mDGEpXqhv7USaEw+H8OD3edE7 dbx3IM2KJCybIW1BbxKrI4A9kfq++JWOofcKSmN8+HEMlwCyxiy0hmsniWBULes0oLr8 izMc3T91kCjjvLbk16DrGvfFGBh/EXFWGjopAJa+MHHwUOprBmGtz9BVbv9+bZfdVXCi bx7M0xNo7gQ26/1/vxfCvj/KMtg0vhJmlwalkcBv5I+DECl6j++zkjvh+VdUm1FPmKyS i5cw== 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=P17mC9DsdjvCzMuBGcdq7RxKqQUVgzZ7CTOF/rQOen+/Zd6BsrFB0w91RMqCKtlpGp qT/SO4veHf1lTvqVzXeotxKf6cCwIreVa9Db9R1axxELLSMtbfX+XsGpwdkjeI6jGnGx 3IEPSf3tnifxvxqs++MyBHVtoKKC+1xo14Sa5Iy7ls9SNvW4vnyXHHiTCJ0qhD62Lwka Vg0TSb5qZehVz935ZpUFz5jHZKVG3sCj93jJNLl0xTN9bFsXzKrRCcJ0fulhYqpTWDpQ gXGCdRdgsv6hSyDOnbtAOm+JeyGQlUP22R4yMRVLe4amg+QsemJ6g7VPSvwxPmXzC6aW UoCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GnH1413E; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r26-20020a62e41a000000b0056cf9ed8f10si17988205pfh.329.2023.01.12.12.40.02; Thu, 12 Jan 2023 12:40:44 -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=GnH1413E; 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 S240515AbjALUHM (ORCPT + 50 others); Thu, 12 Jan 2023 15:07:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241674AbjALUEh (ORCPT ); Thu, 12 Jan 2023 15:04:37 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFE615816 for ; Thu, 12 Jan 2023 12:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673553715; x=1705089715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0LysSy+o68gZus5CsHds3iLhv9K3aJ1XZA9pHukedQ=; b=GnH1413EUyUY6n7jg6jRnSG0WBElisiyL4As58RoxS1/xDc2mHiMw9KN seBWGqibbHhBg0m9GzxZv3UyBfUXC6wpy2y63ldXGVOqSKxsV9iRhEYY4 /xlIHgsxykEUuq+kLEqMuz+9ydiYnozsKj1ga6JbPKVlDo/YIdXxOzDVC nioWVr9b55ksTwQmuAOTEQazdEJEFqI6aQmw06xegu9XSuwv6N7tVV8Dg QbWm//d+H/FEVRg+zJIXGbDg34AtCkPQe7SOe7ll7X1Oa8wliAW4lQAJf NDmlfkRyfRlUIc3Lr1cbSxpnrOHkiEUjxieyVxJL+b/b7cG1BAGlV/vp6 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="325867096" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="325867096" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 12:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="657959925" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="657959925" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2023 12:01:29 -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 RESEND 1/5] perf/x86/uncore: Factor out uncore_device_to_die() Date: Thu, 12 Jan 2023 12:01:01 -0800 Message-Id: <20230112200105.733466-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230112200105.733466-1-kan.liang@linux.intel.com> References: <20230112200105.733466-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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)) { -- 2.35.1