From: Jiri Olsa <jolsa@redhat.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
lkml <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH 3/3] perf tools: Add numa_topology object
Date: Mon, 18 Feb 2019 15:20:42 +0100 [thread overview]
Message-ID: <20190218142042.GA13284@krava> (raw)
In-Reply-To: <CAM9d7cjEaUmYhduf2ddgxOAZw9=1NfsNTScwZZENPzXvUyMBaw@mail.gmail.com>
On Mon, Feb 18, 2019 at 11:08:55PM +0900, Namhyung Kim wrote:
> Hi Jirka,
>
> On Mon, Feb 18, 2019 at 8:39 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Adding numa_topology object to return the list of numa
> > nodes together with their cpus. It will replace the numa
> > code in header.c and will be used from perf record code
> > in following patches.
> >
> > Adding following interface functions to load numa details:
> >
> > struct numa_topology *numa_topology__new(void);
> > void numa_topology__delete(struct numa_topology *tp);
> >
> > And replacing current (copied) local interface, with no
> > functional changes.
> >
> > Link: http://lkml.kernel.org/n/tip-rn15st6hjj7txg2i88v7yff4@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/perf/util/cputopo.c | 120 ++++++++++++++++++++++++++++++++++++++
> > tools/perf/util/cputopo.h | 16 +++++
> > tools/perf/util/header.c | 119 +++++++++----------------------------
> > 3 files changed, 162 insertions(+), 93 deletions(-)
> >
> > diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c
> > index 84470ed4e707..daac3cf90b12 100644
> > --- a/tools/perf/util/cputopo.c
> > +++ b/tools/perf/util/cputopo.c
> > @@ -1,9 +1,11 @@
> > // SPDX-License-Identifier: GPL-2.0
> > #include <sys/param.h>
> > +#include <inttypes.h>
> >
> > #include "cputopo.h"
> > #include "cpumap.h"
> > #include "util.h"
> > +#include "env.h"
> >
> >
> > #define CORE_SIB_FMT \
> > @@ -142,3 +144,121 @@ struct cpu_topology *cpu_topology__new(void)
> > }
> > return tp;
> > }
> > +
> > +static int load_numa_node(struct numa_topology_node *node, int nr)
> > +{
> > + char str[MAXPATHLEN];
> > + char field[32];
> > + char *buf = NULL, *p;
> > + size_t len = 0;
> > + int ret = -1;
> > + FILE *fp;
> > + u64 mem;
> > +
> > + node->node = (u32) nr;
> > +
> > + sprintf(str, "/sys/devices/system/node/node%d/meminfo", nr);
>
> Why not using similar macro like NODE_MEMINFO_FMT?
> Also it'd be better using snprintf() or scnprintf() instead.
right, that code needs to be changed to take /sys from sysfs__mountpoint
but I wanted just to move the code now, with only necessary changes,
like the issues you found below ;-)
>
>
> > + fp = fopen(str, "r");
> > + if (!fp)
> > + return -1;
> > +
> > + while (getline(&buf, &len, fp) > 0) {
> > + /* skip over invalid lines */
> > + if (!strchr(buf, ':'))
> > + continue;
> > + if (sscanf(buf, "%*s %*d %31s %"PRIu64, field, &mem) != 2)
> > + goto err;
> > + if (!strcmp(field, "MemTotal:"))
> > + node->mem_total = mem;
> > + if (!strcmp(field, "MemFree:"))
> > + node->mem_free = mem;
> > + if (node->mem_total && node->mem_free)
> > + break;
> > + }
> > +
> > + fclose(fp);
> > + fp = NULL;
> > + buf = NULL;
>
> No need to make them NULL. Also it'd leak buf..
oops, I'll put free in here
>
>
> > +
> > + ret = -1;
>
> It's not changed yet.
right, will change
thanks,
jirka
prev parent reply other threads:[~2019-02-18 14:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-18 11:39 [PATCHv2 0/3] perf tools: Assorted fixes Jiri Olsa
2019-02-18 11:39 ` [PATCH 1/3] perf header: Fix wrong node write in NUMA_TOPOLOGY feature Jiri Olsa
2019-02-18 11:39 ` [PATCH 2/3] perf tools: Add cpu_topology object Jiri Olsa
2019-02-18 11:39 ` [PATCH 3/3] perf tools: Add numa_topology object Jiri Olsa
2019-02-18 14:08 ` Namhyung Kim
2019-02-18 14:20 ` Jiri Olsa [this message]
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=20190218142042.GA13284@krava \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.