⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disksim_interface.c

📁 目前最精确的磁盘模拟器的第3版
💻 C
📖 第 1 页 / 共 2 页
字号:
    argv[argc++] = "driver*";    argv[argc++] = paramname;    argv[argc++] = paramval;    /* note: these parameter names must match those from     * modules/disksim_ioqueue_param.h, etc */        argv[argc++] = "driver*";    argv[argc++] = "Scheduler:Scheduling policy";    argv[argc++] = sched_alg;        argv[argc++] = "driver*";    argv[argc++] = "Scheduler:Scheduling priority scheme";    argv[argc++] = sched_alg;    argv[argc++] = "driver*";    argv[argc++] = "Scheduler:Timeout scheduling";    argv[argc++] = sched_alg;  }  argv[0] = "disksim";  argv[1] = pfile;  argv[2] = ofile;  argv[3] = "external";  argv[4] = "0";  if(synthio == 1){    argv[5] = "1";  }else{    argv[5] = "0";  }  disksim_setup_disksim (argc, (char **)argv);    /* Note that this call must be redone anytime a disksim checkpoint is */  /* restored -- this prevents old function addresses from polluting    */  /* the restored execution...                                          */  disksim_set_external_io_done_notify (disksim_interface_io_done_notify);    // fprintf (stder, "disksim_initialize done\n");    return (disksim);}/* called once at simulation shutdown time */void disksim_interface_shutdown (struct disksim *disksim_in, SysTime syssimtime){   double curtime = SYSSIMTIME_TO_MS(syssimtime);   disksim = disksim_in;   // fprintf (stderr, "disksim_shutdown\n");   if ((curtime + 0.0001) < simtime) {      fprintf (stderr, "external time is ahead of disksim time: %f > %f\n", curtime, simtime);      exit(1);   }   simtime = curtime;   disksim_cleanup_and_printstats ();   // fprintf (stderr, "disksim_shutdown done\n");}/* Prints the current disksim statistics.  This call does not reset the    *//* statistics, so the simulation can continue to run and calculate running *//* totals.  "syssimtime" should be the current simulated time of the       *//* system-level simulation.                                                */void disksim_interface_dump_stats (struct disksim *disksim_in, SysTime syssimtime){   double curtime = SYSSIMTIME_TO_MS(syssimtime);   disksim = disksim_in;   // fprintf (stderr, "disksim_dump_stats\n");   if ((disksim->intq) && (disksim->intq->time < curtime) && ((disksim->intq->time + 0.0001) >= curtime)) {      curtime = disksim->intq->time;   }   if (((curtime + 0.0001) < simtime) || ((disksim->intq) && (disksim->intq->time < curtime))) {      fprintf (stderr, "external time is mismatched with disksim time: %f vs. %f (%f)\n", curtime, simtime, ((disksim->intq) ? disksim->intq->time : 0.0));      exit (0);   }   simtime = curtime;   disksim_cleanstats();   disksim_printstats();   // fprintf (stderr, "disksim_dump_stats done\n");}static int event_count = 0;/* This is the callback for handling internal disksim events while running *//* as a slave of a system-level simulation.  "syssimtime" should be the    *//* current simulated time of the system-level simulation.                  */void disksim_interface_internal_event (void *disksim_in, SysTime syssimtime){   double curtime = SYSSIMTIME_TO_MS(syssimtime);   disksim = disksim_in;   // fprintf (stderr, "disksim_internal_event\n");   /* if next event time is less than now, error.  Also, if no event is  */   /* ready to be handled, then this is a spurious callback -- it should */   /* not be possible with the descheduling below (allow it if it is not */   /* possible to deschedule.                                            */   if (disksim->intq != NULL && (disksim->intq->time + 0.0001) < curtime) {     fprintf (stderr, "external time is ahead of disksim time: %f > %f\n", curtime, disksim->intq->time);     exit (0);   }   // fprintf(stderr, "disksim_internal_event: intq->time=%f curtime=%f\n", disksim->intq->time, curtime);   /* while next event time is same as now, handle next event */   if(disksim->intq != NULL){     ASSERT (disksim->intq->time >= simtime);   }   while ((disksim->intq != NULL) 	  && (disksim->intq->time <= (curtime + 0.0001)))      {              // fprintf (stderr, "handling internal event: type %d\n", disksim->intq->type);              disksim_simulate_event(event_count++);     }   if (disksim->intq != NULL) {      /* Note: this could be a dangerous operation when employing checkpoint */      /* and, specifically, restore -- functions move around when programs   */      /* are changed and recompiled...                                       */      syssim_schedule_callback (disksim_interface_internal_event, MS_TO_SYSSIMTIME(disksim->intq->time));   }   // fprintf (stderr, "disksim_internal_event done\n");}/* This function should be called by the system-level simulation when    *//* it wants to issue a request into disksim.  "syssimtime" should be the *//* system-level simulation time at which the request should "arrive".    *//* "requestdesc" is the system-level simulator's description of the      *//* request (device number, block number, length, etc.).                  */void disksim_interface_request_arrive (struct disksim *disksim_in, 				       SysTime syssimtime, 				       Request *requestdesc){   double curtime = SYSSIMTIME_TO_MS(syssimtime);   ioreq_event *new;   disksim = disksim_in;   new = (ioreq_event *) getfromextraq();   assert (new != NULL);   new->type = IO_REQUEST_ARRIVE;   new->time = curtime;   new->busno = 0;   new->devno = requestdesc->devno;   new->blkno = requestdesc->blkno;   new->flags = isread(requestdesc) ? READ : WRITE;   if(do_free_blocks == 0 && requestdesc->bytecount != 0){     new->bcount = requestdesc->bytecount / 512;   }else{     new->bcount = requestdesc->sectorcount;   }   /* added for free blocks */   if(1 == requestdesc->background){        }else{     new->flags |= TIME_CRITICAL;   }   /* End Add for free blocks */   new->cause = 0;   new->opid = 0;   new->buf = requestdesc;   io_map_trace_request (new);   /* issue it into simulator */   if (disksim->intq) {      syssim_deschedule_callback (disksim_interface_internal_event);   }   addtointq ((event *)new);   /* while next event time is same as now, handle next event */   while ((disksim->intq != NULL) 	  && (disksim->intq->time <= (curtime + 0.0001)))      {       disksim_simulate_event (event_count++);     }   if (disksim->intq) {      /* Note: this could be a dangerous operation when employing checkpoint */      /* and, specifically, restore -- functions move around when programs   */      /* are changed and recompiled...                                       */      syssim_schedule_callback (disksim_interface_internal_event, MS_TO_SYSSIMTIME(disksim->intq->time));   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -