aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a2d13e8c8fd8..c95b7292be70 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -641,6 +641,7 @@ void tracing_reset_online_cpus(struct trace_array *tr)
641} 641}
642 642
643#define SAVED_CMDLINES 128 643#define SAVED_CMDLINES 128
644#define NO_CMDLINE_MAP UINT_MAX
644static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; 645static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
645static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; 646static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
646static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; 647static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
@@ -652,8 +653,8 @@ static atomic_t trace_record_cmdline_disabled __read_mostly;
652 653
653static void trace_init_cmdlines(void) 654static void trace_init_cmdlines(void)
654{ 655{
655 memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline)); 656 memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline));
656 memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid)); 657 memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid));
657 cmdline_idx = 0; 658 cmdline_idx = 0;
658} 659}
659 660
@@ -745,8 +746,7 @@ void trace_stop_cmdline_recording(void);
745 746
746static void trace_save_cmdline(struct task_struct *tsk) 747static void trace_save_cmdline(struct task_struct *tsk)
747{ 748{
748 unsigned map; 749 unsigned pid, idx;
749 unsigned idx;
750 750
751 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) 751 if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
752 return; 752 return;
@@ -761,13 +761,20 @@ static void trace_save_cmdline(struct task_struct *tsk)
761 return; 761 return;
762 762
763 idx = map_pid_to_cmdline[tsk->pid]; 763 idx = map_pid_to_cmdline[tsk->pid];
764 if (idx >= SAVED_CMDLINES) { 764 if (idx == NO_CMDLINE_MAP) {
765 idx = (cmdline_idx + 1) % SAVED_CMDLINES; 765 idx = (cmdline_idx + 1) % SAVED_CMDLINES;
766 766
767 map = map_cmdline_to_pid[idx]; 767 /*
768 if (map <= PID_MAX_DEFAULT) 768 * Check whether the cmdline buffer at idx has a pid
769 map_pid_to_cmdline[map] = (unsigned)-1; 769 * mapped. We are going to overwrite that entry so we
770 * need to clear the map_pid_to_cmdline. Otherwise we
771 * would read the new comm for the old pid.
772 */
773 pid = map_cmdline_to_pid[idx];
774 if (pid != NO_CMDLINE_MAP)
775 map_pid_to_cmdline[pid] = NO_CMDLINE_MAP;
770 776
777 map_cmdline_to_pid[idx] = tsk->pid;
771 map_pid_to_cmdline[tsk->pid] = idx; 778 map_pid_to_cmdline[tsk->pid] = idx;
772 779
773 cmdline_idx = idx; 780 cmdline_idx = idx;
@@ -794,18 +801,18 @@ void trace_find_cmdline(int pid, char comm[])
794 801
795 __raw_spin_lock(&trace_cmdline_lock); 802 __raw_spin_lock(&trace_cmdline_lock);
796 map = map_pid_to_cmdline[pid]; 803 map = map_pid_to_cmdline[pid];
797 if (map >= SAVED_CMDLINES) 804 if (map != NO_CMDLINE_MAP)
798 goto out; 805 strcpy(comm, saved_cmdlines[map]);
799 806 else
800 strcpy(comm, saved_cmdlines[map]); 807 strcpy(comm, "<...>");
801 808
802 out:
803 __raw_spin_unlock(&trace_cmdline_lock); 809 __raw_spin_unlock(&trace_cmdline_lock);
804} 810}
805 811
806void tracing_record_cmdline(struct task_struct *tsk) 812void tracing_record_cmdline(struct task_struct *tsk)
807{ 813{
808 if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) 814 if (atomic_read(&trace_record_cmdline_disabled) || !tracer_enabled ||
815 !tracing_is_on())
809 return; 816 return;
810 817
811 trace_save_cmdline(tsk); 818 trace_save_cmdline(tsk);