接上一篇文章 read 系统调用剖析
在上一文中,作者已经将Read 整个调用过程从Linux 系统调用(SCI,system call interface)至IO调度的整个流程已经讲解的非常清晰明了,在此对作者表示致敬!
那这里我接着以Android SD卡为例子,分析IO调度后数据的处理流向! 本文代码基于linux kernel 3.0.4.
1. mmcqd
mmcqd 是kernel在/kernel/drivers/mmc/card/queue.c 的mmc_init_queue拉起的一个内核线程,主要作用是把上层IO的request一个个向具体driver发送。
mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd/%d%s",
host->index, subname ? subname : "");
可以看到 mmc_queue_thread 才是实际做事情的,所以我们先来看看他的庐山真面目。
static int mmc_queue_thread(void *d)
{
struct mmc_queue *mq = d;
struct request_queue *q = mq->queue;
current->flags |= PF_MEMALLOC;
down(&mq->thread_sem);
do {
struct request *req = NULL;
spin_lock_irq(q->queue_lock);
set_current_state(TASK_INTERRUPTIBLE);
req = blk_fetch_request(q);
mq->req = req;
spin_unlock_irq(q->que