Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add test_and_set_bit function

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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.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>
Link: http://lkml.kernel.org/r/1414363445-22370-1-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
416c419c 96d78059

+19
+17
tools/perf/util/include/linux/bitmap.h
··· 46 46 __bitmap_or(dst, src1, src2, nbits); 47 47 } 48 48 49 + /** 50 + * test_and_set_bit - Set a bit and return its old value 51 + * @nr: Bit to set 52 + * @addr: Address to count from 53 + */ 54 + static inline int test_and_set_bit(int nr, unsigned long *addr) 55 + { 56 + unsigned long mask = BIT_MASK(nr); 57 + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); 58 + unsigned long old; 59 + 60 + old = *p; 61 + *p = old | mask; 62 + 63 + return (old & mask) != 0; 64 + } 65 + 49 66 #endif /* _PERF_BITOPS_H */
+2
tools/perf/util/include/linux/bitops.h
··· 15 15 #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) 16 16 #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) 17 17 #define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE) 18 + #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) 19 + #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 18 20 19 21 #define for_each_set_bit(bit, addr, size) \ 20 22 for ((bit) = find_first_bit((addr), (size)); \