aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/test/run-trace.c58
-rw-r--r--core/trace.c43
-rw-r--r--external/trace/trace.c2
-rw-r--r--include/trace_types.h46
4 files changed, 78 insertions, 71 deletions
diff --git a/core/test/run-trace.c b/core/test/run-trace.c
index cdd84bd..79c5701 100644
--- a/core/test/run-trace.c
+++ b/core/test/run-trace.c
@@ -174,8 +174,8 @@ static void test_parallel(void)
for (i = 0; i < CPUS; i++) {
fake_cpus[i].trace = p + i * len;
- fake_cpus[i].trace->tb.mask = TBUF_SZ - 1;
- fake_cpus[i].trace->tb.max_size = sizeof(union trace);
+ fake_cpus[i].trace->tb.mask = cpu_to_be64(TBUF_SZ - 1);
+ fake_cpus[i].trace->tb.max_size = cpu_to_be32(sizeof(union trace));
fake_cpus[i].is_secondary = false;
}
@@ -202,27 +202,27 @@ static void test_parallel(void)
i = (i + last) % CPUS;
last = i;
- assert(t.hdr.cpu < CPUS);
- assert(!done[t.hdr.cpu]);
+ assert(be16_to_cpu(t.hdr.cpu) < CPUS);
+ assert(!done[be16_to_cpu(t.hdr.cpu)]);
if (t.hdr.type == TRACE_OVERFLOW) {
/* Conveniently, each record is 16 bytes here. */
- assert(t.overflow.bytes_missed % 16 == 0);
- overflows[i] += t.overflow.bytes_missed / 16;
+ assert(be64_to_cpu(t.overflow.bytes_missed) % 16 == 0);
+ overflows[i] += be64_to_cpu(t.overflow.bytes_missed) / 16;
num_overflows[i]++;
continue;
}
- assert(t.hdr.timestamp % CPUS == t.hdr.cpu);
+ assert(be64_to_cpu(t.hdr.timestamp) % CPUS == be16_to_cpu(t.hdr.cpu));
if (t.hdr.type == TRACE_REPEAT) {
assert(t.hdr.len_div_8 * 8 == sizeof(t.repeat));
- assert(t.repeat.num != 0);
- assert(t.repeat.num <= t.hdr.cpu);
- repeats[t.hdr.cpu] += t.repeat.num;
+ assert(be16_to_cpu(t.repeat.num) != 0);
+ assert(be16_to_cpu(t.repeat.num) <= be16_to_cpu(t.hdr.cpu));
+ repeats[be16_to_cpu(t.hdr.cpu)] += be16_to_cpu(t.repeat.num);
} else if (t.hdr.type == 0x70) {
- done[t.hdr.cpu] = true;
+ done[be16_to_cpu(t.hdr.cpu)] = true;
} else {
- counts[t.hdr.cpu]++;
+ counts[be16_to_cpu(t.hdr.cpu)]++;
}
}
@@ -235,7 +235,7 @@ static void test_parallel(void)
for (i = 0; i < CPUS; i++) {
printf("Child %i: %u produced, %u overflows, %llu total\n", i,
counts[i], overflows[i],
- (long long)fake_cpus[i].trace->tb.end);
+ (long long)be64_to_cpu(fake_cpus[i].trace->tb.end));
assert(counts[i] + repeats[i] <= PER_CHILD_TRACES);
}
/* Child 0 never repeats. */
@@ -276,7 +276,7 @@ int main(void)
trace_add(&minimal, 100, sizeof(trace.hdr));
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.len_div_8 == minimal.hdr.len_div_8);
- assert(trace.hdr.timestamp == timestamp);
+ assert(be64_to_cpu(trace.hdr.timestamp) == timestamp);
/* Make it wrap once. */
for (i = 0; i < TBUF_SZ / (minimal.hdr.len_div_8 * 8) + 1; i++) {
@@ -288,12 +288,12 @@ int main(void)
/* First one must be overflow marker. */
assert(trace.hdr.type == TRACE_OVERFLOW);
assert(trace.hdr.len_div_8 * 8 == sizeof(trace.overflow));
- assert(trace.overflow.bytes_missed == minimal.hdr.len_div_8 * 8);
+ assert(be64_to_cpu(trace.overflow.bytes_missed) == minimal.hdr.len_div_8 * 8);
for (i = 0; i < TBUF_SZ / (minimal.hdr.len_div_8 * 8); i++) {
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.len_div_8 == minimal.hdr.len_div_8);
- assert(trace.hdr.timestamp == i+1);
+ assert(be64_to_cpu(trace.hdr.timestamp) == i+1);
assert(trace.hdr.type == 99 + ((i+1)%2));
}
assert(!trace_get(&trace, &my_fake_cpu->trace->tb));
@@ -309,9 +309,9 @@ int main(void)
assert(trace.hdr.type == TRACE_OVERFLOW);
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.len_div_8 == large.hdr.len_div_8);
- i = trace.hdr.timestamp;
+ i = be64_to_cpu(trace.hdr.timestamp);
while (trace_get(&trace, &my_fake_cpu->trace->tb))
- assert(trace.hdr.timestamp == ++i);
+ assert(be64_to_cpu(trace.hdr.timestamp) == ++i);
/* Test repeats. */
for (i = 0; i < 65538; i++) {
@@ -330,33 +330,33 @@ int main(void)
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.type == TRACE_REPEAT);
assert(trace.hdr.len_div_8 * 8 == sizeof(trace.repeat));
- assert(trace.repeat.num == 65535);
- assert(trace.repeat.timestamp == 65535);
+ assert(be16_to_cpu(trace.repeat.num) == 65535);
+ assert(be64_to_cpu(trace.repeat.timestamp) == 65535);
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
- assert(trace.hdr.timestamp == 65536);
+ assert(be64_to_cpu(trace.hdr.timestamp) == 65536);
assert(trace.hdr.len_div_8 == minimal.hdr.len_div_8);
assert(trace.hdr.type == 100);
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.type == TRACE_REPEAT);
assert(trace.hdr.len_div_8 * 8 == sizeof(trace.repeat));
- assert(trace.repeat.num == 1);
- assert(trace.repeat.timestamp == 65537);
+ assert(be16_to_cpu(trace.repeat.num) == 1);
+ assert(be64_to_cpu(trace.repeat.timestamp) == 65537);
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
- assert(trace.hdr.timestamp == 65538);
+ assert(be64_to_cpu(trace.hdr.timestamp) == 65538);
assert(trace.hdr.len_div_8 == minimal.hdr.len_div_8);
assert(trace.hdr.type == 101);
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
assert(trace.hdr.type == TRACE_REPEAT);
assert(trace.hdr.len_div_8 * 8 == sizeof(trace.repeat));
- assert(trace.repeat.num == 1);
- assert(trace.repeat.timestamp == 65539);
+ assert(be16_to_cpu(trace.repeat.num) == 1);
+ assert(be64_to_cpu(trace.repeat.timestamp) == 65539);
/* Now, test adding repeat while we're reading... */
timestamp = 0;
trace_add(&minimal, 100, sizeof(trace.hdr));
assert(trace_get(&trace, &my_fake_cpu->trace->tb));
- assert(trace.hdr.timestamp == 0);
+ assert(be64_to_cpu(trace.hdr.timestamp) == 0);
assert(trace.hdr.len_div_8 == minimal.hdr.len_div_8);
assert(trace.hdr.type == 100);
@@ -370,9 +370,9 @@ int main(void)
} else {
assert(trace.hdr.type == TRACE_REPEAT);
assert(trace.hdr.len_div_8 * 8 == sizeof(trace.repeat));
- assert(trace.repeat.num == 1);
+ assert(be16_to_cpu(trace.repeat.num) == 1);
}
- assert(trace.repeat.timestamp == i);
+ assert(be64_to_cpu(trace.repeat.timestamp) == i);
assert(!trace_get(&trace, &my_fake_cpu->trace->tb));
}
diff --git a/core/trace.c b/core/trace.c
index 76f3c30..47c10e3 100644
--- a/core/trace.c
+++ b/core/trace.c
@@ -64,7 +64,7 @@ static bool handle_repeat(struct tracebuf *tb, const union trace *trace)
struct trace_repeat *rpt;
u32 len;
- prev = (void *)tb->buf + (tb->last & tb->mask);
+ prev = (void *)tb->buf + be64_to_cpu(tb->last & tb->mask);
if (prev->type != trace->hdr.type
|| prev->len_div_8 != trace->hdr.len_div_8
@@ -76,21 +76,22 @@ static bool handle_repeat(struct tracebuf *tb, const union trace *trace)
return false;
/* If they've consumed prev entry, don't repeat. */
- if (tb->last < tb->start)
+ if (be64_to_cpu(tb->last) < be64_to_cpu(tb->start))
return false;
/* OK, it's a duplicate. Do we already have repeat? */
- if (tb->last + len != tb->end) {
+ if (be64_to_cpu(tb->last) + len != be64_to_cpu(tb->end)) {
+ u64 pos = be64_to_cpu(tb->last) + len;
/* FIXME: Reader is not protected from seeing this! */
- rpt = (void *)tb->buf + ((tb->last + len) & tb->mask);
- assert(tb->last + len + rpt->len_div_8*8 == tb->end);
+ rpt = (void *)tb->buf + (pos & be64_to_cpu(tb->mask));
+ assert(pos + rpt->len_div_8*8 == be64_to_cpu(tb->end));
assert(rpt->type == TRACE_REPEAT);
/* If this repeat entry is full, don't repeat. */
- if (rpt->num == 0xFFFF)
+ if (be16_to_cpu(rpt->num) == 0xFFFF)
return false;
- rpt->num++;
+ rpt->num = cpu_to_be16(be16_to_cpu(rpt->num) + 1);
rpt->timestamp = trace->hdr.timestamp;
return true;
}
@@ -101,15 +102,15 @@ static bool handle_repeat(struct tracebuf *tb, const union trace *trace)
*/
assert(trace->hdr.len_div_8 * 8 >= sizeof(*rpt));
- rpt = (void *)tb->buf + (tb->end & tb->mask);
+ rpt = (void *)tb->buf + be64_to_cpu(tb->end & tb->mask);
rpt->timestamp = trace->hdr.timestamp;
rpt->type = TRACE_REPEAT;
rpt->len_div_8 = sizeof(*rpt) >> 3;
rpt->cpu = trace->hdr.cpu;
rpt->prev_len = trace->hdr.len_div_8 << 3;
- rpt->num = 1;
+ rpt->num = cpu_to_be16(1);
lwsync(); /* write barrier: complete repeat record before exposing */
- tb->end += sizeof(*rpt);
+ tb->end = cpu_to_be64(be64_to_cpu(tb->end) + sizeof(*rpt));
return true;
}
@@ -133,17 +134,20 @@ void trace_add(union trace *trace, u8 type, u16 len)
if (!((1ul << trace->hdr.type) & debug_descriptor.trace_mask))
return;
- trace->hdr.timestamp = mftb();
- trace->hdr.cpu = this_cpu()->server_no;
+ trace->hdr.timestamp = cpu_to_be64(mftb());
+ trace->hdr.cpu = cpu_to_be16(this_cpu()->server_no);
lock(&ti->lock);
/* Throw away old entries before we overwrite them. */
- while ((ti->tb.start + ti->tb.mask + 1) < (ti->tb.end + tsz)) {
+ while ((be64_to_cpu(ti->tb.start) + be64_to_cpu(ti->tb.mask) + 1)
+ < (be64_to_cpu(ti->tb.end) + tsz)) {
struct trace_hdr *hdr;
- hdr = (void *)ti->tb.buf + (ti->tb.start & ti->tb.mask);
- ti->tb.start += hdr->len_div_8 << 3;
+ hdr = (void *)ti->tb.buf +
+ be64_to_cpu(ti->tb.start & ti->tb.mask);
+ ti->tb.start = cpu_to_be64(be64_to_cpu(ti->tb.start) +
+ (hdr->len_div_8 << 3));
}
/* Must update ->start before we rewrite new entries. */
@@ -152,10 +156,11 @@ void trace_add(union trace *trace, u8 type, u16 len)
/* Check for duplicates... */
if (!handle_repeat(&ti->tb, trace)) {
/* This may go off end, and that's why ti->tb.buf is oversize */
- memcpy(ti->tb.buf + (ti->tb.end & ti->tb.mask), trace, tsz);
+ memcpy(ti->tb.buf + be64_to_cpu(ti->tb.end & ti->tb.mask),
+ trace, tsz);
ti->tb.last = ti->tb.end;
lwsync(); /* write barrier: write entry before exposing */
- ti->tb.end += tsz;
+ ti->tb.end = cpu_to_be64(be64_to_cpu(ti->tb.end) + tsz);
}
unlock(&ti->lock);
}
@@ -218,8 +223,8 @@ void init_trace_buffers(void)
any = t->trace;
memset(t->trace, 0, size);
init_lock(&t->trace->lock);
- t->trace->tb.mask = TBUF_SZ - 1;
- t->trace->tb.max_size = MAX_SIZE;
+ t->trace->tb.mask = cpu_to_be64(TBUF_SZ - 1);
+ t->trace->tb.max_size = cpu_to_be32(MAX_SIZE);
trace_add_desc(any, sizeof(t->trace->tb) +
tracebuf_extra());
} else
diff --git a/external/trace/trace.c b/external/trace/trace.c
index 7818ada..745da53 100644
--- a/external/trace/trace.c
+++ b/external/trace/trace.c
@@ -85,7 +85,7 @@ again:
u32 num = be16_to_cpu(t->repeat.num);
/* In case we've read some already... */
- t->repeat.num = cpu_to_be16(num - tb->last_repeat);
+ t->repeat.num = cpu_to_be16(num - be32_to_cpu(tb->last_repeat));
/* Record how many repeats we saw this time. */
tb->last_repeat = cpu_to_be32(num);
diff --git a/include/trace_types.h b/include/trace_types.h
index d1d3690..83c49a2 100644
--- a/include/trace_types.h
+++ b/include/trace_types.h
@@ -17,6 +17,8 @@
#ifndef __TRACE_TYPES_H
#define __TRACE_TYPES_H
+#include <types.h>
+
#define TRACE_REPEAT 1
#define TRACE_OVERFLOW 2
#define TRACE_OPAL 3 /* OPAL call */
@@ -27,56 +29,56 @@
/* One per cpu, plus one for NMIs */
struct tracebuf {
/* Mask to apply to get buffer offset. */
- u64 mask;
+ __be64 mask;
/* This where the buffer starts. */
- u64 start;
+ __be64 start;
/* This is where writer has written to. */
- u64 end;
+ __be64 end;
/* This is where the writer wrote to previously. */
- u64 last;
+ __be64 last;
/* This is where the reader is up to. */
- u64 rpos;
+ __be64 rpos;
/* If the last one we read was a repeat, this shows how many. */
- u32 last_repeat;
+ __be32 last_repeat;
/* Maximum possible size of a record. */
- u32 max_size;
+ __be32 max_size;
char buf[/* TBUF_SZ + max_size */];
};
/* Common header for all trace entries. */
struct trace_hdr {
- u64 timestamp;
+ __be64 timestamp;
u8 type;
u8 len_div_8;
- u16 cpu;
+ __be16 cpu;
u8 unused[4];
};
/* Note: all other entries must be at least as large as this! */
struct trace_repeat {
- u64 timestamp; /* Last repeat happened at this timestamp */
+ __be64 timestamp; /* Last repeat happened at this timestamp */
u8 type; /* == TRACE_REPEAT */
u8 len_div_8;
- u16 cpu;
- u16 prev_len;
- u16 num; /* Starts at 1, ie. 1 repeat, or two traces. */
+ __be16 cpu;
+ __be16 prev_len;
+ __be16 num; /* Starts at 1, ie. 1 repeat, or two traces. */
/* Note that the count can be one short, if read races a repeat. */
};
/* Overflow is special */
struct trace_overflow {
- u64 unused64; /* Timestamp is unused */
+ __be64 unused64; /* Timestamp is unused */
u8 type; /* == TRACE_OVERFLOW */
u8 len_div_8;
u8 unused[6]; /* ie. hdr.cpu is indeterminate */
- u64 bytes_missed;
+ __be64 bytes_missed;
};
/* All other trace types have a full header */
struct trace_opal {
struct trace_hdr hdr;
- u64 token, lr, sp, r3_to_11[9];
+ __be64 token, lr, sp, r3_to_11[9];
};
#define TRACE_FSP_MSG_IN 0
@@ -84,8 +86,8 @@ struct trace_opal {
struct trace_fsp_msg {
struct trace_hdr hdr;
- u32 word0;
- u32 word1;
+ __be32 word0;
+ __be32 word1;
u8 dlen;
u8 dir; /* TRACE_FSP_MSG_IN or TRACE_FSP_MSG_OUT */
u8 data[56]; /* See dlen, but max is 56 bytes. */
@@ -100,9 +102,9 @@ struct trace_fsp_msg {
struct trace_fsp_event {
struct trace_hdr hdr;
- u16 event;
- u16 fsp_state;
- u32 data[4]; /* event type specific */
+ __be16 event;
+ __be16 fsp_state;
+ __be32 data[4]; /* event type specific */
};
#define TRACE_UART_CTX_IRQ 0
@@ -115,7 +117,7 @@ struct trace_uart {
u8 cnt;
u8 irq_state;
u8 unused;
- u16 in_count;
+ __be16 in_count;
};
union trace {