From e0d5caf5c99e25d286d5fb0c908ceb2b32f24eb6 Mon Sep 17 00:00:00 2001 From: Liujie Xie Date: Sun, 20 Feb 2022 16:53:05 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks to select binder worklist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit trace_android_vh_binder_proc_transaction_entry: We need change binder thread so that this work can be added in proc->todo, if we found the binder thread, skip native logic. trace_android_vh_binder_select_worklist_ilocked: we need this because we can't change list point in ”trace_android_vh_binder_thread_read“, otherwise, If a work has beed added in our own defined list before, current may goto retry and loop again and again. Bug: 219898723 Change-Id: Ifdb3429c9ddac521bc75c1d21740ee7cc4b8f143 Signed-off-by: Liujie Xie (cherry picked from commit acefa91e517b9321295429d3a0e534908e2939c1) Signed-off-by: Carlos Llamas (cherry picked from commit d26c0e1c409179ea74aaa89f748006bd76000cc3) --- drivers/android/binder.c | 12 ++++++++++-- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/binder.h | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index a4ca35b4088f..7d784e263d28 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2926,6 +2926,7 @@ static int binder_proc_transaction(struct binder_transaction *t, bool oneway = !!(t->flags & TF_ONE_WAY); bool pending_async = false; struct binder_transaction *t_outdated = NULL; + bool skip = false; BUG_ON(!node); binder_node_lock(node); @@ -2951,7 +2952,10 @@ static int binder_proc_transaction(struct binder_transaction *t, return proc->is_frozen ? BR_FROZEN_REPLY : BR_DEAD_REPLY; } - if (!thread && !pending_async) + trace_android_vh_binder_proc_transaction_entry(proc, t, + &thread, node->debug_id, pending_async, !oneway, &skip); + + if (!thread && !pending_async && !skip) thread = binder_select_thread_ilocked(proc); if (thread) { @@ -4614,6 +4618,10 @@ retry: size_t trsize = sizeof(*trd); binder_inner_proc_lock(proc); + trace_android_vh_binder_select_worklist_ilocked(&list, thread, + proc, wait_for_proc_work); + if (list) + goto skip; if (!binder_worklist_empty_ilocked(&thread->todo)) list = &thread->todo; else if (!binder_worklist_empty_ilocked(&proc->todo) && @@ -4627,7 +4635,7 @@ retry: goto retry; break; } - +skip: if (end - ptr < sizeof(tr) + 4) { binder_inner_proc_unlock(proc); break; diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index ff97e31dbb2d..40b2b2fc51bc 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -134,6 +134,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpuidle_psci_enter); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpuidle_psci_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_wait_for_work); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_proc_transaction_finish); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_proc_transaction_entry); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_select_worklist_ilocked); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sync_txn_recvd); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_balance_anon_file_reclaim); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_show_max_freq); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 7d32b97a3d7f..5d0ee3a605ff 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -61,6 +61,15 @@ DECLARE_HOOK(android_vh_binder_has_work_ilocked, DECLARE_HOOK(android_vh_binder_preset, TP_PROTO(struct hlist_head *hhead, struct mutex *lock), TP_ARGS(hhead, lock)); +DECLARE_HOOK(android_vh_binder_proc_transaction_entry, + TP_PROTO(struct binder_proc *proc, struct binder_transaction *t, + struct binder_thread **thread, int node_debug_id, bool pending_async, + bool sync, bool *skip), + TP_ARGS(proc, t, thread, node_debug_id, pending_async, sync, skip)); +DECLARE_HOOK(android_vh_binder_select_worklist_ilocked, + TP_PROTO(struct list_head **list, struct binder_thread *thread, struct binder_proc *proc, + int wait_for_proc_work), + TP_ARGS(list, thread, proc, wait_for_proc_work)); #endif /* _TRACE_HOOK_BINDER_H */ /* This part must be outside protection */ #include