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