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" |
d0ca268b | 9 | |
71d5d4c9 JA |
10 | #define MINORBITS 20 |
11 | #define MINORMASK ((1U << MINORBITS) - 1) | |
12 | #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) | |
13 | #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) | |
14 | ||
15 | #define SECONDS(x) ((unsigned long long)(x) / 1000000000) | |
16 | #define NANO_SECONDS(x) ((unsigned long long)(x) % 1000000000) | |
17 | #define DOUBLE_TO_NANO_ULL(d) ((unsigned long long)((d) * 1000000000)) | |
18 | ||
19 | #define min(a, b) ((a) < (b) ? (a) : (b)) | |
20 | ||
ae957cbc JA |
21 | #define t_sec(t) ((t)->bytes >> 9) |
22 | #define t_kb(t) ((t)->bytes >> 10) | |
23 | ||
bf0720af JA |
24 | typedef __u32 u32; |
25 | typedef __u8 u8; | |
26 | ||
71d5d4c9 JA |
27 | struct io_stats { |
28 | unsigned long qreads, qwrites, creads, cwrites, mreads, mwrites; | |
4054070a | 29 | unsigned long ireads, iwrites, rrqueue, wrqueue; |
71d5d4c9 JA |
30 | unsigned long long qread_kb, qwrite_kb, cread_kb, cwrite_kb; |
31 | unsigned long long iread_kb, iwrite_kb; | |
32 | unsigned long io_unplugs, timer_unplugs; | |
33 | }; | |
34 | ||
35 | struct per_cpu_info { | |
e820abd7 JA |
36 | unsigned int cpu; |
37 | unsigned int nelems; | |
71d5d4c9 JA |
38 | |
39 | int fd; | |
c0e0dbc2 | 40 | int fdblock; |
71d5d4c9 JA |
41 | char fname[128]; |
42 | ||
43 | struct io_stats io_stats; | |
44 | }; | |
45 | ||
46 | extern FILE *ofp; | |
47 | ||
d0ca268b | 48 | #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) |
e7c9f3ff | 49 | #define SUPPORTED_VERSION (0x05) |
d0ca268b | 50 | |
1e3c4225 | 51 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
6fe4709e JA |
52 | #define be16_to_cpu(x) __bswap_16(x) |
53 | #define be32_to_cpu(x) __bswap_32(x) | |
54 | #define be64_to_cpu(x) __bswap_64(x) | |
55 | #define cpu_to_be16(x) __bswap_16(x) | |
56 | #define cpu_to_be32(x) __bswap_32(x) | |
57 | #define cpu_to_be64(x) __bswap_64(x) | |
ffcf46d8 | 58 | #elif __BYTE_ORDER == __BIG_ENDIAN |
6fe4709e JA |
59 | #define be16_to_cpu(x) (x) |
60 | #define be32_to_cpu(x) (x) | |
61 | #define be64_to_cpu(x) (x) | |
62 | #define cpu_to_be16(x) (x) | |
63 | #define cpu_to_be32(x) (x) | |
64 | #define cpu_to_be64(x) (x) | |
65 | #else | |
66 | #error "Bad arch" | |
67 | #endif | |
68 | ||
69 | static inline int verify_trace(struct blk_io_trace *t) | |
70 | { | |
71 | if (!CHECK_MAGIC(t)) { | |
72 | fprintf(stderr, "bad trace magic %x\n", t->magic); | |
73 | return 1; | |
74 | } | |
75 | if ((t->magic & 0xff) != SUPPORTED_VERSION) { | |
76 | fprintf(stderr, "unsupported trace version %x\n", | |
77 | t->magic & 0xff); | |
78 | return 1; | |
79 | } | |
d0ca268b | 80 | |
6fe4709e JA |
81 | return 0; |
82 | } | |
d0ca268b | 83 | |
6fe4709e JA |
84 | static inline void trace_to_be(struct blk_io_trace *t) |
85 | { | |
86 | t->magic = cpu_to_be32(t->magic); | |
87 | t->sequence = cpu_to_be32(t->sequence); | |
88 | t->time = cpu_to_be64(t->time); | |
89 | t->sector = cpu_to_be64(t->sector); | |
90 | t->bytes = cpu_to_be32(t->bytes); | |
91 | t->action = cpu_to_be32(t->action); | |
92 | t->pid = cpu_to_be32(t->pid); | |
654aaa52 | 93 | t->cpu = cpu_to_be32(t->cpu); |
6fe4709e JA |
94 | t->error = cpu_to_be16(t->error); |
95 | t->pdu_len = cpu_to_be16(t->pdu_len); | |
e7c9f3ff | 96 | t->device = cpu_to_be32(t->device); |
654aaa52 | 97 | /* t->comm is a string (endian neutral) */ |
6fe4709e | 98 | } |
d0ca268b | 99 | |
6fe4709e JA |
100 | static inline void trace_to_cpu(struct blk_io_trace *t) |
101 | { | |
102 | t->magic = be32_to_cpu(t->magic); | |
103 | t->sequence = be32_to_cpu(t->sequence); | |
104 | t->time = be64_to_cpu(t->time); | |
105 | t->sector = be64_to_cpu(t->sector); | |
106 | t->bytes = be32_to_cpu(t->bytes); | |
107 | t->action = be32_to_cpu(t->action); | |
108 | t->pid = be32_to_cpu(t->pid); | |
654aaa52 | 109 | t->cpu = be32_to_cpu(t->cpu); |
6fe4709e JA |
110 | t->error = be16_to_cpu(t->error); |
111 | t->pdu_len = be16_to_cpu(t->pdu_len); | |
e7c9f3ff | 112 | t->device = be32_to_cpu(t->device); |
654aaa52 | 113 | /* t->comm is a string (endian neutral) */ |
6fe4709e | 114 | } |
d0ca268b | 115 | |
71d5d4c9 JA |
116 | extern void set_all_format_specs(char *); |
117 | extern int add_format_spec(char *); | |
118 | extern void process_fmt(char *, struct per_cpu_info *, struct blk_io_trace *, | |
119 | unsigned long long, int, unsigned char *); | |
98f8386b AB |
120 | extern int valid_act_opt(int); |
121 | extern int find_mask_map(char *); | |
71d5d4c9 | 122 | |
d0ca268b | 123 | #endif |