From b13ee5ea88c0090e686cc168a5905f15a7cadc46 Mon Sep 17 00:00:00 2001 From: zhengwei Date: Fri, 11 Apr 2025 14:30:19 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add hook to record binder transaction info Add vendor hook to record binder transaction information and support oem's print binder transaction info. Our function is to help locate whether the problem is caused by binder blocking when ANR or watchdog occurs;So we need to add timestamps, synchronous or asynchronous process information to the binder_procs node, and create our own file node to readbinder_procs, binder_transaction_log and binder_transaction_log_failed, and output them in the format we need. On kernel 6.6, we implement this with an OGKI patch, now we want to achieve this by adding this vendor hook (also helps to reduce our OGKI patches).This is a custom function, which will affect performance. I turn this unction on or off according to different products. It is not available for all OEMs, so it is not available upstream. Bug: 409484697 Change-Id: I36109e9045e284cc8be8dbffb79fc5b509a67c06 Signed-off-by: zhengwei --- drivers/android/binder.c | 5 +++++ drivers/android/binderfs.c | 3 ++- drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/binder.h | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 17a6ce20b765..f29ad0e598c1 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3900,6 +3900,8 @@ static void binder_transaction(struct binder_proc *proc, tcomplete->type = BINDER_WORK_TRANSACTION_COMPLETE; t->work.type = BINDER_WORK_TRANSACTION; + trace_android_vh_binder_transaction_record(tr, t, in_reply_to); + if (reply) { binder_enqueue_thread_work(thread, tcomplete); binder_inner_proc_lock(target_proc); @@ -6298,6 +6300,9 @@ static int binder_open(struct inode *nodp, struct file *filp) filp->private_data = proc; trace_android_vh_binder_preset(&binder_procs, &binder_procs_lock, proc); + trace_android_vh_binder_data_preset(&binder_procs, &binder_procs_lock, + &binder_transaction_log, &binder_transaction_log_failed, + sizeof(struct binder_transaction_log)); mutex_lock(&binder_procs_lock); hlist_for_each_entry(itr, &binder_procs, proc_node) { if (itr->pid == proc->pid) { diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 6602fbf0dbd7..fdd4545e9532 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -31,7 +31,7 @@ #include #include #include - +#include #include "binder_internal.h" #define FIRST_INODE 1 @@ -649,6 +649,7 @@ static int init_binder_logs(struct super_block *sb) ret = PTR_ERR(proc_log_dir); goto out; } + trace_android_rvh_init_binder_logs(sb); info = sb->s_fs_info; info->proc_log_dir = proc_log_dir; diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 2c3aaf0e4660..b0fdb00d6876 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -425,6 +425,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_reply); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_trans); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_proc_transaction); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_thread_read); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_init_binder_logs); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_data_preset); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_record); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_inode_io_list_del); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_redirty_tail_locked); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_queue_io); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 81d840811cba..82f43ec144dc 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -17,6 +17,8 @@ struct binder_proc; struct binder_work; struct binder_buffer; struct binder_transaction_data; +struct binder_transaction_log; + DECLARE_HOOK(android_vh_binder_transaction_init, TP_PROTO(struct binder_transaction *t), TP_ARGS(t)); @@ -112,6 +114,23 @@ 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_transaction_record, + TP_PROTO(struct binder_transaction_data *tr, + struct binder_transaction *t, + struct binder_transaction *in_reply_to), + TP_ARGS(tr, t, in_reply_to)); +DECLARE_HOOK(android_vh_binder_data_preset, + TP_PROTO(struct hlist_head *binder_procs, + struct mutex *binder_procs_lock, + struct binder_transaction_log *binder_transaction_log, + struct binder_transaction_log *binder_transaction_log_failed, + size_t size), + TP_ARGS(binder_procs, + binder_procs_lock, binder_transaction_log, + binder_transaction_log_failed, size)); +DECLARE_RESTRICTED_HOOK(android_rvh_init_binder_logs, + TP_PROTO(struct super_block *sb), + TP_ARGS(sb), 1); DECLARE_HOOK(android_vh_binder_new_ref, TP_PROTO(struct binder_proc *proc, uint32_t ref_desc, int node_debug_id), TP_ARGS(proc, ref_desc, node_debug_id));