Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4503797ybc; Tue, 26 Nov 2019 09:56:23 -0800 (PST) X-Google-Smtp-Source: APXvYqye435MHITV4wOY/DwG8gj3Nojo5sQnlLaaGAK8PrdzNBah99dCsLpgGOurU2IEpP2gAMJn X-Received: by 2002:a50:9555:: with SMTP id v21mr26853858eda.90.1574790983578; Tue, 26 Nov 2019 09:56:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574790983; cv=none; d=google.com; s=arc-20160816; b=iAWolefP2ji4RghE7yhYFL6s5FVu/e9NaXJsmzLQm3ejlvE3n0PxJJ+EAz30OqLDrv +qih5S3VnTwOQkXPpiq8zGfUfSNNsbN9V9tjeElSNiKtt1IH03f9DBtji9P1ulIRSA2r sNxrO+VE2KVfsiNIWkK8nNZd6eJKM1bf5HberRUniKDPyA9NT5JPzrMhoiio6tXJWQQn RGizjUAxaD1B8Up7oaFt3w6DZcUZJDbx0+g8Tr3XmK0Wv0Xy7oExRbHnYcotQR2yKw0N WPTsCGOxgljMYRgsy01jZfF97ZqkRXOuXsomKw+bUSujMUoqvIFzNqAeQwqoCggenlvL Vlqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pZFQ3eFKPADyfKnPbeC6EC5z5nArDGf2T4aMbOXtHzk=; b=KHs6JCLBz4L/rwuLY8j43wwvIGknpxKn1lF3VP2MImwS/Rsuki9hn6xULqbRalh2Oe s9H5pYVKDvhf0KsV/nR/QZ4XdTDp7srM5nqW1V6QLuKmo/xqtirt5GnfYaW0Ym1bRha0 fASdyjUpn4vhFZwBLzez3/rHXsFDqnIg3r9EbkVRPmNKXEMMJT6ftrl0royp41iXkuxs iEH5Y7LhhvQLxtpfjDjE3eUQU4fNAR5RGi6wErHB7e7WfAiV1p8bWT5orJr5Nj0BiWKl X/2QyLFa5yI2skIMHaJdy+NtMvZEAwe7A3IIhfmHhZAPw3ZxXnCQf/xj2qXF1cCzIrRE nIsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si7600398ejx.0.2019.11.26.09.55.58; Tue, 26 Nov 2019 09:56:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbfKZQgo (ORCPT + 99 others); Tue, 26 Nov 2019 11:36:44 -0500 Received: from mga05.intel.com ([192.55.52.43]:53760 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbfKZQgo (ORCPT ); Tue, 26 Nov 2019 11:36:44 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2019 08:36:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,246,1571727600"; d="scan'208";a="359212460" Received: from nntpdsd52-183.inn.intel.com ([10.125.52.183]) by orsmga004.jf.intel.com with ESMTP; 26 Nov 2019 08:36:40 -0800 From: roman.sudarikov@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, eranian@google.com, bgregg@netflix.com, ak@linux.intel.com, kan.liang@linux.intel.com Cc: alexander.antonov@intel.com, roman.sudarikov@linux.intel.com Subject: [PATCH 2/6] perf tools: Helper functions to enumerate and probe PCI devices Date: Tue, 26 Nov 2019 19:36:26 +0300 Message-Id: <20191126163630.17300-3-roman.sudarikov@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191126163630.17300-2-roman.sudarikov@linux.intel.com> References: <20191126163630.17300-1-roman.sudarikov@linux.intel.com> <20191126163630.17300-2-roman.sudarikov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roman Sudarikov This makes aggregation of performance data per I/O device available in the perf user tools. Signed-off-by: Roman Sudarikov Co-developed-by: Alexander Antonov Signed-off-by: Alexander Antonov --- tools/perf/util/Build | 1 + tools/perf/util/pci.c | 53 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pci.h | 23 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tools/perf/util/pci.c create mode 100644 tools/perf/util/pci.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 8dcfca1a882f..02b699f8a10a 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -23,6 +23,7 @@ perf-y += memswap.o perf-y += parse-events.o perf-y += perf_regs.o perf-y += path.o +perf-y += pci.o perf-y += print_binary.o perf-y += rlimit.o perf-y += argv_split.o diff --git a/tools/perf/util/pci.c b/tools/perf/util/pci.c new file mode 100644 index 000000000000..ba1a48e9d0cc --- /dev/null +++ b/tools/perf/util/pci.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helper functions to access PCI CFG space. + * + * Copyright (C) 2019, Intel Corporation + * + * Authors: Roman Sudarikov + * Alexander Antonov + */ +#include "pci.h" +#include +#include +#include +#include + +#define PCI_DEVICE_PATH_TEMPLATE "bus/pci/devices/0000:%02x:%02x.0" +#define PCI_DEVICE_FILE_TEMPLATE PCI_DEVICE_PATH_TEMPLATE"/%s" + +static bool directory_exists(const char * const path) +{ + return (access(path, F_OK) == 0); +} + +bool pci_device_probe(struct bdf bdf) +{ + char path[PATH_MAX]; + + scnprintf(path, PATH_MAX, "%s/"PCI_DEVICE_PATH_TEMPLATE, + sysfs__mountpoint(), bdf.busno, bdf.devno); + return directory_exists(path); +} + +bool is_pci_device_root_port(struct bdf bdf, u8 *secondary, u8 *subordinate) +{ + char path[PATH_MAX]; + int secondary_interim; + int subordinate_interim; + + scnprintf(path, PATH_MAX, PCI_DEVICE_FILE_TEMPLATE, + bdf.busno, bdf.devno, "secondary_bus_number"); + if (!sysfs__read_int(path, &secondary_interim)) { + scnprintf(path, PATH_MAX, PCI_DEVICE_FILE_TEMPLATE, + bdf.busno, bdf.devno, "subordinate_bus_number"); + if (!sysfs__read_int(path, &subordinate_interim)) { + if (secondary) + *secondary = (u8)secondary_interim; + if (subordinate) + *subordinate = (u8)subordinate_interim; + return true; + } + } + return false; +} diff --git a/tools/perf/util/pci.h b/tools/perf/util/pci.h new file mode 100644 index 000000000000..e963b12e10e7 --- /dev/null +++ b/tools/perf/util/pci.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* + * + * Copyright (C) 2019, Intel Corporation + * + * Authors: Roman Sudarikov + * Alexander Antonov + */ +#ifndef _PCI_H +#define _PCI_H + +#include + +struct bdf { + u8 busno; + u8 devno; + u8 funcno; +}; + +bool pci_device_probe(struct bdf bdf); +bool is_pci_device_root_port(struct bdf bdf, u8 *secondary, u8 *subordinate); + +#endif /* _PCI_H */ -- 2.19.1