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;
54 #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
55 #define SUPPORTED_VERSION (0x06)
57 #if __BYTE_ORDER == __LITTLE_ENDIAN
58 #define be16_to_cpu(x) __bswap_16(x)
59 #define be32_to_cpu(x) __bswap_32(x)
60 #define be64_to_cpu(x) __bswap_64(x)
61 #define cpu_to_be16(x) __bswap_16(x)
62 #define cpu_to_be32(x) __bswap_32(x)
63 #define cpu_to_be64(x) __bswap_64(x)
64 #elif __BYTE_ORDER == __BIG_ENDIAN
65 #define be16_to_cpu(x) (x)
66 #define be32_to_cpu(x) (x)
67 #define be64_to_cpu(x) (x)
68 #define cpu_to_be16(x) (x)
69 #define cpu_to_be32(x) (x)
70 #define cpu_to_be64(x) (x)
75 static inline int verify_trace(struct blk_io_trace *t)
77 if (!CHECK_MAGIC(t)) {
78 fprintf(stderr, "bad trace magic %x\n", t->magic);
81 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
82 fprintf(stderr, "unsupported trace version %x\n",
90 static inline void trace_to_be(struct blk_io_trace *t)
92 t->magic = cpu_to_be32(t->magic);
93 t->sequence = cpu_to_be32(t->sequence);
94 t->time = cpu_to_be64(t->time);
95 t->sector = cpu_to_be64(t->sector);
96 t->bytes = cpu_to_be32(t->bytes);
97 t->action = cpu_to_be32(t->action);
98 t->pid = cpu_to_be32(t->pid);
99 t->cpu = cpu_to_be32(t->cpu);
100 t->error = cpu_to_be16(t->error);
101 t->pdu_len = cpu_to_be16(t->pdu_len);
102 t->device = cpu_to_be32(t->device);
103 /* t->comm is a string (endian neutral) */
106 static inline void trace_to_cpu(struct blk_io_trace *t)
108 t->magic = be32_to_cpu(t->magic);
109 t->sequence = be32_to_cpu(t->sequence);
110 t->time = be64_to_cpu(t->time);
111 t->sector = be64_to_cpu(t->sector);
112 t->bytes = be32_to_cpu(t->bytes);
113 t->action = be32_to_cpu(t->action);
114 t->pid = be32_to_cpu(t->pid);
115 t->cpu = be32_to_cpu(t->cpu);
116 t->error = be16_to_cpu(t->error);
117 t->pdu_len = be16_to_cpu(t->pdu_len);
118 t->device = be32_to_cpu(t->device);
119 /* t->comm is a string (endian neutral) */
122 extern void set_all_format_specs(char *);
123 extern int add_format_spec(char *);
124 extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *,
125 unsigned long long, int, unsigned char *);
126 extern int valid_act_opt(int);
127 extern int find_mask_map(char *);