From 4619ee1a42fe841d48abca30e77c59e68882cce1 Mon Sep 17 00:00:00 2001 From: Liujie Xie Date: Wed, 29 Dec 2021 10:16:50 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks for binder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to add some hooks in the binder module so that we can reduce block time until binder thread is available Here are what new hooks do for: 1、android_vh_binder_looper_state_registered: choose a binder thread(do proc work) as a low-level thread.Only this thread has power to excute background binder transaction. 2、android_vh_binder_thread_read: let binder thread do works which come from our list. 3、android_vh_binder_free_proc: free some pointers and variable. 4、android_vh_binder_thread_release: free the list that we create before. 5、android_vh_binder_has_work_ilocked: to check if our list has work. 6、android_vh_binder_read_done: because of we add hook in binder_has_work_ilocked, 7、android_vh_binder_preset: mark target proc's binder threads. binder_has_work_ilocked may return true, so we try to wake up low-level thread immediately. Bug: 212483521 Change-Id: Ic40f452cc4dcf8fc85422e23e6f1a7ad77547309 Signed-off-by: Liujie Xie (cherry picked from commit 8d6074509e4ec7e10acf6ee78277ff8cd19e49d0) --- drivers/android/binder.c | 12 +++++++++++- drivers/android/vendor_hooks.c | 7 +++++++ include/trace/hooks/binder.h | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index a8cf17177c45..a4ca35b4088f 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -542,6 +542,11 @@ static void binder_inc_node_tmpref_ilocked(struct binder_node *node); static bool binder_has_work_ilocked(struct binder_thread *thread, bool do_proc_work) { + int ret = 0; + + trace_android_vh_binder_has_work_ilocked(thread, do_proc_work, &ret); + if (ret) + return true; return thread->process_todo || thread->looper_need_return || (do_proc_work && @@ -4215,6 +4220,7 @@ static int binder_thread_write(struct binder_proc *proc, } thread->looper |= BINDER_LOOPER_STATE_REGISTERED; binder_inner_proc_unlock(proc); + trace_android_vh_binder_looper_state_registered(thread, proc); break; case BC_ENTER_LOOPER: binder_debug(BINDER_DEBUG_THREADS, @@ -4626,6 +4632,7 @@ retry: binder_inner_proc_unlock(proc); break; } + trace_android_vh_binder_thread_read(&list, proc, thread); w = binder_dequeue_work_head_ilocked(list); if (binder_worklist_empty_ilocked(&thread->todo)) thread->process_todo = false; @@ -5089,6 +5096,7 @@ static void binder_free_proc(struct binder_proc *proc) put_task_struct(proc->tsk); put_cred(proc->cred); binder_stats_deleted(BINDER_STAT_PROC); + trace_android_vh_binder_free_proc(proc); kfree(proc); } @@ -5187,6 +5195,7 @@ static int binder_thread_release(struct binder_proc *proc, if (send_reply) binder_send_failed_reply(send_reply, BR_DEAD_REPLY); binder_release_work(proc, &thread->todo); + trace_android_vh_binder_thread_release(proc, thread); binder_thread_dec_tmpref(thread); return active_transactions; } @@ -5263,6 +5272,7 @@ static int binder_ioctl_write_read(struct file *filp, if (!binder_worklist_empty_ilocked(&proc->todo)) binder_wakeup_proc_ilocked(proc); binder_inner_proc_unlock(proc); + trace_android_vh_binder_read_done(proc, thread); if (ret < 0) { if (copy_to_user(ubuf, &bwr, sizeof(bwr))) ret = -EFAULT; @@ -5848,7 +5858,7 @@ static int binder_open(struct inode *nodp, struct file *filp) } hlist_add_head(&proc->proc_node, &binder_procs); mutex_unlock(&binder_procs_lock); - + trace_android_vh_binder_preset(&binder_procs, &binder_procs_lock); if (binder_debugfs_dir_entry_proc && !existing_pid) { char strbuf[11]; diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 49e7058ec32f..ff97e31dbb2d 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -204,3 +204,10 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_readahead_gfp_mask); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_mutex_list_add); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_unlock_slowpath); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_wake_finish); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_looper_state_registered); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_thread_read); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_free_proc); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_thread_release); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_has_work_ilocked); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_read_done); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_preset); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 00e1a6b9ca3c..7d32b97a3d7f 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -39,6 +39,28 @@ DECLARE_HOOK(android_vh_binder_proc_transaction_finish, TP_PROTO(struct binder_proc *proc, struct binder_transaction *t, struct task_struct *binder_th_task, bool pending_async, bool sync), TP_ARGS(proc, t, binder_th_task, pending_async, sync)); +DECLARE_HOOK(android_vh_binder_looper_state_registered, + TP_PROTO(struct binder_thread *thread, struct binder_proc *proc), + TP_ARGS(thread, proc)); +DECLARE_HOOK(android_vh_binder_thread_read, + TP_PROTO(struct list_head **list, struct binder_proc *proc, + struct binder_thread *thread), + TP_ARGS(list, proc, thread)); +DECLARE_HOOK(android_vh_binder_free_proc, + TP_PROTO(struct binder_proc *proc), + TP_ARGS(proc)); +DECLARE_HOOK(android_vh_binder_thread_release, + TP_PROTO(struct binder_proc *proc, struct binder_thread *thread), + TP_ARGS(proc, thread)); +DECLARE_HOOK(android_vh_binder_read_done, + TP_PROTO(struct binder_proc *proc, struct binder_thread *thread), + TP_ARGS(proc, thread)); +DECLARE_HOOK(android_vh_binder_has_work_ilocked, + TP_PROTO(struct binder_thread *thread, bool do_proc_work, int *ret), + TP_ARGS(thread, do_proc_work, ret)); +DECLARE_HOOK(android_vh_binder_preset, + TP_PROTO(struct hlist_head *hhead, struct mutex *lock), + TP_ARGS(hhead, lock)); #endif /* _TRACE_HOOK_BINDER_H */ /* This part must be outside protection */ #include