- 論壇徽章:
- 0
|
設(shè)備結(jié)構(gòu)定義如下:
typedef struct smschar_dev
{
volatile int pending_messages; //! < number of pending messages for this channel
struct cdev cdev; //! < Char device structure -
wait_queue_head_t wtq; //! < wait queue for read and poll to block on
spinlock_t lock; //! < critical section
struct list_head pending_data; //! < list of pending data
}CharDev_ST;
在從一個緩沖區(qū)讀取數(shù)據(jù)的函數(shù)中,代碼大概如下
ssize_t chr_read(struct file * filp, char __user * buf, size_t count, loff_t * f_pos)
{
CharDev_ST *dev = filp-> private_data;
spin_lock(&dev-> lock);
if(wait_event_interruptible(dev-wtq,!list_empty(&dev-> pending_data)))
{
spin_unlock(&dev-> lock);
return -ERESTARTSYS;
}
///在這里讀取數(shù)據(jù)
spin_unlock(&dev-> lock);
}
下面是數(shù)據(jù)到達(dá)時,往該設(shè)備的緩沖區(qū)填充數(shù)據(jù)的函數(shù),大概實現(xiàn)過程:
spinlock_t global_read_ctrl_lock = SPIN_LOCK_UNLOCKED;
static void fill_buffer(u8* buf,int len)
{
unsigned long flags;
spin_lock_irqsave(&global_read_ctrl_lock,flags);
//在這里填充數(shù)據(jù)
wake_up_interruptible (&(pDev-> wtq));
spin_unlock_irqrestore(&global_read_ctrl_lock,flags);
}
在運行的過程中,內(nèi)核打印了BUG: scheduling while atomic,的提示,而且每次讀取一次數(shù)據(jù),就打印一次。我的理解是,內(nèi)核認(rèn)為在chr_read函數(shù)中,會出現(xiàn)占用了dev-> lock的情況下由于wait_event_interruptible造成睡眠的情況。
不知各位有沒有好的解決這個問題的方法?把內(nèi)核的“BUG: scheduling while atomic”提示去掉,我嘗試把chr_read函數(shù)的spin_lock和wait_event_interruptible進(jìn)行對調(diào),那個打印信息倒是去掉了,但是覺得這樣有問題。請各位指點下啊 |
|