From 17fff41db863f170ebea8b5ae5c99ccd874ac4cd Mon Sep 17 00:00:00 2001 From: Zhuguangqing Date: Tue, 9 Mar 2021 15:47:43 +0800 Subject: [PATCH] ANDROID: Add vendor hooks for binder perf tuning Add some hooks in the binder module so that we can do task dependency analysis and statistical work in OEM's module for further optimization. Bug: 235925535 Bug: 281920779 Signed-off-by: Zhuguangqing Change-Id: Id47e59c4e3ccd07b26eef758ada147b98cd1964e Signed-off-by: heshuai1 Signed-off-by: Carlos Llamas [ cmllamas: don't export complete private definition struct binder_alloc in vendor hooks, instead just pass member alloc->free_async_space as implemented by heshuai1 and squashed here ] (cherry picked from commit 254fb1f4034fde523378ee58a501d212a59047b7) --- drivers/android/binder.c | 2 ++ drivers/android/binder_alloc.c | 2 ++ drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/binder.h | 13 +++++++++++++ 4 files changed, 20 insertions(+) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 15ae88216c51..b3a5b79c4bb1 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3187,6 +3187,7 @@ static void binder_transaction(struct binder_proc *proc, target_proc = target_thread->proc; target_proc->tmp_ref++; binder_inner_proc_unlock(target_thread->proc); + trace_android_vh_binder_reply(target_proc, proc, thread, tr); } else { if (tr->target.handle) { struct binder_ref *ref; @@ -3249,6 +3250,7 @@ static void binder_transaction(struct binder_proc *proc, return_error_line = __LINE__; goto err_invalid_target_handle; } + trace_android_vh_binder_trans(target_proc, proc, thread, tr); if (security_binder_transaction(proc->cred, target_proc->cred) < 0) { binder_txn_error("%d:%d transaction credentials failed\n", diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 4ad42b0f75cd..e1620e184903 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -25,6 +25,7 @@ #include #include "binder_alloc.h" #include "binder_trace.h" +#include struct list_lru binder_alloc_lru; @@ -406,6 +407,7 @@ static struct binder_buffer *binder_alloc_new_buf_locked( alloc->pid, extra_buffers_size); return ERR_PTR(-EINVAL); } + trace_android_vh_binder_alloc_new_buf_locked(size, &alloc->free_async_space, is_async); if (is_async && alloc->free_async_space < size + sizeof(struct binder_buffer)) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 75c46edf5eb3..17f1487ba574 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -232,3 +232,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_preset); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_uid); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_free_user); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpuset_fork); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_alloc_new_buf_locked); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_reply); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_trans); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 5d0ee3a605ff..4ae5ef5b3cce 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -70,6 +70,19 @@ 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)); +DECLARE_HOOK(android_vh_binder_alloc_new_buf_locked, + TP_PROTO(size_t size, size_t *free_async_space, int is_async), + TP_ARGS(size, free_async_space, is_async)); +struct binder_transaction_data; +DECLARE_HOOK(android_vh_binder_reply, + TP_PROTO(struct binder_proc *target_proc, struct binder_proc *proc, + struct binder_thread *thread, struct binder_transaction_data *tr), + TP_ARGS(target_proc, proc, thread, tr)); +DECLARE_HOOK(android_vh_binder_trans, + TP_PROTO(struct binder_proc *target_proc, struct binder_proc *proc, + struct binder_thread *thread, struct binder_transaction_data *tr), + TP_ARGS(target_proc, proc, thread, tr)); + #endif /* _TRACE_HOOK_BINDER_H */ /* This part must be outside protection */ #include