From: Matt Helsley Modify oprofile to use the task watcher chain to watch for task exit. oprofile uses task exit as a point to synch buffers. This patch does not modify oprofile to use the task free path of task watchers. oprofile has its own task_free atomic notifier chain. Since its an atomic chain we can't replace it with task watcher. Also, it's called much later when the actual task struct is really about to be freed. Signed-off-by: Matt Helsley Cc: Philippe Elie Cc: Signed-off-by: Andrew Morton --- drivers/oprofile/buffer_sync.c | 11 ++++++----- include/linux/profile.h | 3 +-- kernel/exit.c | 1 - kernel/profile.c | 14 -------------- 4 files changed, 7 insertions(+), 22 deletions(-) diff -puN drivers/oprofile/buffer_sync.c~task-watchers-register-profile-as-a-task-watcher drivers/oprofile/buffer_sync.c --- a/drivers/oprofile/buffer_sync.c~task-watchers-register-profile-as-a-task-watcher +++ a/drivers/oprofile/buffer_sync.c @@ -65,8 +65,9 @@ static int task_exit_notify(struct notif /* To avoid latency problems, we only process the current CPU, * hoping that most samples for the task are on this CPU */ - sync_buffer(raw_smp_processor_id()); - return 0; + if (get_watch_event(val) == WATCH_TASK_EXIT) + sync_buffer(raw_smp_processor_id()); + return NOTIFY_DONE; } @@ -152,7 +153,7 @@ int sync_start(void) err = task_handoff_register(&task_free_nb); if (err) goto out1; - err = profile_event_register(PROFILE_TASK_EXIT, &task_exit_nb); + err = register_task_watcher(&task_exit_nb); if (err) goto out2; err = profile_event_register(PROFILE_MUNMAP, &munmap_nb); @@ -167,7 +168,7 @@ out: out4: profile_event_unregister(PROFILE_MUNMAP, &munmap_nb); out3: - profile_event_unregister(PROFILE_TASK_EXIT, &task_exit_nb); + unregister_task_watcher(&task_exit_nb); out2: task_handoff_unregister(&task_free_nb); out1: @@ -180,7 +181,7 @@ void sync_stop(void) { unregister_module_notifier(&module_load_nb); profile_event_unregister(PROFILE_MUNMAP, &munmap_nb); - profile_event_unregister(PROFILE_TASK_EXIT, &task_exit_nb); + unregister_task_watcher(&task_exit_nb); task_handoff_unregister(&task_free_nb); end_sync(); } diff -puN include/linux/profile.h~task-watchers-register-profile-as-a-task-watcher include/linux/profile.h --- a/include/linux/profile.h~task-watchers-register-profile-as-a-task-watcher +++ a/include/linux/profile.h @@ -26,8 +26,7 @@ void create_prof_cpu_mask(struct proc_di #endif enum profile_type { - PROFILE_TASK_EXIT, - PROFILE_MUNMAP + PROFILE_MUNMAP = 1 }; #ifdef CONFIG_PROFILING diff -puN kernel/exit.c~task-watchers-register-profile-as-a-task-watcher kernel/exit.c --- a/kernel/exit.c~task-watchers-register-profile-as-a-task-watcher +++ a/kernel/exit.c @@ -848,7 +848,6 @@ fastcall NORET_TYPE void do_exit(long co unsigned int mycpu; int notify_result; - profile_task_exit(tsk); tsk->exit_code = code; notify_result = notify_watchers(WATCH_TASK_EXIT, tsk); diff -puN kernel/profile.c~task-watchers-register-profile-as-a-task-watcher kernel/profile.c --- a/kernel/profile.c~task-watchers-register-profile-as-a-task-watcher +++ a/kernel/profile.c @@ -86,15 +86,9 @@ void __init profile_init(void) #ifdef CONFIG_PROFILING -static BLOCKING_NOTIFIER_HEAD(task_exit_notifier); static ATOMIC_NOTIFIER_HEAD(task_free_notifier); static BLOCKING_NOTIFIER_HEAD(munmap_notifier); -void profile_task_exit(struct task_struct * task) -{ - blocking_notifier_call_chain(&task_exit_notifier, 0, task); -} - int profile_handoff_task(struct task_struct * task) { int ret; @@ -122,10 +116,6 @@ int profile_event_register(enum profile_ int err = -EINVAL; switch (type) { - case PROFILE_TASK_EXIT: - err = blocking_notifier_chain_register( - &task_exit_notifier, n); - break; case PROFILE_MUNMAP: err = blocking_notifier_chain_register( &munmap_notifier, n); @@ -141,10 +131,6 @@ int profile_event_unregister(enum profil int err = -EINVAL; switch (type) { - case PROFILE_TASK_EXIT: - err = blocking_notifier_chain_unregister( - &task_exit_notifier, n); - break; case PROFILE_MUNMAP: err = blocking_notifier_chain_unregister( &munmap_notifier, n); _