内核看门狗简介

21 篇文章 2 订阅
3 篇文章 0 订阅

MTK 平台:wd_common_drv.c

static int kwdt_thread(void *arg)
{

	struct sched_param param = {.sched_priority = 99 };
	struct rtc_time tm;
	struct timeval tv = { 0 };
	/* android time */
	struct rtc_time tm_android;
	struct timeval tv_android = { 0 };
	int cpu = 0;
	int local_bit = 0, loc_need_config = 0, loc_timeout = 0;
	struct wd_api *loc_wk_wdt = NULL;

	sched_setscheduler(current, SCHED_FIFO, ¶m);
	set_current_state(TASK_INTERRUPTIBLE);
	for (;;) {

		if (kthread_should_stop()) {
			pr_err("[WDK] kthread_should_stop do !!\n");
			break;
		}
		spin_lock(&lock);
		cpu = smp_processor_id();
		loc_wk_wdt = g_wd_api;
		loc_need_config = g_need_config;
		loc_timeout = g_timeout;
		spin_unlock(&lock);
		/* printk("fwq loc_wk_wdt(%x),loc_wk_wdt->ready(%d)\n",loc_wk_wdt ,loc_wk_wdt->ready); */
		if (loc_wk_wdt && loc_wk_wdt->ready && g_enable) {
			if (loc_need_config) {
				/* daul  mode */
				loc_wk_wdt->wd_config(WDT_DUAL_MODE, loc_timeout);
				spin_lock(&lock);
				g_need_config = 0;
				spin_unlock(&lock);
			}
			/* pr_debug("[WDK]  cpu-task=%d, current_pid=%d\n",  wk_tsk[cpu]->pid,  current->pid); */
			/*to avoid wk_tsk[cpu] had not created out */
			if (wk_tsk[cpu] != 0) {
				if (wk_tsk[cpu]->pid == current->pid) {
					/* only process WDT info if thread-x is on cpu-x */
					spin_lock(&lock);
					local_bit = kick_bit;
					printk_deferred("[WDK], local_bit:0x%x, cpu:%d,RT[%lld]\n",
							local_bit, cpu, sched_clock());
					if ((local_bit & (1 << cpu)) == 0) {
						/* printk("[WDK]: set  WDT kick_bit\n"); */
						local_bit |= (1 << cpu);
						/* aee_rr_rec_wdk_kick_jiffies(jiffies); */
					}
					printk_deferred
					    ("[WDK], local_bit:0x%x, cpu:%d, check bit0x:%x, lasthpg_cpu:%d, lasthpg_act:%d, lasthpg_t:%lld, RT[%lld]\n",
					     local_bit, cpu, wk_check_kick_bit(), lasthpg_cpu, lasthpg_act, lasthpg_t, sched_clock());
					if (local_bit == wk_check_kick_bit()) {
						printk_deferred("[WDK]: kick Ex WDT,RT[%lld]\n",
								sched_clock());
						mtk_wdt_restart(WD_TYPE_NORMAL);	/* for KICK external wdt */
						local_bit = 0;
					}
					kick_bit = local_bit;
					spin_unlock(&lock);					if (local_bit == wk_check_kick_bit()) {
						printk_deferred("[WDK]: kick Ex WDT,RT[%lld]\n",
								sched_clock());
						mtk_wdt_restart(WD_TYPE_NORMAL);	/* for KICK external wdt */
						local_bit = 0;
					}
					
				}
			}
		} else if (0 == g_enable) {
			pr_debug("WDK stop to kick\n");
		} else {
			pr_err("No watch dog driver is hooked\n");
			BUG();
		}
		/*to avoid wk_tsk[cpu] had not created out */
		if (wk_tsk[cpu] != 0) {
			if (wk_tsk[cpu]->pid == current->pid) {
#if (DEBUG_WDK == 1)
				msleep_interruptible(debug_sleep * 1000);
				pr_debug("WD kicker woke up %d\n", debug_sleep);
#endif
				do_gettimeofday(&tv);
				tv_android = tv;
				rtc_time_to_tm(tv.tv_sec, &tm);
				tv_android.tv_sec -= sys_tz.tz_minuteswest * 60;
				rtc_time_to_tm(tv_android.tv_sec, &tm_android);
				printk_deferred
				    ("[thread:%d][RT:%lld] %d-%02d-%02d %02d:%02d:%02d.%u UTC;"
				     "android time %d-%02d-%02d %02d:%02d:%02d.%03d\n",
				     current->pid, sched_clock(), tm.tm_year + 1900, tm.tm_mon + 1,
				     tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
				     (unsigned int)tv.tv_usec, tm_android.tm_year + 1900,
				     tm_android.tm_mon + 1, tm_android.tm_mday, tm_android.tm_hour,
				     tm_android.tm_min, tm_android.tm_sec,
				     (unsigned int)tv_android.tv_usec);
			}
		}
		msleep_interruptible((g_kinterval) * 1000);

#ifdef CONFIG_MTK_AEE_POWERKEY_HANG_DETECT
		if ((cpu == 0) && (wk_tsk[cpu]->pid == current->pid)) {	/* only effect at cpu0 */
			if (aee_kernel_wdt_kick_api(g_kinterval) == WDT_PWK_HANG_FORCE_HWT) {
				printk_deferred("power key trigger HWT\n");
				cpus_kick_bit = 0xFFFF;	/* Try to force to HWT */
			}
		}
#endif
	}
	pr_debug("[WDK] WDT kicker thread stop, cpu:%d, pid:%d\n", cpu, current->pid);
	return 0;
}

log信息:

03-22 19:32:48.433 <4>[ 1243.156500]  (0)[184:wdtk-0][WDK], local_bit:0x1, cpu:0, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1241783575417, RT[1243156495036]
03-22 19:40:14.882 <4>[ 1243.166510]  (1)[186:wdtk-1][WDK], local_bit:0x3, cpu:1, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1241783575417, RT[1243166504728]

03-22 19:40:14.891 <4>[ 1243.176509]  (2)[187:wdtk-2][WDK], local_bit:0x7, cpu:2, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1241783575417, RT[1243176503959]
03-22 19:40:14.921 <4>[ 1243.206501]  (3)[188:wdtk-3][WDK], local_bit:0xf, cpu:3, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1241783575417, RT[1243206495498]

03-22 19:40:34.881 <4>[ 1263.166505]  (0)[184:wdtk-0][WDK], local_bit:0x1, cpu:0, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1245090018348, RT[1263166500007]
03-22 19:40:34.891 <4>[ 1263.176500]  (1)[186:wdtk-1][WDK], local_bit:0x3, cpu:1, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1245090018348, RT[1263176491084]

03-22 19:40:34.902 <4>[ 1263.186523]  (2)[187:wdtk-2][WDK], local_bit:0x7, cpu:2, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1245090018348, RT[1263186517314]
 03-22 19:40:34.931 <4>[ 1263.216497]  (3)[188:wdtk-3][WDK], local_bit:0xf, cpu:3, check bit0x:f, lasthpg_cpu:3, lasthpg_act:1, lasthpg_t:1245090018348, RT[1263216491930]

从log 看每个CPU喂狗时间间隔(RT)大概在20s


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值