public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] perf tools: Header and c2c fixes
@ 2016-10-11 12:14 Jiri Olsa
  2016-10-11 12:14 ` [PATCH 1/6] perf report: Move captured info to generic header info Jiri Olsa
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

hi,
sending few perf.data header fixes and adding
two new c2c report options.

Also available in:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/fixes

thanks,
jirka

---
Jiri Olsa (6):
      perf report: Move captured info to generic header info
      perf header: Display missing features
      perf header: Display feature name on write failure
      perf header: Set nr_numa_nodes only when we parsed all the data
      perf c2c report: Add --no-source option
      perf c2c report: Add --show-all option

 tools/perf/Documentation/perf-c2c.txt |  6 ++++++
 tools/perf/builtin-c2c.c              | 20 +++++++++++++-------
 tools/perf/util/header.c              | 21 +++++++++++++++++++--
 tools/perf/util/session.c             | 10 ----------
 4 files changed, 38 insertions(+), 19 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] perf report: Move captured info to generic header info
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:14 ` [PATCH 2/6] perf header: Display missing features Jiri Olsa
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

It's not displayed in TUI now, putting it into generic part.

Link: http://lkml.kernel.org/n/tip-5fk88kejqgi50ye7xdkhiloz@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/header.c  |  9 +++++++++
 tools/perf/util/session.c | 10 ----------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 85dd0db0a127..b227dfab56c3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2250,9 +2250,18 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
 	struct header_print_data hd;
 	struct perf_header *header = &session->header;
 	int fd = perf_data_file__fd(session->file);
+	struct stat st;
+	int ret;
+
 	hd.fp = fp;
 	hd.full = full;
 
+	ret = fstat(fd, &st);
+	if (ret == -1)
+		return -1;
+
+	fprintf(fp, "# captured on: %s", ctime(&st.st_ctime));
+
 	perf_header__process_sections(header, fd, &hd,
 				      perf_file_section__fprintf_info);
 	return 0;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 5d61242a6e64..f268201048a0 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2025,20 +2025,10 @@ out_delete_map:
 void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
 				bool full)
 {
-	struct stat st;
-	int fd, ret;
-
 	if (session == NULL || fp == NULL)
 		return;
 
-	fd = perf_data_file__fd(session->file);
-
-	ret = fstat(fd, &st);
-	if (ret == -1)
-		return;
-
 	fprintf(fp, "# ========\n");
-	fprintf(fp, "# captured on: %s", ctime(&st.st_ctime));
 	perf_header__fprintf_info(session, fp, full);
 	fprintf(fp, "# ========\n#\n");
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] perf header: Display missing features
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
  2016-10-11 12:14 ` [PATCH 1/6] perf report: Move captured info to generic header info Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:14 ` [PATCH 3/6] perf header: Display feature name on write failure Jiri Olsa
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

Display missing features in header info, like:

  $ perf report --header-only
  # ========
  # captured on: Mon Oct 10 09:39:47 2016
  ...
  # missing features: HEADER_TRACING_DATA HEADER_CPU_TOPOLOGY ...

Link: http://lkml.kernel.org/n/tip-bh5gp84gobdmyl345dcp64se@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/header.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b227dfab56c3..59b67aefa8b2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2251,7 +2251,7 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
 	struct perf_header *header = &session->header;
 	int fd = perf_data_file__fd(session->file);
 	struct stat st;
-	int ret;
+	int ret, bit;
 
 	hd.fp = fp;
 	hd.full = full;
@@ -2264,6 +2264,14 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
 
 	perf_header__process_sections(header, fd, &hd,
 				      perf_file_section__fprintf_info);
+
+	fprintf(fp, "# missing features: ");
+	for_each_clear_bit(bit, header->adds_features, HEADER_LAST_FEATURE) {
+		if (bit)
+			fprintf(fp, "%s ", feat_ops[bit].name);
+	}
+
+	fprintf(fp, "\n");
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] perf header: Display feature name on write failure
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
  2016-10-11 12:14 ` [PATCH 1/6] perf report: Move captured info to generic header info Jiri Olsa
  2016-10-11 12:14 ` [PATCH 2/6] perf header: Display missing features Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:14 ` [PATCH 4/6] perf header: Set nr_numa_nodes only when we parsed all the data Jiri Olsa
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

Display name of feature instead of just the number
during recording data.

Before:
  failed to write feature 13

Now:
  failed to write feature HEADER_CPU_TOPOLOGY

Link: http://lkml.kernel.org/n/tip-k9d9trozi5kkx737cy8n5xh5@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/header.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 59b67aefa8b2..43ded20f1edf 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2290,7 +2290,7 @@ static int do_write_feat(int fd, struct perf_header *h, int type,
 
 		err = feat_ops[type].write(fd, h, evlist);
 		if (err < 0) {
-			pr_debug("failed to write feature %d\n", type);
+			pr_debug("failed to write feature %s\n", feat_ops[type].name);
 
 			/* undo anything written */
 			lseek(fd, (*p)->offset, SEEK_SET);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] perf header: Set nr_numa_nodes only when we parsed all the data
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
                   ` (2 preceding siblings ...)
  2016-10-11 12:14 ` [PATCH 3/6] perf header: Display feature name on write failure Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:14 ` [PATCH 5/6] perf c2c report: Add --no-source option Jiri Olsa
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

Sukadev reported segfault on releasing perf env's numa data.
It's due to nr_numa_nodes being set no matter if the numa
data gets parsed properly. The perf_env__exit crash the on
releasing non existed data.

Setting nr_numa_nodes only when data are parsed out properly.

Reported-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/n/tip-dt9c0zgkt4hybn2cr4xiawta@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/header.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 43ded20f1edf..d89c9c7ef4e5 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1895,7 +1895,6 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
 	if (ph->needs_swap)
 		nr = bswap_32(nr);
 
-	ph->env.nr_numa_nodes = nr;
 	nodes = zalloc(sizeof(*nodes) * nr);
 	if (!nodes)
 		return -ENOMEM;
@@ -1932,6 +1931,7 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
 
 		free(str);
 	}
+	ph->env.nr_numa_nodes = nr;
 	ph->env.numa_nodes = nodes;
 	return 0;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] perf c2c report: Add --no-source option
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
                   ` (3 preceding siblings ...)
  2016-10-11 12:14 ` [PATCH 4/6] perf header: Set nr_numa_nodes only when we parsed all the data Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:14 ` [PATCH 6/6] perf c2c report: Add --show-all option Jiri Olsa
  2016-10-11 12:59 ` [PATCH 0/6] tools lib: Add for_each_clear_bit macro Jiri Olsa
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

Add a possibility to disable source line column with
new --no-source option. It source line data could take
lot of time to retrieve, so it could be a performance
burden for big data.

Link: http://lkml.kernel.org/n/tip-8p6s2727fq8nbsm3it5gix3p@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-c2c.txt |  3 +++
 tools/perf/builtin-c2c.c              | 13 ++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-c2c.txt b/tools/perf/Documentation/perf-c2c.txt
index ba2f4de399c3..33ed4564a8c0 100644
--- a/tools/perf/Documentation/perf-c2c.txt
+++ b/tools/perf/Documentation/perf-c2c.txt
@@ -94,6 +94,9 @@ REPORT OPTIONS
 --full-symbols::
 	Display full length of symbols.
 
+--no-source::
+	Do not display Source:Line column.
+
 C2C RECORD
 ----------
 The perf c2c record command setup options related to HITM cacheline analysis
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 73973da00b31..6656fcbe8d85 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2404,7 +2404,7 @@ static int setup_display(const char *str)
 	for (__tok = strtok_r(__buf, __sep, &__tmp); __tok;	\
 	     __tok = strtok_r(NULL,  __sep, &__tmp))
 
-static int build_cl_output(char *cl_sort)
+static int build_cl_output(char *cl_sort, bool no_source)
 {
 	char *tok, *tmp, *buf = strdup(cl_sort);
 	bool add_pid   = false;
@@ -2426,7 +2426,7 @@ static int build_cl_output(char *cl_sort)
 			add_iaddr = true;
 			add_sym   = true;
 			add_dso   = true;
-			add_src   = true;
+			add_src   = no_source ? false : true;
 		} else if (!strcmp(tok, "dso")) {
 			add_dso = true;
 		} else if (strcmp(tok, "offset")) {
@@ -2462,14 +2462,14 @@ static int build_cl_output(char *cl_sort)
 	return 0;
 }
 
-static int setup_coalesce(const char *coalesce)
+static int setup_coalesce(const char *coalesce, bool no_source)
 {
 	const char *c = coalesce ?: coalesce_default;
 
 	if (asprintf(&c2c.cl_sort, "offset,%s", c) < 0)
 		return -ENOMEM;
 
-	if (build_cl_output(c2c.cl_sort))
+	if (build_cl_output(c2c.cl_sort, no_source))
 		return -1;
 
 	if (asprintf(&c2c.cl_resort, "offset,%s",
@@ -2494,6 +2494,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
 	const char *display = NULL;
 	const char *coalesce = NULL;
+	bool no_source = false;
 	const struct option c2c_options[] = {
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
@@ -2510,6 +2511,8 @@ static int perf_c2c__report(int argc, const char **argv)
 		    "Use the stdio interface"),
 	OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
 		    "Display full length of symbols"),
+	OPT_BOOLEAN(0, "no-source", &no_source,
+		    "Do not display Source Line column"),
 	OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
 			     "print_type,threshold[,print_limit],order,sort_key[,branch],value",
 			     callchain_help, &parse_callchain_opt,
@@ -2545,7 +2548,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	if (err)
 		goto out;
 
-	err = setup_coalesce(coalesce);
+	err = setup_coalesce(coalesce, no_source);
 	if (err) {
 		pr_debug("Failed to initialize hists\n");
 		goto out;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] perf c2c report: Add --show-all option
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
                   ` (4 preceding siblings ...)
  2016-10-11 12:14 ` [PATCH 5/6] perf c2c report: Add --no-source option Jiri Olsa
@ 2016-10-11 12:14 ` Jiri Olsa
  2016-10-11 12:59 ` [PATCH 0/6] tools lib: Add for_each_clear_bit macro Jiri Olsa
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:14 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

Normally we limit the main list to contain only entries
with HITM % value > 0.0005, but it might be useful to display
all captured entries. Adding --show-all option for that.

Link: http://lkml.kernel.org/n/tip-nokgjdwikbegec5jzj4mxhqc@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-c2c.txt | 3 +++
 tools/perf/builtin-c2c.c              | 7 +++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-c2c.txt b/tools/perf/Documentation/perf-c2c.txt
index 33ed4564a8c0..21810d711f5f 100644
--- a/tools/perf/Documentation/perf-c2c.txt
+++ b/tools/perf/Documentation/perf-c2c.txt
@@ -97,6 +97,9 @@ REPORT OPTIONS
 --no-source::
 	Do not display Source:Line column.
 
+--show-all::
+	Show all captured HITM lines, with no regard to HITM % 0.0005 limit.
+
 C2C RECORD
 ----------
 The perf c2c record command setup options related to HITM cacheline analysis
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 6656fcbe8d85..dc4f0636dfa1 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -71,6 +71,7 @@ struct perf_c2c {
 	int			 node_info;
 
 	bool			 show_src;
+	bool			 show_all;
 	bool			 use_stdio;
 	bool			 stats_only;
 	bool			 symbol_full;
@@ -1773,8 +1774,8 @@ static bool he__display(struct hist_entry *he, struct c2c_stats *stats)
 	struct c2c_hist_entry *c2c_he;
 	double ld_dist;
 
-	/* XXX Disabled for now, till we get a command line switch to control this */
-	return true;
+	if (c2c.show_all)
+		return true;
 
 	c2c_he = container_of(he, struct c2c_hist_entry, he);
 
@@ -2513,6 +2514,8 @@ static int perf_c2c__report(int argc, const char **argv)
 		    "Display full length of symbols"),
 	OPT_BOOLEAN(0, "no-source", &no_source,
 		    "Do not display Source Line column"),
+	OPT_BOOLEAN(0, "show-all", &c2c.show_all,
+		    "Show all captured HITM lines."),
 	OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
 			     "print_type,threshold[,print_limit],order,sort_key[,branch],value",
 			     callchain_help, &parse_callchain_opt,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 0/6] tools lib: Add for_each_clear_bit macro
  2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
                   ` (5 preceding siblings ...)
  2016-10-11 12:14 ` [PATCH 6/6] perf c2c report: Add --show-all option Jiri Olsa
@ 2016-10-11 12:59 ` Jiri Olsa
  6 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2016-10-11 12:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Peter Zijlstra, David Ahern, Namhyung Kim,
	Sukadev Bhattiprolu

On Tue, Oct 11, 2016 at 02:14:06PM +0200, Jiri Olsa wrote:
> hi,
> sending few perf.data header fixes and adding
> two new c2c report options.
> 
> Also available in:
>   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
>   perf/fixes
> 
> thanks,
> jirka
> 
> ---
> Jiri Olsa (6):
>       perf report: Move captured info to generic header info
>       perf header: Display missing features
>       perf header: Display feature name on write failure
>       perf header: Set nr_numa_nodes only when we parsed all the data
>       perf c2c report: Add --no-source option
>       perf c2c report: Add --show-all option
> 

oops, forgot to send the initial patch.. it's part of the branch

jirka


---
Adding for_each_clear_bit macro plus all its the necessary
backbone functions. Taken from related kernel code. It will
be used in following patch.

Link: http://lkml.kernel.org/n/tip-cayv2zbqi0nlmg5sjjxs1775@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/include/asm-generic/bitops.h       |  1 +
 tools/include/asm-generic/bitops/__ffz.h | 12 ++++++++++++
 tools/include/asm-generic/bitops/find.h  | 28 ++++++++++++++++++++++++++++
 tools/include/linux/bitops.h             |  5 +++++
 tools/lib/find_bit.c                     | 25 +++++++++++++++++++++++++
 tools/perf/MANIFEST                      |  1 +
 6 files changed, 72 insertions(+)
 create mode 100644 tools/include/asm-generic/bitops/__ffz.h

diff --git a/tools/include/asm-generic/bitops.h b/tools/include/asm-generic/bitops.h
index 653d1bad77de..0304600121da 100644
--- a/tools/include/asm-generic/bitops.h
+++ b/tools/include/asm-generic/bitops.h
@@ -13,6 +13,7 @@
  */
 
 #include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/__ffz.h>
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
diff --git a/tools/include/asm-generic/bitops/__ffz.h b/tools/include/asm-generic/bitops/__ffz.h
new file mode 100644
index 000000000000..6744bd4cdf46
--- /dev/null
+++ b/tools/include/asm-generic/bitops/__ffz.h
@@ -0,0 +1,12 @@
+#ifndef _ASM_GENERIC_BITOPS_FFZ_H_
+#define _ASM_GENERIC_BITOPS_FFZ_H_
+
+/*
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+#define ffz(x)  __ffs(~(x))
+
+#endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
diff --git a/tools/include/asm-generic/bitops/find.h b/tools/include/asm-generic/bitops/find.h
index 31f51547fcd4..5538ecdc964a 100644
--- a/tools/include/asm-generic/bitops/find.h
+++ b/tools/include/asm-generic/bitops/find.h
@@ -15,6 +15,21 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
 		size, unsigned long offset);
 #endif
 
+#ifndef find_next_zero_bit
+
+/**
+ * find_next_zero_bit - find the next cleared bit in a memory region
+ * @addr: The address to base the search on
+ * @offset: The bitnumber to start searching at
+ * @size: The bitmap size in bits
+ *
+ * Returns the bit number of the next zero bit
+ * If no bits are zero, returns @size.
+ */
+unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
+				 unsigned long offset);
+#endif
+
 #ifndef find_first_bit
 
 /**
@@ -30,4 +45,17 @@ extern unsigned long find_first_bit(const unsigned long *addr,
 
 #endif /* find_first_bit */
 
+#ifndef find_first_zero_bit
+
+/**
+ * find_first_zero_bit - find the first cleared bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum number of bits to search
+ *
+ * Returns the bit number of the first cleared bit.
+ * If no bits are zero, returns @size.
+ */
+unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size);
+#endif
+
 #endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 49c929a104ee..fc446343ff41 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -39,6 +39,11 @@ extern unsigned long __sw_hweight64(__u64 w);
 	     (bit) < (size);					\
 	     (bit) = find_next_bit((addr), (size), (bit) + 1))
 
+#define for_each_clear_bit(bit, addr, size) \
+	for ((bit) = find_first_zero_bit((addr), (size));       \
+	     (bit) < (size);                                    \
+	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
+
 /* same as for_each_set_bit() but use bit as value to start with */
 #define for_each_set_bit_from(bit, addr, size) \
 	for ((bit) = find_next_bit((addr), (size), (bit));	\
diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c
index 9122a9e80046..6d8b8f22cf55 100644
--- a/tools/lib/find_bit.c
+++ b/tools/lib/find_bit.c
@@ -82,3 +82,28 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
 	return size;
 }
 #endif
+
+#ifndef find_first_zero_bit
+/*
+ * Find the first cleared bit in a memory region.
+ */
+unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
+{
+	unsigned long idx;
+
+	for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
+		if (addr[idx] != ~0UL)
+			return min(idx * BITS_PER_LONG + ffz(addr[idx]), size);
+	}
+
+	return size;
+}
+#endif
+
+#ifndef find_next_zero_bit
+unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
+				 unsigned long offset)
+{
+	return _find_next_bit(addr, size, offset, ~0UL);
+}
+#endif
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 0bda2cca2b3a..a511e5f31e36 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -51,6 +51,7 @@ tools/include/asm-generic/bitops/arch_hweight.h
 tools/include/asm-generic/bitops/atomic.h
 tools/include/asm-generic/bitops/const_hweight.h
 tools/include/asm-generic/bitops/__ffs.h
+tools/include/asm-generic/bitops/__ffz.h
 tools/include/asm-generic/bitops/__fls.h
 tools/include/asm-generic/bitops/find.h
 tools/include/asm-generic/bitops/fls64.h
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-10-11 13:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-11 12:14 [PATCH 0/6] perf tools: Header and c2c fixes Jiri Olsa
2016-10-11 12:14 ` [PATCH 1/6] perf report: Move captured info to generic header info Jiri Olsa
2016-10-11 12:14 ` [PATCH 2/6] perf header: Display missing features Jiri Olsa
2016-10-11 12:14 ` [PATCH 3/6] perf header: Display feature name on write failure Jiri Olsa
2016-10-11 12:14 ` [PATCH 4/6] perf header: Set nr_numa_nodes only when we parsed all the data Jiri Olsa
2016-10-11 12:14 ` [PATCH 5/6] perf c2c report: Add --no-source option Jiri Olsa
2016-10-11 12:14 ` [PATCH 6/6] perf c2c report: Add --show-all option Jiri Olsa
2016-10-11 12:59 ` [PATCH 0/6] tools lib: Add for_each_clear_bit macro Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox