aboutsummaryrefslogtreecommitdiff
path: root/driver/gator_marshaling.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/gator_marshaling.c')
-rw-r--r--driver/gator_marshaling.c179
1 files changed, 111 insertions, 68 deletions
diff --git a/driver/gator_marshaling.c b/driver/gator_marshaling.c
index a84b280..b2efdd2 100644
--- a/driver/gator_marshaling.c
+++ b/driver/gator_marshaling.c
@@ -7,49 +7,52 @@
*
*/
-static void marshal_summary(long long timestamp, long long uptime) {
+static void marshal_summary(long long timestamp, long long uptime)
+{
int cpu = 0;
gator_buffer_write_packed_int64(cpu, SUMMARY_BUF, timestamp);
gator_buffer_write_packed_int64(cpu, SUMMARY_BUF, uptime);
buffer_check(cpu, SUMMARY_BUF);
}
-static bool marshal_cookie_header(char* text) {
+static bool marshal_cookie_header(const char *text)
+{
int cpu = smp_processor_id();
- return buffer_check_space(cpu, NAME_BUF, strlen(text) + 2*MAXSIZE_PACK32);
+ return buffer_check_space(cpu, NAME_BUF, strlen(text) + 3 * MAXSIZE_PACK32);
}
-static void marshal_cookie(int cookie, char* text) {
+static void marshal_cookie(int cookie, const char *text)
+{
int cpu = smp_processor_id();
- // TODO(dreric01) How long can the string be?
- if (buffer_check_space(cpu, NAME_BUF, 2*MAXSIZE_PACK32)) {
- gator_buffer_write_packed_int(cpu, NAME_BUF, MESSAGE_COOKIE);
- gator_buffer_write_packed_int(cpu, NAME_BUF, cookie);
- gator_buffer_write_string(cpu, NAME_BUF, text);
- }
+ // buffer_check_space already called by marshal_cookie_header
+ gator_buffer_write_packed_int(cpu, NAME_BUF, MESSAGE_COOKIE);
+ gator_buffer_write_packed_int(cpu, NAME_BUF, cookie);
+ gator_buffer_write_string(cpu, NAME_BUF, text);
buffer_check(cpu, NAME_BUF);
}
-static void marshal_thread_name(int pid, char* name) {
+static void marshal_thread_name(int pid, char *name)
+{
unsigned long flags, cpu;
local_irq_save(flags);
cpu = smp_processor_id();
- if (buffer_check_space(cpu, NAME_BUF, TASK_COMM_LEN + 2*MAXSIZE_PACK32 + MAXSIZE_PACK64)) {
+ if (buffer_check_space(cpu, NAME_BUF, TASK_COMM_LEN + 3 * MAXSIZE_PACK32 + MAXSIZE_PACK64)) {
gator_buffer_write_packed_int(cpu, NAME_BUF, MESSAGE_THREAD_NAME);
gator_buffer_write_packed_int64(cpu, NAME_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, NAME_BUF, pid);
gator_buffer_write_string(cpu, NAME_BUF, name);
}
- local_irq_restore(flags);
buffer_check(cpu, NAME_BUF);
+ local_irq_restore(flags);
}
-static bool marshal_backtrace_header(int exec_cookie, int tgid, int pid, int inKernel) {
+static bool marshal_backtrace_header(int exec_cookie, int tgid, int pid, int inKernel)
+{
int cpu = smp_processor_id();
- if (buffer_check_space(cpu, BACKTRACE_BUF, gator_backtrace_depth*2*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, BACKTRACE_BUF, MAXSIZE_PACK64 + 5 * MAXSIZE_PACK32 + gator_backtrace_depth * 2 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int64(cpu, BACKTRACE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, exec_cookie);
- gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, tgid);
+ gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, tgid);
gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, pid);
gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, inKernel);
return true;
@@ -61,13 +64,15 @@ static bool marshal_backtrace_header(int exec_cookie, int tgid, int pid, int inK
return false;
}
-static void marshal_backtrace(unsigned long address, int cookie) {
+static void marshal_backtrace(unsigned long address, int cookie)
+{
int cpu = smp_processor_id();
- gator_buffer_write_packed_int64(cpu, BACKTRACE_BUF, address);
gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, cookie);
+ gator_buffer_write_packed_int64(cpu, BACKTRACE_BUF, address);
}
-static void marshal_backtrace_footer(void) {
+static void marshal_backtrace_footer(void)
+{
int cpu = smp_processor_id();
gator_buffer_write_packed_int(cpu, BACKTRACE_BUF, MESSAGE_END_BACKTRACE);
@@ -75,30 +80,31 @@ static void marshal_backtrace_footer(void) {
buffer_check(cpu, BACKTRACE_BUF);
}
-static bool marshal_event_header(void) {
+static bool marshal_event_header(void)
+{
unsigned long flags, cpu = smp_processor_id();
bool retval = false;
-
+
local_irq_save(flags);
if (buffer_check_space(cpu, BLOCK_COUNTER_BUF, MAXSIZE_PACK32 + MAXSIZE_PACK64)) {
- gator_buffer_write_packed_int(cpu, BLOCK_COUNTER_BUF, 0); // key of zero indicates a timestamp
+ gator_buffer_write_packed_int(cpu, BLOCK_COUNTER_BUF, 0); // key of zero indicates a timestamp
gator_buffer_write_packed_int64(cpu, BLOCK_COUNTER_BUF, gator_get_time());
retval = true;
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, BLOCK_COUNTER_BUF);
+ local_irq_restore(flags);
return retval;
}
-static void marshal_event(int len, int* buffer) {
+static void marshal_event(int len, int *buffer)
+{
unsigned long i, flags, cpu = smp_processor_id();
if (len <= 0)
return;
-
+
// length must be even since all data is a (key, value) pair
if (len & 0x1) {
pr_err("gator: invalid counter data detected and discarded");
@@ -106,27 +112,26 @@ static void marshal_event(int len, int* buffer) {
}
// events must be written in key,value pairs
+ local_irq_save(flags);
for (i = 0; i < len; i += 2) {
- local_irq_save(flags);
- if (!buffer_check_space(cpu, BLOCK_COUNTER_BUF, 2*MAXSIZE_PACK32)) {
- local_irq_restore(flags);
+ if (!buffer_check_space(cpu, BLOCK_COUNTER_BUF, 2 * MAXSIZE_PACK32)) {
break;
}
gator_buffer_write_packed_int(cpu, BLOCK_COUNTER_BUF, buffer[i]);
gator_buffer_write_packed_int(cpu, BLOCK_COUNTER_BUF, buffer[i + 1]);
- local_irq_restore(flags);
}
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, BLOCK_COUNTER_BUF);
+ local_irq_restore(flags);
}
-static void marshal_event64(int len, long long* buffer64) {
+static void marshal_event64(int len, long long *buffer64)
+{
unsigned long i, flags, cpu = smp_processor_id();
if (len <= 0)
return;
-
+
// length must be even since all data is a (key, value) pair
if (len & 0x1) {
pr_err("gator: invalid counter data detected and discarded");
@@ -134,48 +139,47 @@ static void marshal_event64(int len, long long* buffer64) {
}
// events must be written in key,value pairs
+ local_irq_save(flags);
for (i = 0; i < len; i += 2) {
- local_irq_save(flags);
- if (!buffer_check_space(cpu, BLOCK_COUNTER_BUF, 2*MAXSIZE_PACK64)) {
- local_irq_restore(flags);
+ if (!buffer_check_space(cpu, BLOCK_COUNTER_BUF, 2 * MAXSIZE_PACK64)) {
break;
}
gator_buffer_write_packed_int64(cpu, BLOCK_COUNTER_BUF, buffer64[i]);
gator_buffer_write_packed_int64(cpu, BLOCK_COUNTER_BUF, buffer64[i + 1]);
- local_irq_restore(flags);
}
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, BLOCK_COUNTER_BUF);
+ local_irq_restore(flags);
}
#if GATOR_CPU_FREQ_SUPPORT
-static void marshal_event_single(int core, int key, int value) {
+static void marshal_event_single(int core, int key, int value)
+{
unsigned long flags, cpu;
-
+
local_irq_save(flags);
cpu = smp_processor_id();
- if (buffer_check_space(cpu, COUNTER_BUF, MAXSIZE_PACK64 + 3*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, COUNTER_BUF, MAXSIZE_PACK64 + 3 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int64(cpu, COUNTER_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, COUNTER_BUF, core);
gator_buffer_write_packed_int(cpu, COUNTER_BUF, key);
gator_buffer_write_packed_int(cpu, COUNTER_BUF, value);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, COUNTER_BUF);
+ local_irq_restore(flags);
}
#endif
-static void marshal_sched_gpu_start(int unit, int core, int tgid, int pid) {
+static void marshal_sched_gpu_start(int unit, int core, int tgid, int pid)
+{
unsigned long cpu = smp_processor_id(), flags;
if (!per_cpu(gator_buffer, cpu)[GPU_TRACE_BUF])
return;
local_irq_save(flags);
- if (buffer_check_space(cpu, GPU_TRACE_BUF, MAXSIZE_PACK64 + 5*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, GPU_TRACE_BUF, MAXSIZE_PACK64 + 5 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, MESSAGE_GPU_START);
gator_buffer_write_packed_int64(cpu, GPU_TRACE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, unit);
@@ -183,39 +187,39 @@ static void marshal_sched_gpu_start(int unit, int core, int tgid, int pid) {
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, tgid);
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, pid);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, GPU_TRACE_BUF);
+ local_irq_restore(flags);
}
-static void marshal_sched_gpu_stop(int unit, int core) {
+static void marshal_sched_gpu_stop(int unit, int core)
+{
unsigned long cpu = smp_processor_id(), flags;
if (!per_cpu(gator_buffer, cpu)[GPU_TRACE_BUF])
return;
local_irq_save(flags);
- if (buffer_check_space(cpu, GPU_TRACE_BUF, MAXSIZE_PACK64 + 3*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, GPU_TRACE_BUF, MAXSIZE_PACK64 + 3 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, MESSAGE_GPU_STOP);
gator_buffer_write_packed_int64(cpu, GPU_TRACE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, unit);
gator_buffer_write_packed_int(cpu, GPU_TRACE_BUF, core);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, GPU_TRACE_BUF);
+ local_irq_restore(flags);
}
-static void marshal_sched_trace_switch(int tgid, int pid, int cookie, int state) {
+static void marshal_sched_trace_switch(int tgid, int pid, int cookie, int state)
+{
unsigned long cpu = smp_processor_id(), flags;
if (!per_cpu(gator_buffer, cpu)[SCHED_TRACE_BUF])
return;
local_irq_save(flags);
- if (buffer_check_space(cpu, SCHED_TRACE_BUF, MAXSIZE_PACK64 + 5*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, SCHED_TRACE_BUF, MAXSIZE_PACK64 + 5 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, MESSAGE_SCHED_SWITCH);
gator_buffer_write_packed_int64(cpu, SCHED_TRACE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, tgid);
@@ -223,49 +227,88 @@ static void marshal_sched_trace_switch(int tgid, int pid, int cookie, int state)
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, cookie);
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, state);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, SCHED_TRACE_BUF);
+ local_irq_restore(flags);
}
-static void marshal_sched_trace_exit(int tgid, int pid) {
+static void marshal_sched_trace_exit(int tgid, int pid)
+{
unsigned long cpu = smp_processor_id(), flags;
if (!per_cpu(gator_buffer, cpu)[SCHED_TRACE_BUF])
return;
local_irq_save(flags);
- if (buffer_check_space(cpu, SCHED_TRACE_BUF, MAXSIZE_PACK64 + 2*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, SCHED_TRACE_BUF, MAXSIZE_PACK64 + 2 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, MESSAGE_SCHED_EXIT);
gator_buffer_write_packed_int64(cpu, SCHED_TRACE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, SCHED_TRACE_BUF, pid);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, SCHED_TRACE_BUF);
+ local_irq_restore(flags);
}
#if GATOR_CPU_FREQ_SUPPORT
-static void marshal_idle(int core, int state) {
+static void marshal_idle(int core, int state)
+{
unsigned long flags, cpu;
-
+
local_irq_save(flags);
cpu = smp_processor_id();
- if (buffer_check_space(cpu, IDLE_BUF, MAXSIZE_PACK64 + 2*MAXSIZE_PACK32)) {
+ if (buffer_check_space(cpu, IDLE_BUF, MAXSIZE_PACK64 + 2 * MAXSIZE_PACK32)) {
gator_buffer_write_packed_int(cpu, IDLE_BUF, state);
gator_buffer_write_packed_int64(cpu, IDLE_BUF, gator_get_time());
gator_buffer_write_packed_int(cpu, IDLE_BUF, core);
}
- local_irq_restore(flags);
-
// Check and commit; commit is set to occur once buffer is 3/4 full
buffer_check(cpu, IDLE_BUF);
+ local_irq_restore(flags);
}
#endif
-static void marshal_frame(int cpu, int buftype, int frame) {
+static void marshal_frame(int cpu, int buftype)
+{
+ int frame;
+
+ if (!per_cpu(gator_buffer, cpu)[buftype]) {
+ return;
+ }
+
+ switch (buftype) {
+ case SUMMARY_BUF:
+ frame = FRAME_SUMMARY;
+ break;
+ case BACKTRACE_BUF:
+ frame = FRAME_BACKTRACE;
+ break;
+ case NAME_BUF:
+ frame = FRAME_NAME;
+ break;
+ case COUNTER_BUF:
+ frame = FRAME_COUNTER;
+ break;
+ case BLOCK_COUNTER_BUF:
+ frame = FRAME_BLOCK_COUNTER;
+ break;
+ case ANNOTATE_BUF:
+ frame = FRAME_ANNOTATE;
+ break;
+ case SCHED_TRACE_BUF:
+ frame = FRAME_SCHED_TRACE;
+ break;
+ case GPU_TRACE_BUF:
+ frame = FRAME_GPU_TRACE;
+ break;
+ case IDLE_BUF:
+ frame = FRAME_IDLE;
+ break;
+ default:
+ frame = -1;
+ break;
+ }
+
// add response type
if (gator_response_type > 0) {
gator_buffer_write_packed_int(cpu, buftype, gator_response_type);
@@ -280,7 +323,8 @@ static void marshal_frame(int cpu, int buftype, int frame) {
}
#if defined(__arm__) || defined(__aarch64__)
-static void marshal_core_name(const char* name) {
+static void marshal_core_name(const char *name)
+{
int cpu = smp_processor_id();
unsigned long flags;
local_irq_save(flags);
@@ -288,8 +332,7 @@ static void marshal_core_name(const char* name) {
gator_buffer_write_packed_int(cpu, NAME_BUF, HRTIMER_CORE_NAME);
gator_buffer_write_string(cpu, NAME_BUF, name);
}
- local_irq_restore(flags);
-
buffer_check(cpu, NAME_BUF);
+ local_irq_restore(flags);
}
#endif