From 4c2732a1dad1de295c9219ee3afac007b2d7ba05 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 28 Jan 2009 14:36:08 -0800 Subject: Use 'static' as much as possible This change just inserts 'static' on runtime, tapset, and generated C functions and globals, so the compiler can do a better job of optimizing. My tests with small scripts show ~10% reduction in compile time and ~20% reduction in module size. Larger scripts may show less benefit, but I expect purely positive results. --- runtime/task_finder.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'runtime/task_finder.c') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index f982eef1..d9a4cedb 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -22,14 +22,14 @@ struct stap_task_finder_target; #define __STP_TF_RUNNING 1 #define __STP_TF_STOPPING 2 #define __STP_TF_STOPPED 3 -atomic_t __stp_task_finder_state = ATOMIC_INIT(__STP_TF_STARTING); -atomic_t __stp_inuse_count = ATOMIC_INIT (0); +static atomic_t __stp_task_finder_state = ATOMIC_INIT(__STP_TF_STARTING); +static atomic_t __stp_inuse_count = ATOMIC_INIT (0); #define __stp_tf_handler_start() (atomic_inc(&__stp_inuse_count)) #define __stp_tf_handler_end() (atomic_dec(&__stp_inuse_count)) #ifdef DEBUG_TASK_FINDER -atomic_t __stp_attach_count = ATOMIC_INIT (0); +static atomic_t __stp_attach_count = ATOMIC_INIT (0); #define debug_task_finder_attach() (atomic_inc(&__stp_attach_count)) #define debug_task_finder_detach() (atomic_dec(&__stp_attach_count)) @@ -56,7 +56,7 @@ typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt, unsigned long vm_pgoff); #ifdef DEBUG_TASK_FINDER_VMA -int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, +static int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, struct task_struct *tsk, int map_p, char *vm_path, unsigned long vm_start, @@ -907,7 +907,7 @@ utftq_out: } -struct vm_area_struct * +static struct vm_area_struct * __stp_find_file_based_vma(struct mm_struct *mm, unsigned long addr) { struct vm_area_struct *vma = find_vma(mm, addr); @@ -1208,7 +1208,7 @@ struct utrace_engine_ops __stp_utrace_task_finder_ops = { .report_death = stap_utrace_task_finder_report_death, }; -int +static int stap_start_task_finder(void) { int rc = 0; -- cgit From 7c657805a80358ce2429415af931ca1546c2c2d2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 10 Feb 2009 06:54:12 -0600 Subject: Ignores kernel threads (by checking for PF_KTHREAD). 2009-02-10 David Smith * task_finder.c (stap_utrace_detach): Ignores kernel threads by checking task's flags for PF_KTHREAD. (stap_utrace_detach_ops): Ditto. (__stp_utrace_attach): Ditto. --- runtime/task_finder.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'runtime/task_finder.c') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index d9a4cedb..af606356 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -220,6 +220,14 @@ stap_utrace_detach(struct task_struct *tsk, if (tsk == NULL || tsk->pid <= 1) return 0; +#ifdef PF_KTHREAD + // Ignore kernel threads. On systems without PF_KTHREAD, + // we're ok, since kernel threads won't be matched by the + // utrace_attach_task() call below. + if (tsk->flags & PF_KTHREAD) + return 0; +#endif + // Notice we're not calling get_task_mm() here. Normally we // avoid tasks with no mm, because those are kernel threads. // So, why is this function different? When a thread is in @@ -292,6 +300,14 @@ stap_utrace_detach_ops(struct utrace_engine_ops *ops) rcu_read_lock(); do_each_thread(grp, tsk) { +#ifdef PF_KTHREAD + // Ignore kernel threads. On systems without + // PF_KTHREAD, we're ok, since kernel threads won't be + // matched by the stap_utrace_detach() call. + if (task->flags & PF_KTHREAD) + continue; +#endif + rc = stap_utrace_detach(tsk, ops); if (rc != 0) goto udo_err; @@ -397,18 +413,26 @@ __stp_utrace_attach(struct task_struct *tsk, enum utrace_resume_action action) { struct utrace_attached_engine *engine; +#ifndef PF_KTHREAD struct mm_struct *mm; +#endif int rc = 0; // Ignore init if (tsk == NULL || tsk->pid <= 1) return EPERM; +#ifdef PF_KTHREAD + // Ignore kernel threads + if (task->flags & PF_KTHREAD) + return EPERM; +#else // Ignore threads with no mm (which are kernel threads). mm = get_task_mm(tsk); if (! mm) return EPERM; mmput(mm); +#endif engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data); if (IS_ERR(engine)) { -- cgit From ced8de1061ed47f7c3b0cfd4a7cedb338ab42f97 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 10 Feb 2009 09:11:50 -0600 Subject: Fixed typo in last change. 2009-02-10 David Smith * task_finder.c (stap_utrace_detach_ops): Fixed typo. (__stp_utrace_attach): Ditto. --- runtime/task_finder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/task_finder.c') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index af606356..e058c191 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -304,7 +304,7 @@ stap_utrace_detach_ops(struct utrace_engine_ops *ops) // Ignore kernel threads. On systems without // PF_KTHREAD, we're ok, since kernel threads won't be // matched by the stap_utrace_detach() call. - if (task->flags & PF_KTHREAD) + if (tsk->flags & PF_KTHREAD) continue; #endif @@ -424,7 +424,7 @@ __stp_utrace_attach(struct task_struct *tsk, #ifdef PF_KTHREAD // Ignore kernel threads - if (task->flags & PF_KTHREAD) + if (tsk->flags & PF_KTHREAD) return EPERM; #else // Ignore threads with no mm (which are kernel threads). -- cgit From f02fa988a4f37292d0da10f086901246d65013c0 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 11 Feb 2009 09:29:22 -0600 Subject: Fixed __stp_utrace_attach by always checking for mm. 2009-02-11 David Smith * task_finder.c (__stp_utrace_attach): Still checks for mm after checking task's flags for PF_KTHREAD. --- runtime/task_finder.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'runtime/task_finder.c') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index e058c191..9db713c3 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -413,9 +413,7 @@ __stp_utrace_attach(struct task_struct *tsk, enum utrace_resume_action action) { struct utrace_attached_engine *engine; -#ifndef PF_KTHREAD struct mm_struct *mm; -#endif int rc = 0; // Ignore init @@ -426,13 +424,14 @@ __stp_utrace_attach(struct task_struct *tsk, // Ignore kernel threads if (tsk->flags & PF_KTHREAD) return EPERM; -#else - // Ignore threads with no mm (which are kernel threads). +#endif + + // Ignore threads with no mm (which are either kernel threads + // or "mortally wounded" threads). mm = get_task_mm(tsk); if (! mm) return EPERM; mmput(mm); -#endif engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data); if (IS_ERR(engine)) { -- cgit