Commit | Line | Data |
---|---|---|
6fe4709e JA |
1 | #ifndef BLKTRACE_H |
2 | #define BLKTRACE_H | |
d0ca268b | 3 | |
98f8386b | 4 | #include <stdio.h> |
c3ce73f5 | 5 | #include <limits.h> |
6fe4709e | 6 | #include <byteswap.h> |
1e3c4225 JA |
7 | #include <endian.h> |
8 | ||
6fe4709e | 9 | #include "blktrace_api.h" |
210824c3 | 10 | #include "rbtree.h" |
d0ca268b | 11 | |
71d5d4c9 JA |
12 | #define MINORBITS 20 |
13 | #define MINORMASK ((1U << MINORBITS) - 1) | |
14 | #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) | |
15 | #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) | |
16 | ||
17 | #define SECONDS(x) ((unsigned long long)(x) / 1000000000) | |
18 | #define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000) | |
19 | #define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000)) | |
20 | ||
21 | #define min(a, b) ((a) < (b) ? (a) : (b)) | |
6a6d3f0f | 22 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
71d5d4c9 | 23 | |
ae957cbc JA |
24 | #define t_sec(t) ((t)->bytes >> 9) |
25 | #define t_kb(t) ((t)->bytes >> 10) | |
26 | ||
bf0720af JA |
27 | typedef __u32 u32; |
28 | typedef __u8 u8; | |
29 | ||
71d5d4c9 JA |
30 | struct io_stats { |
31 | unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites; | |
4054070a | 32 | unsigned long ireads, iwrites, rrqueue, wrqueue; |
71d5d4c9 JA |
33 | unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb; |
34 | unsigned long long iread_kb, iwrite_kb; | |
fb2ec796 | 35 | unsigned long long mread_kb, mwrite_kb; |
801646d6 CS |
36 | unsigned long qreads_pc, qwrites_pc, ireads_pc, iwrites_pc; |
37 | unsigned long rrqueue_pc, wrqueue_pc, creads_pc, cwrites_pc; | |
38 | unsigned long long qread_kb_pc, qwrite_kb_pc, iread_kb_pc, iwrite_kb_pc; | |
71d5d4c9 JA |
39 | unsigned long io_unplugs, timer_unplugs; |
40 | }; | |
41 | ||
42 | struct per_cpu_info { | |
e820abd7 JA |
43 | unsigned int cpu; |
44 | unsigned int nelems; | |
71d5d4c9 JA |
45 | |
46 | int fd; | |
c0e0dbc2 | 47 | int fdblock; |
c3ce73f5 | 48 | char fname[PATH_MAX]; |
71d5d4c9 JA |
49 | |
50 | struct io_stats io_stats; | |
210824c3 JA |
51 | |
52 | struct rb_root rb_last; | |
53 | unsigned long rb_last_entries; | |
54 | unsigned long last_sequence; | |
55 | unsigned long smallest_seq_read; | |
66930177 JA |
56 | |
57 | struct skip_info *skips_head; | |
58 | struct skip_info *skips_tail; | |
71d5d4c9 JA |
59 | }; |
60 | ||
61 | extern FILE *ofp; | |
017d1660 | 62 | extern int data_is_native; |
7bd4fd0a | 63 | extern struct timespec abs_start_time; |
71d5d4c9 | 64 | |
d0ca268b | 65 | #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) |
bfc70ad5 | 66 | #define SUPPORTED_VERSION (0x07) |
d0ca268b | 67 | |
1e3c4225 | 68 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
6fe4709e JA |
69 | #define be16_to_cpu(x) __bswap_16(x) |
70 | #define be32_to_cpu(x) __bswap_32(x) | |
71 | #define be64_to_cpu(x) __bswap_64(x) | |
72 | #define cpu_to_be16(x) __bswap_16(x) | |
73 | #define cpu_to_be32(x) __bswap_32(x) | |
74 | #define cpu_to_be64(x) __bswap_64(x) | |
ffcf46d8 | 75 | #elif __BYTE_ORDER == __BIG_ENDIAN |
6fe4709e JA |
76 | #define be16_to_cpu(x) (x) |
77 | #define be32_to_cpu(x) (x) | |
78 | #define be64_to_cpu(x) (x) | |
79 | #define cpu_to_be16(x) (x) | |
80 | #define cpu_to_be32(x) (x) | |
81 | #define cpu_to_be64(x) (x) | |
82 | #else | |
83 | #error "Bad arch" | |
84 | #endif | |
85 | ||
86 | static inline int verify_trace(struct blk_io_trace *t) | |
87 | { | |
88 | if (!CHECK_MAGIC(t)) { | |
89 | fprintf(stderr, "bad trace magic %x\n", t->magic); | |
90 | return 1; | |
91 | } | |
92 | if ((t->magic & 0xff) != SUPPORTED_VERSION) { | |
93 | fprintf(stderr, "unsupported trace version %x\n", | |
94 | t->magic & 0xff); | |
95 | return 1; | |
96 | } | |
d0ca268b | 97 | |
6fe4709e JA |
98 | return 0; |
99 | } | |
d0ca268b | 100 | |
6fe4709e JA |
101 | static inline void trace_to_cpu(struct blk_io_trace *t) |
102 | { | |
017d1660 JA |
103 | if (data_is_native) |
104 | return; | |
105 | ||
6fe4709e JA |
106 | t->magic = be32_to_cpu(t->magic); |
107 | t->sequence = be32_to_cpu(t->sequence); | |
108 | t->time = be64_to_cpu(t->time); | |
109 | t->sector = be64_to_cpu(t->sector); | |
110 | t->bytes = be32_to_cpu(t->bytes); | |
111 | t->action = be32_to_cpu(t->action); | |
112 | t->pid = be32_to_cpu(t->pid); | |
bfc70ad5 | 113 | t->device = be32_to_cpu(t->device); |
8e8bb835 | 114 | t->cpu = be32_to_cpu(t->cpu); |
6fe4709e JA |
115 | t->error = be16_to_cpu(t->error); |
116 | t->pdu_len = be16_to_cpu(t->pdu_len); | |
117 | } | |
d0ca268b | 118 | |
017d1660 JA |
119 | /* |
120 | * check whether data is native or not | |
121 | */ | |
e5413c3c | 122 | static inline int check_data_endianness(u32 magic) |
017d1660 | 123 | { |
e5413c3c | 124 | if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { |
017d1660 JA |
125 | data_is_native = 1; |
126 | return 0; | |
127 | } | |
128 | ||
e5413c3c | 129 | magic = __bswap_32(magic); |
017d1660 | 130 | if ((magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { |
017d1660 JA |
131 | data_is_native = 0; |
132 | return 0; | |
133 | } | |
134 | ||
135 | return 1; | |
136 | } | |
137 | ||
71d5d4c9 JA |
138 | extern void set_all_format_specs(char *); |
139 | extern int add_format_spec(char *); | |
140 | extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *, | |
141 | unsigned long long, int, unsigned char *); | |
98f8386b AB |
142 | extern int valid_act_opt(int); |
143 | extern int find_mask_map(char *); | |
bfc70ad5 | 144 | extern char *find_process_name(pid_t); |
71d5d4c9 | 145 | |
d0ca268b | 146 | #endif |