免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1834 | 回复: 2
打印 上一主题 下一主题

驱动卸载宕机 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-14 09:22 |只看该作者 |倒序浏览
自己写的一个监控用户连接的驱动,用到内核线程,在卸载驱动的时候会死锁宕机,不必现,看了堆栈信息是在内核的default_idle里面
下面是堆栈信息

Dead lock in User:
CPU:    7
EIP:    0010:[<8010904c>]    Tainted: GF
EFLAGS: 00000246
eax: 00000000   ebx: 80109020   ecx: 00000007   edx: 87666000
esi: 87666000   edi: 87666000   ebp: ffffe000   esp: 87667fb0
ds: 0018   es: 0018   ss: 0018
Process swapper (pid: 0, stackpage=87667000)
Stack: 801090e2 07040800 00000000 00000000 00000000 0000000d 00000006 8011ffa0
       0000000a 00000400 8029e4df 00000000 80352bc0 80352bf9 8029e265 8032950b
       8029e4d0 0000000b 00000000 00000006
Call Trace:    [<801090e2>] [<8011ffa0>]

Code: c3 8d 76 00 fb eb 0d 90 90 90 90 90 90 90 90 90 90 90 90 90

这是内核的堆栈信息(一小部分)
80109010 T enable_hlt
80109020 T default_idle
80109070 t poll_idle
80109090 T cpu_idle
80109100 T machine_real_restart

所以确定是宕在default_idle,看了default_idle函数用到cpu指针current,下面是内核的代码:
  1. static void default_idle(void)
  2. {
  3.         if (!hlt_counter) {
  4.                 __cli();
  5.                 if (!current->need_resched)
  6.                         safe_halt();
  7.                 else
  8.                         __sti();
  9.         }
  10. }
复制代码
我在内核线程里也用到了指针current,请各位大侠帮忙看下我是不是哪里操作不对了导致了死锁,下面是我的内核线程和卸载关键代码,(内核是2.4版本)

  1. static DECLARE_WAIT_QUEUE_HEAD (connauth_waitqueue);//等待队列
  2. static DECLARE_COMPLETION(connauth_exit);      //完成变量
  3. static int del_thread(void *data)
  4. {
  5.     static int timercnt = 0;
  6.     DECLARE_WAITQUEUE(wait, current);//初始化等待队列
  7.     sprintf(current->comm, "connauth_thd");
  8.     daemonize();

  9.     //阻塞所有线程
  10.         spin_lock_irq(&current->sigmask_lock);
  11.         siginitsetinv(&current->blocked, 0);
  12.         recalc_sigpending(current);
  13.         spin_unlock_irq(&current->sigmask_lock);
  14.    
  15.     add_wait_queue(&connauth_waitqueue, &wait);

  16.     for(;;)
  17.     {
  18.         //处于睡眠状态:30秒
  19.         //放弃cpu 直到被唤醒
  20.         set_current_state(TASK_INTERRUPTIBLE);
  21.         schedule();
  22.                
  23.         //线程退出
  24.         if (stop_connauth_thd)
  25.                         break;
  26.         
  27.         debuglog(8,"thread was wake up\n");
  28.         //下面是线程的工作。。。
  29.     }

  30.     //从等待队列中删除
  31.     set_current_state(TASK_RUNNING);
  32.     remove_wait_queue(&connauth_waitqueue, &wait);
  33.     complete_and_exit(&connauth_exit, 0);//完成并退去,原子操作

  34. }
  35. //卸载驱动时,删除线程代码
  36. static void __exit driver_cleanup(void)
  37. {
  38.     stop_connauth_thd = 1;
  39.     //唤醒线程,以防僵死
  40.     wake_up_interruptible(&connauth_waitqueue);
  41.     wait_for_completion(&connauth_exit);//等待线程退出
  42.      //下面是卸载动作
  43. }
复制代码
我实在是找不到原因所在了,请大哥们帮帮看下了,小弟感激不尽

论坛徽章:
0
2 [报告]
发表于 2010-10-14 09:58 |只看该作者
自己顶

论坛徽章:
0
3 [报告]
发表于 2010-10-15 09:01 |只看该作者
还是没有人帮忙吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP