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

perf tools: Use DECLARE_BITMAP instead of an open-coded array

Use DECLARE_BITMAP instead of an open coded array for our bitmap
of featured sections.

This makes the array an unsigned long instead of a u64 but since
we use a 256 bits bitmap, the array size shouldn't vary between
different boxes.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1255795038-13751-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Frederic Weisbecker and committed by
Ingo Molnar
db9f11e3 2ba08250

+20 -22
+9 -13
tools/perf/util/header.c
··· 8 8 #include "../perf.h" 9 9 #include "trace-event.h" 10 10 11 - #include <linux/bitmap.h> 12 - 13 11 /* 14 12 * Create new perf.data header attribute: 15 13 */ ··· 141 143 struct perf_file_section attrs; 142 144 struct perf_file_section data; 143 145 struct perf_file_section event_types; 144 - feat_mask_t adds_features; 146 + DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); 145 147 }; 146 148 147 149 void perf_header__feat_trace_info(struct perf_header *header) 148 150 { 149 - set_bit(HEADER_TRACE_INFO, perf_header__adds_mask(header)); 151 + set_bit(HEADER_TRACE_INFO, header->adds_features); 150 152 } 151 153 152 154 static void do_write(int fd, void *buf, size_t size) ··· 166 168 { 167 169 struct perf_file_section trace_sec; 168 170 u64 cur_offset = lseek(fd, 0, SEEK_CUR); 169 - unsigned long *feat_mask = perf_header__adds_mask(self); 171 + unsigned long *feat_mask = self->adds_features; 170 172 171 173 if (test_bit(HEADER_TRACE_INFO, feat_mask)) { 172 174 /* Write trace info */ ··· 248 250 }, 249 251 }; 250 252 251 - memcpy(&f_header.adds_features, &self->adds_features, sizeof(feat_mask_t)); 253 + memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); 252 254 253 255 lseek(fd, 0, SEEK_SET); 254 256 do_write(fd, &f_header, sizeof(f_header)); ··· 274 276 275 277 static void perf_header__adds_read(struct perf_header *self, int fd) 276 278 { 277 - const unsigned long *feat_mask = perf_header__adds_mask(self); 279 + const unsigned long *feat_mask = self->adds_features; 278 280 279 281 if (test_bit(HEADER_TRACE_INFO, feat_mask)) { 280 282 struct perf_file_section trace_sec; ··· 304 306 305 307 if (f_header.size != sizeof(f_header)) { 306 308 /* Support the previous format */ 307 - if (f_header.size == offsetof(typeof(f_header), adds_features)) { 308 - unsigned long *mask = (unsigned long *)(void *) 309 - &f_header.adds_features; 310 - bitmap_zero(mask, HEADER_FEAT_BITS); 311 - } else 309 + if (f_header.size == offsetof(typeof(f_header), adds_features)) 310 + bitmap_zero(f_header.adds_features, HEADER_FEAT_BITS); 311 + else 312 312 die("incompatible file format"); 313 313 } 314 314 nr_attrs = f_header.attrs.size / sizeof(f_attr); ··· 342 346 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); 343 347 } 344 348 345 - memcpy(&self->adds_features, &f_header.adds_features, sizeof(feat_mask_t)); 349 + memcpy(&self->adds_features, &f_header.adds_features, sizeof(f_header.adds_features)); 346 350 347 351 perf_header__adds_read(self, fd); 348 352
+3 -8
tools/perf/util/header.h
··· 5 5 #include <sys/types.h> 6 6 #include "types.h" 7 7 8 + #include <linux/bitmap.h> 9 + 8 10 struct perf_header_attr { 9 11 struct perf_event_attr attr; 10 12 int ids, size; ··· 18 16 19 17 #define HEADER_FEAT_BITS 256 20 18 21 - typedef typeof(u64[HEADER_FEAT_BITS / 8]) feat_mask_t; 22 - 23 19 struct perf_header { 24 20 int frozen; 25 21 int attrs, size; ··· 27 27 u64 data_size; 28 28 u64 event_offset; 29 29 u64 event_size; 30 - feat_mask_t adds_features; 30 + DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); 31 31 }; 32 - 33 - static inline unsigned long *perf_header__adds_mask(struct perf_header *self) 34 - { 35 - return (unsigned long *)(void *)&self->adds_features; 36 - } 37 32 38 33 struct perf_header *perf_header__read(int fd); 39 34 void perf_header__write(struct perf_header *self, int fd);
+1
tools/perf/util/include/asm/asm-offsets.h
··· 1 + /* stub */
+7 -1
tools/perf/util/include/linux/types.h
··· 1 - /* stub */ 1 + #ifndef _PERF_LINUX_TYPES_H_ 2 + #define _PERF_LINUX_TYPES_H_ 3 + 4 + #define DECLARE_BITMAP(name,bits) \ 5 + unsigned long name[BITS_TO_LONGS(bits)] 6 + 7 + #endif