From: Yury Norov <ynorov@caviumnetworks.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Kate Stewart <kstewart@linuxfoundation.org>,
Matthew Wilcox <willy@infradead.org>,
Philippe Ombredanne <pombredanne@nexb.com>,
David Ahern <dsahern@gmail.com>,
David Carrillo-Cisneros <davidcc@google.com>,
Andi Kleen <ak@linux.intel.com>,
Jin Yao <yao.jin@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@caviumnetworks.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Snitzer <snitzer@redhat.com>
Subject: [PATCH 2/2] bitmap: sync tools with new bitmap allocation API
Date: Sat, 23 Jun 2018 10:35:02 +0300 [thread overview]
Message-ID: <20180623073502.16321-2-ynorov@caviumnetworks.com> (raw)
In-Reply-To: <20180623073502.16321-1-ynorov@caviumnetworks.com>
On top of next-20180622 and Andy Shevchenko series:
https://lkml.org/lkml/2018/6/18/841
The series mentioned above introduces helpers for bitmap allocation.
tools/ has its own bitmap_alloc() which differs from bitmap_alloc()
proposed in new kernel API, and is equivalent to bitmap_zalloc().
In this series tools is switched to new API.
This is RFC because I didn't find counterpart free() call to some
bitmap_zalloc()'s. So I didn't convert them to bitmap_free(). Could
someone point me out? The functions are:
setup_nodes();
do_read_bitmap(); // Free is called, but only in fail path.
memory_node__read();
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
tools/include/linux/bitmap.h | 19 +++++++++++++++----
tools/perf/builtin-c2c.c | 10 +++++-----
tools/perf/tests/bitmap.c | 4 ++--
tools/perf/tests/mem2node.c | 4 ++--
| 6 +++---
5 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
index 48c208437bbd..b9b85b94c937 100644
--- a/tools/include/linux/bitmap.h
+++ b/tools/include/linux/bitmap.h
@@ -98,12 +98,23 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
}
/**
- * bitmap_alloc - Allocate bitmap
- * @nbits: Number of bits
+ * Allocation and deallocation of bitmap.
*/
-static inline unsigned long *bitmap_alloc(int nbits)
+static inline unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
{
- return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+ (void) flags;
+ return malloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+}
+
+static inline unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+ (void) flags;
+ return calloc(BITS_TO_LONGS(nbits), sizeof(unsigned long));
+}
+
+static inline void bitmap_free(const unsigned long *bitmap)
+{
+ free((unsigned long *)bitmap);
}
/*
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 6a8738f7ead3..d747e98bc37d 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -127,11 +127,11 @@ static void *c2c_he_zalloc(size_t size)
if (!c2c_he)
return NULL;
- c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
+ c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt, 0);
if (!c2c_he->cpuset)
return NULL;
- c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
+ c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt, 0);
if (!c2c_he->nodeset)
return NULL;
@@ -156,8 +156,8 @@ static void c2c_he_free(void *he)
free(c2c_he->hists);
}
- free(c2c_he->cpuset);
- free(c2c_he->nodeset);
+ bitmap_free(c2c_he->cpuset);
+ bitmap_free(c2c_he->nodeset);
free(c2c_he->nodestr);
free(c2c_he->node_stats);
free(c2c_he);
@@ -2051,7 +2051,7 @@ static int setup_nodes(struct perf_session *session)
struct cpu_map *map = n[node].map;
unsigned long *set;
- set = bitmap_alloc(c2c.cpus_cnt);
+ set = bitmap_zalloc(c2c.cpus_cnt, 0);
if (!set)
return -ENOMEM;
diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c
index 96e7fc1ad3f9..a35d44ad54bc 100644
--- a/tools/perf/tests/bitmap.c
+++ b/tools/perf/tests/bitmap.c
@@ -13,7 +13,7 @@ static unsigned long *get_bitmap(const char *str, int nbits)
unsigned long *bm = NULL;
int i;
- bm = bitmap_alloc(nbits);
+ bm = bitmap_zalloc(nbits, 0);
if (map && bm) {
for (i = 0; i < map->nr; i++)
@@ -35,7 +35,7 @@ static int test_bitmap(const char *str)
pr_debug("bitmap: %s\n", buf);
ret = !strcmp(buf, str);
- free(bm);
+ bitmap_free(bm);
return ret;
}
diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c
index d8e3d49d3638..81a9b05dc632 100644
--- a/tools/perf/tests/mem2node.c
+++ b/tools/perf/tests/mem2node.c
@@ -21,7 +21,7 @@ static unsigned long *get_bitmap(const char *str, int nbits)
unsigned long *bm = NULL;
int i;
- bm = bitmap_alloc(nbits);
+ bm = bitmap_zalloc(nbits, 0);
if (map && bm) {
for (i = 0; i < map->nr; i++)
@@ -65,7 +65,7 @@ int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused)
T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050));
for (i = 0; i < ARRAY_SIZE(nodes); i++)
- free(nodes[i].set);
+ bitmap_free(nodes[i].set);
mem2node__exit(&map);
return 0;
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3a6bec22baa3..201c91db95df 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -275,7 +275,7 @@ static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize)
if (ret)
return ret;
- set = bitmap_alloc(size);
+ set = bitmap_zalloc(size, 0);
if (!set)
return -ENOMEM;
@@ -284,7 +284,7 @@ static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize)
for (i = 0; (u64) i < BITS_TO_U64(size); i++) {
ret = do_read_u64(ff, p + i);
if (ret < 0) {
- free(set);
+ bitmap_free(set);
return ret;
}
}
@@ -1277,7 +1277,7 @@ static int memory_node__read(struct memory_node *n, unsigned long idx)
size++;
- n->set = bitmap_alloc(size);
+ n->set = bitmap_zalloc(size, 0);
if (!n->set) {
closedir(dir);
return -ENOMEM;
--
2.17.1
next prev parent reply other threads:[~2018-06-23 7:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-23 7:35 [PATCH 1/2] perf: drop unneeded bitmap_zero() in util/header.c Yury Norov
2018-06-23 7:35 ` Yury Norov [this message]
2018-06-24 21:31 ` [PATCH 2/2] bitmap: sync tools with new bitmap allocation API Dmitry Torokhov
2018-06-24 22:45 ` Yury Norov
2018-07-04 15:36 ` Dmitry Torokhov
2018-07-04 17:24 ` Jiri Olsa
2018-06-25 14:12 ` Arnaldo Carvalho de Melo
2018-07-04 17:30 ` Jiri Olsa
2018-07-04 22:15 ` [PATCH v2 " Yury Norov
2018-07-25 11:22 ` Arnaldo Carvalho de Melo
2018-07-24 20:26 ` [PATCH 1/2] perf: drop unneeded bitmap_zero() in util/header.c Yury Norov
2018-07-25 11:20 ` Arnaldo Carvalho de Melo
2018-08-18 11:24 ` [tip:perf/urgent] perf tools: Drop unneeded bitmap_zero() calls tip-bot for Yury Norov
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=20180623073502.16321-2-ynorov@caviumnetworks.com \
--to=ynorov@caviumnetworks.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davidcc@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dsahern@gmail.com \
--cc=jolsa@redhat.com \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=pombredanne@nexb.com \
--cc=snitzer@redhat.com \
--cc=willy@infradead.org \
--cc=yao.jin@linux.intel.com \
/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).