Use process struct flag to indicate tracing instead of scanning an array.
authorDavide Libenzi <dlibenzi@google.com>
Thu, 8 Oct 2015 19:28:07 +0000 (12:28 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 13 Oct 2015 19:28:35 +0000 (15:28 -0400)
Signed-off-by: Davide Libenzi <dlibenzi@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/env.h
kern/include/syscall.h
kern/src/syscall.c

index 575d019..f6fd7d2 100644 (file)
@@ -111,7 +111,8 @@ struct proc {
 typedef struct proc env_t;
 
 /* Process Flags */
-#define PROC_TRANSITION_TO_M                   0x0001
+#define PROC_TRANSITION_TO_M   (1 << 0)
+#define PROC_TRACED                            (1 << 1)
 
 extern atomic_t num_envs;              // Number of envs
 
@@ -122,4 +123,17 @@ void       env_pagetable_free(env_t* e);
 typedef int (*mem_walk_callback_t)(env_t* e, pte_t pte, void* va, void* arg);
 int            env_user_mem_walk(env_t* e, void* start, size_t len, mem_walk_callback_t callback, void* arg);
 
+static inline void set_traced_proc(struct proc *p, bool traced)
+{
+       if (traced)
+               p->env_flags |= PROC_TRACED;
+       else
+               p->env_flags &= ~PROC_TRACED;
+}
+
+static inline bool is_traced_proc(const struct proc *p)
+{
+       return (p->env_flags & PROC_TRACED) != 0;
+}
+
 #endif // !ROS_KERN_ENV_H
index 6589a36..b94c23d 100644 (file)
@@ -11,7 +11,6 @@
 #define SYSTRACE_LOUD                          0x02
 #define SYSTRACE_ALLPROC                       0x04
 
-#define MAX_NUM_TRACED                         10
 #define MAX_SYSTRACES                          1024
 
 #define SYSCALL_STRLEN                         128
index a703837..a3e8174 100644 (file)
@@ -39,25 +39,15 @@ int systrace_flags = 0;
 struct systrace_record *systrace_buffer = 0;
 uint32_t systrace_bufidx = 0;
 size_t systrace_bufsize = 0;
-struct proc *systrace_procs[MAX_NUM_TRACED] = {0};
 spinlock_t systrace_lock = SPINLOCK_INITIALIZER_IRQSAVE;
 
 // for now, only want this visible here.
 void kprof_write_sysrecord(char *pretty_buf, size_t len);
 
-/* Not enforcing the packing of systrace_procs yet, but don't rely on that */
-static bool proc_is_traced(struct proc *p)
-{
-       for (int i = 0; i < MAX_NUM_TRACED; i++)
-               if (systrace_procs[i] == p)
-                       return true;
-       return false;
-}
-
 static bool __trace_this_proc(struct proc *p)
 {
        return (systrace_flags & SYSTRACE_ON) &&
-              ((systrace_flags & SYSTRACE_ALLPROC) || (proc_is_traced(p)));
+               ((systrace_flags & SYSTRACE_ALLPROC) || is_traced_proc(p));
 }
 
 static size_t systrace_fill_pretty_buf(struct systrace_record *trace)
@@ -2524,7 +2514,7 @@ void run_local_syscall(struct syscall *sysc)
        if ((current_errstr()[0] != 0) && (!sysc->err))
                sysc->err = EUNSPECIFIED;
        finish_sysc(sysc, pcpui->cur_proc);
-       pcpui->cur_kthread->sysc = 0;   /* no longer working on sysc */
+       pcpui->cur_kthread->sysc = NULL;        /* No longer working on sysc */
 }
 
 /* A process can trap and call this function, which will set up the core to
@@ -2595,24 +2585,17 @@ void systrace_start(bool silent)
 
 int systrace_reg(bool all, struct proc *p)
 {
-       int retval = 0;
        spin_lock_irqsave(&systrace_lock);
        if (all) {
                printk("Tracing syscalls for all processes\n");
                systrace_flags |= SYSTRACE_ALLPROC;
-               retval = 0;
        } else {
-               for (int i = 0; i < MAX_NUM_TRACED; i++) {
-                       if (!systrace_procs[i]) {
-                               printk("Tracing syscalls for process %d\n", p->pid);
-                               systrace_procs[i] = p;
-                               retval = 0;
-                               break;
-                       }
-               }
+               set_traced_proc(p, TRUE);
+
+               printk("Tracing syscalls for process %d\n", p->pid);
        }
        spin_unlock_irqsave(&systrace_lock);
-       return retval;
+       return 0;
 }
 
 int systrace_trace_pid(struct proc *p)
@@ -2627,8 +2610,6 @@ void systrace_stop(void)
 {
        spin_lock_irqsave(&systrace_lock);
        systrace_flags = 0;
-       for (int i = 0; i < MAX_NUM_TRACED; i++)
-               systrace_procs[i] = 0;
        spin_unlock_irqsave(&systrace_lock);
 }
 
@@ -2641,12 +2622,9 @@ int systrace_dereg(bool all, struct proc *p)
                printk("No longer tracing syscalls for all processes.\n");
                systrace_flags &= ~SYSTRACE_ALLPROC;
        } else {
-               for (int i = 0; i < MAX_NUM_TRACED; i++) {
-                       if (systrace_procs[i] == p) {
-                               systrace_procs[i] = 0;
-                               printk("No longer tracing syscalls for process %d\n", p->pid);
-                       }
-               }
+               set_traced_proc(p, FALSE);
+
+               printk("No longer tracing syscalls for process %d\n", p->pid);
        }
        spin_unlock_irqsave(&systrace_lock);
        return 0;