aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_output.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-02-03 17:20:41 -0500
committerIngo Molnar <mingo@elte.hu>2009-02-04 14:48:30 -0500
commitd9793bd8018f835c64b10f44e278c86cecb8e932 (patch)
treeda5ad9bc8f3fc7b4eb4ecd398f7c52a6f112d544 /kernel/trace/trace_output.c
parentce70a0b472e06feae3a580ecb3fbef1e1e020a9b (diff)
trace: judicious error checking of trace_seq results
Impact: bugfix and cleanup Some callsites were returning either TRACE_ITER_PARTIAL_LINE if the trace_seq routines (trace_seq_printf, etc) returned 0 meaning its buffer was full, or zero otherwise. But... /* Return values for print_line callback */ enum print_line_t { TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */ TRACE_TYPE_HANDLED = 1, TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */ }; In other cases the return value was not being relayed at all. Most of the time it didn't hurt because the page wasn't get filled, but for correctness sake, handle the return values everywhere. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace_output.c')
-rw-r--r--kernel/trace/trace_output.c123
1 files changed, 51 insertions, 72 deletions
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index c24503b281a..5b3c914053f 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -286,55 +286,41 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
286 return ret; 286 return ret;
287} 287}
288 288
289static void 289static int
290lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) 290lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
291{ 291{
292 int hardirq, softirq; 292 int hardirq, softirq;
293 char *comm; 293 char *comm;
294 294
295 comm = trace_find_cmdline(entry->pid); 295 comm = trace_find_cmdline(entry->pid);
296
297 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
298 trace_seq_printf(s, "%3d", cpu);
299 trace_seq_printf(s, "%c%c",
300 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
301 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
302 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
303
304 hardirq = entry->flags & TRACE_FLAG_HARDIRQ; 296 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
305 softirq = entry->flags & TRACE_FLAG_SOFTIRQ; 297 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
306 if (hardirq && softirq) { 298
307 trace_seq_putc(s, 'H'); 299 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
308 } else { 300 comm, entry->pid, cpu,
309 if (hardirq) { 301 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
310 trace_seq_putc(s, 'h'); 302 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
311 } else { 303 'X' : '.',
312 if (softirq) 304 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
313 trace_seq_putc(s, 's'); 305 'N' : '.',
314 else 306 (hardirq && softirq) ? 'H' :
315 trace_seq_putc(s, '.'); 307 hardirq ? 'h' : softirq ? 's' : '.'))
316 } 308 return 0;
317 }
318 309
319 if (entry->preempt_count) 310 if (entry->preempt_count)
320 trace_seq_printf(s, "%x", entry->preempt_count); 311 return trace_seq_printf(s, "%x", entry->preempt_count);
321 else 312 return trace_seq_puts(s, ".");
322 trace_seq_puts(s, ".");
323} 313}
324 314
325static unsigned long preempt_mark_thresh = 100; 315static unsigned long preempt_mark_thresh = 100;
326 316
327static void 317static int
328lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, 318lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
329 unsigned long rel_usecs) 319 unsigned long rel_usecs)
330{ 320{
331 trace_seq_printf(s, " %4lldus", abs_usecs); 321 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
332 if (rel_usecs > preempt_mark_thresh) 322 rel_usecs > preempt_mark_thresh ? '!' :
333 trace_seq_puts(s, "!: "); 323 rel_usecs > 1 ? '+' : ' ');
334 else if (rel_usecs > 1)
335 trace_seq_puts(s, "+: ");
336 else
337 trace_seq_puts(s, " : ");
338} 324}
339 325
340int trace_print_context(struct trace_iterator *iter) 326int trace_print_context(struct trace_iterator *iter)
@@ -346,22 +332,14 @@ int trace_print_context(struct trace_iterator *iter)
346 unsigned long usec_rem = do_div(t, USEC_PER_SEC); 332 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
347 unsigned long secs = (unsigned long)t; 333 unsigned long secs = (unsigned long)t;
348 334
349 if (!trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid)) 335 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
350 goto partial; 336 comm, entry->pid, entry->cpu, secs, usec_rem);
351 if (!trace_seq_printf(s, "[%03d] ", entry->cpu))
352 goto partial;
353 if (!trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem))
354 goto partial;
355
356 return 0;
357
358partial:
359 return TRACE_TYPE_PARTIAL_LINE;
360} 337}
361 338
362int trace_print_lat_context(struct trace_iterator *iter) 339int trace_print_lat_context(struct trace_iterator *iter)
363{ 340{
364 u64 next_ts; 341 u64 next_ts;
342 int ret;
365 struct trace_seq *s = &iter->seq; 343 struct trace_seq *s = &iter->seq;
366 struct trace_entry *entry = iter->ent, 344 struct trace_entry *entry = iter->ent,
367 *next_entry = trace_find_next_entry(iter, NULL, 345 *next_entry = trace_find_next_entry(iter, NULL,
@@ -376,21 +354,22 @@ int trace_print_lat_context(struct trace_iterator *iter)
376 354
377 if (verbose) { 355 if (verbose) {
378 char *comm = trace_find_cmdline(entry->pid); 356 char *comm = trace_find_cmdline(entry->pid);
379 trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]" 357 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
380 " %ld.%03ldms (+%ld.%03ldms): ", 358 " %ld.%03ldms (+%ld.%03ldms): ", comm,
381 comm, 359 entry->pid, entry->cpu, entry->flags,
382 entry->pid, entry->cpu, entry->flags, 360 entry->preempt_count, iter->idx,
383 entry->preempt_count, iter->idx, 361 ns2usecs(iter->ts),
384 ns2usecs(iter->ts), 362 abs_usecs / USEC_PER_MSEC,
385 abs_usecs/1000, 363 abs_usecs % USEC_PER_MSEC,
386 abs_usecs % 1000, rel_usecs/1000, 364 rel_usecs / USEC_PER_MSEC,
387 rel_usecs % 1000); 365 rel_usecs % USEC_PER_MSEC);
388 } else { 366 } else {
389 lat_print_generic(s, entry, entry->cpu); 367 ret = lat_print_generic(s, entry, entry->cpu);
390 lat_print_timestamp(s, abs_usecs, rel_usecs); 368 if (ret)
369 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
391 } 370 }
392 371
393 return 0; 372 return ret;
394} 373}
395 374
396static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; 375static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
@@ -486,7 +465,7 @@ int unregister_ftrace_event(struct trace_event *event)
486 465
487int trace_nop_print(struct trace_iterator *iter, int flags) 466int trace_nop_print(struct trace_iterator *iter, int flags)
488{ 467{
489 return 0; 468 return TRACE_TYPE_HANDLED;
490} 469}
491 470
492/* TRACE_FN */ 471/* TRACE_FN */
@@ -506,7 +485,7 @@ static int trace_fn_latency(struct trace_iterator *iter, int flags)
506 if (!trace_seq_puts(s, ")\n")) 485 if (!trace_seq_puts(s, ")\n"))
507 goto partial; 486 goto partial;
508 487
509 return 0; 488 return TRACE_TYPE_HANDLED;
510 489
511 partial: 490 partial:
512 return TRACE_TYPE_PARTIAL_LINE; 491 return TRACE_TYPE_PARTIAL_LINE;
@@ -533,7 +512,7 @@ static int trace_fn_trace(struct trace_iterator *iter, int flags)
533 if (!trace_seq_printf(s, "\n")) 512 if (!trace_seq_printf(s, "\n"))
534 goto partial; 513 goto partial;
535 514
536 return 0; 515 return TRACE_TYPE_HANDLED;
537 516
538 partial: 517 partial:
539 return TRACE_TYPE_PARTIAL_LINE; 518 return TRACE_TYPE_PARTIAL_LINE;
@@ -550,7 +529,7 @@ static int trace_fn_raw(struct trace_iterator *iter, int flags)
550 field->parent_ip)) 529 field->parent_ip))
551 return TRACE_TYPE_PARTIAL_LINE; 530 return TRACE_TYPE_PARTIAL_LINE;
552 531
553 return 0; 532 return TRACE_TYPE_HANDLED;
554} 533}
555 534
556static int trace_fn_hex(struct trace_iterator *iter, int flags) 535static int trace_fn_hex(struct trace_iterator *iter, int flags)
@@ -563,7 +542,7 @@ static int trace_fn_hex(struct trace_iterator *iter, int flags)
563 SEQ_PUT_HEX_FIELD_RET(s, field->ip); 542 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
564 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); 543 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
565 544
566 return 0; 545 return TRACE_TYPE_HANDLED;
567} 546}
568 547
569static int trace_fn_bin(struct trace_iterator *iter, int flags) 548static int trace_fn_bin(struct trace_iterator *iter, int flags)
@@ -576,7 +555,7 @@ static int trace_fn_bin(struct trace_iterator *iter, int flags)
576 SEQ_PUT_FIELD_RET(s, field->ip); 555 SEQ_PUT_FIELD_RET(s, field->ip);
577 SEQ_PUT_FIELD_RET(s, field->parent_ip); 556 SEQ_PUT_FIELD_RET(s, field->parent_ip);
578 557
579 return 0; 558 return TRACE_TYPE_HANDLED;
580} 559}
581 560
582static struct trace_event trace_fn_event = { 561static struct trace_event trace_fn_event = {
@@ -611,7 +590,7 @@ static int trace_ctxwake_print(struct trace_iterator *iter, char *delim)
611 T, comm)) 590 T, comm))
612 return TRACE_TYPE_PARTIAL_LINE; 591 return TRACE_TYPE_PARTIAL_LINE;
613 592
614 return 0; 593 return TRACE_TYPE_HANDLED;
615} 594}
616 595
617static int trace_ctx_print(struct trace_iterator *iter, int flags) 596static int trace_ctx_print(struct trace_iterator *iter, int flags)
@@ -644,7 +623,7 @@ static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
644 T)) 623 T))
645 return TRACE_TYPE_PARTIAL_LINE; 624 return TRACE_TYPE_PARTIAL_LINE;
646 625
647 return 0; 626 return TRACE_TYPE_HANDLED;
648} 627}
649 628
650static int trace_ctx_raw(struct trace_iterator *iter, int flags) 629static int trace_ctx_raw(struct trace_iterator *iter, int flags)
@@ -678,7 +657,7 @@ static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
678 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); 657 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
679 SEQ_PUT_HEX_FIELD_RET(s, T); 658 SEQ_PUT_HEX_FIELD_RET(s, T);
680 659
681 return 0; 660 return TRACE_TYPE_HANDLED;
682} 661}
683 662
684static int trace_ctx_hex(struct trace_iterator *iter, int flags) 663static int trace_ctx_hex(struct trace_iterator *iter, int flags)
@@ -705,7 +684,7 @@ static int trace_ctxwake_bin(struct trace_iterator *iter, int flags)
705 SEQ_PUT_FIELD_RET(s, field->next_prio); 684 SEQ_PUT_FIELD_RET(s, field->next_prio);
706 SEQ_PUT_FIELD_RET(s, field->next_state); 685 SEQ_PUT_FIELD_RET(s, field->next_state);
707 686
708 return 0; 687 return TRACE_TYPE_HANDLED;
709} 688}
710 689
711static struct trace_event trace_ctx_event = { 690static struct trace_event trace_ctx_event = {
@@ -739,7 +718,7 @@ static int trace_special_print(struct trace_iterator *iter, int flags)
739 field->arg3)) 718 field->arg3))
740 return TRACE_TYPE_PARTIAL_LINE; 719 return TRACE_TYPE_PARTIAL_LINE;
741 720
742 return 0; 721 return TRACE_TYPE_HANDLED;
743} 722}
744 723
745static int trace_special_hex(struct trace_iterator *iter, int flags) 724static int trace_special_hex(struct trace_iterator *iter, int flags)
@@ -753,7 +732,7 @@ static int trace_special_hex(struct trace_iterator *iter, int flags)
753 SEQ_PUT_HEX_FIELD_RET(s, field->arg2); 732 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
754 SEQ_PUT_HEX_FIELD_RET(s, field->arg3); 733 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
755 734
756 return 0; 735 return TRACE_TYPE_HANDLED;
757} 736}
758 737
759static int trace_special_bin(struct trace_iterator *iter, int flags) 738static int trace_special_bin(struct trace_iterator *iter, int flags)
@@ -767,7 +746,7 @@ static int trace_special_bin(struct trace_iterator *iter, int flags)
767 SEQ_PUT_FIELD_RET(s, field->arg2); 746 SEQ_PUT_FIELD_RET(s, field->arg2);
768 SEQ_PUT_FIELD_RET(s, field->arg3); 747 SEQ_PUT_FIELD_RET(s, field->arg3);
769 748
770 return 0; 749 return TRACE_TYPE_HANDLED;
771} 750}
772 751
773static struct trace_event trace_special_event = { 752static struct trace_event trace_special_event = {
@@ -801,7 +780,7 @@ static int trace_stack_print(struct trace_iterator *iter, int flags)
801 goto partial; 780 goto partial;
802 } 781 }
803 782
804 return 0; 783 return TRACE_TYPE_HANDLED;
805 784
806 partial: 785 partial:
807 return TRACE_TYPE_PARTIAL_LINE; 786 return TRACE_TYPE_PARTIAL_LINE;
@@ -830,7 +809,7 @@ static int trace_user_stack_print(struct trace_iterator *iter, int flags)
830 if (!trace_seq_putc(s, '\n')) 809 if (!trace_seq_putc(s, '\n'))
831 goto partial; 810 goto partial;
832 811
833 return 0; 812 return TRACE_TYPE_HANDLED;
834 813
835 partial: 814 partial:
836 return TRACE_TYPE_PARTIAL_LINE; 815 return TRACE_TYPE_PARTIAL_LINE;
@@ -859,7 +838,7 @@ static int trace_print_print(struct trace_iterator *iter, int flags)
859 if (!trace_seq_printf(s, ": %s", field->buf)) 838 if (!trace_seq_printf(s, ": %s", field->buf))
860 goto partial; 839 goto partial;
861 840
862 return 0; 841 return TRACE_TYPE_HANDLED;
863 842
864 partial: 843 partial:
865 return TRACE_TYPE_PARTIAL_LINE; 844 return TRACE_TYPE_PARTIAL_LINE;
@@ -874,7 +853,7 @@ static int trace_print_raw(struct trace_iterator *iter, int flags)
874 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf)) 853 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
875 goto partial; 854 goto partial;
876 855
877 return 0; 856 return TRACE_TYPE_HANDLED;
878 857
879 partial: 858 partial:
880 return TRACE_TYPE_PARTIAL_LINE; 859 return TRACE_TYPE_PARTIAL_LINE;