ftrace: add tracepoint for itimer
Subsystems (2)
PATCH 3/3 ftrace: add tracepoint for itimer
This patch can trace itimer start/expire/cancle event
Example ftrace output:
<...>-4183 [001] 66533.730163: itimer_start: task=main which=0 it_value=13000000000 it_interval=0
<idle>-0 [001] 66546.698154: itimer_expire: task=main which=0
<...>-4183 [000] 66546.698533: itimer_cancel: task=main which=0--- include/trace/events/timer.h | 66 ++++++++++++++++++++++++++++++++++++++++++ kernel/itimer.c | 17 +++++++++-- kernel/posix-cpu-timers.c | 3 ++ 3 files changed, 83 insertions(+), 3 deletions(-)
include/trace/events/timer.h +66 -0
@@ -175,6 +175,72 @@ TRACE_EVENT(hrtimer_cancel,TP_printk ("timer=%p func=%pf" , __entry->timer, __entry->function) ); +TRACE_EVENT (itimer_start, + + TP_PROTO(int which, struct itimerval *value), + +TP_ARGS (which, value), + +TP_STRUCT__entry ( + __field( int, which ) + __field( unsigned long long, it_value ) + __field( unsigned long long, it_interval ) +__string ( comm, current->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __entry->it_value = (which == ITIMER_REAL ? + ktime_to_ns(timeval_to_ktime(value->it_value)) : + timeval_to_cputime(&value->it_value)); + __entry->it_interval = (which == ITIMER_REAL ? + ktime_to_ns(timeval_to_ktime(value->it_interval)) : + timeval_to_cputime(&value->it_interval)); + __assign_str(comm, current->comm); + ), + +TP_printk ("task=%s which=%d it_value=%llu it_interval=%llu" ,__get_str (comm), + __entry->which, __entry->it_value, __entry->it_interval) +); + +TRACE_EVENT (itimer_expire, + + TP_PROTO(int which, struct task_struct *task), + +TP_ARGS (which, task), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, task->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, task->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); + +TRACE_EVENT (itimer_cancel, + + TP_PROTO(int which), + +TP_ARGS (which), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, current->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, current->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); +#endif /* _TRACE_TIMER_H */ /* This part must be outside protection */
kernel/itimer.c +14 -3
@@ -12,6 +12,7 @@#include <linux/time.h> #include <linux/posix-timers.h> #include <linux/hrtimer.h> +#include <trace/events/timer.h> #include <asm/uaccess.h>
@@ -123,6 +124,7 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)struct signal_struct *sig = container_of(timer, struct signal_struct, real_timer); +trace_itimer_expire (ITIMER_REAL ,pid_task (sig->leader_pid,PIDTYPE_PID ));kill_pid_info (SIGALRM ,SEND_SIG_PRIV , sig->leader_pid);return HRTIMER_NORESTART ;
@@ -168,8 +170,11 @@ again: tsk->signal->it_real_incr =timeval_to_ktime (value->it_interval);hrtimer_start (timer, expires,HRTIMER_MODE_REL ); - }else +trace_itimer_start (ITIMER_REAL , value); + }else { tsk->signal->it_real_incr.tv64 =0 ; +trace_itimer_cancel (ITIMER_REAL ); + }spin_unlock_irq (&tsk->sighand->siglock);break ;
@@ -186,7 +191,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_VIRT , &nval, &cval); - } +trace_itimer_start (ITIMER_VIRTUAL , value); + }else +trace_itimer_cancel (ITIMER_VIRTUAL ); + tsk->signal->it_virt_expires = nval; tsk->signal->it_virt_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);
@@ -208,7 +216,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_PROF , &nval, &cval); - } +trace_itimer_start (ITIMER_PROF , value); + }else +trace_itimer_cancel (ITIMER_PROF ); + tsk->signal->it_prof_expires = nval; tsk->signal->it_prof_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);
kernel/posix-cpu-timers.c +3 -0
@@ -8,6 +8,7 @@#include <linux/math64.h> #include <asm/uaccess.h> #include <linux/kernel_stat.h> +#include <trace/events/timer.h> /* * Called after updating RLIMIT_CPU to set timer expiration if necessary.
@@ -1160,6 +1161,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_prof_expires =cputime_add ( sig->it_prof_expires, ptime); } +trace_itimer_expire (ITIMER_PROF , tsk);__group_send_sig_info (SIGPROF ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_prof_expires, cputime_zero) &&
@@ -1176,6 +1178,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_virt_expires =cputime_add ( sig->it_virt_expires, utime); } +trace_itimer_expire (ITIMER_VIRTUAL , tsk);__group_send_sig_info (SIGVTALRM ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_virt_expires, cputime_zero) &&
Signature · 1 line
1.6.1.2
Steven Rostedt
maintainerQuoted 34 lines · Xiao Guangrong
This patch can trace itimer start/expire/cancle event
Example ftrace output:
<...>-4183 [001] 66533.730163: itimer_start: task=main which=0 it_value=13000000000 it_interval=0 <idle>-0 [001] 66546.698154: itimer_expire: task=main which=0 <...>-4183 [000] 66546.698533: itimer_cancel: task=main which=0Signed-off-by Mathieu Desnoyers <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>--- include/trace/events/timer.h | 66 ++++++++++++++++++++++++++++++++++++++++++ kernel/itimer.c | 17 +++++++++-- kernel/posix-cpu-timers.c | 3 ++ 3 files changed, 83 insertions(+), 3 deletions(-)include/trace/events/timer.h +11
-0@@ -175,6 +175,72 @@ TRACE_EVENT(hrtimer_cancel,TP_printk ("timer=%p func=%pf" , __entry->timer, __entry->function) ); +TRACE_EVENT(itimer_start, + + TP_PROTO(int which, struct itimerval *value), + + TP_ARGS(which, value), + + TP_STRUCT__entry( + __field( int, which ) + __field( unsigned long long, it_value ) + __field( unsigned long long, it_interval ) + __string( comm, current->comm )
include/trace/events/timer.h TRACE_EVENT(hrtimer_cancel, · line 198
Quoted 10 lines
include/trace/events/timer.h +10
-0+ ), + + TP_fast_assign( + __entry->which = which; + __entry->it_value = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_value)) : +timeval_to_cputime (&value->it_value)); + __entry->it_interval = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_interval)) : +timeval_to_cputime (&value->it_interval));
Wouldn't it be faster to do these time conversions in the printk instead of the trace point?
Quoted 137 lines
include/trace/events/timer.h +45
-0+__assign_str (comm, current->comm); + ), + +TP_printk ("task=%s which=%d it_value=%llu it_interval=%llu" ,__get_str (comm), + __entry->which, __entry->it_value, __entry->it_interval) +); + +TRACE_EVENT (itimer_expire, + + TP_PROTO(int which, struct task_struct *task), + +TP_ARGS (which, task), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, task->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, task->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); + +TRACE_EVENT (itimer_cancel, + + TP_PROTO(int which), + +TP_ARGS (which), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, current->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, current->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); +#endif /* _TRACE_TIMER_H */ /* This part must be outside protection */ kernel/itimer.c +14
-3@@ -12,6 +12,7 @@#include <linux/time.h> #include <linux/posix-timers.h> #include <linux/hrtimer.h> +#include <trace/events/timer.h> #include <asm/uaccess.h> @@ -123,6 +124,7 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)struct signal_struct *sig = container_of(timer, struct signal_struct, real_timer); +trace_itimer_expire (ITIMER_REAL ,pid_task (sig->leader_pid,PIDTYPE_PID ));kill_pid_info (SIGALRM ,SEND_SIG_PRIV , sig->leader_pid);return HRTIMER_NORESTART ;@@ -168,8 +170,11 @@ again: tsk->signal->it_real_incr =timeval_to_ktime (value->it_interval);hrtimer_start (timer, expires,HRTIMER_MODE_REL ); - }else +trace_itimer_start (ITIMER_REAL , value); + }else { tsk->signal->it_real_incr.tv64 =0 ; +trace_itimer_cancel (ITIMER_REAL ); + }spin_unlock_irq (&tsk->sighand->siglock);break ;@@ -186,7 +191,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_VIRT , &nval, &cval); - } +trace_itimer_start (ITIMER_VIRTUAL , value); + }else +trace_itimer_cancel (ITIMER_VIRTUAL ); + tsk->signal->it_virt_expires = nval; tsk->signal->it_virt_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);@@ -208,7 +216,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_PROF , &nval, &cval); - } +trace_itimer_start (ITIMER_PROF , value); + }else +trace_itimer_cancel (ITIMER_PROF ); + tsk->signal->it_prof_expires = nval; tsk->signal->it_prof_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);kernel/posix-cpu-timers.c +3
-0@@ -8,6 +8,7 @@#include <linux/math64.h> #include <asm/uaccess.h> #include <linux/kernel_stat.h> +#include <trace/events/timer.h> /* * Called after updating RLIMIT_CPU to set timer expiration if necessary. @@ -1160,6 +1161,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_prof_expires =cputime_add ( sig->it_prof_expires, ptime); } +trace_itimer_expire (ITIMER_PROF , tsk);__group_send_sig_info (SIGPROF ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_prof_expires, cputime_zero) &&@@ -1176,6 +1178,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_virt_expires =cputime_add ( sig->it_virt_expires, utime); } +trace_itimer_expire (ITIMER_VIRTUAL , tsk);__group_send_sig_info (SIGVTALRM ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_virt_expires, cputime_zero) &&Signature · 1 line
1.6.1.2
Quoted 42 lines · Steven Rostedt
Quoted 39 lines · Xiao Guangrong
This patch can trace itimer start/expire/cancle event
Example ftrace output:
<...>-4183 [001] 66533.730163: itimer_start: task=main which=0 it_value=13000000000 it_interval=0 <idle>-0 [001] 66546.698154: itimer_expire: task=main which=0 <...>-4183 [000] 66546.698533: itimer_cancel: task=main which=0Signed-off-by Mathieu Desnoyers <[email protected]>Signed-off-by Xiao Guangrong <[email protected]>--- include/trace/events/timer.h | 66 ++++++++++++++++++++++++++++++++++++++++++ kernel/itimer.c | 17 +++++++++-- kernel/posix-cpu-timers.c | 3 ++ 3 files changed, 83 insertions(+), 3 deletions(-)include/trace/events/timer.h +16
-0@@ -175,6 +175,72 @@ TRACE_EVENT(hrtimer_cancel,TP_printk ("timer=%p func=%pf" , __entry->timer, __entry->function) ); +TRACE_EVENT(itimer_start, + + TP_PROTO(int which, struct itimerval *value), + + TP_ARGS(which, value), + + TP_STRUCT__entry( + __field( int, which ) + __field( unsigned long long, it_value ) + __field( unsigned long long, it_interval ) + __string( comm, current->comm ) + ), + + TP_fast_assign( + __entry->which = which; + __entry->it_value = (which == ITIMER_REAL ?
Quoted 9 lines
include/trace/events/timer.h TRACE_EVENT(hrtimer_cancel, · line 198
Quoted 5 lines
include/trace/events/timer.h +5
-0+ ktime_to_ns(timeval_to_ktime(value->it_value)) : + timeval_to_cputime(&value->it_value)); + __entry->it_interval = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_interval)) : +timeval_to_cputime (&value->it_interval));Wouldn't it be faster to do these time conversions in the printk instead of the trace point?
Hi Steven:
Thank for you review, I will correct it.
:-)
Quoted 139 lines
Quoted 137 lines
include/trace/events/timer.h +45
-0+__assign_str (comm, current->comm); + ), + +TP_printk ("task=%s which=%d it_value=%llu it_interval=%llu" ,__get_str (comm), + __entry->which, __entry->it_value, __entry->it_interval) +); + +TRACE_EVENT (itimer_expire, + + TP_PROTO(int which, struct task_struct *task), + +TP_ARGS (which, task), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, task->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, task->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); + +TRACE_EVENT (itimer_cancel, + + TP_PROTO(int which), + +TP_ARGS (which), + +TP_STRUCT__entry ( + __field( int , which ) +__string ( comm, current->comm ) + ), + +TP_fast_assign ( + __entry->which = which; + __assign_str(comm, current->comm); + ), + +TP_printk ("task=%s which=%d" ,__get_str (comm), __entry->which) +); +#endif /* _TRACE_TIMER_H */ /* This part must be outside protection */ kernel/itimer.c +14
-3@@ -12,6 +12,7 @@#include <linux/time.h> #include <linux/posix-timers.h> #include <linux/hrtimer.h> +#include <trace/events/timer.h> #include <asm/uaccess.h> @@ -123,6 +124,7 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)struct signal_struct *sig = container_of(timer, struct signal_struct, real_timer); +trace_itimer_expire (ITIMER_REAL ,pid_task (sig->leader_pid,PIDTYPE_PID ));kill_pid_info (SIGALRM ,SEND_SIG_PRIV , sig->leader_pid);return HRTIMER_NORESTART ;@@ -168,8 +170,11 @@ again: tsk->signal->it_real_incr =timeval_to_ktime (value->it_interval);hrtimer_start (timer, expires,HRTIMER_MODE_REL ); - }else +trace_itimer_start (ITIMER_REAL , value); + }else { tsk->signal->it_real_incr.tv64 =0 ; +trace_itimer_cancel (ITIMER_REAL ); + }spin_unlock_irq (&tsk->sighand->siglock);break ;@@ -186,7 +191,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_VIRT , &nval, &cval); - } +trace_itimer_start (ITIMER_VIRTUAL , value); + }else +trace_itimer_cancel (ITIMER_VIRTUAL ); + tsk->signal->it_virt_expires = nval; tsk->signal->it_virt_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);@@ -208,7 +216,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_PROF , &nval, &cval); - } +trace_itimer_start (ITIMER_PROF , value); + }else +trace_itimer_cancel (ITIMER_PROF ); + tsk->signal->it_prof_expires = nval; tsk->signal->it_prof_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock);kernel/posix-cpu-timers.c +3
-0@@ -8,6 +8,7 @@#include <linux/math64.h> #include <asm/uaccess.h> #include <linux/kernel_stat.h> +#include <trace/events/timer.h> /* * Called after updating RLIMIT_CPU to set timer expiration if necessary. @@ -1160,6 +1161,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_prof_expires =cputime_add ( sig->it_prof_expires, ptime); } +trace_itimer_expire (ITIMER_PROF , tsk);__group_send_sig_info (SIGPROF ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_prof_expires, cputime_zero) &&@@ -1176,6 +1178,7 @@ static void check_process_timers(struct task_struct *tsk, sig->it_virt_expires =cputime_add ( sig->it_virt_expires, utime); } +trace_itimer_expire (ITIMER_VIRTUAL , tsk);__group_send_sig_info (SIGVTALRM ,SEND_SIG_PRIV , tsk); } if (!cputime_eq(sig->it_virt_expires, cputime_zero) &&Signature · 1 line
1.6.1.2
Quoted 13 lines · Xiao Guangrong
include/trace/events/timer.h +13
-0+TRACE_EVENT(itimer_start, + + TP_PROTO(int which, struct itimerval *value), + + TP_ARGS(which, value), + + TP_STRUCT__entry( + __field( int, which ) + __field( unsigned long long, it_value ) + __field( unsigned long long, it_interval ) + __string( comm, current->comm ) + ), +
include/trace/events/timer.h TRACE_EVENT(hrtimer_cancel, · line 200
Quoted 10 lines
include/trace/events/timer.h +10
-0+TP_fast_assign ( + __entry->which = which; + __entry->it_value = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_value)) : +timeval_to_cputime (&value->it_value)); + __entry->it_interval = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_interval)) : +timeval_to_cputime (&value->it_interval)); +__assign_str (comm, current->comm); + ),
Again, conversion of raw values needs to be done when we analyse the trace and not in the fast path.
....
kernel/itimer.c again: · line 174
Quoted 1 line
kernel/itimer.c +1
-0+ }else {
} else {please
kernel/itimer.c again: · line 195
Quoted 13 lines
kernel/itimer.c +4
-1tsk->signal->it_real_incr.tv64 =0 ; +trace_itimer_cancel (ITIMER_REAL ); + }spin_unlock_irq (&tsk->sighand->siglock);break ;@@ -186,7 +191,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_VIRT , &nval, &cval); - } +trace_itimer_start (ITIMER_VIRTUAL , value); + }else
Please run your patches through checkpatch.pl
Thanks,
tglx
Quoted 19 lines · Thomas Gleixner
Quoted 18 lines · Xiao Guangrong
include/trace/events/timer.h +18
-0+TRACE_EVENT(itimer_start, + + TP_PROTO(int which, struct itimerval *value), + + TP_ARGS(which, value), + + TP_STRUCT__entry( + __field( int, which ) + __field( unsigned long long, it_value ) + __field( unsigned long long, it_interval ) + __string( comm, current->comm ) + ), + + TP_fast_assign( + __entry->which = which; + __entry->it_value = (which == ITIMER_REAL ? + ktime_to_ns(timeval_to_ktime(value->it_value)) : + timeval_to_cputime(&value->it_value));
Quoted 9 lines
include/trace/events/timer.h TRACE_EVENT(hrtimer_cancel, · line 200
Quoted 5 lines
include/trace/events/timer.h +5
-0+ __entry->it_interval = (which ==ITIMER_REAL ? +ktime_to_ns (timeval_to_ktime (value->it_interval)) : +timeval_to_cputime (&value->it_interval)); +__assign_str (comm, current->comm); + ),Again, conversion of raw values needs to be done when we analyse the trace and not in the fast path.
OK
Quoted 11 lines
....
kernel/itimer.c again: · line 174
Quoted 1 line
kernel/itimer.c +1
-0+ }else {} else {please
Quoted 4 lines
kernel/itimer.c +2
-0tsk->signal->it_real_incr.tv64 =0 ; +trace_itimer_cancel (ITIMER_REAL ); + }
Quoted 12 lines
kernel/itimer.c again: · line 195
Quoted 9 lines
kernel/itimer.c +2
-1spin_unlock_irq (&tsk->sighand->siglock);break ;@@ -186,7 +191,10 @@ again: jiffies_to_cputime(1));set_process_cpu_timer (tsk,CPUCLOCK_VIRT , &nval, &cval); - } +trace_itimer_start (ITIMER_VIRTUAL , value); + }else Please run your patches through checkpatch.pl
Thank for you advice.
Quoted 5 lines
Thanks,
tglx