推荐源码阅读的的工具是sourceInsight3.5,直接将源码文件导入,就会生成一个各文件关联的工程,这个工具可自行百度,配合Nodepad++修改注释阅读更好,因为SI不知道为什么对中文注释输入的支持不是很好。继续昨天的源码阅读。
昨天研究到disksim.c中的extarq队列的操作函数,extraq队列就像是预先申请的空的内存,今天看的是intq队列操作函数,intq是处理调度event的队列。
开始介绍intq的相关函数:
disksim_dumpintq ()
函数
先给出该函数在disksim.c
中的的原代码段:
static void disksim_dumpintq ()
{
event *tmp;
int i = 0;
tmp = disksim->intq;
while (tmp != NULL) {
i++;
fprintf (outputfile, "time %f, type %d\n",
tmp->time, tmp->type);
tmp = tmp->next;
}
}
disksim->inq
和disksim->extraq
一样都是指向队列的头部元素。这个函数就是遍历intq队列,将intq队列里面每个event的信息(队列中的event的time,Type)输出到outputfile中去,可能是为了之后的调试使用的函数。
INLINE void addtointq (event *newint)
函数
一看这个函数也是一个内联函数,和之前的addtoextraq
很像,先看其函数原代码段:
INLINE void addtointq (event *newint)
{
/* WARNING -- HORRIBLE HACK BELOW
* In order to make the Memulator run (which sometimes has events arrive
* "late") I've (JLG) commented out the following snippet. A better
* solution should be arrived at...
*/
#if 0
if ((temp->time + DISKSIM_TIME_THRESHOLD) < simtime) {
//如果当前的event的时间比simtime还要早,就是已经错过了调度
fprintf(stderr, "Attempting to addtointq an event whose time has passed\n");
fprintf(stderr, "simtime %f, curr->time %f, type = %d\n", simtime, temp->time, temp->type);
exit(1);
}
#endif
switch(disksim->trace_mode) {
//这边关于disksim->trace_mode指的是负载还是?有待考证
case DISKSIM_MASTER:
//这个Master模式下把,新加入的newint写入到tracepipes[1]中
if(write(disksim->tracepipes[1], (char *)newint, sizeof(event)) <= 0)
{
// printf("addtointq() -- master write fd = %d\n", disksim->tracepipes[1]);
// perror("addtointq() -- master write");
}
break;
case DISKSIM_SLAVE:
//这个SLAVE模式下把tracepipes[0]中的内容传到tmpevt(event类型)中去
{
event tmpevt;
double timediff;
// printf("addtointq() -- slave read\n");
ddbg_assert(read(disksim->tracepipes[0], (char *)&tmpevt, sizeof(event)) > 0);
timediff = fabs(tmpevt.time - newint->time);//计算tmpevt和newint的时间差
/* printf("remote event: %d %f, local event: %d %f\n", */
/* tmpevt.type, */
/* newint->type, */
/*