static void __spin_lock_debug(raw_spinlock_t *lock) { u64 i; u64 loops = loops_per_jiffy * LOOP_HZ; int print_once = 1; char aee_str[40]; unsigned long long t1; t1 = sched_clock(); for (;;) { for (i = 0; i < loops; i++) { if (arch_spin_trylock(&lock->raw_lock)) return; __delay(1); } /* lockup suspected: */ printk("spin time: %llu ns(start:%llu ns, lpj:%lu, HZ:%d)", sched_clock() - t1, t1, loops_per_jiffy, (int)LOOP_HZ); if (print_once) { print_once = 0; spin_dump(lock, "lockup"); #ifdef CONFIG_SMP trigger_all_cpu_backtrace(); #endif debug_show_all_locks(); snprintf( aee_str, 40, "Spinlock lockup:%s\n", current->comm); aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DUMMY_DUMP | DB_OPT_FTRACE, aee_str,"spinlock debugger\n"); } } }
static void spin_bug(raw_spinlock_t *lock, const char *msg) { char aee_str[50]; // if (!debug_locks_off()) // return; spin_dump(lock, msg); snprintf( aee_str, 50, "Spinlock %s :%s\n", current->comm, msg); aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DUMMY_DUMP | DB_OPT_FTRACE, aee_str,"spinlock debugger\n"); }
static int hang_detect_thread(void *arg) { /* unsigned long flags; */ struct sched_param param = {.sched_priority = RTPM_PRIO_WDT }; LOGE("[Hang_Detect] hang_detect thread starts.\n"); sched_setscheduler(current, SCHED_FIFO, ¶m); while (1) { if ((1 == hd_detect_enabled) && (FindTaskByName("system_server") != -1)) { LOGE("[Hang_Detect] hang_detect thread counts down %d:%d.\n", hang_detect_counter, hd_timeout); if (hang_detect_counter <= 0) { ShowStatus(); } if (hang_detect_counter == 0) { LOGE("[Hang_Detect] we should triger HWT ...\n"); if(aee_mode!=AEE_MODE_CUSTOMER_USER) { aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_NE_JBT_TRACES|DB_OPT_DISPLAY_HANG_DUMP, "\nCRDISPATCH_KEY:SS Hang\n","we triger HWT "); msleep(30 * 1000); } else //only Customer user load trigger HWT { aee_kernel_exception_api(__FILE__, __LINE__, DB_OPT_NE_JBT_TRACES|DB_OPT_DISPLAY_HANG_DUMP, "\nCRDISPATCH_KEY:SS Hang\n","we triger HWT "); msleep(30 * 1000); local_irq_disable(); while (1); BUG(); } } hang_detect_counter--; } else { /* incase of system_server restart, we give 2 mins more.(4*HD_INTER) */ if (1 == hd_detect_enabled) { hang_detect_counter = hd_timeout + 4; hd_detect_enabled = 0; } LOGE("[Hang_Detect] hang_detect disabled.\n"); } msleep((HD_INTER) * 1000); } return 0; }
static void spin_bug(raw_spinlock_t *lock, const char *msg) { char aee_str[50]; spin_dump(lock, msg); snprintf( aee_str, 50, "Spinlock %s :%s\n", current->comm, msg); if(!strcmp(msg,"bad magic")){ printk("[spin lock debug] bad magic:%08x, should be %08x, may use an un-initial spin_lock or mem corrupt\n", lock->magic, SPINLOCK_MAGIC); printk(">>>>>>>>>>>>>> Let's KE <<<<<<<<<<<<<<\n"); BUG_ON(1); } aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DUMMY_DUMP | DB_OPT_FTRACE, aee_str,"spinlock debugger\n"); #ifdef CONFIG_PANIC_ON_DEBUG_SPINLOCK panic("Please check this spin bug warning! if it is okay, disable CONFIG_PANIC_ON_DEBUG_SPINLOCK and ignore this warning!\n"); #endif }
static void spin_bug(raw_spinlock_t *lock, const char *msg) { char aee_str[50]; // if (!debug_locks_off()) // return; spin_dump(lock, msg); snprintf( aee_str, 50, "Spinlock %s :%s\n", current->comm, msg); if(!strcmp(msg,"bad magic")){ printk("[spin lock debug] bad magic:%08x, should be %08x, may use an un-initial spin_lock or mem corrupt\n", lock->magic, SPINLOCK_MAGIC); printk(">>>>>>>>>>>>>> Let's KE <<<<<<<<<<<<<<\n"); BUG_ON(1); } aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DUMMY_DUMP | DB_OPT_FTRACE, aee_str,"spinlock debugger\n"); }
static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) { struct task_struct *tsk; struct task_struct *selected = NULL; int rem = 0; int tasksize; int i; int min_score_adj = OOM_SCORE_ADJ_MAX + 1; int selected_tasksize = 0; int selected_oom_score_adj; int array_size = ARRAY_SIZE(lowmem_adj); int other_free = global_page_state(NR_FREE_PAGES) - totalreserve_pages; int other_file = global_page_state(NR_FILE_PAGES) - global_page_state(NR_SHMEM); /* * If we already have a death outstanding, then * bail out right away; indicating to vmscan * that we have nothing further to offer on * this pass. * */ if (lowmem_deathpending && time_before_eq(jiffies, lowmem_deathpending_timeout)) return 0; if (!spin_trylock(&lowmem_shrink_lock)){ lowmem_print(4, "lowmem_shrink lock faild\n"); return -1; } /* For JB: FOREGROUND is adj0 (Default lowmem_adj of AMS is 0, 1, 2, 4, 9, 15) */ /* For ICS: HOME is adj6 (Default lowmem_adj of AMS is 0, 1, 2, 4, 9, 15) */ if (other_free <= lowmem_minfree[1]) { /* Notify Kernel that we should consider Android threshold */ lmk_adjz_minfree = lowmem_minfree[0]; } else { lmk_adjz_minfree = 0; } if (lowmem_adj_size < array_size) array_size = lowmem_adj_size; if (lowmem_minfree_size < array_size) array_size = lowmem_minfree_size; for (i = 0; i < array_size; i++) { if (other_free < lowmem_minfree[i] && other_file < lowmem_minfree[i]) { min_score_adj = lowmem_adj[i]; break; } } if (sc->nr_to_scan > 0) lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %d\n", sc->nr_to_scan, sc->gfp_mask, other_free, other_file, min_score_adj); rem = global_page_state(NR_ACTIVE_ANON) + global_page_state(NR_ACTIVE_FILE) + global_page_state(NR_INACTIVE_ANON) + global_page_state(NR_INACTIVE_FILE); if (sc->nr_to_scan <= 0 || min_score_adj == OOM_SCORE_ADJ_MAX + 1) { lowmem_print(5, "lowmem_shrink %lu, %x, return %d\n", sc->nr_to_scan, sc->gfp_mask, rem); /* * disable indication if low memory */ #if defined (CONFIG_MTK_AEE_FEATURE) && defined (CONFIG_MT_ENG_BUILD) if (in_lowmem) { in_lowmem = 0; lowmem_indicator = 1; DAL_LowMemoryOff(); } #endif spin_unlock(&lowmem_shrink_lock); return rem; } selected_oom_score_adj = min_score_adj; // add debug log #ifdef CONFIG_MT_ENG_BUILD if (min_score_adj <= lowmem_debug_adj) { lowmem_print(1, "======low memory killer=====\n"); lowmem_print(1, "Free memory other_free: %d, other_file:%d pages\n", other_free, other_file); } #endif rcu_read_lock(); for_each_process(tsk) { struct task_struct *p; int oom_score_adj; if (tsk->flags & PF_KTHREAD) continue; p = find_lock_task_mm(tsk); if (!p) continue; if (test_tsk_thread_flag(p, TIF_MEMDIE) && time_before_eq(jiffies, lowmem_deathpending_timeout)) { lowmem_print(1, "lowmem_shrink return directly, due to %d (%s) is dying\n", p->pid, p->comm); task_unlock(p); rcu_read_unlock(); spin_unlock(&lowmem_shrink_lock); return 0; } /* We use oom_score_adj to represent oom_adj here although the later has been deprecated by kernel. */ /* This is because that JB AMS still uses oom_adj to stand for the importantance of activities. */ /* oom_score_adj = p->signal->oom_score_adj; - 2012.07.16 - */ oom_score_adj = p->signal->oom_adj; #ifdef CONFIG_MT_ENG_BUILD if (min_score_adj <= lowmem_debug_adj) lowmem_print(1, "Candidate %d (%s), adj %d, rss %lu, to kill\n", p->pid, p->comm, oom_score_adj, get_mm_rss(p->mm)); #endif if (oom_score_adj < min_score_adj) { task_unlock(p); continue; } tasksize = get_mm_rss(p->mm); task_unlock(p); if (tasksize <= 0) continue; if (selected) { if (oom_score_adj < selected_oom_score_adj) continue; if (oom_score_adj == selected_oom_score_adj && tasksize <= selected_tasksize) continue; } selected = p; selected_tasksize = tasksize; selected_oom_score_adj = oom_score_adj; lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n", p->pid, p->comm, oom_score_adj, tasksize); } if (selected) { lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n", selected->pid, selected->comm, selected_oom_score_adj, selected_tasksize); lowmem_deathpending = selected; lowmem_deathpending_timeout = jiffies + HZ; #ifdef CONFIG_MT_ENG_BUILD if (min_score_adj <= lowmem_debug_adj) { lowmem_print(1, "low memory info:\n"); show_free_areas_minimum(); } #endif /* * when kill adj=0 process trigger kernel warning, only in MTK internal eng/non_LCA load */ #if defined (CONFIG_MTK_AEE_FEATURE) && defined (CONFIG_MT_ENG_BUILD) && \ !defined (MTK_LCA_SUPPORT) && !defined (PARTIAL_BUILD) //mtk internal if (selected_oom_score_adj <= 0) { // can set 16 for test lowmem_print(1, "low memory trigger kernel warning\n"); aee_kernel_warning_api("LMK", 0, DB_OPT_DEFAULT|DB_OPT_DUMPSYS_ACTIVITY, "Framework low memory", "please contact AP/AF memory module owner\n"); } #endif /* * show an indication if low memory */ #if defined (CONFIG_MTK_AEE_FEATURE) && defined (CONFIG_MT_ENG_BUILD) if (lowmem_indicator && selected_oom_score_adj <= 1) { lowmem_print(5, "low memory: raise aee warning\n"); in_lowmem = 1; lowmem_indicator = 0; DAL_LowMemoryOn(); //aee_kernel_warning(module_name, lowmem_warning); } #endif send_sig(SIGKILL, selected, 0); set_tsk_thread_flag(selected, TIF_MEMDIE); rem -= selected_tasksize; } lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n", sc->nr_to_scan, sc->gfp_mask, rem); rcu_read_unlock(); spin_unlock(&lowmem_shrink_lock); return rem; }
static void __spin_lock_debug(raw_spinlock_t *lock) { #ifdef CONFIG_MTK_MUTATION u64 i; u64 loops = loops_per_jiffy * LOOP_HZ; int print_once = 1; char aee_str[50]; unsigned long long t1,t2; t1 = sched_clock(); t2 = t1; for (;;) { for (i = 0; i < loops; i++) { if (arch_spin_trylock(&lock->raw_lock)) return; __delay(1); } if(sched_clock() - t2 < WARNING_TIME) continue; t2 = sched_clock(); if(oops_in_progress != 0) continue; // in exception follow, printk maybe spinlock error /* lockup suspected: */ printk("spin time: %llu ns(start:%llu ns, lpj:%lu, LPHZ:%d), value: 0x%08x\n", sched_clock() - t1, t1, loops_per_jiffy, (int)LOOP_HZ, lock->raw_lock.slock); if (print_once) { print_once = 0; spin_dump(lock, "lockup suspected"); #ifdef CONFIG_SMP trigger_all_cpu_backtrace(); #endif debug_show_all_locks(); snprintf( aee_str, 50, "Spinlock lockup:%s\n", current->comm); aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DUMMY_DUMP | DB_OPT_FTRACE, aee_str,"spinlock debugger\n"); #ifdef CONFIG_PANIC_ON_DEBUG_SPINLOCK panic("Please check this spin_lock bug warning! if it is okay, disable CONFIG_PANIC_ON_DEBUG_SPINLOCK and ignore this warning!\n"); #endif } } #else //CONFIG_MTK_MUTATION u64 i; u64 loops = loops_per_jiffy * HZ; for (i = 0; i < loops; i++) { if (arch_spin_trylock(&lock->raw_lock)) return; __delay(1); } /* lockup suspected: */ spin_dump(lock, "lockup suspected"); #ifdef CONFIG_SMP trigger_all_cpu_backtrace(); #endif /* * The trylock above was causing a livelock. Give the lower level arch * specific lock code a chance to acquire the lock. We have already * printed a warning/backtrace at this point. The non-debug arch * specific code might actually succeed in acquiring the lock. If it is * not successful, the end-result is the same - there is no forward * progress. */ arch_spin_lock(&lock->raw_lock); #endif //CONFIG_MTK_MUTATION }
static ssize_t tsallts_write(struct file *file, const char __user *buffer, size_t count, loff_t *data) { int len = 0, i; struct temp_data { int trip[10]; int t_type[10]; char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20]; char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20]; int time_msec; char desc[512]; }; struct temp_data *ptr_temp_data = kmalloc(sizeof(*ptr_temp_data), GFP_KERNEL); tsallts_printk("[tsallts_write_ts2]\n"); if (ptr_temp_data == NULL) { pr_warn("[%s] kmalloc fail\n\n", __func__); return -ENOMEM; } len = (count < (sizeof(ptr_temp_data->desc) - 1)) ? count : (sizeof(ptr_temp_data->desc) - 1); if (copy_from_user(ptr_temp_data->desc, buffer, len)) { kfree(ptr_temp_data); return 0; } ptr_temp_data->desc[len] = '\0'; if (sscanf (ptr_temp_data->desc, "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d", &num_trip, &ptr_temp_data->trip[0], &ptr_temp_data->t_type[0], ptr_temp_data->bind0, &ptr_temp_data->trip[1], &ptr_temp_data->t_type[1], ptr_temp_data->bind1, &ptr_temp_data->trip[2], &ptr_temp_data->t_type[2], ptr_temp_data->bind2, &ptr_temp_data->trip[3], &ptr_temp_data->t_type[3], ptr_temp_data->bind3, &ptr_temp_data->trip[4], &ptr_temp_data->t_type[4], ptr_temp_data->bind4, &ptr_temp_data->trip[5], &ptr_temp_data->t_type[5], ptr_temp_data->bind5, &ptr_temp_data->trip[6], &ptr_temp_data->t_type[6], ptr_temp_data->bind6, &ptr_temp_data->trip[7], &ptr_temp_data->t_type[7], ptr_temp_data->bind7, &ptr_temp_data->trip[8], &ptr_temp_data->t_type[8], ptr_temp_data->bind8, &ptr_temp_data->trip[9], &ptr_temp_data->t_type[9], ptr_temp_data->bind9, &ptr_temp_data->time_msec) == 32) { tsallts_dprintk("[tsallts_write_ts2] tsallts_unregister_thermal\n"); if (thz_dev) { mtk_thermal_zone_device_unregister(thz_dev); thz_dev = NULL; } if (num_trip < 0 || num_trip > 10) { aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "tsallts_write2", "Bad argument"); tsallts_dprintk("[tsallts_write2] bad argument\n"); kfree(ptr_temp_data); return -EINVAL; } for (i = 0; i < num_trip; i++) g_THERMAL_TRIP[i] = ptr_temp_data->t_type[i]; g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0'; for (i = 0; i < 20; i++) { g_bind0[i] = ptr_temp_data->bind0[i]; g_bind1[i] = ptr_temp_data->bind1[i]; g_bind2[i] = ptr_temp_data->bind2[i]; g_bind3[i] = ptr_temp_data->bind3[i]; g_bind4[i] = ptr_temp_data->bind4[i]; g_bind5[i] = ptr_temp_data->bind5[i]; g_bind6[i] = ptr_temp_data->bind6[i]; g_bind7[i] = ptr_temp_data->bind7[i]; g_bind8[i] = ptr_temp_data->bind8[i]; g_bind9[i] = ptr_temp_data->bind9[i]; } tsallts_dprintk("[tsallts_write1] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,", g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]); tsallts_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,", g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]); tsallts_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]); tsallts_dprintk("[tsallts_write1] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,", g_bind0, g_bind1, g_bind2, g_bind3); tsallts_dprintk("cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n", g_bind4, g_bind5, g_bind6, g_bind7, g_bind8, g_bind9); for (i = 0; i < num_trip; i++) trip_temp[i] = ptr_temp_data->trip[i]; interval = ptr_temp_data->time_msec; tsallts_dprintk("[tsallts_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,", trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]); tsallts_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,", trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]); tsallts_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval); tsallts_dprintk("[tsallts_write1] tsallts_register_thermal\n"); if (NULL == thz_dev) { thz_dev = mtk_thermal_zone_device_register("mtkts2", num_trip, NULL, &tsallts_dev_ops, 0, 0, 0, interval); } kfree(ptr_temp_data); return count; } tsallts_dprintk("[tsallts_write1] bad argument\n"); aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "tsallts_write2", "Bad argument"); kfree(ptr_temp_data); return -EINVAL; }