public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf tools: Add test_and_set_bit function
@ 2014-10-26 22:44 Jiri Olsa
  2014-10-26 22:44 ` [PATCH 2/3] perf script perl: Removing event cache as it's no longer needed Jiri Olsa
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jiri Olsa @ 2014-10-26 22:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jiri Olsa, Adrian Hunter, Arnaldo Carvalho de Melo, David Ahern,
	Frederic Weisbecker, Ingo Molnar, Namhyung Kim, Paul Mackerras,
	Peter Zijlstra

Set a bit and return its old value. Stolen from kernel
sources, will be used in next patches.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/include/linux/bitmap.h | 17 +++++++++++++++++
 tools/perf/util/include/linux/bitops.h |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h
index 01ffd12dc791..40bd21488032 100644
--- a/tools/perf/util/include/linux/bitmap.h
+++ b/tools/perf/util/include/linux/bitmap.h
@@ -46,4 +46,21 @@ static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
 		__bitmap_or(dst, src1, src2, nbits);
 }
 
+/**
+ * test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ */
+static inline int test_and_set_bit(int nr, unsigned long *addr)
+{
+	unsigned long mask = BIT_MASK(nr);
+	unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+	unsigned long old;
+
+	old = *p;
+	*p = old | mask;
+
+	return (old & mask) != 0;
+}
+
 #endif /* _PERF_BITOPS_H */
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h
index dadfa7e54287..c3294163de17 100644
--- a/tools/perf/util/include/linux/bitops.h
+++ b/tools/perf/util/include/linux/bitops.h
@@ -15,6 +15,8 @@
 #define BITS_TO_U64(nr)         DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
 #define BITS_TO_U32(nr)         DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
 #define BITS_TO_BYTES(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE)
+#define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
+#define BIT_MASK(nr)            (1UL << ((nr) % BITS_PER_LONG))
 
 #define for_each_set_bit(bit, addr, size) \
 	for ((bit) = find_first_bit((addr), (size));		\
-- 
1.9.3


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

end of thread, other threads:[~2014-11-07  5:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-26 22:44 [PATCH 1/3] perf tools: Add test_and_set_bit function Jiri Olsa
2014-10-26 22:44 ` [PATCH 2/3] perf script perl: Removing event cache as it's no longer needed Jiri Olsa
2014-11-07  5:31   ` [tip:perf/core] perf script perl: Removing event cache as it' s " tip-bot for Jiri Olsa
2014-10-26 22:44 ` [PATCH 3/3] perf script python: Removing event cache as it's " Jiri Olsa
2014-11-07  5:32   ` [tip:perf/core] perf script python: Removing event cache as it' s " tip-bot for Jiri Olsa
2014-11-04  8:39 ` [PATCH 1/3] perf tools: Add test_and_set_bit function Namhyung Kim
2014-11-07  5:31 ` [tip:perf/core] " tip-bot for Jiri Olsa

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