diff options
| author | Mister Oyster <oysterized@gmail.com> | 2017-05-28 19:25:32 +0200 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-05-28 19:34:49 +0200 |
| commit | 0694ac72d74e7ba1c1571437ca35b44aca8c3cf8 (patch) | |
| tree | a162644a76a390e2c4cbe51bb040fefebce1ed74 | |
| parent | 8b747813de365e4ed837b28e6c19500c60c61154 (diff) | |
mtk: binder: remove debug stuff to ease future merge
| -rw-r--r-- | drivers/android/binder.c | 2403 |
1 files changed, 11 insertions, 2392 deletions
diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 418333d53..311a3ee30 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -15,7 +15,6 @@ * */ -#define DEBUG 1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <asm/cacheflush.h> @@ -43,8 +42,6 @@ #include <linux/delay.h> #include <linux/kthread.h> #include <linux/rtc.h> -#include <linux/aee.h> - #include <uapi/linux/android/binder.h> #include "binder_trace.h" @@ -63,74 +60,7 @@ static struct binder_node *binder_context_mgr_node; static kuid_t binder_context_mgr_uid = INVALID_UID; static int binder_last_id; static struct workqueue_struct *binder_deferred_workqueue; - -#define RT_PRIO_INHERIT "v1.7" -#ifdef RT_PRIO_INHERIT -#include <linux/sched/rt.h> -#endif - -#define MTK_BINDER_DEBUG "v0.1" /* defined for mtk internal added debug code */ - -/************************************************************************************************************************/ -/* MTK Death Notify | */ -/* Debug Log Prefix | Description */ -/* --------------------------------------------------------------------- */ -/* [DN #1] | Some one requests Death Notify from upper layer. */ -/* [DN #2] | Some one cancels Death Notify from upper layer. */ -/* [DN #3] | Binder Driver sends Death Notify to all requesters' Binder Thread. */ -/* [DN #4] | Some requester's binder_thread_read() handles Death Notify works. */ -/* [DN #5] | Some requester sends confirmation to Binder Driver. (In IPCThreadState.cpp) */ -/* [DN #6] | Finally receive requester's confirmation from upper layer. */ -/************************************************************************************************************************/ -#define MTK_DEATH_NOTIFY_MONITOR "v0.1" - -/** - * Revision history of binder monitor - * - * v0.1 - enhance debug log - * v0.2 - transaction timeout log - * v0.2.1 - buffer allocation debug - */ -#ifdef CONFIG_MT_ENG_BUILD -#define BINDER_MONITOR "v0.2.1" /* BINDER_MONITOR only turn on for eng build */ -#endif - -#ifdef BINDER_MONITOR -#define MAX_SERVICE_NAME_LEN 32 -/************************************************************************************************************************/ -/* Payload layout of addService(): */ -/* | Parcel header | IServiceManager.descriptor | Parcel header | Service name | ... */ -/* (Please refer ServiceManagerNative.java:addService()) */ -/* IServiceManager.descriptor is 'android.os.IServiceManager' interleaved with character '\0'. */ -/* that is, 'a', '\0', 'n', '\0', 'd', '\0', 'r', '\0', 'o', ... */ -/* so the offset of Service name = Parcel header x2 + strlen(android.os.IServiceManager) x2 = 8x2 + 26x2 = 68 */ -/************************************************************************************************************************/ -#define MAGIC_SERVICE_NAME_OFFSET 68 - -#define MAX_ENG_TRANS_LOG_BUFF_LEN 10240 static pid_t system_server_pid; -static int binder_check_buf_pid; -static int binder_check_buf_tid; -static unsigned long binder_log_level = 0; -char aee_msg[512]; -char aee_word[100]; -static int bt_folder = 0;//just for native backtrace -#define TRANS_LOG_LEN 210 -char large_msg[TRANS_LOG_LEN]; - -#define BINDER_PERF_EVAL "V0.1" -#endif - -#ifdef BINDER_PERF_EVAL -/* binder_perf_evalue bitmap - * bit: ...3210 - * ||_ 1: send counter enable - * |__ 1: timeout counter enable - */ -static unsigned int binder_perf_evalue = 0; -#define BINDER_PERF_SEND_COUNTER 0x1 -#define BINDER_PERF_TIMEOUT_COUNTER 0x2 -#endif #define BINDER_DEBUG_ENTRY(name) \ static int binder_##name##_open(struct inode *inode, struct file *file) \ @@ -146,33 +76,6 @@ static const struct file_operations binder_##name##_fops = { \ .release = single_release, \ } -#ifdef BINDER_MONITOR -#define BINDER_DEBUG_SETTING_ENTRY(name) \ -static int binder_##name##_open(struct inode *inode, struct file *file) \ -{ \ - return single_open(file, binder_##name##_show, inode->i_private); \ -} \ -\ -static const struct file_operations binder_##name##_fops = { \ - .owner = THIS_MODULE, \ - .open = binder_##name##_open, \ - .read = seq_read, \ - .write = binder_##name##_write, \ - .llseek = seq_lseek, \ - .release = single_release, \ -} -#endif - -//LCH add, for binder pages leakage debug -#ifdef CONFIG_MT_ENG_BUILD -#define MTK_BINDER_PAGE_USED_RECORD -#endif - -#ifdef MTK_BINDER_PAGE_USED_RECORD -static unsigned int binder_page_used = 0; -static unsigned int binder_page_used_peak = 0; -#endif - static int binder_proc_show(struct seq_file *m, void *unused); BINDER_DEBUG_ENTRY(proc); @@ -235,15 +138,6 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error, pr_info(x); \ } while (0) -#ifdef BINDER_MONITOR -#define binder_user_error(x...) \ - do { \ - if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \ - pr_err(x); \ - if (binder_stop_on_user_error) \ - binder_stop_on_user_error = 2; \ - } while (0) -#else #define binder_user_error(x...) \ do { \ if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \ @@ -251,7 +145,6 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error, if (binder_stop_on_user_error) \ binder_stop_on_user_error = 2; \ } while (0) -#endif enum binder_stat_types { BINDER_STAT_PROC, @@ -294,25 +187,11 @@ struct binder_transaction_log_entry { int to_node; int data_size; int offsets_size; -#ifdef BINDER_MONITOR - unsigned int code; - struct timespec timestamp; - char service[MAX_SERVICE_NAME_LEN]; - int fd; - struct timeval tv; - struct timespec readstamp; - struct timespec endstamp; -#endif }; struct binder_transaction_log { int next; int full; -#ifdef BINDER_MONITOR - unsigned size; - struct binder_transaction_log_entry *entry; -#else struct binder_transaction_log_entry entry[32]; -#endif }; static struct binder_transaction_log binder_transaction_log; static struct binder_transaction_log binder_transaction_log_failed; @@ -324,43 +203,13 @@ static struct binder_transaction_log_entry *binder_transaction_log_add( e = &log->entry[log->next]; memset(e, 0, sizeof(*e)); log->next++; -#ifdef BINDER_MONITOR - if (log->next == log->size) { - log->next = 0; - log->full = 1; - } -#else if (log->next == ARRAY_SIZE(log->entry)) { log->next = 0; log->full = 1; } -#endif return e; } -#ifdef BINDER_MONITOR -static struct binder_transaction_log_entry entry_failed[32]; - -/* log_disable bitmap - * bit: 31...43210 - * | |||||_ 0: log enable / 1: log disable - * | ||||__ 1: self resume - * | |||____2: manually trigger kernel warning for buffer allocation - * | ||____ 3: 1:rt_inherit log enable / 0: rt_inherit log disable - * | | - */ -static int log_disable; -#define BINDER_LOG_RESUME 0x2 -#define BINDER_BUF_WARN 0x4 -#ifdef RT_PRIO_INHERIT -#define BINDER_RT_LOG_ENABLE 0x8 -#endif -#ifdef CONFIG_MTK_EXTMEM -extern void* extmem_malloc_page_align(size_t bytes); -#else -static struct binder_transaction_log_entry entry_t[MAX_ENG_TRANS_LOG_BUFF_LEN]; -#endif -#endif struct binder_work { struct list_head entry; enum { @@ -395,12 +244,6 @@ struct binder_node { unsigned accept_fds:1; unsigned min_priority:8; struct list_head async_todo; -#ifdef BINDER_MONITOR - char name[MAX_SERVICE_NAME_LEN]; -#endif -#ifdef MTK_BINDER_DEBUG - int async_pid; -#endif }; struct binder_ref_death { @@ -435,9 +278,7 @@ struct binder_buffer { unsigned debug_id:29; struct binder_transaction *transaction; -#ifdef BINDER_MONITOR - struct binder_transaction_log_entry *log_entry; -#endif + struct binder_node *target_node; size_t data_size; size_t offsets_size; @@ -450,31 +291,6 @@ enum binder_deferred_state { BINDER_DEFERRED_RELEASE = 0x04, }; -#ifdef BINDER_MONITOR -enum wait_on_reason { - WAIT_ON_NONE = 0U, - WAIT_ON_READ = 1U, - WAIT_ON_EXEC = 2U, - WAIT_ON_REPLY_READ = 3U -}; -#endif - -#ifdef BINDER_PERF_EVAL -#define BC_CODE_NR 60 -#define BC_STATS_NR 30 -struct binder_bc_stats { - char service[MAX_SERVICE_NAME_LEN]; - unsigned int code[BC_CODE_NR]; - unsigned int code_num[BC_CODE_NR]; -}; -struct binder_timeout_stats { - unsigned long bto[WAIT_ON_REPLY_READ]; - struct timespec read_t[32]; - struct timespec exec_t[32]; - struct timespec rrply_t[32]; -}; -#endif - struct binder_proc { struct hlist_node proc_node; struct rb_root threads; @@ -509,22 +325,6 @@ struct binder_proc { int ready_threads; long default_priority; struct dentry *debugfs_entry; -#ifdef RT_PRIO_INHERIT - unsigned long default_rt_prio:16; - unsigned long default_policy:16; -#endif -#ifdef BINDER_MONITOR - struct binder_buffer *large_buffer; -#endif -#ifdef BINDER_PERF_EVAL - int bc_t; - struct binder_bc_stats *bc_stats[BC_STATS_NR]; - struct binder_timeout_stats to_stats; -#endif -#ifdef MTK_BINDER_PAGE_USED_RECORD - unsigned int page_used; - unsigned int page_used_peak; -#endif }; enum { @@ -549,10 +349,6 @@ struct binder_thread { /* we are also waiting on */ wait_queue_head_t wait; struct binder_stats stats; -#ifdef BINDER_PERF_EVAL - struct binder_timeout_stats to_stats; -#endif - }; struct binder_transaction { @@ -572,820 +368,11 @@ struct binder_transaction { long priority; long saved_priority; kuid_t sender_euid; -#ifdef RT_PRIO_INHERIT - unsigned long rt_prio:16; - unsigned long policy:16; - unsigned long saved_rt_prio:16; - unsigned long saved_policy:16; -#endif -#ifdef BINDER_MONITOR - struct timespec timestamp; - - enum wait_on_reason wait_on; - enum wait_on_reason bark_on; - struct rb_node rb_node; /* by bark_time */ - struct timespec bark_time; - struct timespec exe_timestamp; - struct timeval tv; - char service[MAX_SERVICE_NAME_LEN]; - pid_t fproc; - pid_t fthrd; - pid_t tproc; - pid_t tthrd; - unsigned int log_idx; -#endif }; static void binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer); -static inline void binder_lock(const char *tag); -static inline void binder_unlock(const char *tag); - -#ifdef BINDER_MONITOR -/* work should be done within how many secs */ -#define WAIT_BUDGET_READ 2 -#define WAIT_BUDGET_EXEC 4 -#define WAIT_BUDGET_MIN min(WAIT_BUDGET_READ, WAIT_BUDGET_EXEC) - -static struct rb_root bwdog_transacts; - -static const char *binder_wait_on_str[] = { - "none", - "read", - "exec", - "rply" -}; - -struct binder_timeout_log_entry { - enum wait_on_reason r; - pid_t from_proc; - pid_t from_thrd; - pid_t to_proc; - pid_t to_thrd; - unsigned over_sec; - struct timespec ts; - struct timeval tv; - unsigned int code; - char service[MAX_SERVICE_NAME_LEN]; - int debug_id; -}; - -struct binder_timeout_log { - int next; - int full; -#ifdef BINDER_PERF_EVAL - struct binder_timeout_log_entry entry[256]; -#else - struct binder_timeout_log_entry entry[64]; -#endif -}; - -static struct binder_timeout_log binder_timeout_log_t; - -/** - * binder_timeout_log_add - Insert a timeout log - */ -static struct binder_timeout_log_entry *binder_timeout_log_add(void) -{ - struct binder_timeout_log *log = &binder_timeout_log_t; - struct binder_timeout_log_entry *e; - - e = &log->entry[log->next]; - memset(e, 0, sizeof(*e)); - log->next++; - if (log->next == ARRAY_SIZE(log->entry)) { - log->next = 0; - log->full = 1; - } - return e; -} - -/** - * binder_print_bwdog - Output info of a timeout transaction - * @t: pointer to the timeout transaction - * @cur_in: current timespec while going to print - * @e: timeout log entry to record - * @r: output reason, either while barking or after barked - */ -static void binder_print_bwdog(struct binder_transaction *t, - struct timespec *cur_in, - struct binder_timeout_log_entry *e, - enum wait_on_reason r) -{ - struct rtc_time tm; - struct timespec *startime; - struct timespec cur, sub_t; - - if (cur_in && e) { - memcpy(&cur, cur_in, sizeof(struct timespec)); - } else { - do_posix_clock_monotonic_gettime(&cur); - //monotonic_to_bootbased(&cur); - } - startime = (r == WAIT_ON_EXEC) ? &t->exe_timestamp : &t->timestamp; - sub_t = timespec_sub(cur, *startime); - -#ifdef BINDER_PERF_EVAL - if ( !(cur_in && e) && (binder_perf_evalue & BINDER_PERF_TIMEOUT_COUNTER)) - { - switch (r) - { - case WAIT_ON_READ: - { - if (t->to_proc) - { - unsigned long proc_t = t->to_proc->to_stats.bto[r - 1] ++; - t->to_proc->to_stats.read_t[(proc_t % 32)] = sub_t; - } - break; - } - case WAIT_ON_EXEC: - { - if (t->to_proc) - { - unsigned long proc_t = t->to_proc->to_stats.bto[r - 1] ++; - t->to_proc->to_stats.exec_t[(proc_t % 32)] = sub_t; - } - if (t->to_thread) - { - unsigned long thread_t = t->to_thread->to_stats.bto[r - 1] ++; - t->to_thread->to_stats.exec_t[(thread_t % 32)] = sub_t; - } - break; - } - case WAIT_ON_REPLY_READ: - { - if (t->to_proc) - { - unsigned long proc_t = t->to_proc->to_stats.bto[r - 1] ++; - t->to_proc->to_stats.rrply_t[(proc_t % 32)] = sub_t; - } - if (t->to_thread) - { - unsigned long thread_t = t->to_thread->to_stats.bto[r - 1] ++; - t->to_thread->to_stats.rrply_t[(thread_t % 32)] = sub_t; - } - - break; - } - case WAIT_ON_NONE: - break; - default: - break; - } - } -#endif - rtc_time_to_tm(t->tv.tv_sec, &tm); - pr_debug("%d %s %d:%d to %d:%d %s %u.%03ld " - "sec (%s) dex_code %u start_at %lu.%03ld android " - "%d-%02d-%02d %02d:%02d:%02d.%03lu\n", - t->debug_id, binder_wait_on_str[r], - t->fproc, t->fthrd, t->tproc, t->tthrd, - (cur_in && e) ? "over" : "total", - (unsigned)sub_t.tv_sec, (sub_t.tv_nsec / NSEC_PER_MSEC), - t->service, t->code, - - (unsigned long)startime->tv_sec, - (startime->tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(t->tv.tv_usec / USEC_PER_MSEC)); - - if (e) { - e->over_sec = sub_t.tv_sec; - memcpy(&e->ts, startime, sizeof(struct timespec)); - } -} - -/** - * binder_bwdog_safe - Check a transaction is monitor-free or not - * @t: pointer to the transaction to check - * - * Returns 1 means safe. - */ -static inline int binder_bwdog_safe(struct binder_transaction *t) -{ - return (t->wait_on == WAIT_ON_NONE) ? 1 : 0; -} - -/** - * binder_query_bwdog - Check a transaction is queued or not - * @t: pointer to the transaction to check - * - * Returns a pointer points to t, or NULL if it's not queued. - */ -static struct rb_node **binder_query_bwdog(struct binder_transaction *t) -{ - struct rb_node **p = &bwdog_transacts.rb_node; - struct rb_node *parent = NULL; - struct binder_transaction *transact = NULL; - int comp; - - while (*p) { - parent = *p; - transact = rb_entry(parent, struct binder_transaction, rb_node); - - comp = timespec_compare(&t->bark_time, &transact->bark_time); - if (comp < 0) - p = &(*p)->rb_left; - else if (comp > 0) - p = &(*p)->rb_right; - else - break; - } - return p; -} - -/** - * binder_queue_bwdog - Queue a transaction to keep tracking - * @t: pointer to the transaction being tracked - * @budget: seconds, which this transaction can afford - */ -static void binder_queue_bwdog(struct binder_transaction *t, time_t budget) -{ - struct rb_node **p = &bwdog_transacts.rb_node; - struct rb_node *parent = NULL; - struct binder_transaction *transact = NULL; - int ret; - - do_posix_clock_monotonic_gettime(&t->bark_time); - //monotonic_to_bootbased(&t->bark_time); - t->bark_time.tv_sec += budget; - - while (*p) { - parent = *p; - transact = rb_entry(parent, struct binder_transaction, rb_node); - - ret = timespec_compare(&t->bark_time, &transact->bark_time); - if (ret < 0) - p = &(*p)->rb_left; - else if (ret > 0) - p = &(*p)->rb_right; - else { - pr_debug("%d found same key\n", - t->debug_id); - t->bark_time.tv_nsec += 1; - p = &(*p)->rb_right; - } - } - rb_link_node(&t->rb_node, parent, p); - rb_insert_color(&t->rb_node, &bwdog_transacts); -} - -/** - * binder_cancel_bwdog - Cancel a transaction from tracking list - * @t: pointer to the transaction being cancelled - */ -static void binder_cancel_bwdog(struct binder_transaction *t) -{ - struct rb_node **p = NULL; - - if (binder_bwdog_safe(t)) { - if (t->bark_on) { - binder_print_bwdog(t, NULL, NULL, t->bark_on); - t->bark_on = WAIT_ON_NONE; - } - return; - } - - p = binder_query_bwdog(t); - if (*p == NULL) { - pr_err("%d waits %s, but not queued...\n", - t->debug_id, binder_wait_on_str[t->wait_on]); - return; - } - - rb_erase(&t->rb_node, &bwdog_transacts); - t->wait_on = WAIT_ON_NONE; -} - -/** - * binder_bwdog_bark - - * Barking funcion while timeout. Record target process or thread, which - * cannot handle transaction in time, including todo list. Also add a log - * entry for AMS reference. - * - * @t: pointer to the transaction, which triggers watchdog - * @cur: current kernel timespec - */ -static void binder_bwdog_bark(struct binder_transaction *t, struct timespec *cur) -{ - struct binder_timeout_log_entry *e; - - - if (binder_bwdog_safe(t)) { - pr_debug("%d watched, but wait nothing\n", - t->debug_id); - return; - } - - e = binder_timeout_log_add(); - binder_print_bwdog(t, cur, e, t->wait_on); - - e->r = t->wait_on; - e->from_proc = t->fproc; - e->from_thrd = t->fthrd; - e->debug_id = t->debug_id; - memcpy(&e->tv, &t->tv, sizeof(struct timeval)); - - switch (t->wait_on) { - case WAIT_ON_READ: { - if (!t->to_proc) { - pr_err("%d has NULL target\n", - t->debug_id); - return; - } - e->to_proc = t->tproc; - e->to_thrd = t->tthrd; - e->code = t->code; - strcpy(e->service, t->service); - break; - } - case WAIT_ON_EXEC: { - if (!t->to_thread) { - pr_err("%d has NULL target for " - "execution\n", t->debug_id); - return; - } - e->to_proc = t->tproc; - e->to_thrd = t->tthrd; - e->code = t->code; - strcpy(e->service, t->service); - goto dumpBackTrace; - } - - case WAIT_ON_REPLY_READ: { - if (!t->to_thread) { - pr_err("%d has NULL target thread\n", - t->debug_id); - return; - } - e->to_proc = t->tproc; - e->to_thrd = t->tthrd; - strcpy(e->service, ""); - break; - } - - default: { - return; - } - } - -dumpBackTrace: - return; -} - -/** - * binder_bwdog_thread - Main thread to check timeout list periodically - */ -static int binder_bwdog_thread(void *__unused) -{ - unsigned long sleep_sec; - struct rb_node *n = NULL; - struct timespec cur_time; - struct binder_transaction *t = NULL; - - for (;;) { - binder_lock(__func__); - do_posix_clock_monotonic_gettime(&cur_time); - //monotonic_to_bootbased(&cur_time); - - for (n = rb_first(&bwdog_transacts); n != NULL; n = rb_next(n)) { - t = rb_entry(n, struct binder_transaction, rb_node); - if (timespec_compare(&cur_time, &t->bark_time) < 0) - break; - - binder_bwdog_bark(t, &cur_time); - rb_erase(&t->rb_node, &bwdog_transacts); - t->bark_on = t->wait_on; - t->wait_on = WAIT_ON_NONE; - } - - if (!n) - sleep_sec = WAIT_BUDGET_MIN; - else - sleep_sec = timespec_sub(t->bark_time, cur_time).tv_sec; - binder_unlock(__func__); - - msleep(sleep_sec * MSEC_PER_SEC); - } - pr_debug("%s exit...\n", __func__); - return 0; -} - -/** - * binder_usermodehelper - Call shell to do some command - * @cmd: string of command - * @w: wait type - */ -static void binder_usermodehelper(char *cmd, int w) -{ - int ret; - char *envp[] = {"HOME=/", "TERM=linux", "PATH=/sbin:/system/bin", NULL}; - char *argv[] = {"/system/bin/sh", "-c", "", NULL}; - - argv[2] = cmd; - pr_debug("%s\n", argv[2]); - if ((ret = call_usermodehelper(argv[0], argv, envp, w)) != 0) - pr_err("%s: return %d\n", __func__, ret); -} - -/** - * find_process_by_pid - convert pid to task_struct - * @pid: pid for convert task - */ -static inline struct task_struct *find_process_by_pid(pid_t pid) -{ - return pid ? find_task_by_vpid(pid) : NULL; -} -/** - * binder_find_buffer_sender - find the sender task_struct of this buffer - * @buf binder buffer - * @tsk task_struct of buf sender - */ -static struct task_struct *binder_find_buffer_sender(struct binder_buffer *buf) -{ - struct binder_transaction *t; - struct binder_transaction_log_entry *e; - struct task_struct *tsk; - t = buf->transaction; - if (t && t->fproc) - tsk = find_process_by_pid(t->fproc); - - else - { - e = buf->log_entry; - if ((buf->debug_id == e->debug_id) && e->from_proc) - tsk = find_process_by_pid(e->from_proc); - else - tsk = NULL; - } - return tsk; -} - -/** - * copy from /kernel/fs/proc/base.c and modified to get task full name - */ -static int binder_proc_pid_cmdline(struct task_struct *task, char * buf) -{ - int res = 0; - unsigned int len; - struct mm_struct *mm; - /*============ add begin =============================*/ - char c = ' '; - char *str; - unsigned int size; - char *buffer; - - if (NULL == task) - goto out; - /*============ add end ===============================*/ - mm = get_task_mm(task); - if (!mm) - goto out; - if (!mm->arg_end) - goto out_mm; /* Shh! No looking before we're done */ - /*============ add begin =============================*/ - buffer = kzalloc(PAGE_SIZE, GFP_KERNEL); - if (NULL == buffer) - goto out_mm; - /*============ add end ===============================*/ - - len = mm->arg_end - mm->arg_start; - - if (len > PAGE_SIZE) - len = PAGE_SIZE; - - res = access_process_vm(task, mm->arg_start, buffer, len, 0); - - // If the nul at the end of args has been overwritten, then - // assume application is using setproctitle(3). - if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) { - len = strnlen(buffer, res); - if (len < res) { - res = len; - } else { - len = mm->env_end - mm->env_start; - if (len > PAGE_SIZE - res) - len = PAGE_SIZE - res; - res += access_process_vm(task, mm->env_start, buffer+res, len, 0); - res = strnlen(buffer, res); - } - } - /*============ add begin =============================*/ - str = strchr(buffer, c); - if (NULL != str) - size = (unsigned int)(str - buffer); - else - size = res; - if (size > 256) - size = 256; - snprintf(buf, size, buffer); - kfree(buffer); - /*============ add end ===============================*/ -out_mm: - mmput(mm); -out: - return res; -} - -/** - * binder_print_buf - Print buffer info - * @t: transaction - * @buffer: target buffer - * @dest: dest string pointer - * @success: does this buffer allocate success - * @check: check this log for owner finding - */ -static void binder_print_buf(struct binder_buffer *buffer, char *dest, int success, int check) -{ - struct rtc_time tm; - struct binder_transaction *t = buffer->transaction; - char str[TRANS_LOG_LEN]; - struct task_struct *sender_tsk; - struct task_struct *rec_tsk; - char sender_name[256], rec_name[256]; - int len_s, len_r; - if (NULL == t) { - struct binder_transaction_log_entry *log_entry = buffer->log_entry; - rtc_time_to_tm(log_entry->tv.tv_sec, &tm); - if ((log_entry != NULL) && (buffer->debug_id == log_entry->debug_id)) - { - sender_tsk = find_process_by_pid(log_entry->from_proc); - rec_tsk = find_process_by_pid(log_entry->to_proc); - len_s = binder_proc_pid_cmdline(sender_tsk, sender_name); - len_r = binder_proc_pid_cmdline(rec_tsk, rec_name); - snprintf(str, sizeof(str), - "binder:check=%d,success=%d,id=%d,call=%s,type=%s," - "from=%d,tid=%d,name=%s,to=%d,name=%s,tid=%d,name=%s," - "size=%zd,node=%d,handle=%d,dex=%u,auf=%d,start=%lu.%03ld," - "android=%d-%02d-%02d %02d:%02d:%02d.%03lu\n", - check, success, buffer->debug_id, - buffer->async_transaction ? "async" : "sync", - (2 == log_entry->call_type) ? "reply" : - ((1 == log_entry->call_type) ? "async" : "call"), - log_entry->from_proc, log_entry->from_thread, - len_s ? sender_name : ((sender_tsk != NULL) ? sender_tsk->comm : ""), - log_entry->to_proc, - len_r ? rec_name : ((rec_tsk != NULL) ? rec_tsk->comm : ""), - log_entry->to_thread, log_entry->service, - (buffer->data_size + buffer->offsets_size), - log_entry->to_node, log_entry->target_handle, log_entry->code, - buffer->allow_user_free, - (unsigned long)log_entry->timestamp.tv_sec, - (log_entry->timestamp.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(log_entry->tv.tv_usec / USEC_PER_MSEC)); - } - else - snprintf(str, sizeof(str), "binder:check=%d,success=%d,id=%d,call=%s, ," - ",,,,,,,size=%zd,,,," - "auf=%d,,\n", - check, success, buffer->debug_id, - buffer->async_transaction ? "async" : "sync", - (buffer->data_size + buffer->offsets_size), - buffer->allow_user_free); - } - else - { - rtc_time_to_tm(t->tv.tv_sec, &tm); - sender_tsk = find_process_by_pid(t->fproc); - rec_tsk = find_process_by_pid(t->tproc); - len_s = binder_proc_pid_cmdline(sender_tsk, sender_name); - len_r = binder_proc_pid_cmdline(rec_tsk, rec_name); - snprintf(str, sizeof(str), - "binder:check=%d,success=%d,id=%d,call=%s,type=%s," - "from=%d,tid=%d,name=%s,to=%d,name=%s,tid=%d,name=%s," - "size=%zd,,,dex=%u,auf=%d,start=%lu.%03ld,android=" - "%d-%02d-%02d %02d:%02d:%02d.%03lu\n", - check, success, t->debug_id, - buffer->async_transaction ? "async" : "sync ", - binder_wait_on_str[t->wait_on], - t->fproc, t->fthrd, - len_s ? sender_name : ((sender_tsk != NULL) ? sender_tsk->comm : ""), - t->tproc, - len_r ? rec_name : ((rec_tsk != NULL) ? rec_tsk->comm : ""), - t->tthrd, t->service, - (buffer->data_size+buffer->offsets_size), t->code, - buffer->allow_user_free, - (unsigned long)t->timestamp.tv_sec, - (t->timestamp.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(t->tv.tv_usec / USEC_PER_MSEC)); - } - pr_debug("%s", str); - if (dest != NULL) - strncat(dest, str, sizeof(str) - strlen(dest) - 1); -} - -/** - * binder_check_buf_checked - - * Consider buffer related issue usually makes a series of failure. - * Only care about the first problem time to minimize debug overhead. - */ -static int binder_check_buf_checked(void) -{ - return (binder_check_buf_pid == -1); -} - -static size_t binder_buffer_size(struct binder_proc *proc, - struct binder_buffer *buffer); - -/** - * binder_check_buf - Dump necessary info for buffer usage analysis - * @target_proc: receiver - * @size: requested size - * @is_async: 1 if an async call - */ -static void binder_check_buf(struct binder_proc *target_proc, - size_t size, int is_async) -{ - struct rb_node *n; - struct binder_buffer *buffer; - int i; - int large_buffer_count = 0; - unsigned int name_size = 256; - size_t tmp_size, threshold; - struct task_struct *sender; - struct task_struct *larger; - char *sender_name, *rec_name; - struct timespec exp_timestamp; - struct timeval tv; - struct rtc_time tm; -#if defined(CONFIG_MTK_AEE_FEATURE) - int db_flag = DB_OPT_BINDER_INFO; -#endif - int len_s, len_r; - - pr_debug("buffer allocation failed on %d:0 " - "%s from %d:%d size %zd\n", - target_proc->pid, - is_async ? "async" : "call ", - binder_check_buf_pid, binder_check_buf_tid, size); - - sender_name = kzalloc(size, GFP_KERNEL); - rec_name = kzalloc(size, GFP_KERNEL); - if (sender_name == NULL) { - kfree(sender_name); - return -ENOMEM; - } - if (rec_name == NULL) { - kfree(rec_name); - return -ENOMEM; - } - if (binder_check_buf_checked()) - return; - /* check blocked service for async call */ - if (is_async) { - pr_debug("buffer allocation failed on %d:0 " - "(%s) async service blocked\n", - target_proc->pid, - target_proc->tsk ? target_proc->tsk->comm : ""); - } - - pr_debug("%d:0 pending transactions:\n", target_proc->pid); - threshold = target_proc->buffer_size/16; - for (n = rb_last(&target_proc->allocated_buffers), i = 0; - n; n = rb_prev(n), i++) - { - buffer = rb_entry(n, struct binder_buffer, rb_node); - tmp_size = binder_buffer_size(target_proc, buffer); - BUG_ON(buffer->free); - - if (tmp_size > threshold) - { - if ((NULL == target_proc->large_buffer) || - (target_proc->large_buffer && - (tmp_size > binder_buffer_size(target_proc, target_proc->large_buffer)))) - target_proc->large_buffer = buffer; - large_buffer_count ++; - binder_print_buf(buffer, NULL, 1, 0); - } - else - { - if (i < 20) - binder_print_buf(buffer, NULL, 1, 0); - } - } - pr_debug("%d:0 total pending trans: %d(%d large isze)\n", - target_proc->pid, i, large_buffer_count); - - do_posix_clock_monotonic_gettime(&exp_timestamp); - //monotonic_to_bootbased(&exp_timestamp); - do_gettimeofday(&tv); - /* consider time zone. translate to android time */ - tv.tv_sec -= (sys_tz.tz_minuteswest * 60); - rtc_time_to_tm(tv.tv_sec, &tm); - - sender = find_process_by_pid(binder_check_buf_pid); - len_s = binder_proc_pid_cmdline(sender, sender_name); - len_r = binder_proc_pid_cmdline(target_proc->tsk, rec_name); - if (size > threshold) - { - if (target_proc->large_buffer) - { - pr_debug("on %d:0 the largest pending trans is:\n", - target_proc->pid); - binder_print_buf(target_proc->large_buffer, large_msg, 1, 0); - } - snprintf(aee_word, sizeof(aee_word), "check %s: large binder trans fail on %d:0 size %zd", - len_s ? sender_name : ((sender != NULL) ? sender->comm : ""), - target_proc->pid, size); - snprintf(aee_msg, sizeof(aee_msg), "BINDER_BUF_DEBUG\n%s" - "binder:check=%d,success=%d,,call=%s,,from=%d,tid=%d," - "name=%s,to=%d,name=%s,,,size=%zd,,,," - ",start=%lu.%03ld,android=" - "%d-%02d-%02d %02d:%02d:%02d.%03lu\n" - "large data size,check sender %d(%s)!\n" - "check kernel log for more info\n", - large_msg, 1, 0, is_async ? "async" : "sync", - binder_check_buf_pid, binder_check_buf_tid, - len_s ? sender_name : ((sender != NULL) ? sender->comm : ""), - target_proc->pid, - len_r ? rec_name : - ((target_proc->tsk != NULL) ? target_proc->tsk->comm : ""), - size, - (unsigned long)exp_timestamp.tv_sec, - (exp_timestamp.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(tv.tv_usec / USEC_PER_MSEC), - binder_check_buf_pid, sender ? sender->comm : ""); - } - else - { - if (target_proc->large_buffer) - { - pr_debug("on %d:0 the largest pending trans is:\n", - target_proc->pid); - binder_print_buf(target_proc->large_buffer, large_msg, 1, 1); - larger = binder_find_buffer_sender(target_proc->large_buffer); - snprintf(aee_word, sizeof(aee_word), "check %s: large binder trans", - (larger != NULL) ? larger->comm : ""); - snprintf(aee_msg, sizeof(aee_msg), "BINDER_BUF_DEBUG:\n%s" - "binder:check=%d,success=%d,,call=%s,,from=%d,tid=%d,name=%s," - "to=%d,name=%s,,,size=%zd,,,," - ",start=%lu.%03ld,android=" - "%d-%02d-%02d %02d:%02d:%02d.%03lu\n" - "large data size,check sender %d(%s)!\n" - "check kernel log for more info\n", - large_msg, 0, 0, is_async ? "async" : "sync", - binder_check_buf_pid, binder_check_buf_tid, - len_s ? sender_name : ((sender != NULL) ? sender->comm : ""), - target_proc->pid, - len_r ? rec_name : - ((target_proc->tsk != NULL) ? target_proc->tsk->comm : ""), - size, - (unsigned long)exp_timestamp.tv_sec, - (exp_timestamp.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(tv.tv_usec / USEC_PER_MSEC), - (larger != NULL) ? larger->pid : 0, - (larger != NULL) ? larger->comm : ""); - - } - else - { - snprintf(aee_word, sizeof(aee_word), "check %s: binder buffer exhaust ", - len_r ? rec_name : - ((target_proc->tsk != NULL) ? target_proc->tsk->comm : "")); - snprintf(aee_msg, sizeof(aee_msg), "BINDER_BUF_DEBUG\n" - "binder:check=%d,success=%d,,call=%s,,from=%d,tid=%d,name=%s," - "to=%d,name=%s,,,size=%zd,,,," - ",start=%lu.%03ld,android=" - "%d-%02d-%02d %02d:%02d:%02d.%03lu\n" - "%d small trans pending, check receiver %d(%s)!\n" - "check kernel log for more info\n", - 1, 0, is_async ? "async" : "sync", - binder_check_buf_pid, binder_check_buf_tid, - len_s ? sender_name : ((sender != NULL) ? sender->comm : ""), - target_proc->pid, - len_r ? rec_name : - ((target_proc->tsk != NULL) ? target_proc->tsk->comm : ""), - size, - (unsigned long)exp_timestamp.tv_sec, - (exp_timestamp.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(tv.tv_usec / USEC_PER_MSEC), - i, target_proc->pid, - target_proc->tsk ? target_proc->tsk->comm : ""); - } - - } - - binder_check_buf_pid = -1; - binder_check_buf_tid = -1; - kfree(sender_name); - kfree(rec_name); - aee_kernel_warning_api(__FILE__, __LINE__, db_flag, &aee_word[0],&aee_msg[0]); - -} -#endif static int task_get_unused_fd_flags(struct binder_proc *proc, int flags) { struct files_struct *files = proc->files; @@ -1459,7 +446,6 @@ static void binder_set_nice(long nice) binder_debug(BINDER_DEBUG_PRIORITY_CAP, "%d: nice value %ld not allowed use %ld instead\n", current->pid, nice, min_nice); - set_user_nice(current, min_nice); if (min_nice < 20) return; @@ -1471,7 +457,8 @@ static size_t binder_buffer_size(struct binder_proc *proc, { if (list_is_last(&buffer->entry, &proc->buffers)) return proc->buffer + proc->buffer_size - (void *)buffer->data; - return (size_t)list_entry(buffer->entry.next, + else + return (size_t)list_entry(buffer->entry.next, struct binder_buffer, entry) - (size_t)buffer->data; } @@ -1612,14 +599,6 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate, proc->pid, page_addr); goto err_alloc_page_failed; } -#ifdef MTK_BINDER_PAGE_USED_RECORD - binder_page_used++; - proc->page_used++; - if(binder_page_used > binder_page_used_peak) - binder_page_used_peak = binder_page_used; - if (proc->page_used > proc->page_used_peak) - proc->page_used_peak = proc->page_used; -#endif tmp_area.addr = page_addr; tmp_area.size = PAGE_SIZE + PAGE_SIZE /* guard page? */; page_array_ptr = page; @@ -1657,12 +636,6 @@ err_vm_insert_page_failed: err_map_kernel_failed: __free_page(*page); *page = NULL; -#ifdef MTK_BINDER_PAGE_USED_RECORD - if(binder_page_used > 0) - binder_page_used--; - if (proc->page_used > 0) - proc->page_used--; -#endif err_alloc_page_failed: ; } @@ -1685,9 +658,6 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc, void *has_page_addr; void *end_page_addr; size_t size; -#ifdef MTK_BINDER_DEBUG - size_t proc_max_size; -#endif if (proc->vma == NULL) { pr_err("%d: binder_alloc_buf, no vma\n", proc->pid); @@ -1703,31 +673,11 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc, return NULL; } -#ifdef MTK_BINDER_DEBUG - proc_max_size = (is_async ? (proc->buffer_size/2) : proc->buffer_size); - - if(proc_max_size < size + sizeof(struct binder_buffer)){ - binder_user_error("%d: got transaction with too large size " - "%s alloc size %zd-%zd allowed size %zd\n", proc->pid, - is_async ? "async" : "sync", data_size, offsets_size, - (proc_max_size - sizeof(struct binder_buffer))); - return NULL; - } -#endif if (is_async && proc->free_async_space < size + sizeof(struct binder_buffer)) { -#ifdef MTK_BINDER_DEBUG - pr_err("%d: binder_alloc_buf size %zd " - "failed, no async space left (%zd)\n", - proc->pid, size, proc->free_async_space); -#else binder_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: binder_alloc_buf size %zd failed, no async space left\n", proc->pid, size); -#endif -#ifdef BINDER_MONITOR - binder_check_buf(proc, size, 1); -#endif return NULL; } @@ -1746,23 +696,9 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc, break; } } -#ifdef BINDER_MONITOR - if (log_disable & BINDER_BUF_WARN) - { - if (size > 64) - { - pr_err("%d: binder_alloc_buf size %zd failed, UT auto triggerd!\n", - proc->pid, size); - binder_check_buf(proc, size, 0); - } - } -#endif if (best_fit == NULL) { pr_err("%d: binder_alloc_buf size %zd failed, " "no address space\n", proc->pid, size); -#ifdef BINDER_MONITOR - binder_check_buf(proc, size, 0); -#endif return NULL; } if (n == NULL) { @@ -1889,9 +825,6 @@ static void binder_free_buf(struct binder_proc *proc, BUG_ON(buffer->transaction != NULL); BUG_ON((void *)buffer < proc->buffer); BUG_ON((void *)buffer > proc->buffer + proc->buffer_size); -#ifdef BINDER_MONITOR - buffer->log_entry = NULL; -#endif if (buffer->async_transaction) { proc->free_async_space += size + sizeof(struct binder_buffer); @@ -2088,7 +1021,6 @@ static struct binder_ref *binder_get_ref(struct binder_proc *proc, return NULL; } - static struct binder_ref *binder_get_ref_for_node(struct binder_proc *proc, struct binder_node *node) { @@ -2246,9 +1178,6 @@ static void binder_pop_transaction(struct binder_thread *target_thread, t->need_reply = 0; if (t->buffer) t->buffer->transaction = NULL; -#ifdef BINDER_MONITOR - binder_cancel_bwdog(t); -#endif kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); } @@ -2381,63 +1310,6 @@ static void binder_transaction_buffer_release(struct binder_proc *proc, } } -#ifdef RT_PRIO_INHERIT -static void mt_sched_setscheduler_nocheck(struct task_struct *p, int policy, struct sched_param *param) -{ - int ret; - if (policy == SCHED_FIFO || policy == SCHED_RR) - param->sched_priority |= MT_ALLOW_RT_PRIO_BIT; - - ret = sched_setscheduler_nocheck(p, policy, param); - if (ret) - pr_err("set scheduler fail, error code: %d\n", ret); -} -#endif - -#ifdef BINDER_MONITOR -/* binder_update_transaction_time - update read/exec done time for transaction -** step: -** 0: start // not used -** 1: read -** 2: reply -*/ -static void binder_update_transaction_time(struct binder_transaction_log *t_log, - struct binder_transaction *bt, int step) -{ - if (step < 1 || step > 2) { - pr_err("update trans time fail, wrong step value for id %d\n", - bt->debug_id); - return; - } - - if ((NULL == bt) || (bt->log_idx == -1) || (bt->log_idx > (t_log->size - 1))) - return; - if (t_log->entry[bt->log_idx].debug_id == bt->debug_id) { - if (step == 1) - do_posix_clock_monotonic_gettime(&t_log->entry[bt->log_idx].readstamp); - else if (step == 2) - do_posix_clock_monotonic_gettime(&t_log->entry[bt->log_idx].endstamp); - } -} -/* binder_update_transaction_tid - update to thread pid transaction -*/ -static void binder_update_transaction_ttid(struct binder_transaction_log *t_log, - struct binder_transaction *bt) -{ - if ((NULL == bt) || (NULL == t_log)) - return; - if ((bt->log_idx == -1) || (bt->log_idx > (t_log->size - 1))) - return; - if (bt->tthrd < 0) - return; - if ((t_log->entry[bt->log_idx].debug_id == bt->debug_id) && - (t_log->entry[bt->log_idx].to_thread == 0)){ - t_log->entry[bt->log_idx].to_thread = bt->tthrd; - } -} - -#endif - static void binder_transaction(struct binder_proc *proc, struct binder_thread *thread, struct binder_transaction_data *tr, int reply) @@ -2455,40 +1327,13 @@ static void binder_transaction(struct binder_proc *proc, struct binder_transaction_log_entry *e; uint32_t return_error; -#ifdef BINDER_MONITOR - struct binder_transaction_log_entry log_entry; - unsigned int log_idx = -1; - - if ((reply && (tr->data_size < (proc->buffer_size/16))) || log_disable) - e = &log_entry; - else - { - e = binder_transaction_log_add(&binder_transaction_log); - if (binder_transaction_log.next) - log_idx = binder_transaction_log.next - 1; - else - log_idx = binder_transaction_log.size - 1; - } -#else e = binder_transaction_log_add(&binder_transaction_log); -#endif e->call_type = reply ? 2 : !!(tr->flags & TF_ONE_WAY); e->from_proc = proc->pid; e->from_thread = thread->pid; e->target_handle = tr->target.handle; e->data_size = tr->data_size; e->offsets_size = tr->offsets_size; -#ifdef BINDER_MONITOR - e->code = tr->code; - /* fd 0 is also valid... set initial value to -1 */ - e->fd = -1; - do_posix_clock_monotonic_gettime(&e->timestamp); - //monotonic_to_bootbased(&e->timestamp); - - do_gettimeofday(&e->tv); - /* consider time zone. translate to android time */ - e->tv.tv_sec -= (sys_tz.tz_minuteswest * 60); -#endif if (reply) { in_reply_to = thread->transaction_stack; @@ -2498,29 +1343,7 @@ static void binder_transaction(struct binder_proc *proc, return_error = BR_FAILED_REPLY; goto err_empty_call_stack; } -#ifdef BINDER_MONITOR - binder_cancel_bwdog(in_reply_to); -#endif binder_set_nice(in_reply_to->saved_priority); -#ifdef RT_PRIO_INHERIT - if (rt_task(current) && (MAX_RT_PRIO != in_reply_to->saved_rt_prio) && - !(thread->looper & (BINDER_LOOPER_STATE_REGISTERED | - BINDER_LOOPER_STATE_ENTERED))) { - struct sched_param param = { - .sched_priority = in_reply_to->saved_rt_prio, - }; - mt_sched_setscheduler_nocheck(current, - in_reply_to->saved_policy, ¶m); -#ifdef BINDER_MONITOR - if (log_disable & BINDER_RT_LOG_ENABLE) - { - pr_debug("reply reset %d sched_policy from %d to %d rt_prio from %d to %d\n", - proc->pid, in_reply_to->policy, in_reply_to->saved_policy, - in_reply_to->rt_prio, in_reply_to->saved_rt_prio); - } -#endif - } -#endif if (in_reply_to->to_thread != thread) { binder_user_error("%d:%d got reply transaction with bad transaction stack, transaction %d has target %d:%d\n", proc->pid, thread->pid, in_reply_to->debug_id, @@ -2535,16 +1358,6 @@ static void binder_transaction(struct binder_proc *proc, thread->transaction_stack = in_reply_to->to_parent; target_thread = in_reply_to->from; if (target_thread == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d got reply transaction " - "with bad transaction reply_from, " - "transaction %d has target %d:%d\n", - proc->pid, thread->pid, in_reply_to->debug_id, - in_reply_to->to_proc ? - in_reply_to->to_proc->pid : 0, - in_reply_to->to_thread ? - in_reply_to->to_thread->pid : 0); -#endif return_error = BR_DEAD_REPLY; goto err_dead_binder; } @@ -2560,9 +1373,6 @@ static void binder_transaction(struct binder_proc *proc, goto err_dead_binder; } target_proc = target_thread->proc; -#ifdef BINDER_MONITOR - e->service[0] = '\0'; -#endif } else { if (tr->target.handle) { struct binder_ref *ref; @@ -2577,25 +1387,13 @@ static void binder_transaction(struct binder_proc *proc, } else { target_node = binder_context_mgr_node; if (target_node == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d " - "binder_context_mgr_node is NULL\n", - proc->pid, thread->pid); -#endif return_error = BR_DEAD_REPLY; goto err_no_context_mgr_node; } } e->to_node = target_node->debug_id; -#ifdef BINDER_MONITOR - strcpy(e->service, target_node->name); -#endif target_proc = target_node->proc; if (target_proc == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d target_proc is NULL\n", - proc->pid, thread->pid); -#endif return_error = BR_DEAD_REPLY; goto err_dead_binder; } @@ -2635,30 +1433,13 @@ static void binder_transaction(struct binder_proc *proc, /* TODO: reuse incoming transaction for reply */ t = kzalloc(sizeof(*t), GFP_KERNEL); if (t == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d transaction allocation failed\n", - proc->pid, thread->pid); -#endif return_error = BR_FAILED_REPLY; goto err_alloc_t_failed; } -#ifdef BINDER_MONITOR - memcpy(&t->timestamp, &e->timestamp, sizeof(struct timespec)); - //do_gettimeofday(&t->tv); - /* consider time zone. translate to android time */ - //t->tv.tv_sec -= (sys_tz.tz_minuteswest * 60); - memcpy(&t->tv, &e->tv, sizeof(struct timeval)); - if (!reply) - strcpy(t->service, target_node->name); -#endif binder_stats_created(BINDER_STAT_TRANSACTION); tcomplete = kzalloc(sizeof(*tcomplete), GFP_KERNEL); if (tcomplete == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d tcomplete allocation failed\n", - proc->pid, thread->pid); -#endif return_error = BR_FAILED_REPLY; goto err_alloc_tcomplete_failed; } @@ -2667,63 +1448,6 @@ static void binder_transaction(struct binder_proc *proc, t->debug_id = ++binder_last_id; e->debug_id = t->debug_id; -#ifdef BINDER_PERF_EVAL - if (!reply && (binder_perf_evalue & BINDER_PERF_SEND_COUNTER)) - { - int i, j; - int err_code = 0; - proc->bc_t++; - for (i = 0; i < BC_STATS_NR; i++) - { - if (proc->bc_stats[i] == NULL) - proc->bc_stats[i] = kzalloc(sizeof(struct binder_bc_stats), GFP_KERNEL); - if (proc->bc_stats[i] == NULL) { - pr_err("perf_e kzalloc fail for proc %d bc_stats[%d]\n", proc->pid, i); - err_code = 1; - goto out_err; - } - if(!strcmp(proc->bc_stats[i]->service, "") && - (0 == proc->bc_stats[i]->code[0])) - { - strcpy(proc->bc_stats[i]->service, e->service); - break; - } - else if (!strcmp(proc->bc_stats[i]->service, e->service)) - break; - else - continue; - } - if (BC_STATS_NR == i){ - pr_err("perf_e bc_Stats array size" - " is not enough\n"); - err_code = 2; - goto out_err; - } - for (j = 0; j < BC_CODE_NR; j++) - { - if (0 == proc->bc_stats[i]->code[j]) - { - proc->bc_stats[i]->code[j] = e->code; - proc->bc_stats[i]->code_num[j]++; - break; - } - else if (proc->bc_stats[i]->code[j] == e->code) - { - proc->bc_stats[i]->code_num[j]++; - break; - } - else - continue; - } - if (BC_CODE_NR == j) { - pr_err("perf_e bc_code array size" - " is not enough\n"); - err_code = 3; - } -out_err: - pr_err("perf_e update proc %d bc_stats error %d\n", proc->pid, err_code); - } -#endif if (reply) binder_debug(BINDER_DEBUG_TRANSACTION, "%d:%d BC_REPLY %d -> %d:%d, data %016llx-%016llx size %lld-%lld\n", @@ -2741,19 +1465,6 @@ out_err: (u64)tr->data.ptr.offsets, (u64)tr->data_size, (u64)tr->offsets_size); -#ifdef BINDER_MONITOR - t->fproc = proc->pid; - t->fthrd = thread->pid; - t->tproc = target_proc->pid; - t->tthrd = target_thread ? target_thread->pid : 0; - t->log_idx = log_idx; - - if (!binder_check_buf_checked()) - { - binder_check_buf_pid = proc->pid; - binder_check_buf_tid = thread->pid; - } -#endif if (!reply && !(tr->flags & TF_ONE_WAY)) t->from = thread; else @@ -2764,30 +1475,18 @@ out_err: t->code = tr->code; t->flags = tr->flags; t->priority = task_nice(current); -#ifdef RT_PRIO_INHERIT - t->rt_prio = current->rt_priority; - t->policy = current->policy; - t->saved_rt_prio = MAX_RT_PRIO; -#endif trace_binder_transaction(reply, t, target_node); t->buffer = binder_alloc_buf(target_proc, tr->data_size, tr->offsets_size, !reply && (t->flags & TF_ONE_WAY)); if (t->buffer == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d buffer allocation failed " - "on %d:0\n", proc->pid, thread->pid, target_proc->pid); -#endif return_error = BR_FAILED_REPLY; goto err_binder_alloc_buf_failed; } t->buffer->allow_user_free = 0; t->buffer->debug_id = t->debug_id; t->buffer->transaction = t; -#ifdef BINDER_MONITOR - t->buffer->log_entry = e; -#endif t->buffer->target_node = target_node; trace_binder_transaction_alloc_buf(t->buffer); if (target_node) @@ -2842,50 +1541,11 @@ out_err: if (node == NULL) { node = binder_new_node(proc, fp->binder, fp->cookie); if (node == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d create new node failed\n", - proc->pid, thread->pid); -#endif return_error = BR_FAILED_REPLY; goto err_binder_new_node_failed; } node->min_priority = fp->flags & FLAT_BINDER_FLAG_PRIORITY_MASK; node->accept_fds = !!(fp->flags & FLAT_BINDER_FLAG_ACCEPTS_FDS); -#ifdef BINDER_MONITOR - { - unsigned int i, len = 0; - char *tmp; - /* this is an addService() transaction identified by: - * fp->type == BINDER_TYPE_BINDER && tr->target.handle == 0 - */ - if (tr->target.handle == 0) { - /* hack into addService() payload: - * service name string is located at MAGIC_SERVICE_NAME_OFFSET, - * and interleaved with character '\0'. - * for example, 'p', '\0', 'h', '\0', 'o', '\0', 'n', '\0', 'e' - */ - for (i = 0; (2 * i) < tr->data_size; i++) { - if ((2 * i) < MAGIC_SERVICE_NAME_OFFSET) - continue; - /* prevent array index overflow */ - if (len >= (MAX_SERVICE_NAME_LEN - 1)) - break; - tmp = (char *)(uintptr_t)(tr->data.ptr.buffer + (2 * i)); - len += sprintf((node->name) + len, "%c", *tmp); - } - node->name[len] = '\0'; - } else { - node->name[0] = '\0'; - } - /* via addService of activity service, identify - * system_server's process id. - */ - if (!strcmp(node->name, "activity")) { - system_server_pid = proc->pid; - pr_debug("system_server %d\n", system_server_pid); - } - } -#endif } if (fp->cookie != node->cookie) { binder_user_error("%d:%d sending u%016llx node %d, cookie mismatch %016llx != %016llx\n", @@ -2901,10 +1561,6 @@ out_err: } ref = binder_get_ref_for_node(target_proc, node); if (ref == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d get binder ref failed\n", - proc->pid, thread->pid); -#endif return_error = BR_FAILED_REPLY; goto err_binder_get_ref_for_node_failed; } @@ -2956,10 +1612,6 @@ out_err: struct binder_ref *new_ref; new_ref = binder_get_ref_for_node(target_proc, ref->node); if (new_ref == NULL) { -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d get new binder ref failed\n", - proc->pid, thread->pid); -#endif return_error = BR_FAILED_REPLY; goto err_binder_get_ref_for_node_failed; } @@ -3009,13 +1661,6 @@ out_err: target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC); if (target_fd < 0) { fput(file); -#ifdef MTK_BINDER_DEBUG - binder_user_error("%d:%d to %d failed due to %d no unused fd available(%d:%s fd leak?), %d\n", - proc->pid, thread->pid, - target_proc->pid, target_proc->pid, target_proc->pid, - target_proc->tsk ? target_proc->tsk->comm : "", - target_fd); -#endif return_error = BR_FAILED_REPLY; goto err_get_unused_fd_failed; } @@ -3026,9 +1671,6 @@ out_err: /* TODO: fput? */ fp->binder = 0; fp->handle = target_fd; -#ifdef BINDER_MONITOR - e->fd = target_fd; -#endif } break; default: @@ -3040,9 +1682,6 @@ out_err: } if (reply) { BUG_ON(t->buffer->async_transaction != 0); -#ifdef BINDER_MONITOR - binder_update_transaction_time(&binder_transaction_log,in_reply_to, 2); -#endif binder_pop_transaction(target_thread, in_reply_to); } else if (!(t->flags & TF_ONE_WAY)) { BUG_ON(t->buffer->async_transaction != 0); @@ -3062,67 +1701,8 @@ out_err: list_add_tail(&t->work.entry, target_list); tcomplete->type = BINDER_WORK_TRANSACTION_COMPLETE; list_add_tail(&tcomplete->entry, &thread->todo); -#ifdef RT_PRIO_INHERIT - if (target_wait) { - unsigned long flag; - wait_queue_t *curr, *next; - bool is_lock = false; - - spin_lock_irqsave(&target_wait->lock, flag); - is_lock = true; - list_for_each_entry_safe(curr, next, &target_wait->task_list, task_list) { - unsigned flags = curr->flags; - struct task_struct *tsk = curr->private; - if (tsk == NULL) { - spin_unlock_irqrestore(&target_wait->lock, flag); - is_lock = false; - wake_up_interruptible(target_wait); - break; - } -# ifdef MTK_BINDER_DEBUG - if (tsk->state == TASK_UNINTERRUPTIBLE) { - pr_err("from %d:%d to %d:%d target " - "thread state: %ld\n", - proc->pid, thread->pid, - tsk->tgid, tsk->pid, tsk->state); - show_stack(tsk, NULL); - } -# endif - if (!reply && (t->policy == SCHED_RR || t->policy == SCHED_FIFO)&& - t->rt_prio > tsk->rt_priority && - !(t->flags & TF_ONE_WAY)) { - struct sched_param param = { - .sched_priority = t->rt_prio, - }; - - t->saved_rt_prio = tsk->rt_priority; - t->saved_policy = tsk->policy; - mt_sched_setscheduler_nocheck(tsk, t->policy, ¶m); -#ifdef BINDER_MONITOR - if (log_disable & BINDER_RT_LOG_ENABLE) - { - pr_debug("write set %d sched_policy from %d to %d rt_prio from %d to %d\n", - tsk->pid, t->saved_policy, t->policy, - t->saved_rt_prio, t->rt_prio); - } -#endif - } - if (curr->func(curr, TASK_INTERRUPTIBLE, 0, NULL) && - (flags & WQ_FLAG_EXCLUSIVE)) - break; - } - if (is_lock) - spin_unlock_irqrestore(&target_wait->lock, flag); - } -#else if (target_wait) wake_up_interruptible(target_wait); -#endif - -#ifdef BINDER_MONITOR - t->wait_on = reply ? WAIT_ON_REPLY_READ : WAIT_ON_READ; - binder_queue_bwdog(t, (time_t)WAIT_BUDGET_READ); -#endif return; err_get_unused_fd_failed: @@ -3142,9 +1722,6 @@ err_binder_alloc_buf_failed: kfree(tcomplete); binder_stats_deleted(BINDER_STAT_TRANSACTION_COMPLETE); err_alloc_tcomplete_failed: -#ifdef BINDER_MONITOR - binder_cancel_bwdog(t); -#endif kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); err_alloc_t_failed: @@ -3340,23 +1917,9 @@ static int binder_thread_write(struct binder_proc *proc, struct binder_thread *t if (buffer->async_transaction && buffer->target_node) { BUG_ON(!buffer->target_node->has_async_transaction); if (list_empty(&buffer->target_node->async_todo)) -#ifdef MTK_BINDER_DEBUG - { -#endif buffer->target_node->has_async_transaction = 0; -#ifdef MTK_BINDER_DEBUG - buffer->target_node->async_pid = 0; - } -#endif else -#ifdef MTK_BINDER_DEBUG - { -#endif list_move_tail(buffer->target_node->async_todo.next, &thread->todo); -#ifdef MTK_BINDER_DEBUG - buffer->target_node->async_pid = thread->pid; - } -#endif } trace_binder_transaction_buffer_release(buffer); binder_transaction_buffer_release(proc, buffer, NULL); @@ -3434,22 +1997,6 @@ static int binder_thread_write(struct binder_proc *proc, struct binder_thread *t target); break; } -#ifdef MTK_DEATH_NOTIFY_MONITOR - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #%s]binder: %d:%d %s %d(%s) cookie 0x%016llx\n", - cmd == BC_REQUEST_DEATH_NOTIFICATION ? "1" : "2", - proc->pid, thread->pid, - cmd == BC_REQUEST_DEATH_NOTIFICATION ? - "BC_REQUEST_DEATH_NOTIFICATION" : - "BC_CLEAR_DEATH_NOTIFICATION", - ref->node->proc ? ref->node->proc->pid : 0, -#ifdef BINDER_MONITOR - ref->node ? ref->node->name : "", -#else - "", -#endif - (u64)cookie); -#else binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, "%d:%d %s %016llx ref %d desc %d s %d w %d for node %d\n", proc->pid, thread->pid, @@ -3458,7 +2005,6 @@ static int binder_thread_write(struct binder_proc *proc, struct binder_thread *t "BC_CLEAR_DEATH_NOTIFICATION", (u64)cookie, ref->debug_id, ref->desc, ref->strong, ref->weak, ref->node->debug_id); -#endif if (cmd == BC_REQUEST_DEATH_NOTIFICATION) { if (ref->death) { @@ -3522,11 +2068,6 @@ static int binder_thread_write(struct binder_proc *proc, struct binder_thread *t if (get_user(cookie, (binder_uintptr_t __user *)ptr)) return -EFAULT; -#ifdef MTK_DEATH_NOTIFY_MONITOR - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #6]binder: %d:%d cookie 0x%016llx\n", proc->pid, thread->pid, (u64)cookie); -#endif - ptr += sizeof(void *); list_for_each_entry(w, &proc->delivered_death, entry) { struct binder_ref_death *tmp_death = container_of(w, struct binder_ref_death, work); @@ -3620,9 +2161,9 @@ retry: pr_err("read put err2 %u to user %pK, thread error %u:%u\n", thread->return_error2, ptr, thread->return_error, thread->return_error2); binder_stat_br(proc, thread, thread->return_error2); + thread->return_error2 = BR_OK; if (ptr == end) goto done; - thread->return_error2 = BR_OK; } if (put_user(thread->return_error, (uint32_t __user *)ptr)) return -EFAULT; @@ -3652,30 +2193,7 @@ retry: wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2); } -#ifdef RT_PRIO_INHERIT - /* disable preemption to prevent from schedule-out immediately */ - preempt_disable(); -#endif binder_set_nice(proc->default_priority); -#ifdef RT_PRIO_INHERIT - if (rt_task(current) && !binder_has_proc_work(proc, thread)) { - /* make sure binder has no work before setting priority back*/ - struct sched_param param = { - .sched_priority = proc->default_rt_prio, - }; -#ifdef BINDER_MONITOR - if (log_disable & BINDER_RT_LOG_ENABLE) - { - pr_debug("enter threadpool reset %d sched_policy from %u to %d rt_prio from %u to %d\n", - current->pid, current->policy, proc->default_policy, - current->rt_priority, proc->default_rt_prio); - } -#endif - mt_sched_setscheduler_nocheck(current, - proc->default_policy, ¶m); - } - preempt_enable_no_resched(); -#endif if (non_block) { if (!binder_has_proc_work(proc, thread)) ret = -EAGAIN; @@ -3723,9 +2241,6 @@ retry: switch (w->type) { case BINDER_WORK_TRANSACTION: { t = container_of(w, struct binder_transaction, work); -#ifdef BINDER_MONITOR - binder_cancel_bwdog(t); -#endif } break; case BINDER_WORK_TRANSACTION_COMPLETE: { cmd = BR_TRANSACTION_COMPLETE; @@ -3813,32 +2328,6 @@ retry: uint32_t cmd; death = container_of(w, struct binder_ref_death, work); - -#ifdef MTK_DEATH_NOTIFY_MONITOR - switch (w->type) { - case BINDER_WORK_DEAD_BINDER: - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #4]binder: %d:%d BINDER_WORK_DEAD_BINDER cookie 0x%016llx\n", - proc->pid, thread->pid, (u64)death->cookie); - break; - case BINDER_WORK_DEAD_BINDER_AND_CLEAR: - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #4]binder: %d:%d BINDER_WORK_DEAD_BINDER_AND_CLEAR cookie " - "0x%016llx\n", proc->pid, thread->pid, (u64)death->cookie); - break; - case BINDER_WORK_CLEAR_DEATH_NOTIFICATION: - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #4]binder: %d:%d BINDER_WORK_CLEAR_DEATH_NOTIFICATION cookie " - "0x%016llx\n", proc->pid, thread->pid, (u64)death->cookie); - break; - default: - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #4]binder: %d:%d UNKNOWN-%d cookie 0x%016llx\n", - proc->pid, thread->pid, w->type, (u64)death->cookie); - break; - } -#endif - if (w->type == BINDER_WORK_CLEAR_DEATH_NOTIFICATION) cmd = BR_CLEAR_DEATH_NOTIFICATION_DONE; else @@ -3879,29 +2368,6 @@ retry: tr.target.ptr = target_node->ptr; tr.cookie = target_node->cookie; t->saved_priority = task_nice(current); -#ifdef RT_PRIO_INHERIT - /* since we may fail the rt inherit due to target - * wait queue task_list is empty, check again here. - */ - if ((SCHED_RR == t->policy || SCHED_FIFO == t->policy) && t->rt_prio > current->rt_priority && - !(t->flags & TF_ONE_WAY)) { - struct sched_param param = { - .sched_priority = t->rt_prio, - }; - - t->saved_rt_prio = current->rt_priority; - t->saved_policy = current->policy; - mt_sched_setscheduler_nocheck(current, t->policy, ¶m); -#ifdef BINDER_MONITOR - if (log_disable & BINDER_RT_LOG_ENABLE) - { - pr_debug("read set %d sched_policy from %d to %d rt_prio from %d to %d\n", - proc->pid, t->saved_policy, t->policy, - t->saved_rt_prio, t->rt_prio); - } -#endif - } -#endif if (t->priority < target_node->min_priority && !(t->flags & TF_ONE_WAY)) binder_set_nice(t->priority); @@ -3960,28 +2426,8 @@ retry: t->to_parent = thread->transaction_stack; t->to_thread = thread; thread->transaction_stack = t; -#ifdef BINDER_MONITOR - do_posix_clock_monotonic_gettime(&t->exe_timestamp); - //monotonic_to_bootbased(&t->exe_timestamp); - do_gettimeofday(&t->tv); - /* consider time zone. translate to android time */ - t->tv.tv_sec -= (sys_tz.tz_minuteswest * 60); - t->wait_on = WAIT_ON_EXEC; - t->tthrd = thread->pid; - binder_queue_bwdog(t, (time_t)WAIT_BUDGET_EXEC); - binder_update_transaction_time(&binder_transaction_log, t, 1); - binder_update_transaction_ttid(&binder_transaction_log, t); -#endif } else { t->buffer->transaction = NULL; -#ifdef BINDER_MONITOR - binder_cancel_bwdog(t); - if (cmd == BR_TRANSACTION && (t->flags & TF_ONE_WAY)) { - binder_update_transaction_time(&binder_transaction_log, t, 1); - t->tthrd = thread->pid; - binder_update_transaction_ttid(&binder_transaction_log, t); - } -#endif kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); } @@ -4026,9 +2472,6 @@ static void binder_release_work(struct list_head *list) "undelivered transaction %d\n", t->debug_id); t->buffer->transaction = NULL; -#ifdef BINDER_MONITOR - binder_cancel_bwdog(t); -#endif kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); } @@ -4113,25 +2556,6 @@ static int binder_free_thread(struct binder_proc *proc, t->debug_id, (t->to_thread == thread) ? "in" : "out"); -#ifdef MTK_BINDER_DEBUG - pr_err("%d: %pK from %d:%d to %d:%d code %x flags %x " - "pri %ld r%d " -#ifdef BINDER_MONITOR - "start %lu.%06lu" -#endif - , - t->debug_id, t, - t->from ? t->from->proc->pid : 0, - t->from ? t->from->pid : 0, - t->to_proc ? t->to_proc->pid : 0, - t->to_thread ? t->to_thread->pid : 0, - t->code, t->flags, t->priority, t->need_reply -#ifdef BINDER_MONITOR - , (unsigned long)t->timestamp.tv_sec, - (t->timestamp.tv_nsec / NSEC_PER_USEC) -#endif - ); -#endif if (t->to_thread == thread) { t->to_proc = NULL; t->to_thread = NULL; @@ -4232,35 +2656,35 @@ static int binder_ioctl_write_read(struct file *filp, if (thread->proc != proc) { int i; unsigned int *p; - pr_debug(KERN_ERR "binder: " + printk(KERN_ERR "binder: " "thread->proc != proc\n"); - pr_debug(KERN_ERR "binder: thread %pK\n", + printk(KERN_ERR "binder: thread %pK\n", thread); p = (unsigned int *)thread - 32; for (i = -4; i <= 3; i++, p+=8) { - pr_debug(KERN_ERR "%pK %08x %08x " + printk(KERN_ERR "%pK %08x %08x " "%08x %08x %08x %08x " "%08x %08x\n", p, *(p), *(p+1), *(p+2), *(p+3), *(p+4), *(p+5), *(p+6), *(p+7)); } - pr_debug(KERN_ERR "binder: thread->proc " + printk(KERN_ERR "binder: thread->proc " "%pK\n", thread->proc); p = (unsigned int *)thread->proc - 32; for (i = -4; i <= 5; i++, p+=8) { - pr_debug(KERN_ERR "%pK %08x %08x " + printk(KERN_ERR "%pK %08x %08x " "%08x %08x %08x %08x " "%08x %08x\n", p, *(p), *(p+1), *(p+2), *(p+3), *(p+4), *(p+5), *(p+6), *(p+7)); } - pr_debug(KERN_ERR "binder: proc %pK\n", + printk(KERN_ERR "binder: proc %pK\n", proc); p = (unsigned int *)proc - 32; for (i = -4; i <= 5; i++, p+=8) { - pr_debug(KERN_ERR "%pK %08x %08x " + printk(KERN_ERR "%pK %08x %08x " "%08x %08x %08x %08x " "%08x %08x\n", p, *(p), *(p+1), *(p+2), @@ -4322,11 +2746,6 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp, struct binder_thread ret = -ENOMEM; goto out; } -#ifdef BINDER_MONITOR - strcpy(binder_context_mgr_node->name, "servicemanager"); - pr_debug("%d:%d set as servicemanager uid %d\n", - proc->pid, thread->pid, binder_context_mgr_uid); -#endif binder_context_mgr_node->local_weak_refs++; binder_context_mgr_node->local_strong_refs++; binder_context_mgr_node->has_strong_ref = 1; @@ -4559,10 +2978,6 @@ static int binder_open(struct inode *nodp, struct file *filp) INIT_LIST_HEAD(&proc->todo); init_waitqueue_head(&proc->wait); proc->default_priority = task_nice(current); -#ifdef RT_PRIO_INHERIT - proc->default_rt_prio = current->rt_priority; - proc->default_policy = current->policy; -#endif binder_lock(__func__); @@ -4607,15 +3022,9 @@ static void binder_deferred_flush(struct binder_proc *proc) } wake_up_interruptible_all(&proc->wait); -#ifdef MTK_BINDER_DEBUG - if (wake_count) - pr_debug("binder_flush: %d woke %d threads\n", proc->pid, - wake_count); -#else binder_debug(BINDER_DEBUG_OPEN_CLOSE, "binder_flush: %d woke %d threads\n", proc->pid, wake_count); -#endif } static int binder_release(struct inode *nodp, struct file *filp) @@ -4631,15 +3040,6 @@ static int binder_node_release(struct binder_node *node, int refs) { struct binder_ref *ref; int death = 0; -#ifdef BINDER_MONITOR - int sys_reg = 0; -#endif -#if defined(MTK_DEATH_NOTIFY_MONITOR) || defined(MTK_BINDER_DEBUG) - int dead_pid = node->proc ? node->proc->pid : 0; - char dead_pname[TASK_COMM_LEN] = ""; - if(node->proc && node->proc->tsk) - strcpy(dead_pname, node->proc->tsk->comm); -#endif list_del_init(&node->work.entry); binder_release_work(&node->async_todo); @@ -4662,22 +3062,6 @@ static int binder_node_release(struct binder_node *node, int refs) if (!ref->death) continue; -#ifdef MTK_DEATH_NOTIFY_MONITOR - binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION, - "[DN #3]binder: %d:(%s) cookie 0x%016llx\n", - dead_pid, -#ifdef BINDER_MONITOR - node->name, -#else - dead_pname, -#endif - (u64)ref->death->cookie); -#endif -#ifdef BINDER_MONITOR - if (!sys_reg && - ref->proc->pid == system_server_pid) - sys_reg = 1; -#endif death++; if (list_empty(&ref->death->work.entry)) { @@ -4689,14 +3073,6 @@ static int binder_node_release(struct binder_node *node, int refs) BUG(); } -#if defined(BINDER_MONITOR) && defined(MTK_BINDER_DEBUG) - if (sys_reg) - pr_debug("%d:%s node %d:%s exits with %d:system_server DeathNotify\n", - dead_pid, dead_pname, - node->debug_id, node->name, - system_server_pid); -#endif - binder_debug(BINDER_DEBUG_DEAD_BINDER, "node %d now dead, refs %d, death %d\n", node->debug_id, refs, death); @@ -4769,25 +3145,6 @@ static void binder_deferred_release(struct binder_proc *proc) pr_err("release proc %d, transaction %d, not freed\n", proc->pid, t->debug_id); /*BUG();*/ -#ifdef MTK_BINDER_DEBUG - pr_err("%d: %pK from %d:%d to %d:%d code %x flags %x " - "pri %ld r%d " -#ifdef BINDER_MONITOR - "start %lu.%06lu" -#endif - , - t->debug_id, t, - t->from ? t->from->proc->pid : 0, - t->from ? t->from->pid : 0, - t->to_proc ? t->to_proc->pid : 0, - t->to_thread ? t->to_thread->pid : 0, - t->code, t->flags, t->priority, t->need_reply -#ifdef BINDER_MONITOR - , (unsigned long)t->timestamp.tv_sec, - (t->timestamp.tv_nsec / NSEC_PER_USEC) -#endif - ); -#endif } binder_free_buf(proc, buffer); @@ -4813,12 +3170,6 @@ static void binder_deferred_release(struct binder_proc *proc) unmap_kernel_range((unsigned long)page_addr, PAGE_SIZE); __free_page(proc->pages[i]); page_count++; -#ifdef MTK_BINDER_PAGE_USED_RECORD - if(binder_page_used > 0) - binder_page_used--; - if (proc->page_used > 0) - proc->page_used--; -#endif } kfree(proc->pages); vfree(proc->buffer); @@ -4831,18 +3182,6 @@ static void binder_deferred_release(struct binder_proc *proc) __func__, proc->pid, threads, nodes, incoming_refs, outgoing_refs, active_transactions, buffers, page_count); -#ifdef BINDER_PERF_EVAL - { - int i; - for (i = 0; i < BC_STATS_NR; i++) { - if (proc->bc_stats[i] != NULL) { - kfree(proc->bc_stats[i]); - proc->bc_stats[i] = NULL; - pr_debug("binder_release: release %d bc_stats[%d]\n", proc->pid, i); - } - } - } -#endif kfree(proc); } @@ -4904,10 +3243,6 @@ binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer) static void print_binder_transaction(struct seq_file *m, const char *prefix, struct binder_transaction *t) { -#ifdef BINDER_MONITOR - struct rtc_time tm; - rtc_time_to_tm(t->tv.tv_sec, &tm); -#endif seq_printf(m, "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d", prefix, t->debug_id, t, @@ -4917,37 +3252,15 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix, t->to_thread ? t->to_thread->pid : 0, t->code, t->flags, t->priority, t->need_reply); if (t->buffer == NULL) { -#ifdef BINDER_MONITOR - seq_printf(m, " start %lu.%06lu android %d-%02d-%02d %02d:%02d:%02d.%03lu" - " buffer free\n", - (unsigned long)t->timestamp.tv_sec, - (t->timestamp.tv_nsec / NSEC_PER_USEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(t->tv.tv_usec / USEC_PER_MSEC)); -#else seq_puts(m, " buffer free\n"); -#endif return; } if (t->buffer->target_node) seq_printf(m, " node %d", t->buffer->target_node->debug_id); -#ifdef BINDER_MONITOR - seq_printf(m, " size %zd:%zd data %pK auf %d start %lu.%06lu" - " android %d-%02d-%02d %02d:%02d:%02d.%03lu\n", - t->buffer->data_size, t->buffer->offsets_size, - t->buffer->data, t->buffer->allow_user_free, - (unsigned long)t->timestamp.tv_sec, - (t->timestamp.tv_nsec / NSEC_PER_USEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(t->tv.tv_usec / USEC_PER_MSEC)); -#else seq_printf(m, " size %zd:%zd data %pK\n", t->buffer->data_size, t->buffer->offsets_size, t->buffer->data); -#endif } static void print_binder_buffer(struct seq_file *m, const char *prefix, @@ -5038,29 +3351,17 @@ static void print_binder_node(struct seq_file *m, struct binder_node *node) hlist_for_each_entry(ref, &node->refs, node_entry) count++; -#ifdef BINDER_MONITOR - seq_printf(m, " node %d (%s): u%016llx c%016llx hs %d hw %d ls %d lw %d is %d iw %d", - node->debug_id, node->name, (u64)node->ptr, (u64)node->cookie, - node->has_strong_ref, node->has_weak_ref, - node->local_strong_refs, node->local_weak_refs, - node->internal_strong_refs, count); -#else seq_printf(m, " node %d: u%016llx c%016llx hs %d hw %d ls %d lw %d is %d iw %d", node->debug_id, (u64)node->ptr, (u64)node->cookie, node->has_strong_ref, node->has_weak_ref, node->local_strong_refs, node->local_weak_refs, node->internal_strong_refs, count); -#endif if (count) { seq_puts(m, " proc"); hlist_for_each_entry(ref, &node->refs, node_entry) seq_printf(m, " %d", ref->proc->pid); } seq_puts(m, "\n"); -#ifdef MTK_BINDER_DEBUG - if (node->async_pid) - seq_printf(m, " pending async transaction on %d:\n", node->async_pid); -#endif list_for_each_entry(w, &node->async_todo, entry) print_binder_work(m, " ", " pending async transaction", w); @@ -5198,112 +3499,6 @@ static void print_binder_stats(struct seq_file *m, const char *prefix, } } -#ifdef BINDER_PERF_EVAL -static void print_binder_timeout_stats(struct seq_file *m, const char *prefix, - struct binder_timeout_stats *to_stats) -{ - int i, j; - - BUILD_BUG_ON(ARRAY_SIZE(to_stats->bto) != - (ARRAY_SIZE(binder_wait_on_str) - 1)); - for (i = 0; i < ARRAY_SIZE(to_stats->bto); i++) - { - if (to_stats->bto[i]) - seq_printf(m, "%s%s: %lu\n", prefix, - binder_wait_on_str[i + 1], to_stats->bto[i]); - } - for (i = 0, j = 0; i < ARRAY_SIZE(to_stats->read_t); i++) - { - struct timespec sub_t = to_stats->read_t[i]; - if (sub_t.tv_sec) - { - j++; - if (!i) - seq_printf(m, "%s%s: timeout total time list:\n", - prefix, binder_wait_on_str[WAIT_ON_READ]); - - seq_printf(m, " %s%u.%03ld", prefix, - (unsigned)sub_t.tv_sec, (sub_t.tv_nsec / NSEC_PER_MSEC)); - } - } - if (j) - seq_printf(m, "\n"); - for (i = 0, j = 0; i < ARRAY_SIZE(to_stats->exec_t); i++) - { - struct timespec sub_t = to_stats->exec_t[i]; - if (sub_t.tv_sec) - { - j++; - if (!i) - seq_printf(m, "%s%s: timeout total time list:\n", - prefix, binder_wait_on_str[WAIT_ON_EXEC]); - - seq_printf(m, " %s%u.%03ld", prefix, - (unsigned)sub_t.tv_sec, (sub_t.tv_nsec / NSEC_PER_MSEC)); - } - } - if (j) - seq_printf(m, "\n"); - for (i = 0, j = 0; i < ARRAY_SIZE(to_stats->rrply_t); i++) - { - struct timespec sub_t = to_stats->rrply_t[i]; - if (sub_t.tv_sec) - { - j++; - if (!i) - seq_printf(m, "%s%s: timeout total time list:\n", - prefix, binder_wait_on_str[WAIT_ON_REPLY_READ]); - - seq_printf(m, " %s%u.%03ld", prefix, - (unsigned)sub_t.tv_sec, (sub_t.tv_nsec / NSEC_PER_MSEC)); - } - } - if (j) - seq_printf(m, "\n"); -} - -static void print_binder_proc_perf_timeout_stats(struct seq_file *m, - struct binder_proc *proc) -{ - struct rb_node *n; - int i; - - int proc_to_counter = 0; - for (i = 0; i < ARRAY_SIZE(proc->to_stats.bto); i++) - { - proc_to_counter += proc->to_stats.bto[i]; - if (proc_to_counter > 0) - break; - } - if (proc_to_counter > 0) - { - seq_printf(m, "proc %d(%s) timeout stats:\n", - proc->pid, (proc->tsk != NULL) ? proc->tsk->comm : ""); - print_binder_timeout_stats(m, " ", &proc->to_stats); - - seq_printf(m, " threads timeout stats:\n"); - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) - { - int thread_to_counter = 0; - struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node); - for (i = 0; i < ARRAY_SIZE(thread->to_stats.bto); i++) - { - thread_to_counter += thread->to_stats.bto[i]; - if (thread_to_counter > 0) - break; - } - if (thread_to_counter > 0) - { - seq_printf(m, " thread: %d\n", thread->pid); - print_binder_timeout_stats(m, " ", &thread->to_stats); - } - } - } - -} - -#endif - static void print_binder_proc_stats(struct seq_file *m, struct binder_proc *proc) { @@ -5400,61 +3595,6 @@ static int binder_stats_show(struct seq_file *m, void *unused) return 0; } -#ifdef BINDER_PERF_EVAL -static int binder_perf_stats_show(struct seq_file *m, void *unused) -{ - struct binder_proc *proc; - int do_lock = !binder_debug_no_lock; - - if (do_lock) - binder_lock(__func__); - - seq_puts(m, "binder stats:\n"); - //print_binder_stats(m, "", &binder_stats); - - if (binder_perf_evalue & BINDER_PERF_SEND_COUNTER) - { - seq_puts(m, "binder send transaction stats:\n"); - hlist_for_each_entry(proc, &binder_procs, proc_node) - { - if (proc->bc_t) - { - int i, j; - seq_printf(m, "proc %d(%s): %d\n", proc->pid, - proc->tsk ? proc->tsk->comm : "", - proc->bc_t); - for (i = 0; i < BC_STATS_NR; i++) - { - if (proc->bc_stats[i] == NULL) - break; - if (!strcmp(proc->bc_stats[i]->service, "") && - (0 == proc->bc_stats[i]->code[0])) - break; - seq_printf(m, " service %s\n", proc->bc_stats[i]->service); - for (j = 0; j < BC_CODE_NR; j++) - { - if (0 == proc->bc_stats[i]->code_num[j]) - break; - seq_printf(m, " dex %u: %u\n", proc->bc_stats[i]->code[j], proc->bc_stats[i]->code_num[j]); - } - } - - } - } - - } - - if (binder_perf_evalue & BINDER_PERF_TIMEOUT_COUNTER) - { - seq_puts(m, "binder transaction time out stats:\n"); - hlist_for_each_entry(proc, &binder_procs, proc_node) - print_binder_proc_perf_timeout_stats(m,proc); - } - if (do_lock) - binder_unlock(__func__); - return 0; -} -#endif static int binder_transactions_show(struct seq_file *m, void *unused) { struct binder_proc *proc; @@ -5499,101 +3639,14 @@ static int binder_proc_show(struct seq_file *m, void *unused) static void print_binder_transaction_log_entry(struct seq_file *m, struct binder_transaction_log_entry *e) { -#ifdef BINDER_MONITOR - char tmp[30]; - struct rtc_time tm; - struct timespec sub_read_t, sub_total_t; - unsigned long read_ms =0; - unsigned long total_ms = 0; - - memset(&sub_read_t, 0, sizeof(sub_read_t)); - memset(&sub_total_t, 0, sizeof(sub_total_t)); - - if (e->fd != -1) - sprintf(tmp, " (fd %d)", e->fd); - else - tmp[0] = '\0'; - - if ((e->call_type == 0) && timespec_valid_strict(&e->endstamp) && - (timespec_compare(&e->endstamp, &e->timestamp) > 0)) { - sub_total_t = timespec_sub(e->endstamp, e->timestamp); - total_ms = ((unsigned long)sub_total_t.tv_sec)*MSEC_PER_SEC + - sub_total_t.tv_nsec / NSEC_PER_MSEC; - } - if ((e->call_type == 1) && timespec_valid_strict(&e->readstamp) && - (timespec_compare(&e->readstamp, &e->timestamp) > 0)) { - sub_read_t = timespec_sub(e->readstamp, e->timestamp); - read_ms = ((unsigned long)sub_read_t.tv_sec)*MSEC_PER_SEC + - sub_read_t.tv_nsec / NSEC_PER_MSEC; - } - - rtc_time_to_tm(e->tv.tv_sec, &tm); - seq_printf(m, - "%d: %s from %d:%d to %d:%d node %d handle %d (%s) size %d:%d%s " - "dex %u start %lu.%06lu android %d-%02d-%02d %02d:%02d:%02d.%03lu read %lu.%06lu %s %lu.%06lu total %lu.%06lums\n", - e->debug_id, (e->call_type == 2) ? "reply" : - ((e->call_type == 1) ? "async" : "call "), - e->from_proc, e->from_thread, e->to_proc, e->to_thread, - e->to_node, e->target_handle, e->service, - e->data_size, e->offsets_size, tmp, e->code, - (unsigned long)e->timestamp.tv_sec, - (e->timestamp.tv_nsec / NSEC_PER_USEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(e->tv.tv_usec / USEC_PER_MSEC), - (unsigned long)e->readstamp.tv_sec, - (e->readstamp.tv_nsec / NSEC_PER_USEC), - (e->call_type == 0) ? "end" : "", - (e->call_type == 0) ? ((unsigned long)e->endstamp.tv_sec) : 0, - (e->call_type == 0) ? (e->endstamp.tv_nsec / NSEC_PER_USEC) : 0, - (e->call_type == 0) ? total_ms : read_ms, - (e->call_type == 0) ? (sub_total_t.tv_nsec % NSEC_PER_MSEC) : - (sub_read_t.tv_nsec % NSEC_PER_MSEC)); -#else seq_printf(m, "%d: %s from %d:%d to %d:%d node %d handle %d size %d:%d\n", e->debug_id, (e->call_type == 2) ? "reply" : ((e->call_type == 1) ? "async" : "call "), e->from_proc, e->from_thread, e->to_proc, e->to_thread, e->to_node, e->target_handle, e->data_size, e->offsets_size); -#endif -} - -#ifdef BINDER_MONITOR -static void log_resume_func(struct work_struct *w) -{ - pr_debug("transaction log is self resumed\n"); - log_disable = 0; } -static DECLARE_DELAYED_WORK(log_resume_work, log_resume_func); - -static int binder_transaction_log_show(struct seq_file *m, void *unused) -{ - struct binder_transaction_log *log = m->private; - int i; - - if (!log->entry) - return 0; - - if (log->full) { - for (i = log->next; i < log->size; i++) - print_binder_transaction_log_entry(m, &log->entry[i]); - } - for (i = 0; i < log->next; i++) - print_binder_transaction_log_entry(m, &log->entry[i]); - - if (log_disable & BINDER_LOG_RESUME) { - pr_debug("%d (%s) read transaction log and " - "resume\n", - task_pid_nr(current), current->comm); - cancel_delayed_work(&log_resume_work); - log_disable = 0; - } - return 0; -} -#else - static int binder_transaction_log_show(struct seq_file *m, void *unused) { struct binder_transaction_log *log = m->private; @@ -5607,7 +3660,6 @@ static int binder_transaction_log_show(struct seq_file *m, void *unused) print_binder_transaction_log_entry(m, &log->entry[i]); return 0; } -#endif static const struct file_operations binder_fops = { .owner = THIS_MODULE, @@ -5626,371 +3678,6 @@ static struct miscdevice binder_miscdev = { .fops = &binder_fops }; -#ifdef BINDER_PERF_EVAL -static void binder_perf_timeout_zero_init(struct binder_timeout_stats *to_stats) -{ - memset(&to_stats->bto[0], 0, sizeof(to_stats->bto)); - memset(&to_stats->read_t[0], 0, sizeof(to_stats->read_t)); - memset(&to_stats->exec_t[0], 0, sizeof(to_stats->exec_t)); - memset(&to_stats->rrply_t[0], 0, sizeof(to_stats->rrply_t)); -} - - -static void binder_perf_stats_timeout_clean(void) -{ - struct binder_proc *proc; - struct rb_node *n; - int do_lock = !binder_debug_no_lock; - - if (do_lock) - binder_lock(__func__); - hlist_for_each_entry(proc, &binder_procs, proc_node) - { - binder_perf_timeout_zero_init(&proc->to_stats); - for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) - { - struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node); - binder_perf_timeout_zero_init(&thread->to_stats); - } - } - if (do_lock) - binder_unlock(__func__); -} - -static void binder_perf_stats_bct_clean(void) -{ - struct binder_proc *proc; - int do_lock = !binder_debug_no_lock; - - if (do_lock) - binder_lock(__func__); - hlist_for_each_entry(proc, &binder_procs, proc_node) - { - int i; - proc->bc_t = 0; - for (i = 0; i < BC_STATS_NR; i++) - { - if (proc->bc_stats[i] != NULL) { - kfree(proc->bc_stats[i]); - proc->bc_stats[i] = NULL; - } - } - } - if (do_lock) - binder_unlock(__func__); -} - -static int binder_perf_evalue_show(struct seq_file *m, void *unused) -{ - seq_printf(m, " Current binder performance evalue is: %u\n", binder_perf_evalue); - return 0; -} - -static ssize_t binder_perf_evalue_write(struct file *filp, const char *ubuf, - size_t cnt, loff_t *data) -{ - char buf[32]; - size_t copy_size = cnt; - unsigned long val; - int ret; - - if (cnt >= sizeof(buf)) - copy_size = 32 - 1; - buf[copy_size] = '\0'; - - if (copy_from_user(&buf, ubuf, copy_size)) - return -EFAULT; - - pr_debug("[Binder] Set binder perf evalue:%u -> ", binder_perf_evalue); - ret = strict_strtoul(buf, 10, &val); - if (ret < 0 ) { - pr_debug("Null\ninvalid string, need number foramt, err:%d \n",ret); - pr_debug("perf evalue level: 0 ---- 3 \n"); - pr_debug(" Less ---- More\n"); - return cnt; //string to unsined long fail - } - pr_debug("%lu\n", val); - if (val < 4) { - binder_perf_evalue = val; - if (0 == (val & BINDER_PERF_SEND_COUNTER)) - binder_perf_stats_bct_clean(); - if (0 == (val & BINDER_PERF_TIMEOUT_COUNTER)) - binder_perf_stats_timeout_clean(); - } else { - pr_debug("invalid value:%lu, should be 0 ~ 3\n", val); - } - pr_debug("%d (%s) set performance evaluate type %s %s\n", - task_pid_nr(current), current->comm, - (binder_perf_evalue & BINDER_PERF_SEND_COUNTER) ? "sender counter enable" : "", - (binder_perf_evalue & BINDER_PERF_TIMEOUT_COUNTER) ? - "time out counter enable" : ""); - - return cnt; -} -#endif -#ifdef BINDER_MONITOR -static int binder_log_level_show(struct seq_file *m, void *unused) -{ - seq_printf(m, " Current log level: %lu\n", binder_log_level); - return 0; -} - -static ssize_t binder_log_level_write(struct file *filp, const char *ubuf, - size_t cnt, loff_t *data) -{ - char buf[32]; - size_t copy_size = cnt; - unsigned long val; - int ret; - - if (cnt >= sizeof(buf)) - copy_size = 32 - 1; - buf[copy_size] = '\0'; - - if (copy_from_user(&buf, ubuf, copy_size)) - return -EFAULT; - - pr_debug("[Binder] Set binder log level:%lu -> ", binder_log_level); - ret = strict_strtoul(buf, 10, &val); - if (ret < 0) { - pr_debug("Null\ninvalid string, need number foramt, err:%d \n",ret); - pr_debug("Log Level: 0 ---- 4 \n"); - pr_debug(" Less ---- More\n"); - return cnt; //string to unsined long fail - } - pr_debug("%lu\n", val); - if (val == 0) { - binder_debug_mask = - BINDER_DEBUG_USER_ERROR | BINDER_DEBUG_FAILED_TRANSACTION | - BINDER_DEBUG_DEAD_TRANSACTION ; - binder_log_level = val; - } else if (val == 1) { - binder_debug_mask = - BINDER_DEBUG_USER_ERROR | BINDER_DEBUG_FAILED_TRANSACTION | - BINDER_DEBUG_DEAD_TRANSACTION | BINDER_DEBUG_DEAD_BINDER | - BINDER_DEBUG_DEATH_NOTIFICATION ; - binder_log_level = val; - } else if (val == 2) { - binder_debug_mask = - BINDER_DEBUG_USER_ERROR | BINDER_DEBUG_FAILED_TRANSACTION | - BINDER_DEBUG_DEAD_TRANSACTION | BINDER_DEBUG_DEAD_BINDER | - BINDER_DEBUG_DEATH_NOTIFICATION |BINDER_DEBUG_THREADS | - BINDER_DEBUG_TRANSACTION | BINDER_DEBUG_TRANSACTION_COMPLETE ; - binder_log_level = val; - } else if (val == 3) { - binder_debug_mask = - BINDER_DEBUG_USER_ERROR | BINDER_DEBUG_FAILED_TRANSACTION | - BINDER_DEBUG_DEAD_TRANSACTION | BINDER_DEBUG_DEAD_BINDER | - BINDER_DEBUG_DEATH_NOTIFICATION | BINDER_DEBUG_THREADS | - BINDER_DEBUG_TRANSACTION | BINDER_DEBUG_TRANSACTION_COMPLETE | - BINDER_DEBUG_OPEN_CLOSE | BINDER_DEBUG_READ_WRITE ; - binder_log_level = val; - } else if (val == 4) { - binder_debug_mask = - BINDER_DEBUG_USER_ERROR | BINDER_DEBUG_FAILED_TRANSACTION | - BINDER_DEBUG_DEAD_TRANSACTION | BINDER_DEBUG_DEAD_BINDER | - BINDER_DEBUG_DEATH_NOTIFICATION | BINDER_DEBUG_THREADS | - BINDER_DEBUG_OPEN_CLOSE | BINDER_DEBUG_READ_WRITE | - BINDER_DEBUG_TRANSACTION | BINDER_DEBUG_TRANSACTION_COMPLETE | - BINDER_DEBUG_USER_REFS | BINDER_DEBUG_INTERNAL_REFS | - BINDER_DEBUG_PRIORITY_CAP |BINDER_DEBUG_FREE_BUFFER | - BINDER_DEBUG_BUFFER_ALLOC ; - binder_log_level = val; - } else { - pr_debug("invalid value:%lu, should be 0 ~ 4\n", val); - } - return cnt; -} - -static void print_binder_timeout_log_entry(struct seq_file *m, - struct binder_timeout_log_entry *e) -{ - struct rtc_time tm; - - rtc_time_to_tm(e->tv.tv_sec, &tm); - seq_printf(m, "%d:%s %d:%d to %d:%d spends %u000 ms (%s) dex_code %u " - "start_at %lu.%03ld android %d-%02d-%02d %02d:%02d:%02d.%03lu\n", - e->debug_id, binder_wait_on_str[e->r], - e->from_proc, e->from_thrd, e->to_proc, e->to_thrd, - e->over_sec, e->service, e->code, - (unsigned long)e->ts.tv_sec, - (e->ts.tv_nsec / NSEC_PER_MSEC), - (tm.tm_year + 1900), (tm.tm_mon + 1), tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned long)(e->tv.tv_usec / USEC_PER_MSEC)); -} - -static int binder_timeout_log_show(struct seq_file *m, void *unused) -{ - struct binder_timeout_log *log = m->private; - int i, latest; - int end_idx = ARRAY_SIZE(log->entry) - 1; - - binder_lock(__func__); - - latest = log->next ? (log->next - 1) : end_idx; - if (log->next == 0 && !log->full) - goto timeout_log_show_unlock; - - if (latest >= ARRAY_SIZE(log->entry) || latest < 0) { - int j; - - pr_alert("timeout log index error, " - "log %pK latest %d next %d end_idx %d\n", - log, latest, log->next, end_idx); - for (j = -4; j <= 3; j++) { - unsigned int *tmp = (unsigned int *)log + (j * 8); - pr_alert("0x%pK %08x %08x %08x %08x " - "%08x %08x %08x %08x\n", - tmp, - *tmp, *(tmp + 1), *(tmp + 2), *(tmp + 3), - *(tmp + 4), *(tmp + 5), *(tmp + 6), - *(tmp + 7)); - } - aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_SWT_JBT_TRACES|DB_OPT_BINDER_INFO, "binder: timeout log index error", - "detect for memory corruption\n\n" - "check kernel log for more details\n"); - goto timeout_log_show_unlock; - } - - for (i = latest; i >= 0; i--) - print_binder_timeout_log_entry(m, &log->entry[i]); - if (log->full) { - for (i = end_idx; i > latest; i--) - print_binder_timeout_log_entry(m, &log->entry[i]); - } - -timeout_log_show_unlock: - binder_unlock(__func__); - return 0; -} - -BINDER_DEBUG_SETTING_ENTRY(log_level); -#ifdef BINDER_PERF_EVAL -BINDER_DEBUG_SETTING_ENTRY(perf_evalue); -#endif -BINDER_DEBUG_ENTRY(timeout_log); -#ifdef BINDER_PERF_EVAL -BINDER_DEBUG_ENTRY(perf_stats); -#endif - -static int binder_transaction_log_enable_show(struct seq_file *m, void *unused) -{ -#ifdef BINDER_MONITOR - seq_printf(m, " Current transaciton log is %s %s %s" -#ifdef RT_PRIO_INHERIT - " %s" -#endif - "\n", - (log_disable & 0x1) ? "disabled" : "enabled", - (log_disable & BINDER_LOG_RESUME) ? "(self resume)" : "", - (log_disable & BINDER_BUF_WARN) ? "(buf warning enabled)" : "" -#ifdef RT_PRIO_INHERIT - - ,(log_disable & BINDER_RT_LOG_ENABLE) ? "(rt inherit log enabled)" : "" -#endif - ); -#else - seq_printf(m, " Current transaciton log is %s %s\n", - log_disable ? "disabled" : "enabled", - (log_disable & BINDER_LOG_RESUME) ? "(self resume)" : ""); -#endif - return 0; -} - -static ssize_t binder_transaction_log_enable_write(struct file *filp, - const char *ubuf, - size_t cnt, loff_t *data) -{ - char buf[32]; - size_t copy_size = cnt; - unsigned long val; - int ret; - - if (cnt >= sizeof(buf)) - copy_size = 32 - 1; - - buf[copy_size] = '\0'; - - if (copy_from_user(&buf, ubuf, copy_size)) - return -EFAULT; - - ret = strict_strtoul(buf, 10, &val); - if (ret < 0) { - pr_debug("failed to switch logging, " - "need number format\n"); - return cnt; - } - - log_disable = !(val & 0x1); - if (log_disable && (val & BINDER_LOG_RESUME)) { - log_disable |= BINDER_LOG_RESUME; - queue_delayed_work(binder_deferred_workqueue, - &log_resume_work, (120 * HZ)); - } -#ifdef BINDER_MONITOR - if (val & BINDER_BUF_WARN) { - log_disable |= BINDER_BUF_WARN; - } -#ifdef RT_PRIO_INHERIT - if (val & BINDER_RT_LOG_ENABLE) { - log_disable |= BINDER_RT_LOG_ENABLE; - } -#endif - pr_debug("%d (%s) set transaction log %s %s %s" -#ifdef RT_PRIO_INHERIT - " %s" -#endif - "\n", - task_pid_nr(current), current->comm, - (log_disable & 0x1) ? "disabled" : "enabled", - (log_disable & BINDER_LOG_RESUME) ? - "(self resume)" : "", - (log_disable & BINDER_BUF_WARN) ? "(buf warning)" : "" -#ifdef RT_PRIO_INHERIT - ,(log_disable & BINDER_RT_LOG_ENABLE) ? "(rt inherit log enabled)" : "" -#endif - ); -#else - pr_debug("%d (%s) set transaction log %s %s\n", - task_pid_nr(current), current->comm, - log_disable ? "disabled" : "enabled", - (log_disable & BINDER_LOG_RESUME) ? - "(self resume)" : ""); -#endif - return cnt; -} -BINDER_DEBUG_SETTING_ENTRY(transaction_log_enable); -# endif - -#ifdef MTK_BINDER_PAGE_USED_RECORD -static int binder_page_used_show(struct seq_file *s, void *p) -{ - struct binder_proc *proc; - int do_lock = !binder_debug_no_lock; - seq_printf(s, "page_used:%d[%dMB]\npage_used_peak:%d[%dMB]\n", - binder_page_used, binder_page_used>>8, - binder_page_used_peak, binder_page_used_peak>>8); - - if (do_lock) - binder_lock(__func__); - seq_puts(s, "binder page stats by binder_proc:\n"); - hlist_for_each_entry(proc, &binder_procs, proc_node) - { - seq_printf(s, " proc %d(%s):page_used:%d[%dMB] page_used_peak:%d[%dMB]\n", - proc->pid, proc->tsk ? proc->tsk->comm : " ", - proc->page_used, proc->page_used>>8, - proc->page_used_peak, proc->page_used_peak>>8); - } - if (do_lock) - binder_unlock(__func__); - - return 0; -} - -BINDER_DEBUG_ENTRY(page_used); -#endif - BINDER_DEBUG_ENTRY(state); BINDER_DEBUG_ENTRY(stats); BINDER_DEBUG_ENTRY(transactions); @@ -5999,34 +3686,6 @@ BINDER_DEBUG_ENTRY(transaction_log); static int __init binder_init(void) { int ret; -#ifdef BINDER_MONITOR - struct task_struct *th; - - - th = kthread_create(binder_bwdog_thread, NULL, "binder_watchdog"); - if (IS_ERR(th)) { - pr_err("fail to create watchdog thread " - "(err:%li)\n", PTR_ERR(th)); - } else { - wake_up_process(th); - } - - binder_transaction_log_failed.entry = &entry_failed[0]; - binder_transaction_log_failed.size = ARRAY_SIZE(entry_failed); - -#ifdef CONFIG_MTK_EXTMEM - binder_transaction_log.entry = extmem_malloc_page_align(sizeof(struct binder_transaction_log_entry)*MAX_ENG_TRANS_LOG_BUFF_LEN); - binder_transaction_log.size = MAX_ENG_TRANS_LOG_BUFF_LEN; - - if(binder_transaction_log.entry == NULL) { - pr_err("%s[%s] ext emory alloc failed!!!\n", __FILE__, __FUNCTION__); - binder_transaction_log.entry = vmalloc(sizeof(struct binder_transaction_log_entry)*MAX_ENG_TRANS_LOG_BUFF_LEN); - } -#else - binder_transaction_log.entry = &entry_t[0]; - binder_transaction_log.size = ARRAY_SIZE(entry_t); -#endif -#endif binder_deferred_workqueue = create_singlethread_workqueue("binder"); if (!binder_deferred_workqueue) @@ -6063,46 +3722,6 @@ static int __init binder_init(void) binder_debugfs_dir_entry_root, &binder_transaction_log_failed, &binder_transaction_log_fops); -#ifdef BINDER_MONITOR - /* system_server is the main writer, remember to - * change group as "system" for write permission - * via related init.rc */ - debugfs_create_file("transaction_log_enable", - (S_IRUGO | S_IWUSR | S_IWGRP), - binder_debugfs_dir_entry_root, - NULL, - &binder_transaction_log_enable_fops); - debugfs_create_file("log_level", - (S_IRUGO | S_IWUSR | S_IWGRP), - binder_debugfs_dir_entry_root, - NULL, - &binder_log_level_fops); - debugfs_create_file("timeout_log", - S_IRUGO, - binder_debugfs_dir_entry_root, - &binder_timeout_log_t, - &binder_timeout_log_fops); -#endif -#ifdef BINDER_PERF_EVAL - debugfs_create_file("perf_evalue", - (S_IRUGO | S_IWUSR | S_IWGRP), - binder_debugfs_dir_entry_root, - NULL, - &binder_perf_evalue_fops); - debugfs_create_file("perf_stats", - S_IRUGO, - binder_debugfs_dir_entry_root, - NULL, - &binder_perf_stats_fops); - -#endif -#ifdef MTK_BINDER_PAGE_USED_RECORD - debugfs_create_file("page_used", - S_IRUGO, - binder_debugfs_dir_entry_root, - NULL, - &binder_page_used_fops); -#endif } return ret; } |
