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