From 05c23b7a503851e3be7e68453899e0ed922016f7 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, 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 --- drivers/android/binder.c | 10 ++++++++++ drivers/android/vendor_hooks.c | 6 ++++++ include/trace/hooks/binder.h | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 78f8cf0d6626..dcbcadadaa4d 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -491,6 +491,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 && @@ -3620,6 +3625,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, @@ -4044,6 +4050,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; @@ -4510,6 +4517,7 @@ static void binder_free_proc(struct binder_proc *proc) put_task_struct(proc->tsk); put_cred(eproc->cred); binder_stats_deleted(BINDER_STAT_PROC); + trace_android_vh_binder_free_proc(proc); kfree(eproc); } @@ -4608,6 +4616,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; } @@ -4684,6 +4693,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; diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index b667f6919da0..f1e530388bd0 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -402,3 +402,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_css_online); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_free); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_alloc); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_subpage_dma_contig_alloc); +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); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 16dd0a2a6514..42d974f76573 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -79,7 +79,25 @@ DECLARE_HOOK(android_vh_binder_print_transaction_info, TP_PROTO(struct seq_file *m, struct binder_proc *proc, const char *prefix, struct binder_transaction *t), TP_ARGS(m, proc, prefix, t)); - +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)); /* macro versions of hooks are no longer required */ #endif /* _TRACE_HOOK_BINDER_H */