tracing: fix incorrect return type of ns2usecs()
[firefly-linux-kernel-4.4.55.git] / kernel / trace / trace_output.c
index ef8fd661b217c337b02069f9882b87a664a01326..64b54a59c55b585ff3b979f216ba0451273ee6e4 100644 (file)
@@ -19,6 +19,38 @@ static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
 
 static int next_event_type = __TRACE_LAST_TYPE + 1;
 
+enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       struct trace_entry *entry = iter->ent;
+       struct bprint_entry *field;
+       int ret;
+
+       trace_assign_type(field, entry);
+
+       ret = trace_seq_bprintf(s, field->fmt, field->buf);
+       if (!ret)
+               return TRACE_TYPE_PARTIAL_LINE;
+
+       return TRACE_TYPE_HANDLED;
+}
+
+enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       struct trace_entry *entry = iter->ent;
+       struct print_entry *field;
+       int ret;
+
+       trace_assign_type(field, entry);
+
+       ret = trace_seq_printf(s, "%s", field->buf);
+       if (!ret)
+               return TRACE_TYPE_PARTIAL_LINE;
+
+       return TRACE_TYPE_HANDLED;
+}
+
 /**
  * trace_seq_printf - sequence printing of trace information
  * @s: trace sequence descriptor
@@ -105,7 +137,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
        return 1;
 }
 
-int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
 {
        if (len > ((PAGE_SIZE - 1) - s->len))
                return 0;
@@ -116,10 +148,10 @@ int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
        return len;
 }
 
-int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
+int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
 {
        unsigned char hex[HEX_CHARS];
-       unsigned char *data = mem;
+       const unsigned char *data = mem;
        int i, j;
 
 #ifdef __BIG_ENDIAN
@@ -135,6 +167,19 @@ int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
        return trace_seq_putmem(s, hex, j);
 }
 
+void *trace_seq_reserve(struct trace_seq *s, size_t len)
+{
+       void *ret;
+
+       if (len > ((PAGE_SIZE - 1) - s->len))
+               return NULL;
+
+       ret = s->buffer + s->len;
+       s->len += len;
+
+       return ret;
+}
+
 int trace_seq_path(struct trace_seq *s, struct path *path)
 {
        unsigned char *p;
@@ -309,9 +354,9 @@ static int
 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
 {
        int hardirq, softirq;
-       char *comm;
+       char comm[TASK_COMM_LEN];
 
-       comm = trace_find_cmdline(entry->pid);
+       trace_find_cmdline(entry->pid, comm);
        hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
        softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
 
@@ -346,10 +391,12 @@ int trace_print_context(struct trace_iterator *iter)
 {
        struct trace_seq *s = &iter->seq;
        struct trace_entry *entry = iter->ent;
-       char *comm = trace_find_cmdline(entry->pid);
        unsigned long long t = ns2usecs(iter->ts);
        unsigned long usec_rem = do_div(t, USEC_PER_SEC);
        unsigned long secs = (unsigned long)t;
+       char comm[TASK_COMM_LEN];
+
+       trace_find_cmdline(entry->pid, comm);
 
        return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
                                comm, entry->pid, iter->cpu, secs, usec_rem);
@@ -372,8 +419,11 @@ int trace_print_lat_context(struct trace_iterator *iter)
        rel_usecs = ns2usecs(next_ts - iter->ts);
 
        if (verbose) {
-               char *comm = trace_find_cmdline(entry->pid);
-               ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
+               char comm[TASK_COMM_LEN];
+
+               trace_find_cmdline(entry->pid, comm);
+
+               ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
                                       " %ld.%03ldms (+%ld.%03ldms): ", comm,
                                       entry->pid, iter->cpu, entry->flags,
                                       entry->preempt_count, iter->idx,
@@ -444,6 +494,11 @@ int register_ftrace_event(struct trace_event *event)
 
        mutex_lock(&trace_event_mutex);
 
+       if (!event) {
+               ret = next_event_type++;
+               goto out;
+       }
+
        if (!event->type)
                event->type = next_event_type++;
        else if (event->type > __TRACE_LAST_TYPE) {
@@ -565,7 +620,7 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
 }
 
 static struct trace_event trace_fn_event = {
-       .type           = TRACE_FN,
+       .type           = TRACE_FN,
        .trace          = trace_fn_trace,
        .raw            = trace_fn_raw,
        .hex            = trace_fn_hex,
@@ -577,14 +632,15 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
                                             char *delim)
 {
        struct ctx_switch_entry *field;
-       char *comm;
+       char comm[TASK_COMM_LEN];
        int S, T;
 
+
        trace_assign_type(field, iter->ent);
 
        T = task_state_char(field->next_state);
        S = task_state_char(field->prev_state);
-       comm = trace_find_cmdline(field->next_pid);
+       trace_find_cmdline(field->next_pid, comm);
        if (!trace_seq_printf(&iter->seq,
                              " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
                              field->prev_pid,
@@ -696,7 +752,7 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
 }
 
 static struct trace_event trace_ctx_event = {
-       .type           = TRACE_CTX,
+       .type           = TRACE_CTX,
        .trace          = trace_ctx_print,
        .raw            = trace_ctx_raw,
        .hex            = trace_ctx_hex,
@@ -704,7 +760,7 @@ static struct trace_event trace_ctx_event = {
 };
 
 static struct trace_event trace_wake_event = {
-       .type           = TRACE_WAKE,
+       .type           = TRACE_WAKE,
        .trace          = trace_wake_print,
        .raw            = trace_wake_raw,
        .hex            = trace_wake_hex,
@@ -759,7 +815,7 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter,
 }
 
 static struct trace_event trace_special_event = {
-       .type           = TRACE_SPECIAL,
+       .type           = TRACE_SPECIAL,
        .trace          = trace_special_print,
        .raw            = trace_special_print,
        .hex            = trace_special_hex,
@@ -796,7 +852,7 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter,
 }
 
 static struct trace_event trace_stack_event = {
-       .type           = TRACE_STACK,
+       .type           = TRACE_STACK,
        .trace          = trace_stack_print,
        .raw            = trace_special_print,
        .hex            = trace_special_hex,
@@ -825,20 +881,20 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
 }
 
 static struct trace_event trace_user_stack_event = {
-       .type           = TRACE_USER_STACK,
+       .type           = TRACE_USER_STACK,
        .trace          = trace_user_stack_print,
        .raw            = trace_special_print,
        .hex            = trace_special_hex,
        .binary         = trace_special_bin,
 };
 
-/* TRACE_PRINT */
+/* TRACE_BPRINT */
 static enum print_line_t
-trace_print_print(struct trace_iterator *iter, int flags)
+trace_bprint_print(struct trace_iterator *iter, int flags)
 {
        struct trace_entry *entry = iter->ent;
        struct trace_seq *s = &iter->seq;
-       struct print_entry *field;
+       struct bprint_entry *field;
 
        trace_assign_type(field, entry);
 
@@ -858,9 +914,10 @@ trace_print_print(struct trace_iterator *iter, int flags)
 }
 
 
-static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
+static enum print_line_t
+trace_bprint_raw(struct trace_iterator *iter, int flags)
 {
-       struct print_entry *field;
+       struct bprint_entry *field;
        struct trace_seq *s = &iter->seq;
 
        trace_assign_type(field, iter->ent);
@@ -878,12 +935,55 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
 }
 
 
+static struct trace_event trace_bprint_event = {
+       .type           = TRACE_BPRINT,
+       .trace          = trace_bprint_print,
+       .raw            = trace_bprint_raw,
+};
+
+/* TRACE_PRINT */
+static enum print_line_t trace_print_print(struct trace_iterator *iter,
+                                          int flags)
+{
+       struct print_entry *field;
+       struct trace_seq *s = &iter->seq;
+
+       trace_assign_type(field, iter->ent);
+
+       if (!seq_print_ip_sym(s, field->ip, flags))
+               goto partial;
+
+       if (!trace_seq_printf(s, ": %s", field->buf))
+               goto partial;
+
+       return TRACE_TYPE_HANDLED;
+
+ partial:
+       return TRACE_TYPE_PARTIAL_LINE;
+}
+
+static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
+{
+       struct print_entry *field;
+
+       trace_assign_type(field, iter->ent);
+
+       if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
+               goto partial;
+
+       return TRACE_TYPE_HANDLED;
+
+ partial:
+       return TRACE_TYPE_PARTIAL_LINE;
+}
+
 static struct trace_event trace_print_event = {
        .type           = TRACE_PRINT,
        .trace          = trace_print_print,
        .raw            = trace_print_raw,
 };
 
+
 static struct trace_event *events[] __initdata = {
        &trace_fn_event,
        &trace_ctx_event,
@@ -891,6 +991,7 @@ static struct trace_event *events[] __initdata = {
        &trace_special_event,
        &trace_stack_event,
        &trace_user_stack_event,
+       &trace_bprint_event,
        &trace_print_event,
        NULL
 };