linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Andi Kleen <ak@linux.intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Rogers <irogers@google.com>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v4 3/5] perf stat: Helper functions for PCIe root ports list in iostat mode
Date: Thu, 4 Feb 2021 21:32:43 +0900	[thread overview]
Message-ID: <CAM9d7cjs5Su824v+02rEWd5jgvt8tGsMmoXftXBsj-mTTU_xkA@mail.gmail.com> (raw)
In-Reply-To: <20210203135830.38568-4-alexander.antonov@linux.intel.com>

On Wed, Feb 3, 2021 at 10:58 PM Alexander Antonov
<alexander.antonov@linux.intel.com> wrote:
>
> 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>
> ---
>  tools/perf/arch/x86/util/iostat.c | 124 ++++++++++++++++++++++++++++++
>  1 file changed, 124 insertions(+)
>  create mode 100644 tools/perf/arch/x86/util/iostat.c
>
> diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
> new file mode 100644
> index 000000000000..961e540106e6
> --- /dev/null
> +++ b/tools/perf/arch/x86/util/iostat.c
> @@ -0,0 +1,124 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * perf iostat
> + *
> + * Copyright (C) 2020, Intel Corporation
> + *
> + * Authors: Alexander Antonov <alexander.antonov@linux.intel.com>
> + */
> +
> +#include <api/fs/fs.h>
> +#include <linux/kernel.h>
> +#include <linux/err.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>
> +#include "util/cpumap.h"
> +#include "util/debug.h"
> +#include "util/iostat.h"
> +#include "util/counts.h"
> +#include "path.h"
> +
> +struct iio_root_port {
> +       u32 domain;
> +       u8 bus;
> +       u8 die;
> +       u8 pmu_idx;
> +       int idx;
> +};
> +
> +struct iio_root_ports_list {
> +       struct iio_root_port **rps;
> +       int nr_entries;
> +};
> +
> +static void iio_root_port_show(FILE *output,
> +                              const struct iio_root_port * const rp)
> +{
> +       if (output && rp)
> +               fprintf(output, "S%d-uncore_iio_%d<%04x:%02x>\n",
> +                       rp->die, rp->pmu_idx, rp->domain, rp->bus);
> +}
> +
> +static struct iio_root_port *iio_root_port_new(u32 domain, u8 bus,
> +                                              u8 die, u8 pmu_idx)
> +{
> +       struct iio_root_port *p = calloc(1, sizeof(*p));
> +
> +       if (p) {
> +               p->domain = domain;
> +               p->bus = bus;
> +               p->die = die;
> +               p->pmu_idx = pmu_idx;
> +       }
> +       return p;
> +}
> +
> +static struct iio_root_ports_list *iio_root_ports_list_new(void)
> +{
> +       struct iio_root_ports_list *list = calloc(1, sizeof(*list));
> +
> +       if (list) {
> +               list->rps = calloc(1, sizeof(struct iio_root_port *));

This seems unnecessary now.

Thanks,
Namhyung


> +               if (!list->rps) {
> +                       free(list);
> +                       list = NULL;
> +               }
> +       }
> +       return list;
> +}
> +
> +static void iio_root_ports_list_free(struct iio_root_ports_list *list)
> +{
> +       int idx;
> +
> +       if (list) {
> +               for (idx = 0; idx < list->nr_entries; idx++)
> +                       free(list->rps[idx]);
> +               free(list->rps);
> +               free(list);
> +       }
> +}
> +
> +static struct iio_root_port *iio_root_port_find_by_notation(
> +       const struct iio_root_ports_list * const list, u32 domain, u8 bus)
> +{
> +       int idx;
> +       struct iio_root_port *rp;
> +
> +       if (list) {
> +               for (idx = 0; idx < list->nr_entries; idx++) {
> +                       rp = list->rps[idx];
> +                       if (rp && rp->domain == domain && rp->bus == bus)
> +                               return rp;
> +               }
> +       }
> +       return NULL;
> +}
> +
> +static int iio_root_ports_list_insert(struct iio_root_ports_list *list,
> +                                     struct iio_root_port * const rp)
> +{
> +       struct iio_root_port **tmp_buf;
> +
> +       if (list && rp) {
> +               rp->idx = list->nr_entries++;
> +               tmp_buf = realloc(list->rps,
> +                                 list->nr_entries * sizeof(*list->rps));
> +               if (!tmp_buf) {
> +                       pr_err("Failed to realloc memory\n");
> +                       return -ENOMEM;
> +               }
> +               tmp_buf[rp->idx] = rp;
> +               list->rps = tmp_buf;
> +       }
> +       return 0;
> +}
> --
> 2.19.1
>

  reply	other threads:[~2021-02-04 12:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 13:58 [PATCH v4 0/5] perf stat: Introduce iostat mode to provide I/O performance metrics Alexander Antonov
2021-02-03 13:58 ` [PATCH v4 1/5] perf stat: Add AGGR_PCIE_PORT mode Alexander Antonov
2021-02-04 12:07   ` Namhyung Kim
2021-02-08 11:30     ` Alexander Antonov
2021-02-10 10:02       ` Namhyung Kim
2021-02-03 13:58 ` [PATCH v4 2/5] perf stat: Basic support for iostat in perf Alexander Antonov
2021-02-04 12:22   ` Namhyung Kim
2021-02-08 11:55     ` Alexander Antonov
2021-02-10 10:07       ` Namhyung Kim
2021-02-03 13:58 ` [PATCH v4 3/5] perf stat: Helper functions for PCIe root ports list in iostat mode Alexander Antonov
2021-02-04 12:32   ` Namhyung Kim [this message]
2021-02-08 11:58     ` Alexander Antonov
2021-02-03 13:58 ` [PATCH v4 4/5] perf stat: Enable iostat mode for x86 platforms Alexander Antonov
2021-03-09  7:51   ` liuqi (BA)
2021-03-10 16:19     ` Alexander Antonov
2021-03-11  7:02       ` liuqi (BA)
2021-02-03 13:58 ` [PATCH v4 5/5] perf: Update .gitignore file Alexander Antonov
2021-02-03 20:55 ` [PATCH v4 0/5] perf stat: Introduce iostat mode to provide I/O performance metrics Arnaldo Carvalho de Melo
2021-02-04 12:35   ` Namhyung Kim

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=CAM9d7cjs5Su824v+02rEWd5jgvt8tGsMmoXftXBsj-mTTU_xkA@mail.gmail.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).