From patchwork Fri Mar 31 07:03:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 77571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp377485vqo; Fri, 31 Mar 2023 00:20:48 -0700 (PDT) X-Google-Smtp-Source: AKy350aDtPzzQjochf6r2Fyfl0oeWK2GoMdlB9lRRxDBO/VlBWP1gF/NJXTS3qet1EbaM8zqTGug X-Received: by 2002:a05:6402:417:b0:4c1:2252:f72c with SMTP id q23-20020a056402041700b004c12252f72cmr22877931edv.27.1680247248696; Fri, 31 Mar 2023 00:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680247248; cv=none; d=google.com; s=arc-20160816; b=Ikf2FvMHI0Ne1/hwfWXZaVk7tLuax+hy0NvxcLWGaUEC2kqIu982yxZgMuE6tOY7ym pUf/Pjfh8NWOWUJbBJYC0FyCtg3JoQ6QvSlNLnmAw+LGZAyFZa52mExqZmACfvApMA1K L2JcCWoSIZYlo4ACQ2jh2YGuJ++9uDT7vcKc0NRjGoVBWhW1JRwBatloeXfHAThHftGu FzJ362yozYBy3MSOxsorm9pKqbDeC2MJDj2EVAna1rxb1qM5zXaQBXArhNJiSboOYrFA 8LfJ7avyZOBSDgp9DXQYkU+8++dXwcxYu3jVkt2zNC3JhD7XOvzhzVI6PIZHI8UuxuZ7 FEdQ== 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; bh=dnjFqPf9c1pwWfIechqxrtsl7RFewouC34mvA+hRuDU=; b=N1YFHyXy6upeduBddgyvi4DyBaqjryeJgJq6YaiF3A7bHa8XkRyLv8P+NFCL4X7ynB 48u/rlATfuJ73+4Kht1wudH6VIKaV/1LODxWTozO6ZKmR8cufp90ddha+HF/ftLCcVoU sfMiHhdOWep5CgFOKcJCXyOC4UwNGlFFVPV4FH9aCbg/Gila7dMpp35AmlfJdpjlbPcG kRHNFfCGWRYbvSut0puqPfLb9omaAAebT6dtdPm4n0uXwCCCzRAgMO1l2bIUajT63doK +xtWkwuHsfRciYhg1KuqdGN8GyB9q0qBE1OuuZpdw//bUHR2LssGBVsEaQsnINyfev3R femQ== 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 bm28-20020a0564020b1c00b004acc6c7a631si1449380edb.179.2023.03.31.00.20.24; Fri, 31 Mar 2023 00:20:48 -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 S230358AbjCaHER (ORCPT + 99 others); Fri, 31 Mar 2023 03:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbjCaHEI (ORCPT ); Fri, 31 Mar 2023 03:04:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B89012CE6; Fri, 31 Mar 2023 00:03:53 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pnrmk100ZzKw3b; Fri, 31 Mar 2023 15:01:26 +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.21; Fri, 31 Mar 2023 15:03:50 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH v2 1/4] hwtracing: hisi_ptt: Factor out filter allocation and release operation Date: Fri, 31 Mar 2023 15:03:07 +0800 Message-ID: <20230331070310.5465-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230331070310.5465-1-yangyicong@huawei.com> References: <20230331070310.5465-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761866939249060439?= X-GMAIL-MSGID: =?utf-8?q?1761866939249060439?= From: Yicong Yang Factor out the allocation and release of filters. This will make it easier to extend and manage the function of the filter. Signed-off-by: Yicong Yang --- drivers/hwtracing/ptt/hisi_ptt.c | 63 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 30f1525639b5..bbbee8c2d7fd 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -354,6 +354,39 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) return 0; } +static void hisi_ptt_del_free_filters(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + list_del(&filter->list); + kfree(filter); +} + +static struct hisi_ptt_filter_desc * +hisi_ptt_alloc_add_filters(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) +{ + struct hisi_ptt_filter_desc *filter; + + filter = kzalloc(sizeof(*filter), GFP_KERNEL); + if (!filter) { + pci_err(hisi_ptt->pdev, "failed to add filter for %s\n", + pci_name(pdev)); + return NULL; + } + + filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); + filter->is_port = pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT; + if (filter->is_port) { + list_add_tail(&filter->list, &hisi_ptt->port_filters); + + /* Update the available port mask */ + hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true); + } else { + list_add_tail(&filter->list, &hisi_ptt->req_filters); + } + + return filter; +} + static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) { struct pci_dev *root_port = pcie_find_root_port(pdev); @@ -374,23 +407,9 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) * should be partial initialized and users would know which filter fails * through the log. Other functions of PTT device are still available. */ - filter = kzalloc(sizeof(*filter), GFP_KERNEL); - if (!filter) { - pci_err(hisi_ptt->pdev, "failed to add filter %s\n", pci_name(pdev)); + filter = hisi_ptt_alloc_add_filters(hisi_ptt, pdev); + if (!filter) return -ENOMEM; - } - - filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); - - if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT) { - filter->is_port = true; - list_add_tail(&filter->list, &hisi_ptt->port_filters); - - /* Update the available port mask */ - hisi_ptt->port_mask |= hisi_ptt_get_filter_val(filter->devid, true); - } else { - list_add_tail(&filter->list, &hisi_ptt->req_filters); - } return 0; } @@ -400,15 +419,11 @@ static void hisi_ptt_release_filters(void *data) struct hisi_ptt_filter_desc *filter, *tmp; struct hisi_ptt *hisi_ptt = data; - list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list) { - list_del(&filter->list); - kfree(filter); - } + list_for_each_entry_safe(filter, tmp, &hisi_ptt->req_filters, list) + hisi_ptt_del_free_filters(hisi_ptt, filter); - list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list) { - list_del(&filter->list); - kfree(filter); - } + list_for_each_entry_safe(filter, tmp, &hisi_ptt->port_filters, list) + hisi_ptt_del_free_filters(hisi_ptt, filter); } static int hisi_ptt_config_trace_buf(struct hisi_ptt *hisi_ptt) From patchwork Fri Mar 31 07:03:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 77560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp371412vqo; Fri, 31 Mar 2023 00:06:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZY+Ql6h9h/4qdfShaaofyQDDn1gEE0GE+zsA5SpSWgUxbvLuEY+5o9JaFWxIQMsLK+tNgW X-Received: by 2002:a17:906:1502:b0:93d:e6c8:ed5e with SMTP id b2-20020a170906150200b0093de6c8ed5emr8168217ejd.20.1680246382235; Fri, 31 Mar 2023 00:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680246382; cv=none; d=google.com; s=arc-20160816; b=wav2OlSRLmdoLCB8C+Tpn9SDIDhe4EZ9efRcDcgt2lyb9FJR/OAHY0QCgcnU6Et0w0 3AXSxxFKG39uafhRyEFpG446PddRXqzrAWLG3qxikoce1eS2SdYKtdGhy/cPBur61qmP aYTl6gqwV8qmwlO1lkj2jX8FRUTwCOi9/Ki2b0IDFdeJ4aS4Lt6ulxiKC7kjZBUR9E1v /fizNMmjNLEwq6JXg9TziID2s7lJ8zKJFZrKDiU3O5hK3OVYWBbgR7Ljk0F0z/+1iOnE ZHqYYXKF2WxTrIqH5bB2YxThHuv4f4AsdI75OiKQuH5I6JyTUYAJshD+BSCYZT7bC/9D eMcA== 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; bh=9p01eoE2Q/2F3NhTrAmjFnrjo+i8lZwAKEy9dhSMUYk=; b=HQP+mtFK9SCsUAHcmtebBHtFeqCp0hYuAC5XFDLShjLsXVMIqDni+OKozzYX2om44C zmkDiOaTp+4l+r8R8AEh7DssInu6nfMhlA+Xc03kF5R5aawYxjYfGbjH8NNNGDjCu3fw ec58M2y3tEu/Ty87m8YuWdgmsAVZjWOdZQIaq/tn5hy+ssBJ1FDRzhZ7XbyeV+xyWLXC BU+GHNnjkVgYy7Su4UJRPnIC0QCfVn45d/lGz08BjyGnhzFkXP21uO+NUKVIvLTJn3YH te4AsI+V5wphPZGQgaDt9AjdqaDy1kIl2yJlQgwZOqUJ9IdZ5d9SRVKTEshvAJT+Mf/L qIVw== 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 kw2-20020a170907770200b0091fe6232debsi1456056ejc.293.2023.03.31.00.05.57; Fri, 31 Mar 2023 00:06:22 -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 S230381AbjCaHEU (ORCPT + 99 others); Fri, 31 Mar 2023 03:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjCaHEI (ORCPT ); Fri, 31 Mar 2023 03:04:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F751A45D; Fri, 31 Mar 2023 00:03:53 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pnrmk352SzKwDG; Fri, 31 Mar 2023 15:01:26 +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.21; Fri, 31 Mar 2023 15:03:50 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH v2 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list Date: Fri, 31 Mar 2023 15:03:08 +0800 Message-ID: <20230331070310.5465-3-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230331070310.5465-1-yangyicong@huawei.com> References: <20230331070310.5465-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761866030748173230?= X-GMAIL-MSGID: =?utf-8?q?1761866030748173230?= From: Yicong Yang The PCIe devices supported by the PTT trace can be removed/rescanned by hotplug or through sysfs. Add support for dynamically updating the available filter list by registering a PCI bus notifier block. Then user can always get latest information about available tracing filters and driver can block the invalid filters of which related devices no longer exist in the system. Signed-off-by: Yicong Yang --- Documentation/trace/hisi-ptt.rst | 6 +- drivers/hwtracing/ptt/hisi_ptt.c | 146 ++++++++++++++++++++++++++++++- drivers/hwtracing/ptt/hisi_ptt.h | 36 ++++++++ 3 files changed, 184 insertions(+), 4 deletions(-) diff --git a/Documentation/trace/hisi-ptt.rst b/Documentation/trace/hisi-ptt.rst index 4f87d8e21065..3641aca4287a 100644 --- a/Documentation/trace/hisi-ptt.rst +++ b/Documentation/trace/hisi-ptt.rst @@ -153,9 +153,9 @@ Endpoint function can be specified in one trace. Specifying both Root Port and function at the same time is not supported. Driver maintains a list of available filters and will check the invalid inputs. -Currently the available filters are detected in driver's probe. If the supported -devices are removed/added after probe, you may need to reload the driver to update -the filters. +The available filters will be dynamically updates, which means you will always +get correct filter information when hotplug events happen, or when you manually +remove/rescan the devices. 2. Type ------- diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index bbbee8c2d7fd..b16bc18421cd 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -357,6 +357,9 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) static void hisi_ptt_del_free_filters(struct hisi_ptt *hisi_ptt, struct hisi_ptt_filter_desc *filter) { + if (filter->is_port) + hisi_ptt->port_mask &= ~hisi_ptt_get_filter_val(filter->devid, true); + list_del(&filter->list); kfree(filter); } @@ -387,6 +390,108 @@ hisi_ptt_alloc_add_filters(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) return filter; } +static void hisi_ptt_update_filters(struct work_struct *work) +{ + struct delayed_work *delayed_work = to_delayed_work(work); + struct hisi_ptt_filter_update_info info; + struct hisi_ptt_filter_desc *filter; + struct hisi_ptt *hisi_ptt; + + hisi_ptt = container_of(delayed_work, struct hisi_ptt, work); + + if (!mutex_trylock(&hisi_ptt->filter_lock)) { + schedule_delayed_work(&hisi_ptt->work, HISI_PTT_WORK_DELAY_MS); + return; + } + + while (kfifo_get(&hisi_ptt->filter_update_kfifo, &info)) { + if (info.is_add) { + /* + * Notify the users if failed to add this filter, others + * still work and available. See the comments in + * hisi_ptt_init_filters(). + */ + filter = hisi_ptt_alloc_add_filters(hisi_ptt, info.pdev); + if (!filter) + continue; + } else { + bool is_port = pci_pcie_type(info.pdev) == PCI_EXP_TYPE_ROOT_PORT; + u16 devid = PCI_DEVID(info.pdev->bus->number, info.pdev->devfn); + struct hisi_ptt_filter_desc *tmp; + struct list_head *target_list; + + target_list = is_port ? &hisi_ptt->port_filters : + &hisi_ptt->req_filters; + + list_for_each_entry_safe(filter, tmp, target_list, list) + if (filter->devid == devid) { + hisi_ptt_del_free_filters(hisi_ptt, filter); + break; + } + } + } + + mutex_unlock(&hisi_ptt->filter_lock); +} + +static void hisi_ptt_update_fifo_in(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_update_info *info) +{ + struct pci_dev *root_port = pcie_find_root_port(info->pdev); + u32 port_devid; + + if (!root_port) + return; + + port_devid = PCI_DEVID(root_port->bus->number, root_port->devfn); + if (port_devid < hisi_ptt->lower_bdf || + port_devid > hisi_ptt->upper_bdf) + return; + + /* + * The FIFO size is 16 which is sufficient for almost all the cases, + * since each PCIe core will have most 8 Root Ports (typically only + * 1~4 Root Ports). On failure log the failed filter and let user + * handle it. + */ + if (kfifo_in_spinlocked(&hisi_ptt->filter_update_kfifo, info, 1, + &hisi_ptt->filter_update_lock)) + schedule_delayed_work(&hisi_ptt->work, 0); + else + pci_warn(hisi_ptt->pdev, + "filter update fifo overflow for target %s\n", + pci_name(info->pdev)); +} + +/* + * A PCI bus notifier is used here for dynamically updating the filter + * list. + */ +static int hisi_ptt_notifier_call(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct hisi_ptt *hisi_ptt = container_of(nb, struct hisi_ptt, hisi_ptt_nb); + struct hisi_ptt_filter_update_info info; + struct device *dev = data; + + info.pdev = to_pci_dev(dev); + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + info.is_add = true; + break; + case BUS_NOTIFY_DEL_DEVICE: + info.is_add = false; + break; + default: + return 0; + } + + hisi_ptt_update_fifo_in(hisi_ptt, &info); + + return 0; +} + static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) { struct pci_dev *root_port = pcie_find_root_port(pdev); @@ -466,8 +571,13 @@ static int hisi_ptt_init_ctrls(struct hisi_ptt *hisi_ptt) int ret; u32 reg; + INIT_DELAYED_WORK(&hisi_ptt->work, hisi_ptt_update_filters); + INIT_KFIFO(hisi_ptt->filter_update_kfifo); + spin_lock_init(&hisi_ptt->filter_update_lock); + INIT_LIST_HEAD(&hisi_ptt->port_filters); INIT_LIST_HEAD(&hisi_ptt->req_filters); + mutex_init(&hisi_ptt->filter_lock); ret = hisi_ptt_config_trace_buf(hisi_ptt); if (ret) @@ -633,14 +743,19 @@ static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config) * For Requester ID filters, walk the available filter list to see * whether we have one matched. */ + mutex_lock(&hisi_ptt->filter_lock); if (!hisi_ptt->trace_ctrl.is_port) { list_for_each_entry(filter, &hisi_ptt->req_filters, list) { - if (val == hisi_ptt_get_filter_val(filter->devid, filter->is_port)) + if (val == hisi_ptt_get_filter_val(filter->devid, filter->is_port)) { + mutex_unlock(&hisi_ptt->filter_lock); return 0; + } } } else if (bitmap_subset(&val, &port_mask, BITS_PER_LONG)) { + mutex_unlock(&hisi_ptt->filter_lock); return 0; } + mutex_unlock(&hisi_ptt->filter_lock); return -EINVAL; } @@ -916,6 +1031,31 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) &hisi_ptt->hisi_ptt_pmu); } +static void hisi_ptt_unregister_filter_update_notifier(void *data) +{ + struct hisi_ptt *hisi_ptt = data; + + bus_unregister_notifier(&pci_bus_type, &hisi_ptt->hisi_ptt_nb); + + /* Cancel any work that has been queued */ + cancel_delayed_work_sync(&hisi_ptt->work); +} + +/* Register the bus notifier for dynamically updating the filter list */ +static int hisi_ptt_register_filter_update_notifier(struct hisi_ptt *hisi_ptt) +{ + int ret; + + hisi_ptt->hisi_ptt_nb.notifier_call = hisi_ptt_notifier_call; + ret = bus_register_notifier(&pci_bus_type, &hisi_ptt->hisi_ptt_nb); + if (ret) + return ret; + + return devm_add_action_or_reset(&hisi_ptt->pdev->dev, + hisi_ptt_unregister_filter_update_notifier, + hisi_ptt); +} + /* * The DMA of PTT trace can only use direct mappings due to some * hardware restriction. Check whether there is no IOMMU or the @@ -987,6 +1127,10 @@ static int hisi_ptt_probe(struct pci_dev *pdev, return ret; } + ret = hisi_ptt_register_filter_update_notifier(hisi_ptt); + if (ret) + pci_warn(pdev, "failed to register filter update notifier, ret = %d", ret); + ret = hisi_ptt_register_pmu(hisi_ptt); if (ret) { pci_err(pdev, "failed to register PMU device, ret = %d", ret); diff --git a/drivers/hwtracing/ptt/hisi_ptt.h b/drivers/hwtracing/ptt/hisi_ptt.h index 5beb1648c93a..a389b943944c 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.h +++ b/drivers/hwtracing/ptt/hisi_ptt.h @@ -11,12 +11,15 @@ #include #include +#include #include #include +#include #include #include #include #include +#include #define DRV_NAME "hisi_ptt" @@ -71,6 +74,11 @@ #define HISI_PTT_WAIT_TRACE_TIMEOUT_US 100UL #define HISI_PTT_WAIT_POLL_INTERVAL_US 10UL +/* FIFO size for dynamically updating the PTT trace filter list. */ +#define HISI_PTT_FILTER_UPDATE_FIFO_SIZE 16 +/* Delay time for filter updating work */ +#define HISI_PTT_WORK_DELAY_MS 100UL + #define HISI_PCIE_CORE_PORT_ID(devfn) ((PCI_SLOT(devfn) & 0x7) << 1) /* Definition of the PMU configs */ @@ -143,6 +151,16 @@ struct hisi_ptt_filter_desc { u16 devid; }; +/** + * struct hisi_ptt_filter_update_info - Information for PTT filter updating + * @pdev: the PCI device to update in the filter list + * @is_add: adding to the filter or not + */ +struct hisi_ptt_filter_update_info { + struct pci_dev *pdev; + bool is_add; +}; + /** * struct hisi_ptt_pmu_buf - Descriptor of the AUX buffer of PTT trace * @length: size of the AUX buffer @@ -161,6 +179,7 @@ struct hisi_ptt_pmu_buf { * struct hisi_ptt - Per PTT device data * @trace_ctrl: the control information of PTT trace * @hotplug_node: node for register cpu hotplug event + * @hisi_ptt_nb: dynamic filter update notifier * @hisi_ptt_pmu: the pum device of trace * @iobase: base IO address of the device * @pdev: pci_dev of this PTT device @@ -170,10 +189,15 @@ struct hisi_ptt_pmu_buf { * @lower_bdf: the lower BDF range of the PCI devices managed by this PTT device * @port_filters: the filter list of root ports * @req_filters: the filter list of requester ID + * @filter_lock: lock to protect the filters * @port_mask: port mask of the managed root ports + * @work: delayed work for filter updating + * @filter_update_lock: spinlock to protect the filter update fifo + * @filter_update_fifo: fifo of the filters waiting to update the filter list */ struct hisi_ptt { struct hisi_ptt_trace_ctrl trace_ctrl; + struct notifier_block hisi_ptt_nb; struct hlist_node hotplug_node; struct pmu hisi_ptt_pmu; void __iomem *iobase; @@ -192,7 +216,19 @@ struct hisi_ptt { */ struct list_head port_filters; struct list_head req_filters; + struct mutex filter_lock; u16 port_mask; + + /* + * We use a delayed work here to avoid indefinitely waiting for + * the hisi_ptt->mutex which protecting the filter list. The + * work will be delayed only if the mutex can not be held, + * otherwise no delay will be applied. + */ + struct delayed_work work; + spinlock_t filter_update_lock; + DECLARE_KFIFO(filter_update_kfifo, struct hisi_ptt_filter_update_info, + HISI_PTT_FILTER_UPDATE_FIFO_SIZE); }; #define to_hisi_ptt(pmu) container_of(pmu, struct hisi_ptt, hisi_ptt_pmu) From patchwork Fri Mar 31 07:03:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 77563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp374105vqo; Fri, 31 Mar 2023 00:12:29 -0700 (PDT) X-Google-Smtp-Source: AKy350YGujMDtF9Vkrh6e4Ef6f2+lLHW/YCYqJ6iSEE+GCnVVczTX0V/WNO023mwXpBJuToVrhi5 X-Received: by 2002:a17:90b:3ece:b0:23f:6edd:41da with SMTP id rm14-20020a17090b3ece00b0023f6edd41damr29645988pjb.29.1680246749768; Fri, 31 Mar 2023 00:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680246749; cv=none; d=google.com; s=arc-20160816; b=D6AhUsuf6mL+AS1hEB6MeebV1ebPwnZeNGVscJSfT78LTsK35JRSi3+w+RJOBONmY/ ytPHxKKA+pNuE8yvUB9al1OKXhBQIrql6k5dfrCvEguugbTKRrI+VXZJ/XQUXN40AmSi T4jtEUJ+v9zGYwdaZ4f1xS5ByO1OrmbHvlmCQlLKQzTdmCfnwobtvSUnnhV6Q90/nImL DEisHrvE8MHVJnng1bUG5NqAjDdxggT3HXBG6ZRW9sIsaEawYdJbtfSKt3L3UiSoFDSV AAQ3EFBnPgxoCmSicBQ79oVa4ajnPXCPC5McD+b6XnApK5ALFG4Lw0OFI0LOpvnsA0lo WdEQ== 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; bh=lGFT/SSK296AAznFkqrbDq8/pFjUXob50oIdyM7+600=; b=IM9vBRO4rd4v/vEMgY0OBd578xnfUuVQJyIBiKiblbxJFa8GqCtYSt6NlGsRl7K3jb 3z7DjJ6qQ7nSuQnezOIpTmxvXmH/R91Nt0T2SPzp6TLxQX9jHrV8658x3XKpzXbh7CXv dlNSjNXZ6a4OFOi7DT1vHBTisL1iDTG/+X+zCuIkfQo4OJlbigIC7u7WVMaRrjOpTBPg jpADqKdHBgd4GUMgu8z2yfiAmAR/EQWk2OLGFYmO725+QM4g02QVafUR8pQ5LE3/x5S3 l62KqAeu6QVlQg89sdLZ3968sGAQtd58TSgdd8+G892iX3sSD73j/NOoibHYHlOEMN7u zFOw== 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 r14-20020a17090a4dce00b0022c1c376f57si1162784pjl.33.2023.03.31.00.12.16; Fri, 31 Mar 2023 00:12:29 -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 S230440AbjCaHEX (ORCPT + 99 others); Fri, 31 Mar 2023 03:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230355AbjCaHEI (ORCPT ); Fri, 31 Mar 2023 03:04:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30BBD1A47E; Fri, 31 Mar 2023 00:03:53 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PnrlJ67kqzSqVH; Fri, 31 Mar 2023 15:00:12 +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.21; Fri, 31 Mar 2023 15:03:51 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH v2 3/4] hwtracing: hisi_ptt: Export available filters through sysfs Date: Fri, 31 Mar 2023 15:03:09 +0800 Message-ID: <20230331070310.5465-4-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230331070310.5465-1-yangyicong@huawei.com> References: <20230331070310.5465-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761866415921672479?= X-GMAIL-MSGID: =?utf-8?q?1761866415921672479?= From: Yicong Yang The PTT can only filter the traced TLP headers by the Root Ports or the Requester ID of the Endpoint, which are located on the same core of the PTT device. The filter value used is derived from the BDF number of the supported Root Port or the Endpoint. It's not friendly enough for the users since it requires the user to be familiar enough with the platform and calculate the filter value manually. This patch export the available filters through sysfs. Each available filters is presented as an individual file with the name of the BDF number of the related PCIe device. The files are created under $(PTT PMU dir)/available_root_port_filters and $(PTT PMU dir)/available_requester_filters respectively. The filter value can be known by reading the related file. Then the users can easily know the available filters for trace and get the filter values without calculating. Signed-off-by: Yicong Yang --- .../ABI/testing/sysfs-devices-hisi_ptt | 50 +++++ Documentation/trace/hisi-ptt.rst | 6 + drivers/hwtracing/ptt/hisi_ptt.c | 210 ++++++++++++++++++ drivers/hwtracing/ptt/hisi_ptt.h | 16 ++ 4 files changed, 282 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-devices-hisi_ptt b/Documentation/ABI/testing/sysfs-devices-hisi_ptt index 82de6d710266..fe5b742b037b 100644 --- a/Documentation/ABI/testing/sysfs-devices-hisi_ptt +++ b/Documentation/ABI/testing/sysfs-devices-hisi_ptt @@ -59,3 +59,53 @@ Description: (RW) Control the allocated buffer watermark of outbound packets. The available tune data is [0, 1, 2]. Writing a negative value will return an error, and out of range values will be converted to 2. The value indicates a probable level of the event. + +What: /sys/devices/hisi_ptt_/root_port_filters +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: This directory contains the files providing the PCIe Root Port filters + information used for PTT trace. Each file is named after the supported + Root Port device name ::.. + + See the description of the "filter" in Documentation/trace/hisi-ptt.rst + for more information. + +What: /sys/devices/hisi_ptt_/root_port_filters/multiselect +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not. + +What: /sys/devices/hisi_ptt_/root_port_filters/ +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: (Read) Indicates the filter value of this Root Port filter, which + can be used to control the TLP headers to trace by the PTT trace. + +What: /sys/devices/hisi_ptt_/requester_filters +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: This directory contains the files providing the PCIe Requester filters + information used for PTT trace. Each file is named after the supported + Endpoint device name ::.. + + See the description of the "filter" in Documentation/trace/hisi-ptt.rst + for more information. + +What: /sys/devices/hisi_ptt_/requester_filters/multiselect +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not. + +What: /sys/devices/hisi_ptt_/requester_filters/ +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang +Description: (Read) Indicates the filter value of this Requester filter, which + can be used to control the TLP headers to trace by the PTT trace. diff --git a/Documentation/trace/hisi-ptt.rst b/Documentation/trace/hisi-ptt.rst index 3641aca4287a..b8c7d71aee32 100644 --- a/Documentation/trace/hisi-ptt.rst +++ b/Documentation/trace/hisi-ptt.rst @@ -148,6 +148,12 @@ For example, if the desired filter is Endpoint function 0000:01:00.1 the filter value will be 0x00101. If the desired filter is Root Port 0000:00:10.0 then then filter value is calculated as 0x80001. +The driver also presents every supported Root Port and Requester filter through +sysfs. Each filter will be an individual file with name of its related PCIe +device name (domain:bus:device.function). The files of Root Port filters are +under $(PTT PMU dir)/root_port_filters and files of Requester filters +are under $(PTT PMU dir)/requester_filters. + Note that multiple Root Ports can be specified at one time, but only one Endpoint function can be specified in one trace. Specifying both Root Port and function at the same time is not supported. Driver maintains a list of diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index b16bc18421cd..71bc0c784c51 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -361,6 +361,7 @@ static void hisi_ptt_del_free_filters(struct hisi_ptt *hisi_ptt, hisi_ptt->port_mask &= ~hisi_ptt_get_filter_val(filter->devid, true); list_del(&filter->list); + kfree(filter->name); kfree(filter); } @@ -376,6 +377,14 @@ hisi_ptt_alloc_add_filters(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) return NULL; } + filter->name = kstrdup(pci_name(pdev), GFP_KERNEL); + if (!filter->name) { + pci_err(hisi_ptt->pdev, "failed to allocate name for filter %s\n", + pci_name(pdev)); + kfree(filter); + return NULL; + } + filter->devid = PCI_DEVID(pdev->bus->number, pdev->devfn); filter->is_port = pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT; if (filter->is_port) { @@ -390,6 +399,137 @@ hisi_ptt_alloc_add_filters(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) return filter; } +static ssize_t hisi_ptt_filter_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct hisi_ptt_filter_desc *filter; + unsigned long filter_val; + + filter = container_of(attr, struct hisi_ptt_filter_desc, attr); + filter_val = hisi_ptt_get_filter_val(filter->devid, filter->is_port) | + (filter->is_port ? HISI_PTT_PMU_FILTER_IS_PORT : 0); + + return sysfs_emit(buf, "0x%05lx\n", filter_val); +} + +static int hisi_ptt_create_rp_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode = 0400; /* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + + return sysfs_add_file_to_group(kobj, &filter->attr.attr, + HISI_PTT_RP_FILTERS_GRP_NAME); +} + +static void hisi_ptt_remove_rp_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + sysfs_remove_file_from_group(kobj, &filter->attr.attr, + HISI_PTT_RP_FILTERS_GRP_NAME); +} + +static int hisi_ptt_create_req_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode = 0400; /* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + + return sysfs_add_file_to_group(kobj, &filter->attr.attr, + HISI_PTT_REQ_FILTERS_GRP_NAME); +} + +static void hisi_ptt_remove_req_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + sysfs_remove_file_from_group(kobj, &filter->attr.attr, + HISI_PTT_REQ_FILTERS_GRP_NAME); +} + +static int hisi_ptt_create_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + int ret; + + if (filter->is_port) + ret = hisi_ptt_create_rp_filter_attr(hisi_ptt, filter); + else + ret = hisi_ptt_create_req_filter_attr(hisi_ptt, filter); + + if (ret) + pci_err(hisi_ptt->pdev, "failed to create sysfs attribute for filter %s\n", + filter->name); + + return ret; +} + +static void hisi_ptt_remove_filter_attr(struct hisi_ptt *hisi_ptt, + struct hisi_ptt_filter_desc *filter) +{ + if (filter->is_port) + hisi_ptt_remove_rp_filter_attr(hisi_ptt, filter); + else + hisi_ptt_remove_req_filter_attr(hisi_ptt, filter); +} + +static void hisi_ptt_remove_all_filter_attributes(void *data) +{ + struct hisi_ptt_filter_desc *filter; + struct hisi_ptt *hisi_ptt = data; + + mutex_lock(&hisi_ptt->filter_lock); + + list_for_each_entry(filter, &hisi_ptt->req_filters, list) + hisi_ptt_remove_filter_attr(hisi_ptt, filter); + + list_for_each_entry(filter, &hisi_ptt->port_filters, list) + hisi_ptt_remove_filter_attr(hisi_ptt, filter); + + hisi_ptt->sysfs_inited = false; + mutex_unlock(&hisi_ptt->filter_lock); +} + +static int hisi_ptt_init_filter_attributes(struct hisi_ptt *hisi_ptt) +{ + struct hisi_ptt_filter_desc *filter; + int ret; + + mutex_lock(&hisi_ptt->filter_lock); + + list_for_each_entry(filter, &hisi_ptt->port_filters, list) { + ret = hisi_ptt_create_filter_attr(hisi_ptt, filter); + if (ret) + goto out; + } + + list_for_each_entry(filter, &hisi_ptt->req_filters, list) { + ret = hisi_ptt_create_filter_attr(hisi_ptt, filter); + if (ret) + goto out; + } + + ret = devm_add_action_or_reset(&hisi_ptt->pdev->dev, + hisi_ptt_remove_all_filter_attributes, + hisi_ptt); + if (ret) + goto out; + + hisi_ptt->sysfs_inited = true; +out: + mutex_unlock(&hisi_ptt->filter_lock); + return ret; +} + static void hisi_ptt_update_filters(struct work_struct *work) { struct delayed_work *delayed_work = to_delayed_work(work); @@ -414,6 +554,18 @@ static void hisi_ptt_update_filters(struct work_struct *work) filter = hisi_ptt_alloc_add_filters(hisi_ptt, info.pdev); if (!filter) continue; + + /* + * If filters' sysfs entries hasn't been initialized, + * then we're still at probe stage. Add the filters to + * the list and later hisi_ptt_init_filter_attributes() + * will create sysfs attributes for all the filters. + */ + if (hisi_ptt->sysfs_inited && + hisi_ptt_create_filter_attr(hisi_ptt, filter)) { + hisi_ptt_del_free_filters(hisi_ptt, filter); + continue; + } } else { bool is_port = pci_pcie_type(info.pdev) == PCI_EXP_TYPE_ROOT_PORT; u16 devid = PCI_DEVID(info.pdev->bus->number, info.pdev->devfn); @@ -426,6 +578,10 @@ static void hisi_ptt_update_filters(struct work_struct *work) list_for_each_entry_safe(filter, tmp, target_list, list) if (filter->devid == devid) { hisi_ptt_del_free_filters(hisi_ptt, filter); + + if (hisi_ptt->sysfs_inited) + hisi_ptt_remove_filter_attr(hisi_ptt, filter); + break; } } @@ -653,10 +809,58 @@ static struct attribute_group hisi_ptt_pmu_format_group = { .attrs = hisi_ptt_pmu_format_attrs, }; +static ssize_t hisi_ptt_filter_multiselect_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct dev_ext_attribute *ext_attr; + + ext_attr = container_of(attr, struct dev_ext_attribute, attr); + return sysfs_emit(buf, "%s\n", (char *)ext_attr->var); +} + +static struct dev_ext_attribute root_port_filters_multiselect = { + .attr = { + .attr = { .name = "multiselect", .mode = 0400 }, + .show = hisi_ptt_filter_multiselect_show, + }, + .var = "1", +}; + +static struct attribute *hisi_ptt_pmu_root_ports_attrs[] = { + &root_port_filters_multiselect.attr.attr, + NULL +}; + +static struct attribute_group hisi_ptt_pmu_root_ports_group = { + .name = HISI_PTT_RP_FILTERS_GRP_NAME, + .attrs = hisi_ptt_pmu_root_ports_attrs, +}; + +static struct dev_ext_attribute requester_filters_multiselect = { + .attr = { + .attr = { .name = "multiselect", .mode = 0400 }, + .show = hisi_ptt_filter_multiselect_show, + }, + .var = "0", +}; + +static struct attribute *hisi_ptt_pmu_requesters_attrs[] = { + &requester_filters_multiselect.attr.attr, + NULL +}; + +static struct attribute_group hisi_ptt_pmu_requesters_group = { + .name = HISI_PTT_REQ_FILTERS_GRP_NAME, + .attrs = hisi_ptt_pmu_requesters_attrs, +}; + static const struct attribute_group *hisi_ptt_pmu_groups[] = { &hisi_ptt_cpumask_attr_group, &hisi_ptt_pmu_format_group, &hisi_ptt_tune_group, + &hisi_ptt_pmu_root_ports_group, + &hisi_ptt_pmu_requesters_group, NULL }; @@ -1137,6 +1341,12 @@ static int hisi_ptt_probe(struct pci_dev *pdev, return ret; } + ret = hisi_ptt_init_filter_attributes(hisi_ptt); + if (ret) { + pci_err(pdev, "failed to init sysfs filter attributes, ret = %d", ret); + return ret; + } + return 0; } diff --git a/drivers/hwtracing/ptt/hisi_ptt.h b/drivers/hwtracing/ptt/hisi_ptt.h index a389b943944c..b1feb81bc60e 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.h +++ b/drivers/hwtracing/ptt/hisi_ptt.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -139,15 +140,28 @@ struct hisi_ptt_trace_ctrl { u32 type:4; }; +/* + * sysfs attribute group name for root port filters and requester filters: + * /sys/devices/hisi_ptt_/root_port_filters + * and + * /sys/devices/hisi_ptt_/requester_filters + */ +#define HISI_PTT_RP_FILTERS_GRP_NAME "root_port_filters" +#define HISI_PTT_REQ_FILTERS_GRP_NAME "requester_filters" + /** * struct hisi_ptt_filter_desc - Descriptor of the PTT trace filter + * @attr: sysfs attribute of this filter * @list: entry of this descriptor in the filter list * @is_port: the PCI device of the filter is a Root Port or not + * @name: name of this filter, same as the name of the related PCI device * @devid: the PCI device's devid of the filter */ struct hisi_ptt_filter_desc { + struct device_attribute attr; struct list_head list; bool is_port; + char *name; u16 devid; }; @@ -190,6 +204,7 @@ struct hisi_ptt_pmu_buf { * @port_filters: the filter list of root ports * @req_filters: the filter list of requester ID * @filter_lock: lock to protect the filters + * @sysfs_inited: whether the filters' sysfs entries has been initialized * @port_mask: port mask of the managed root ports * @work: delayed work for filter updating * @filter_update_lock: spinlock to protect the filter update fifo @@ -217,6 +232,7 @@ struct hisi_ptt { struct list_head port_filters; struct list_head req_filters; struct mutex filter_lock; + bool sysfs_inited; u16 port_mask; /* From patchwork Fri Mar 31 07:03:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 77561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp373692vqo; Fri, 31 Mar 2023 00:11:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Z534CCBP2TE/FiGccdoASqN5hNg4ufVNFJpDIMiwL77tYfuL6kq5Je6EsvHhruvlL5QKQP X-Received: by 2002:a17:902:ecca:b0:1a1:defc:30d8 with SMTP id a10-20020a170902ecca00b001a1defc30d8mr29273508plh.32.1680246687481; Fri, 31 Mar 2023 00:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680246687; cv=none; d=google.com; s=arc-20160816; b=GQpG494G4G9V0gNfwH0BWAc8zXv4STo4eA9+QK2Z4v4f3I/yVpIluPWzfccpvpJ14Y qeM3sq4JfTciYMiebNU1IxF2fDs471t978iQunvrfBJb0hdrEmL5aBcS1pEdmvDArCc5 qRZhJiJ9OHso0eM37o3LAtdkdBbZQ1lfWTRxHSz+egU2OGZpZpWcBgUK0tjHugZLboHL I8oQLmK+ttQv93Fiji6tT1U5gBnO65L9s2eEIfKXEY/kKXzM7k4czhohNcJNC8iZ+zyy uHIMNaSeDu5jvYG8U8HCuNvrRKQeNO++U/akI4OnfEgWPLClpLl9DbyTpd1sB4eTIzON ae1g== 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; bh=0chF1GNLQO2PrhK+OUVYCr6xLlnT5KslZggHwPrQH1w=; b=IH5fVId04sU8Ya5AB6SON21NtYE/JL7ZWzfY1yibNIjQMbWwnurcchzN+R9qgp2VKK sT4/P6dXyl2jKI8Nx5AKX+FYYuaZOqeYpJoevrprmL9Oh5KvKCBw6FbAmC06F6BTJon3 31f5bdR4vrilZZDqxyrmEV2qBTGj2Dss+nChCaTMN7z6MMl0Bi1EbLCQaBzqMgNQPKpJ NTa6hC1/P2Fnb20CW3cXwhfoD5idFAIXkrqUxfAhhW2gDFWKTOsrJKvGKy/MJTOGa+Dd rI8Pmu1755uLyAPaCdwJ+Qz9ucPDLMv11/MiFoEAlBJWet6nD8eGM4taPj7L1SqiOQYq v2+Q== 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 m1-20020a655301000000b0050fb7c5a656si1686530pgq.190.2023.03.31.00.11.14; Fri, 31 Mar 2023 00:11:27 -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 S230398AbjCaHEO (ORCPT + 99 others); Fri, 31 Mar 2023 03:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjCaHEI (ORCPT ); Fri, 31 Mar 2023 03:04:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D3081A47F; Fri, 31 Mar 2023 00:03:53 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pnrmk5TmszKwCk; Fri, 31 Mar 2023 15:01:26 +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.21; Fri, 31 Mar 2023 15:03:51 +0800 From: Yicong Yang To: , , , , , CC: , , , , Subject: [PATCH v2 4/4] hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU Date: Fri, 31 Mar 2023 15:03:10 +0800 Message-ID: <20230331070310.5465-5-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230331070310.5465-1-yangyicong@huawei.com> References: <20230331070310.5465-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761866350428447405?= X-GMAIL-MSGID: =?utf-8?q?1761866350428447405?= From: Yicong Yang The PTT trace collects PCIe TLP headers from the PCIe link and don't have the ability to exclude certain context. It doesn't support itrace as well. So only advertise PERF_PMU_CAP_NO_EXCLUDE. This will greatly save the storage of final data. Tested tracing idle link for ~15s, without this patch we'll collect ~28.682MB data for context related information and with this patch it reduced to ~0.226MB. Signed-off-by: Yicong Yang --- drivers/hwtracing/ptt/hisi_ptt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 71bc0c784c51..b0f070ad88a1 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -1205,7 +1205,7 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) hisi_ptt->hisi_ptt_pmu = (struct pmu) { .module = THIS_MODULE, - .capabilities = PERF_PMU_CAP_EXCLUSIVE | PERF_PMU_CAP_ITRACE, + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, .task_ctx_nr = perf_sw_context, .attr_groups = hisi_ptt_pmu_groups, .event_init = hisi_ptt_pmu_event_init,