From patchwork Tue Aug 8 12:51:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 132770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2334520vqr; Tue, 8 Aug 2023 12:04:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbnxGi3+vUmMOGZs7oLj8OmsHlnsdCNmut0pC7ERkl/7LUcQ6cr9xsmlE6SKDjt9zrIsRA X-Received: by 2002:a19:641a:0:b0:4f8:714e:27a8 with SMTP id y26-20020a19641a000000b004f8714e27a8mr359602lfb.0.1691521480166; Tue, 08 Aug 2023 12:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691521480; cv=none; d=google.com; s=arc-20160816; b=EG9eOYSjTAXUl+ynyQXDT786CWAr01zeOpgLpI1e2p70JXagUc6HSf3zgAx4NhR4WO m+/JJrlIg7zOaTnLvdaiu29T9vWZ/jMScop1ltewRa6AeDKY187mqYTB3X+aaA+YGriw /4rzlfv8Lz+cfkFcTJ2xAwHZECDzMPiXUETmQhFQGhI26nZ46h1+8+hVCGOJZri2SnaN yOFUbs7Ysy3jWFXPjDkZevyBobbJ5B+qze0+hSd07UkyOobqpb1jzeFjS5ictaj7Pyez 8vTk9KB1BD6BfLo/Nzuoa3YBncX7RluVG/kj55u1039ZE1s91YJMe9fU2wwJMgY8k+fW tOgg== 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 :message-id:date:subject:cc:to:from; bh=N+PeMMRMSfBeckPtcUA8cZVkqVJOT2BqnxIgx32ebhI=; fh=Som+eq5y8klQ4eI2R4977nJLf7zh+/Hljgr+WElRPtQ=; b=rB/apyXvge5fVM40v6XEr8I1N/sj343g+kE328qJawWp7+c08jOhQo1aLZs+buKxQ5 v4T4aqeLerqKBCgC+tazXcVAVyCoDDJ7eFzed2yPuqo3gT2FB2X09MoZJ2r+v3VLmj7W 3c4BPVw2H/XJAJaRfxKerZu8PnnF6e6UZZD+BEzvWmhNp59WpIzXl7T87tfrMA3IdrDN 9oybTxo6pCO0Q9+7QYQD+clXxe7jg4gEPHVXA00LmX48CwMCYyT1Vmbz/VFQLoafFJCE RNags2hyXS1SfROq0BJOZLG+Kji320lfXGaPIFqnesSgYvChDShcyLG1bjJg6zdhFwfh clMg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020aa7c703000000b005232846fe62si5861482edq.446.2023.08.08.12.04.15; Tue, 08 Aug 2023 12:04:40 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235405AbjHHS0b (ORCPT + 99 others); Tue, 8 Aug 2023 14:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235361AbjHHS0J (ORCPT ); Tue, 8 Aug 2023 14:26:09 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7176B23373 for ; Tue, 8 Aug 2023 10:41:22 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RKtMX0KczzNmyf; Tue, 8 Aug 2023 20:50:32 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 20:54:00 +0800 From: Yicong Yang To: , , CC: , , , , , Subject: [PATCH] drivers/perf: hisi: Schedule perf session according to locality Date: Tue, 8 Aug 2023 20:51:47 +0800 Message-ID: <20230808125147.2080-1-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773688827488083030 X-GMAIL-MSGID: 1773688827488083030 From: Yicong Yang The PCIe PMUs locate on different NUMA node but currently we don't consider it and likely stack all the sessions on the same CPU: [root@localhost tmp]# cat /sys/devices/hisi_pcie*/cpumask 0 0 0 0 0 0 This can be optimize a bit to use a local CPU for the PMU. Signed-off-by: Yicong Yang --- drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index e10fc7cb9493..60ecf469782b 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -665,7 +665,7 @@ static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node); if (pcie_pmu->on_cpu == -1) { - pcie_pmu->on_cpu = cpu; + pcie_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(&pcie_pmu->pdev->dev)); WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(cpu))); } @@ -676,14 +676,23 @@ static int hisi_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) { struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node); unsigned int target; + cpumask_t mask; + int numa_node; /* Nothing to do if this CPU doesn't own the PMU */ if (pcie_pmu->on_cpu != cpu) return 0; pcie_pmu->on_cpu = -1; - /* Choose a new CPU from all online cpus. */ - target = cpumask_any_but(cpu_online_mask, cpu); + + /* Choose a local CPU from all online cpus. */ + numa_node = dev_to_node(&pcie_pmu->pdev->dev); + if (cpumask_and(&mask, cpumask_of_node(numa_node), cpu_online_mask) && + cpumask_andnot(&mask, &mask, cpumask_of(cpu))) + target = cpumask_any(&mask); + else + target = cpumask_any_but(cpu_online_mask, cpu); + if (target >= nr_cpu_ids) { pci_err(pcie_pmu->pdev, "There is no CPU to set\n"); return 0;