Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Helper functions for PCIe root ports list in iostat mode

Introduce helper functions to control PCIe root ports list.
These helpers will be used in the follow-up patch.

Signed-off-by: Alexander Antonov <alexander.antonov@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey V Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210419094147.15909-3-alexander.antonov@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Alexander Antonov and committed by
Arnaldo Carvalho de Melo
19776d3c f07952b1

+110
+110
tools/perf/arch/x86/util/iostat.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * perf iostat 4 + * 5 + * Copyright (C) 2020, Intel Corporation 6 + * 7 + * Authors: Alexander Antonov <alexander.antonov@linux.intel.com> 8 + */ 9 + 10 + #include <api/fs/fs.h> 11 + #include <linux/kernel.h> 12 + #include <linux/err.h> 13 + #include <limits.h> 14 + #include <stdio.h> 15 + #include <string.h> 16 + #include <errno.h> 17 + #include <sys/types.h> 18 + #include <sys/stat.h> 19 + #include <fcntl.h> 20 + #include <dirent.h> 21 + #include <unistd.h> 22 + #include <stdlib.h> 23 + #include <regex.h> 24 + #include "util/cpumap.h" 25 + #include "util/debug.h" 26 + #include "util/iostat.h" 27 + #include "util/counts.h" 28 + #include "path.h" 29 + 30 + struct iio_root_port { 31 + u32 domain; 32 + u8 bus; 33 + u8 die; 34 + u8 pmu_idx; 35 + int idx; 36 + }; 37 + 38 + struct iio_root_ports_list { 39 + struct iio_root_port **rps; 40 + int nr_entries; 41 + }; 42 + 43 + static void iio_root_port_show(FILE *output, 44 + const struct iio_root_port * const rp) 45 + { 46 + if (output && rp) 47 + fprintf(output, "S%d-uncore_iio_%d<%04x:%02x>\n", 48 + rp->die, rp->pmu_idx, rp->domain, rp->bus); 49 + } 50 + 51 + static struct iio_root_port *iio_root_port_new(u32 domain, u8 bus, 52 + u8 die, u8 pmu_idx) 53 + { 54 + struct iio_root_port *p = calloc(1, sizeof(*p)); 55 + 56 + if (p) { 57 + p->domain = domain; 58 + p->bus = bus; 59 + p->die = die; 60 + p->pmu_idx = pmu_idx; 61 + } 62 + return p; 63 + } 64 + 65 + static void iio_root_ports_list_free(struct iio_root_ports_list *list) 66 + { 67 + int idx; 68 + 69 + if (list) { 70 + for (idx = 0; idx < list->nr_entries; idx++) 71 + free(list->rps[idx]); 72 + free(list->rps); 73 + free(list); 74 + } 75 + } 76 + 77 + static struct iio_root_port *iio_root_port_find_by_notation( 78 + const struct iio_root_ports_list * const list, u32 domain, u8 bus) 79 + { 80 + int idx; 81 + struct iio_root_port *rp; 82 + 83 + if (list) { 84 + for (idx = 0; idx < list->nr_entries; idx++) { 85 + rp = list->rps[idx]; 86 + if (rp && rp->domain == domain && rp->bus == bus) 87 + return rp; 88 + } 89 + } 90 + return NULL; 91 + } 92 + 93 + static int iio_root_ports_list_insert(struct iio_root_ports_list *list, 94 + struct iio_root_port * const rp) 95 + { 96 + struct iio_root_port **tmp_buf; 97 + 98 + if (list && rp) { 99 + rp->idx = list->nr_entries++; 100 + tmp_buf = realloc(list->rps, 101 + list->nr_entries * sizeof(*list->rps)); 102 + if (!tmp_buf) { 103 + pr_err("Failed to realloc memory\n"); 104 + return -ENOMEM; 105 + } 106 + tmp_buf[rp->idx] = rp; 107 + list->rps = tmp_buf; 108 + } 109 + return 0; 110 + }