System hanged and CPU high under kernel code wait_event() and wake_up()

吃可爱长大的小学妹 提交于 2019-12-11 12:46:51

问题


I have two kernel threads which run a() and b() respectively. a() is trying to wake up b() as follows.

a() {
    while(1) {
       while( atomic_read(status) != SET_SLEEP )
           msleep(10);

       atomic_set(status, SET_RUN);
       printk( "..." );
       wake_up( wq );
    }

b() {
    while(1) {
        atomic_set(status, SET_SLEEP);
        printk( "..." );
        wait_event( wq, atomic_read(status) != SET_SLEEP );
        printk( "..." );
    }

After running both for a long time, whole system will be hanged and CPU got high. No any panic message is printed. Is there anyone has idea?


回答1:


The more we want to solve, the less we get....

As Lizz mentioned, I added many printk to print some information for debugging. But I got nothing because 'printk' is the most responsible for the bug.

I did the following experiment and I found an unbelievable result.
Run 1 thread of a() and 1024 threads of b(). a() is waking up each b() in a while loop
Modify printk as follows.

write_lock_bh( &pk_lock );
printk( "print some debugging message" );
write_unlock_bh( &pk_lock );

Run once with lock and run once without lock.
Without lock, it hangs.
With lock, it runs properly.

Originally, printk is for debugging. Now it seems to be the root cause.

Is there anyone has such experience?




回答2:


try put a lock on status, lock will flush the statue in CPU a's cache into main memory so that CPU b gets the latest update. Or maybe set status as volatile.



来源:https://stackoverflow.com/questions/19372205/system-hanged-and-cpu-high-under-kernel-code-wait-event-and-wake-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!