📄 disksim_interface.c
字号:
* the restored execution... */ disksim_set_external_io_done_notify(disksim_interface_io_done_notify); // fprintf (stder, "disksim_initialize done\n"); return 0;}/* called once at simulation initialization time */struct disksim_interface * disksim_interface_initialize (const char *pfile, const char *ofile, disksim_interface_complete_t comp, disksim_interface_sched_t sched, disksim_interface_desched_t desched, void *ctx, int argc, char **argv){ struct disksim_interface *iface = calloc(1, sizeof(struct disksim_interface)); ddbg_assert(iface != 0); iface->complete_fn = comp; iface->sched_fn = sched; iface->desched_fn = desched; iface->ctx = ctx; iface->disksim = calloc(1, sizeof(struct disksim)); disksim = iface->disksim; disksim_interface_initialize_latency(iface, pfile, ofile, 0, // latency_weight NULL, // paramval NULL, // paramname 0, // synthio NULL, // sched_alg argc, argv); disksim->notify_ctx = iface; return iface;}/* called once at simulation shutdown time */void disksim_interface_shutdown (struct disksim_interface *iface, double syssimtime){ double curtime = syssimtime; disksim = iface->disksim; // 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_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_interface *iface, double syssimtime){ double curtime = syssimtime; disksim = iface->disksim; // 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 (1); } 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 (struct disksim_interface *iface, double syssimtime, void *junk){ double curtime = syssimtime; disksim = iface->disksim; // 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 (1); } // 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... */ iface->sched_fn(disksim_interface_internal_event, disksim->intq->time, iface->ctx); } // 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_interface *iface, double syssimtime, struct disksim_request *requestdesc){ ioreq_event *new; double curtime = syssimtime; disksim = iface->disksim; 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 = requestdesc->flags; new->bcount = requestdesc->bytecount / 512; new->batchno = requestdesc->batchno; new->batch_complete = requestdesc->batch_complete; new->flags |= TIME_CRITICAL; new->cause = 0; new->opid = 0; new->buf = requestdesc; io_map_trace_request (new); /* issue it into simulator */ if (disksim->intq) { iface->desched_fn(0.0, iface->ctx); } 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... */ iface->sched_fn(disksim_interface_internal_event, disksim->intq->time, iface->ctx); }}void disksim_free_disksim(struct disksim_interface *iface) { disksim_cleanup(); free(iface->disksim); free(iface);}double disksim_time_to_msec(double x) { return x; }double disksim_time_from_msec(double x) { return x; }struct dm_disk_if *disksim_getdiskmodel(struct disksim_interface *i, int disknum) { return i->disksim->diskinfo->disks[disknum]->model;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -