📄 disksim_ioqueue.c
字号:
if (delay < mintime) { if (posonly) { temp_delay = device_get_servtime(test->devno, test, checkcache, (mintime - delay)); //fprintf(outputfile, "temp_delay = %f\n",temp_delay); delay += temp_delay; } else { delay += device_get_acctime(test->devno, test, (mintime - delay)); } if (ageweight == 1) { delay *= (weight - age) / weight; } //fprintf(outputfile, "get_request_from_sptf...:: delay = %f\n", delay); // fprintf(stderr,"serv %f old eff = %f new %f blkno %ld\n",temp_serv, mintime, delay,temp->blkno); if (delay < mintime) { best = temp; mintime = delay; } } } else { //fprintf(outputfile, "not READY_TO_GO\n"); } temp = temp->next; } addtoextraq((event *) test); /* fprintf (stderr, "Selected request: %f, cylno %d, blkno %d, read %d, devno %d\n", mintime, best->cylinder, best->blkno, (best->flags & READ), best->iolist->devno);*/ return(best);}static double service_time(unsigned int current_cyl, unsigned int current_sector, unsigned int current_head, unsigned int target_cyl, unsigned int target_sector, unsigned int target_head, int read, unsigned int blocks, disk *currdisk){ int i; double seektime = 0.0; double rotation = 0.0; double xfer = 0.0; unsigned int current_max_sectors = 0; unsigned int target_max_sectors = 0; double current_angle = 0.0; double target_angle = 0.0; double period = dm_time_itod(currdisk->model->mech->dm_period(currdisk->model)); // get the seek time { struct dm_mech_state p1, p2; uint64_t nsecs; p1.cyl = current_cyl; p1.head = current_head; p2.cyl = target_cyl; p2.head = target_head; nsecs = currdisk->model->mech->dm_seek_time(currdisk->model, &p1, &p2, read); seektime = dm_time_itod(nsecs); } /* for(i = 0; i <currdisk->numbands; i++){ *//* if(target_cyl < currdisk->bands[i].endcyl && target_max_sectors == 0){ *//* target_max_sectors = currdisk->bands[i].blkspertrack; *//* } *//* if(current_cyl < currdisk->bands[i].endcyl && current_max_sectors == 0){ *//* current_max_sectors = currdisk->bands[i].blkspertrack; *//* } *//* } */ target_angle = (float)target_sector / (float)target_max_sectors; current_angle = (float)current_sector / (float)current_max_sectors; // make sure its in [0,1] if(target_angle < current_angle){ target_angle += 1.0; } // get the rotation time { struct dm_mech_state p1, p2; uint64_t nsecs; p1.theta = dm_angle_dtoi(current_angle); p2.theta = dm_angle_dtoi(target_angle); nsecs = currdisk->model->mech->dm_rottime(currdisk->model, p1.theta, p2.theta); rotation = dm_time_itod(nsecs); } while(rotation < seektime){ rotation += period; } xfer = ((float)blocks / (float)target_max_sectors) * period; // fprintf(stderr,"From %d to %d: seek %f, rotate %f xfer %f\n",current_cyl, target_cyl,seektime,rotation,xfer); return(xfer + rotation);}#define MAX_TSPS 10static double min_time;static int current_head=0;static int sched_count=0;static iobuf *requests[MAX_TSPS];static void remove_tsps(iobuf *tmp){ int i; iobuf *temp; temp = tmp; for(i=0;i<sched_count;i++){ if(requests[current_head+i] == temp){ if((current_head+i+1) < MAX_TSPS){ requests[current_head+i] = requests[current_head+i+1]; temp = requests[current_head+i+1]; }else{ requests[current_head+i] = NULL; } } } if(sched_count != 0){ sched_count--; }}static void calc_sp(iobuf **array, subqueue *queue, int checkcache, int no_requests){ int i; int sector; ioreq_event *test; struct disk *singledisk; unsigned int last_head = 0; iobuf *temp = NULL; char start = 0; double acc_time=0.0; unsigned int last_cylinder = 0; unsigned int last_sector = 0; // fprintf(stderr,"calc_sp YEAH\n"); singledisk = getdisk(queue->bigqueue->devno); test = (ioreq_event *) getfromextraq(); for (i=0; i<no_requests; i++) { temp = array[i]; /* if(acc_time > min_time){ break; }*/ test->blkno = temp->blkno; test->bcount = temp->totalsize; test->devno = temp->iolist->devno; test->flags = temp->flags; test->time = simtime; device_get_mapping(queue->bigqueue->cylmaptype, temp->iolist->devno, temp->blkno, NULL, NULL, §or); if(start == 0){ start = 1; acc_time = device_get_acctime(test->devno, test, 100000); }else{ acc_time += service_time(last_cylinder, last_sector, last_head, temp->cylinder, (unsigned int) sector, temp->surface, (temp->flags & READ), temp->totalsize, singledisk); } last_sector = sector; last_cylinder = temp->cylinder; last_head = temp->surface; } if(acc_time < min_time){ // fprintf(stderr,"time = %f\n",acc_time); //fprintf(stderr,"Setting up acc_time\n"); for (i=0; i<MAX_TSPS; i++) { if(i<no_requests){ // fprintf(stderr,"i = %d %d\n",i,array[i]->blkno); requests[i] = array[i]; }else{ requests[i] = NULL; } } // fprintf(stderr,"\n"); min_time = acc_time; sched_count = no_requests; current_head = 0; } addtoextraq((event *) test);}static void perm(iobuf **array, int m, subqueue *queue, int checkcache, int no_requests){ int i; iobuf *temp; // fprintf(stderr,"perm\n"); if(m == 0){ /* for(i=0;i<no_requests;i++){ fprintf(stderr,"%ld ",array[i]->blkno); } fprintf(stderr,"\n");*/ calc_sp(array, queue, checkcache, no_requests); }else{ for(i=0;i<m;i++){ temp = array[i]; array[i] = array[m-1]; array[m-1] = temp; perm(array,m-1,queue,checkcache,no_requests); temp = array[m-1]; array[m-1] = array[i]; array[i] = temp; } }}/* Queue contains >= 2 items when called */static iobuf *ioqueue_get_request_from_opt_tsps_queue(subqueue *queue, int checkcache, int ageweight, int posonly){ int i; iobuf *temp; iobuf *best = NULL; ioreq_event *test; double acc_time; /* iobuf *best2 = NULL; double mintime = 100000.0; double mintime2 = 100000.0; double mintime3 = 100000.0; double readdelay; double writedelay; double delay; double age; double weight; double acc_time=0.0; double serv_time=0.0; double seek_time=0.0; double effciency=0.0; double band_mult=0.0; struct disk *singledisk; unsigned int max_sectors=0; unsigned int temp_sectors=0;*/ int request_count=0; iobuf *test_requests[MAX_TSPS]; // ioreq_event *tmp; ASSERT((ageweight >= 0) && (ageweight <= 3)); /* singledisk = getdisk(queue->bigqueue->devno); for(j=0;j<singledisk->numbands;j++){ if(singledisk->bands[j].blkspertrack > max_sectors){ max_sectors = singledisk->bands[j].blkspertrack; } } readdelay = queue->bigqueue->readdelay; writedelay = queue->bigqueue->writedelay; weight = (double) queue->bigqueue->to_time;*/ if(sched_count != 0){ if(requests[current_head] != NULL){ best = requests[current_head]; test = (ioreq_event *) getfromextraq(); test->blkno = best->blkno; test->bcount = best->totalsize; test->devno = best->iolist->devno; test->flags = best->flags; test->time = simtime; acc_time = device_get_acctime(test->devno, test, 100000); addtoextraq((event *) test); current_head++; sched_count--; fprintf (stderr, "2Selected request: %f, cylno %d, blkno %d, read %d, devno %d\n", acc_time, best->cylinder, best->blkno, (best->flags & READ), best->iolist->devno); return(best); }else{ fprintf(stderr,"ERROR: request NULL with count != 0\n"); abort(); } } temp = queue->list->next; //fprintf(outputfile, "get_request_from_sptf:: listlen = %d\n", queue->listlen); min_time = 100000; for (i=0; i<queue->listlen; i++) { if (READY_TO_GO(temp,queue) && (ioqueue_seqstream_head(queue->bigqueue, queue->list->next, temp))) { test_requests[request_count] = temp; request_count++; if(request_count == MAX_TSPS){ break; } /* test->blkno = temp->blkno; test->bcount = temp->totalsize; test->devno = temp->iolist->devno; test->flags = temp->flags; delay = (temp->flags & READ) ? readdelay : writedelay; test->time = simtime + delay; if (ageweight) { tmp = temp->iolist; age = tmp->time; while (tmp) { if (tmp->time < age) { age = tmp->time; } tmp = tmp->next; } age = simtime - age; } if ((ageweight == 2) || ((ageweight == 3) && (test->flags & (TIME_CRITICAL | TIME_LIMITED)))) { delay -= age * weight * (double) 0.001; } if (delay < mintime) { serv_time = device_get_servtime(test->devno, test, checkcache, (mintime - delay)); seek_time = device_get_seektime(test->devno, test, checkcache, (mintime - delay)); acc_time = device_get_acctime(test->devno, test, checkcache, (mintime - delay)); for(j=0;j<singledisk->numbands;j++){ if(singledisk->bands[j].endcyl >= temp->cylinder){ temp_sectors = singledisk->bands[j].blkspertrack; break; } } band_mult = ((double)temp_sectors/(double)max_sectors); if ((temp->totalsize/acc_time) > effciency) { best = temp; effciency = (temp->totalsize/acc_time); mintime3 = serv_time; } if(serv_time < mintime2){ best2 = temp; mintime2 = serv_time; } }*/ } else { //fprintf(outputfile, "not READY_TO_GO\n"); } temp = temp->next; } if(request_count != MAX_TSPS){ for(i=request_count;i<MAX_TSPS;i++){ test_requests[i] = NULL; } } /* if(best2 != best){ fprintf (stderr, "\n\n\n\n\nSelected request: %f, cylno %d, blkno %d, read %d, devno %d\n", mintime3, best->cylinder, best->blkno, (best->flags & READ), best->iolist->devno); fprintf (stderr, "Best 2Selected request: %f, cylno %d, blkno %d, read %d, devno %d\n\n\n\n\n\n", mintime2, best2->cylinder, best2->blkno, (best2->flags & READ), best2->iolist->devno); }*//* fprintf (stderr, "Selected request: %f, cylno %d, blkno %d, read %d, devno %d\n", mintime, best->cylinder, best->blkno, (best->flags & READ), best->iolist->devno);*/ perm(test_requests,request_count,queue,checkcache,request_count); fprintf(stderr,"sched count = %d\n",sched_count); if(sched_count != 0){ if(requests[current_head] != NULL){ best = requests[current_head]; test = (ioreq_event *) getfromextraq(); test->blkno = best->blkno; test->bcount = best->totalsize; test->devno = best->iolist->devno; test->flags = best->flags; test->time = simtime; acc_time = device_get_acctime(test->devno, test, 100000); addtoextraq((event *) test); current_head++; sched_count--; fprintf (stderr, "3Selected request: %f, cylno %d, blkno %d, read %d, devno %d %f\n", acc_time, best->cylinder, best->blkno, (best->flags & READ), best->iolist->devno, min_time); return(best); }else{ fprintf(stderr,"ERROR: request NULL with count != 0\n"); abort(); } }else{ fprintf(stderr,"ERROR: sched count = 0\n"); abort(); } fprintf(stderr, "blah\n"); return(best);}static iobuf *ioqueue_get_request_from_opt_sptf_rot_weight_queue (subqueue *queue, int checkcache, int ageweight, int posonly){ int i; iobuf *temp; ioreq_event *test; double readdelay; double writedelay; double delay; double weight; ioreq_event *tmp; iobuf *best = NULL; double mintime = 100000.0; double minsubtract = 0.0; double age = 0.0; double temp_delay = 0.0; double temp_seek = 0.0; ASSERT((ageweight >= 0) && (ageweight <= 3)); readdelay = queue->bigqueue->readdelay; writedelay = queue->bigqueue->writedelay; weight = (double) queue->bigqueue->to_time; test = (ioreq_event *) getfromextraq(); temp = queue->list->next; for (i=0; i<queue->listlen; i++) { if (READY_TO_GO(temp,queue) && (ioqueue_seqstream_head(queue->bigqueue, queue->list->next, temp))) { test->blkno = temp->blkno; test->bcount = temp->totalsize; test->devno = temp->iolist->devno; test->flags = temp->flags; delay = (temp->flags & READ) ? readdelay : writedelay;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -