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