disksim_simos_interface.c
来自「目前最精确的磁盘模拟器的第3版」· C语言 代码 · 共 417 行 · 第 1/2 页
C
417 行
DEBUG_TRACE(("disksim_interface_initialize\n")); diskTICSperMSEC = (1000.0 * CPU_CLOCK); DEBUG_TRACE(("disksim_interface_initialize:: diskTICSperMSEC = %f\n", diskTICSperMSEC)); InternalCallback = (DiskSimInternalCallback *)ZMALLOC(sizeof(DiskSimInternalCallback), "InternalCallback"); argv[0] = "disksim"; argv[1] = pfile; argv[2] = ofile; argv[3] = "external"; argv[4] = "0"; argv[5] = "0"; disksim_setup_disksim (6, (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);#ifdef DISKSIM_DEBUG disk_access_dump_file = fopen("disk_access_dump_file", "RW");#endif DEBUG_TRACE(("disksim_interface_initialize done\n")); return (disksim);}/* called once at simulation shutdown time */void disksim_interface_shutdown (struct disksim *disksim_in, TICS systime){ double curtime = TICStoMSEC(CPUVec.CycleCount(0)); disksim = disksim_in; DEBUG_TRACE(("disksim_interface_shutdown:: curtime = %f msec, %d tics\n", curtime, CPUVec.CycleCount(0))); if ((curtime + DISKSIM_TIME_THRESHOLD) < simtime) { fprintf (stderr, "external time is ahead of disksim time: %f > %f\n", curtime, simtime); exit(1); } free(InternalCallback); simtime = curtime; disksim_cleanup_and_printstats ();#ifdef DISKSIM_DEBUG fclose(disk_access_dump_file);#endif DEBUG_TRACE(("disksim_interface_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, TICS systime){ double curtime = TICStoMSEC(CPUVec.CycleCount(0)); disksim = disksim_in; DEBUG_TRACE(("disksim_interface_dump_stats:: curtime = %f msec, %d tics\n", curtime, CPUVec.CycleCount(0))); if ((disksim->intq) && (disksim->intq->time < curtime) && ((disksim->intq->time + DISKSIM_TIME_THRESHOLD) >= curtime)) { curtime = disksim->intq->time; } if (((curtime + DISKSIM_TIME_THRESHOLD) < 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(); DEBUG_TRACE(("disksim_interface_dump_stats done\n"));}/* 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 (int cpuNum, EventCallbackHdr *hdr, void *disksim_in){ TICS systime = CPUVec.CycleCount(0); double curtime = TICStoMSEC(systime); DiskSimInternalCallback *cback = (DiskSimInternalCallback *)hdr; disksim = disksim_in; DEBUG_TRACE(("disksim_interface_internal_event:: curtime = %f msec, %d tics\n", curtime, systime)); DEBUG_TRACE(("disksim_interface_internal_event:: hdr->num = %d\n", cback->num)); /* 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 + DISKSIM_TIME_THRESHOLD) < curtime)) { fprintf (stderr, "external time is ahead of disksim time: %f > %f\n", curtime, ((disksim->intq) ? disksim->intq->time : 0.0)); exit (0); } DEBUG_TRACE(("disksim_interface_internal_event:: disksim->intq->time=%f curtime=%f, diff = %f\n", disksim->intq->time, curtime, curtime - disksim->intq->time)); DEBUG_TRACE(("disksim_interface_internal_event:: disksim->intq->time=%d curtime=%d, diff = %d\n", MSECtoTICS(disksim->intq->time), systime, curtime - MSECtoTICS(disksim->intq->time))); /* while next event time is same as now, handle next event */ ASSERT (disksim->intq->time >= simtime); while ((disksim->intq != NULL) && (disksim->intq->time <= (curtime + DISKSIM_TIME_THRESHOLD))) { DEBUG_TRACE(("disksim_interface_internal_event:: handling internal event: type %d\n", disksim->intq->type)); disksim_simulate_event(); } 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... */ (cback->num)++; EventDoCallback(0, disksim_interface_internal_event, (EventCallbackHdr *)cback, (void *)disksim, MSECtoTICS(disksim->intq->time) - systime); DEBUG_TRACE(("disksim_interface_internal_event:: scheduled new internal event %d at %d\n", cback->num, MSECtoTICS(disksim->intq->time))); } DEBUG_TRACE(("disksim_interface_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, Request *r){ TICS systime = CPUVec.CycleCount(0); double curtime = TICStoMSEC(systime); ioreq_event *new = (ioreq_event *) getfromextraq(); DEBUG_TRACE(("disksim_interface_request_arrive:: curtime = %f msec, %d tics\n", curtime, systime)); disksim = disksim_in; // new = (ioreq_event *) getfromextraq(); assert (new != NULL); new->type = IO_REQUEST_ARRIVE; new->time = curtime; new->busno = 0; new->devno = r->device_num; new->blkno = r->block_num; new->bcount = (r->bytecount) / 512; new->flags = (r->read_write == 'R') ? READ : WRITE; new->cause = 0; new->opid = 0; new->buf = r; io_map_trace_request (new); /* issue it into simulator */ if (disksim->intq) { DEBUG_TRACE(("disksim_interface_request_arrive:: removing InternalCallback\n")); EventCallbackRemove((EventCallbackHdr *)InternalCallback); } addtointq ((event *)new); /* while next event time is same as now, handle next event */ while ((disksim->intq != NULL) && (disksim->intq->time <= (curtime + DISKSIM_TIME_THRESHOLD))) { disksim_simulate_event (); } 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... */ (InternalCallback->num)++; DEBUG_TRACE(("disksim_interface_request_arrive:: scheduling new internal event %d at %d\n", InternalCallback->num, MSECtoTICS(disksim->intq->time))); EventDoCallback(0, disksim_interface_internal_event, (EventCallbackHdr *)InternalCallback, (void *)disksim, (MSECtoTICS(disksim->intq->time) - systime)); } DEBUG_TRACE(("disksim_interface_request_arrive done\n"));}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?