8 #include "blktrace_api.h"
12 #define MINORMASK ((1U << MINORBITS) - 1)
13 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
14 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
16 #define SECONDS(x) ((unsigned long long)(x) / 1000000000)
17 #define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000)
18 #define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000))
20 #define min(a, b) ((a) < (b) ? (a) : (b))
22 #define t_sec(t) ((t)->bytes >> 9)
23 #define t_kb(t) ((t)->bytes >> 10)
29 unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites;
30 unsigned long ireads, iwrites, rrqueue, wrqueue;
31 unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb;
32 unsigned long long iread_kb, iwrite_kb;
33 unsigned long io_unplugs, timer_unplugs;
44 struct io_stats io_stats;
46 struct rb_root rb_last;
47 unsigned long rb_last_entries;
48 unsigned long last_sequence;
49 unsigned long smallest_seq_read;
51 struct skip_info *skips_head;
52 struct skip_info *skips_tail;
57 #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
58 #define SUPPORTED_VERSION (0x06)
60 #if __BYTE_ORDER == __LITTLE_ENDIAN
61 #define be16_to_cpu(x) __bswap_16(x)
62 #define be32_to_cpu(x) __bswap_32(x)
63 #define be64_to_cpu(x) __bswap_64(x)
64 #define cpu_to_be16(x) __bswap_16(x)
65 #define cpu_to_be32(x) __bswap_32(x)
66 #define cpu_to_be64(x) __bswap_64(x)
67 #elif __BYTE_ORDER == __BIG_ENDIAN
68 #define be16_to_cpu(x) (x)
69 #define be32_to_cpu(x) (x)
70 #define be64_to_cpu(x) (x)
71 #define cpu_to_be16(x) (x)
72 #define cpu_to_be32(x) (x)
73 #define cpu_to_be64(x) (x)
78 static inline int verify_trace(struct blk_io_trace *t)
80 if (!CHECK_MAGIC(t)) {
81 fprintf(stderr, "bad trace magic %x\n", t->magic);
84 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
85 fprintf(stderr, "unsupported trace version %x\n",
93 static inline void trace_to_be(struct blk_io_trace *t)
95 t->magic = cpu_to_be32(t->magic);
96 t->sequence = cpu_to_be32(t->sequence);
97 t->time = cpu_to_be64(t->time);
98 t->sector = cpu_to_be64(t->sector);
99 t->bytes = cpu_to_be32(t->bytes);
100 t->action = cpu_to_be32(t->action);
101 t->pid = cpu_to_be32(t->pid);
102 t->cpu = cpu_to_be32(t->cpu);
103 t->error = cpu_to_be16(t->error);
104 t->pdu_len = cpu_to_be16(t->pdu_len);
105 t->device = cpu_to_be32(t->device);
106 /* t->comm is a string (endian neutral) */
109 static inline void trace_to_cpu(struct blk_io_trace *t)
111 t->magic = be32_to_cpu(t->magic);
112 t->sequence = be32_to_cpu(t->sequence);
113 t->time = be64_to_cpu(t->time);
114 t->sector = be64_to_cpu(t->sector);
115 t->bytes = be32_to_cpu(t->bytes);
116 t->action = be32_to_cpu(t->action);
117 t->pid = be32_to_cpu(t->pid);
118 t->cpu = be32_to_cpu(t->cpu);
119 t->error = be16_to_cpu(t->error);
120 t->pdu_len = be16_to_cpu(t->pdu_len);
121 t->device = be32_to_cpu(t->device);
122 /* t->comm is a string (endian neutral) */
125 extern void set_all_format_specs(char *);
126 extern int add_format_spec(char *);
127 extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
128 unsigned long long, int, unsigned char *);
129 extern int valid_act_opt(int);
130 extern int find_mask_map(char *);