ANDROID: vendor_hooks: Add hooks for binder

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 <xieliujie@oppo.com>
This commit is contained in:
Liujie Xie
2021-12-29 10:16:50 +08:00
committed by Todd Kjos
parent e99926fdfa
commit 05c23b7a50
3 changed files with 35 additions and 1 deletions

View File

@@ -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, static bool binder_has_work_ilocked(struct binder_thread *thread,
bool do_proc_work) 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 || return thread->process_todo ||
thread->looper_need_return || thread->looper_need_return ||
(do_proc_work && (do_proc_work &&
@@ -3620,6 +3625,7 @@ static int binder_thread_write(struct binder_proc *proc,
} }
thread->looper |= BINDER_LOOPER_STATE_REGISTERED; thread->looper |= BINDER_LOOPER_STATE_REGISTERED;
binder_inner_proc_unlock(proc); binder_inner_proc_unlock(proc);
trace_android_vh_binder_looper_state_registered(thread, proc);
break; break;
case BC_ENTER_LOOPER: case BC_ENTER_LOOPER:
binder_debug(BINDER_DEBUG_THREADS, binder_debug(BINDER_DEBUG_THREADS,
@@ -4044,6 +4050,7 @@ retry:
binder_inner_proc_unlock(proc); binder_inner_proc_unlock(proc);
break; break;
} }
trace_android_vh_binder_thread_read(&list, proc, thread);
w = binder_dequeue_work_head_ilocked(list); w = binder_dequeue_work_head_ilocked(list);
if (binder_worklist_empty_ilocked(&thread->todo)) if (binder_worklist_empty_ilocked(&thread->todo))
thread->process_todo = false; thread->process_todo = false;
@@ -4510,6 +4517,7 @@ static void binder_free_proc(struct binder_proc *proc)
put_task_struct(proc->tsk); put_task_struct(proc->tsk);
put_cred(eproc->cred); put_cred(eproc->cred);
binder_stats_deleted(BINDER_STAT_PROC); binder_stats_deleted(BINDER_STAT_PROC);
trace_android_vh_binder_free_proc(proc);
kfree(eproc); kfree(eproc);
} }
@@ -4608,6 +4616,7 @@ static int binder_thread_release(struct binder_proc *proc,
if (send_reply) if (send_reply)
binder_send_failed_reply(send_reply, BR_DEAD_REPLY); binder_send_failed_reply(send_reply, BR_DEAD_REPLY);
binder_release_work(proc, &thread->todo); binder_release_work(proc, &thread->todo);
trace_android_vh_binder_thread_release(proc, thread);
binder_thread_dec_tmpref(thread); binder_thread_dec_tmpref(thread);
return active_transactions; return active_transactions;
} }
@@ -4684,6 +4693,7 @@ static int binder_ioctl_write_read(struct file *filp,
if (!binder_worklist_empty_ilocked(&proc->todo)) if (!binder_worklist_empty_ilocked(&proc->todo))
binder_wakeup_proc_ilocked(proc); binder_wakeup_proc_ilocked(proc);
binder_inner_proc_unlock(proc); binder_inner_proc_unlock(proc);
trace_android_vh_binder_read_done(proc, thread);
if (ret < 0) { if (ret < 0) {
if (copy_to_user(ubuf, &bwr, sizeof(bwr))) if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
ret = -EFAULT; ret = -EFAULT;

View File

@@ -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_free);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_alloc); 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_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);

View File

@@ -79,7 +79,25 @@ DECLARE_HOOK(android_vh_binder_print_transaction_info,
TP_PROTO(struct seq_file *m, struct binder_proc *proc, TP_PROTO(struct seq_file *m, struct binder_proc *proc,
const char *prefix, struct binder_transaction *t), const char *prefix, struct binder_transaction *t),
TP_ARGS(m, proc, prefix, 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 */ /* macro versions of hooks are no longer required */
#endif /* _TRACE_HOOK_BINDER_H */ #endif /* _TRACE_HOOK_BINDER_H */