From patchwork Tue Aug 15 13:06:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 135763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp9727vqi; Wed, 16 Aug 2023 06:26:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3k12pN43U+Kfl6L2nps3YZzZ5HdcA8sH6cmGtNxE9Jhm/TQICp3TWPYC3RHJog72pNy+i X-Received: by 2002:a17:906:73c8:b0:99c:f47a:2354 with SMTP id n8-20020a17090673c800b0099cf47a2354mr1355942ejl.70.1692192375594; Wed, 16 Aug 2023 06:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692192375; cv=none; d=google.com; s=arc-20160816; b=hnGdfTlIcgW/Oo9SY8jdQELm8P1j5xEa7G1TA/ufxNA08tpTsZ7wHaxxDvV+ICczDV HU8/u63SmhhMZrQLoWgwn1iVca018H5u6a+GMkjaPC/dnVmqpdITF/K85cZiVDeub44f IF7JC/hrD2o/7tSnGVuu5pXT7oumLharlcfblJUwCfL44BIGX4O55U3N+2eSRp9NVazq cqjMEKqBuN/pmgb4bPwhJhPfP6crppYryqXage+fu/jqmESGELpe0manfgQuO4KfbL/0 sbbhKxh7PnG4iyhkHTUKQhUbP5RvxsQuR2YD7d4W/n/ZBCwzhKPTZmTWNwXPplUl0M9P OVwA== 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=dNQtYkeSnU7MuhQumK72/yaGmaCqueJ4SKMd+r3R0gs=; fh=Som+eq5y8klQ4eI2R4977nJLf7zh+/Hljgr+WElRPtQ=; b=unZlrx3hfstJHjLXqhQ/RC8MMkTvvWnibTKIIyJ/PMmO0uLTgLUJxq5orOtYxUn9UQ VGv1UZTrDsNt/h5n2alD8JYWKR45Qk/CRvuonVkHm+RwiUV62PwrwotlGJj35qLGmKyZ CZX0Z9uktQdDTY/MEEkVYDEfORtCD+DXhgsLsBFUngiBDqOCldvuQYOmv4GT5zjJ/2fE dKALHhjlwLKV0KljENbJE16BhiVPMvj3Ziig4/+Oew4+IUL9OMnEA7z9SRLwd/zmvRSn BHy6g3kXL5s/FIW+yiXWeeuae1GhaDB/7vQQqi68xqycveck0NmIT5yp6//IvRYAPsIr UIAw== 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 lz22-20020a170906fb1600b00993211b85acsi11142122ejb.216.2023.08.16.06.25.51; Wed, 16 Aug 2023 06:26:15 -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 S237386AbjHONI4 (ORCPT + 99 others); Tue, 15 Aug 2023 09:08:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237363AbjHONIg (ORCPT ); Tue, 15 Aug 2023 09:08:36 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CCC910C0 for ; Tue, 15 Aug 2023 06:08:34 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RQBPV74kczrSYH; Tue, 15 Aug 2023 21:07:10 +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.31; Tue, 15 Aug 2023 21:08:30 +0800 From: Yicong Yang To: , , CC: , , , , , Subject: [PATCH v2] drivers/perf: hisi: Schedule perf session according to locality Date: Tue, 15 Aug 2023 21:06:13 +0800 Message-ID: <20230815130613.535-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: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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: 1774306338706748120 X-GMAIL-MSGID: 1774392312257151224 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 Change since v2: - Make interrupt affinity consistent with CPU in online handler Link: https://lore.kernel.org/all/20230808125147.2080-1-yangyicong@huawei.com/ --- drivers/perf/hisilicon/hisi_pcie_pmu.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index e10fc7cb9493..5a00adb2de8c 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -665,8 +665,8 @@ 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; - WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(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(pcie_pmu->on_cpu))); } return 0; @@ -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;