mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 3/6] perf stat: Helper functions for list of IIO devices
Date: Tue, 26 Nov 2019 19:36:27 +0300	[thread overview]
Message-ID: <20191126163630.17300-4-roman.sudarikov@linux.intel.com> (raw)
In-Reply-To: <20191126163630.17300-3-roman.sudarikov@linux.intel.com>

From: Roman Sudarikov <roman.sudarikov@linux.intel.com>

Helper functions to iterate through and manipulate with list
of struct iio_device objects. The following patch will use it.

Signed-off-by: Roman Sudarikov <roman.sudarikov@linux.intel.com>
Co-developed-by: Alexander Antonov <alexander.antonov@intel.com>
Signed-off-by: Alexander Antonov <alexander.antonov@intel.com>
---
 tools/perf/arch/x86/util/iiostat.c | 178 +++++++++++++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 tools/perf/arch/x86/util/iiostat.c

diff --git a/tools/perf/arch/x86/util/iiostat.c b/tools/perf/arch/x86/util/iiostat.c
new file mode 100644
index 000000000000..b93b9b9da418
--- /dev/null
+++ b/tools/perf/arch/x86/util/iiostat.c
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * perf stat --iiostat
+ *
+ * Copyright (C) 2019, Intel Corporation
+ *
+ * Authors: Roman Sudarikov <roman.sudarikov@intel.com>
+ *	    Alexander Antonov <alexander.antonov@intel.com>
+ */
+#include "path.h"
+#include "pci.h"
+#include <api/fs/fs.h>
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include "util/debug.h"
+#include "util/iiostat.h"
+#include "util/counts.h"
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <regex.h>
+
+struct dev_info {
+	struct bdf bdf;
+	u8 ch_mask;
+	u8 socket;
+	u8 pmu_idx;
+	u8 root_port_nr;
+};
+
+struct iio_device {
+	struct list_head node;
+	struct dev_info	dev_info;
+	int idx;
+};
+
+struct iio_devs_list {
+	struct list_head devices;
+	int nr_entries;
+};
+
+/**
+ * __iio_devs_for_each_device - iterate thru all the iio devices
+ * @list: list_head instance to iterate
+ * @device: struct iio_device iterator
+ */
+#define __iio_devs_for_each_device(list, device) \
+		list_for_each_entry(device, list, node)
+
+/**
+ * iio_devs_list_for_each_device - iterate thru all the iio devices
+ * @list: iio_devs_list instance to iterate
+ * @device: struct iio_device iterator
+ */
+#define iio_devs_list_for_each_device(list, device) \
+	__iio_devs_for_each_device(&(list->devices), device)
+
+/**
+ * __iio_devs_for_each_device_safe - safely iterate thru all the iio devices
+ * @devices: list_head instance to iterate
+ * @tmp: struct iio_device temp iterator
+ * @device: struct iio_device iterator
+ */
+#define __iio_devs_for_each_device_safe(devices, tmp, device) \
+		list_for_each_entry_safe(device, tmp, devices, node)
+
+/**
+ * iio_devs_list_for_each_device_safe - safely iterate thru all the iio devices
+ * @list: iio_devs_list instance to iterate
+ * @tmp: struct iio_device temp iterator
+ * @device: struct iio_device iterator
+ */
+#define iio_devs_list_for_each_device_safe(list, tmp, device) \
+		__iio_devs_for_each_device_safe(&(list->devices), tmp, device)
+
+#define iio_device_delete_from_list(device) \
+		list_del(&(device->node))
+
+static struct iio_device *iio_device_new(struct dev_info *info)
+{
+	struct iio_device *p =
+		(struct iio_device *)calloc(1, sizeof(struct iio_device));
+
+	if (p) {
+		INIT_LIST_HEAD(&(p->node));
+		p->dev_info = *info;
+		p->idx = -1;
+	}
+	return p;
+}
+
+static void iio_device_delete(struct iio_device *device)
+{
+	if (device) {
+		list_del_init(&(device->node));
+		free(device);
+	}
+}
+
+static void iiostat_device_show(FILE *output,
+			const struct iio_device * const device)
+{
+	if (output && device)
+		fprintf(output, "S%d-RootPort%d-uncore_iio_%d<%02x:%02x.%x>\n",
+			device->dev_info.socket,
+			device->dev_info.root_port_nr, device->dev_info.pmu_idx,
+			device->dev_info.bdf.busno, device->dev_info.bdf.devno,
+			device->dev_info.bdf.funcno);
+}
+
+static struct iio_devs_list *iio_devs_list_new(void)
+{
+	struct iio_devs_list *devs_list =
+		(struct iio_devs_list *)calloc(1, sizeof(struct iio_devs_list));
+
+	if (devs_list)
+		INIT_LIST_HEAD(&(devs_list->devices));
+	return devs_list;
+}
+
+static void iio_devs_list_free(struct iio_devs_list *list)
+{
+	struct iio_device *tmp_device;
+	struct iio_device *device;
+
+	if (list) {
+		iio_devs_list_for_each_device_safe(list, tmp_device, device)
+			iio_device_delete(device);
+		list_del_init(&(list->devices));
+		free(list);
+	}
+}
+
+static bool is_same_iio_device(struct bdf lhd, struct bdf rhd)
+{
+	return (lhd.busno == rhd.busno) && (lhd.devno == rhd.devno) &&
+		(lhd.funcno == rhd.funcno);
+}
+
+static void iio_devs_list_add_device(struct iio_devs_list *list,
+				      struct iio_device * const device)
+{
+	struct iio_device *it;
+
+	if (list && device) {
+		iio_devs_list_for_each_device(list, it)
+			if (is_same_iio_device(it->dev_info.bdf, device->dev_info.bdf))
+				return;
+		device->idx = list->nr_entries++;
+		list_add_tail(&(device->node), &(list->devices));
+	}
+}
+
+static void iio_devs_list_join_list(struct iio_devs_list *dest,
+				     struct iio_devs_list *src)
+{
+	int idx = 0;
+	struct iio_device *it;
+
+	if (dest && src) {
+		if (dest->nr_entries) {
+			it = list_last_entry(&(dest->devices),
+					     struct iio_device, node);
+			idx = it->idx + 1;
+		}
+		iio_devs_list_for_each_device(src, it)
+			it->idx = idx++;
+		list_splice_tail(&(src->devices), &(dest->devices));
+		dest->nr_entries += src->nr_entries;
+	}
+}
-- 
2.19.1


  reply	other threads:[~2019-11-26 16:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 16:36 [PATCH 0/6] perf x86: Exposing IO stack to IO PMON mapping through sysfs roman.sudarikov
2019-11-26 16:36 ` [PATCH 1/6] perf x86: Infrastructure for exposing an Uncore unit to PMON mapping roman.sudarikov
2019-11-26 16:36   ` [PATCH 2/6] perf tools: Helper functions to enumerate and probe PCI devices roman.sudarikov
2019-11-26 16:36     ` roman.sudarikov [this message]
2019-11-26 16:36       ` [PATCH 4/6] perf stat: New --iiostat mode to provide I/O performance metrics roman.sudarikov
2019-11-26 16:36         ` [PATCH 5/6] perf tools: Add feature check for libpci roman.sudarikov
2019-11-26 16:36           ` [PATCH 6/6] perf stat: Add PCI device name to --iiostat output roman.sudarikov
2019-12-02 14:00   ` [PATCH 1/6] perf x86: Infrastructure for exposing an Uncore unit to PMON mapping Peter Zijlstra
2019-12-02 19:47   ` Stephane Eranian
2019-12-03  3:00     ` Andi Kleen
2019-12-04 18:48     ` Sudarikov, Roman
2019-12-05 18:02       ` Stephane Eranian
2019-12-05 22:28         ` Andi Kleen
2019-12-06 16:08         ` Sudarikov, Roman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191126163630.17300-4-roman.sudarikov@linux.intel.com \
    --to=roman.sudarikov@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bgregg@netflix.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®