6 #include <asm/byteorder.h>
7 #include "blktrace_api.h"
10 #define MINORMASK ((1U << MINORBITS) - 1)
11 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
12 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
14 #define SECONDS(x) ((unsigned long long)(x) / 1000000000)
15 #define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000)
16 #define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000))
18 #define min(a, b) ((a) < (b) ? (a) : (b))
24 unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
25 unsigned long ireads, iwrites;
26 unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
27 unsigned long long iread_kb, iwrite_kb;
28 unsigned long io_unplugs, timer_unplugs;
38 struct io_stats io_stats;
43 #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
44 #define SUPPORTED_VERSION (0x05)
46 #if defined(__LITTLE_ENDIAN_BITFIELD)
47 #define be16_to_cpu(x) __bswap_16(x)
48 #define be32_to_cpu(x) __bswap_32(x)
49 #define be64_to_cpu(x) __bswap_64(x)
50 #define cpu_to_be16(x) __bswap_16(x)
51 #define cpu_to_be32(x) __bswap_32(x)
52 #define cpu_to_be64(x) __bswap_64(x)
53 #elif defined(__BIG_ENDIAN_BITFIELD)
54 #define be16_to_cpu(x) (x)
55 #define be32_to_cpu(x) (x)
56 #define be64_to_cpu(x) (x)
57 #define cpu_to_be16(x) (x)
58 #define cpu_to_be32(x) (x)
59 #define cpu_to_be64(x) (x)
64 static inline int verify_trace(struct blk_io_trace *t)
66 if (!CHECK_MAGIC(t)) {
67 fprintf(stderr, "bad trace magic %x\n", t->magic);
70 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
71 fprintf(stderr, "unsupported trace version %x\n",
79 static inline void trace_to_be(struct blk_io_trace *t)
81 t->magic = cpu_to_be32(t->magic);
82 t->sequence = cpu_to_be32(t->sequence);
83 t->time = cpu_to_be64(t->time);
84 t->sector = cpu_to_be64(t->sector);
85 t->bytes = cpu_to_be32(t->bytes);
86 t->action = cpu_to_be32(t->action);
87 t->pid = cpu_to_be32(t->pid);
88 t->cpu = cpu_to_be32(t->cpu);
89 t->error = cpu_to_be16(t->error);
90 t->pdu_len = cpu_to_be16(t->pdu_len);
91 t->device = cpu_to_be32(t->device);
92 /* t->comm is a string (endian neutral) */
95 static inline void trace_to_cpu(struct blk_io_trace *t)
97 t->magic = be32_to_cpu(t->magic);
98 t->sequence = be32_to_cpu(t->sequence);
99 t->time = be64_to_cpu(t->time);
100 t->sector = be64_to_cpu(t->sector);
101 t->bytes = be32_to_cpu(t->bytes);
102 t->action = be32_to_cpu(t->action);
103 t->pid = be32_to_cpu(t->pid);
104 t->cpu = be32_to_cpu(t->cpu);
105 t->error = be16_to_cpu(t->error);
106 t->pdu_len = be16_to_cpu(t->pdu_len);
107 t->device = be32_to_cpu(t->device);
108 /* t->comm is a string (endian neutral) */
111 extern void set_all_format_specs(char *);
112 extern int add_format_spec(char *);
113 extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
114 unsigned long long, int, unsigned char *);