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

📄 disksim_ioqueue.c

📁 disksim是一个非常优秀的磁盘仿真工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * DiskSim Storage Subsystem Simulation Environment (Version 4.0) * Revision Authors: John Bucy, Greg Ganger * Contributors: John Griffin, Jiri Schindler, Steve Schlosser * * Copyright (c) of Carnegie Mellon University, 2001-2008. * * This software is being provided by the copyright holders under the * following license. By obtaining, using and/or copying this software, * you agree that you have read, understood, and will comply with the * following terms and conditions: * * Permission to reproduce, use, and prepare derivative works of this * software is granted provided the copyright and "No Warranty" statements * are included with all reproductions and derivative works and associated * documentation. This software may also be redistributed without charge * provided that the copyright and "No Warranty" statements are included * in all redistributions. * * NO WARRANTY. THIS SOFTWARE IS FURNISHED ON AN "AS IS" BASIS. * CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER * EXPRESSED OR IMPLIED AS TO THE MATTER INCLUDING, BUT NOT LIMITED * TO: WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY * OF RESULTS OR RESULTS OBTAINED FROM USE OF THIS SOFTWARE. CARNEGIE * MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT * TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. * COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE * OR DOCUMENTATION. * *//* * DiskSim Storage Subsystem Simulation Environment (Version 2.0) * Revision Authors: Greg Ganger * Contributors: Ross Cohen, John Griffin, Steve Schlosser * * Copyright (c) of Carnegie Mellon University, 1999. * * Permission to reproduce, use, and prepare derivative works of * this software for internal use is granted provided the copyright * and "No Warranty" statements are included with all reproductions * and derivative works. This software may also be redistributed * without charge provided that the copyright and "No Warranty" * statements are included in all redistributions. * * NO WARRANTY. THIS SOFTWARE IS FURNISHED ON AN "AS IS" BASIS. * CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER * EXPRESSED OR IMPLIED AS TO THE MATTER INCLUDING, BUT NOT LIMITED * TO: WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY * OF RESULTS OR RESULTS OBTAINED FROM USE OF THIS SOFTWARE. CARNEGIE * MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT * TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. *//* * DiskSim Storage Subsystem Simulation Environment * Authors: Greg Ganger, Bruce Worthington, Yale Patt * * Copyright (C) 1993, 1995, 1997 The Regents of the University of Michigan  * * This software is being provided by the copyright holders under the * following license. By obtaining, using and/or copying this software, * you agree that you have read, understood, and will comply with the * following terms and conditions: * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose and without fee or royalty is * hereby granted, provided that the full text of this NOTICE appears on * ALL copies of the software and documentation or portions thereof, * including modifications, that you make. * * THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, * BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR * THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT * HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE OR * DOCUMENTATION. * *  This software is provided AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESSED OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS * OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES, * INCLUDING SPECIAL , INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, * WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION WITH THE * USE OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS * BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH DAMAGES * * The names and trademarks of copyright holders or authors may NOT be * used in advertising or publicity pertaining to the software without * specific, written prior permission. Title to copyright in this software * and any associated documentation will at all times remain with copyright * holders. */#include "disksim_ioqueue.h"#include "modules/modules.h"// schlos - i'm going to have to modify this to account for batched queues#define READY_TO_GO(iobufptr,queue) ( \                                     ((iobufptr)->state == WAITING) && \                                     (((queue)->enablement == NULL) || ((*(queue)->enablement)((iobufptr)->iolist))) && \                                     (((queue)->sched_alg != BATCH_FCFS) || (((queue)->sched_alg == BATCH_FCFS) && ((iobufptr)->batch_complete == TRUE))) \				    )/* Sequential Stream Schemes */#define IOQUEUE_CONCAT_READS		1#define IOQUEUE_CONCAT_WRITES		2#define IOQUEUE_CONCAT_BOTH		3#define IOQUEUE_SEQSTREAM_READS		4#define IOQUEUE_SEQSTREAM_WRITES	8#define IOQUEUE_SEQSTREAM_EITHER	16/* Sub queue identifications */#define IOQUEUE_BASE		1#define IOQUEUE_TIMEOUT		2#define IOQUEUE_PRIORITY	3/* Buffer states while in ioqueue */#define WAITING		0#define PENDING		1/* Priority schemes */#define ALLEQUAL	0#define TWOQUEUE	1/* Timeout schemes */#define NOTIMEOUT	0#define BASETIMEOUT	1#define HALFTIMEOUT	2/* Directions of movement for scanning policies */#define ASC     1#define DESC    2/* read-only globals used during readparams phase */static char *statdesc_accstats		=	"Physical access time";static char *statdesc_qtimestats	=	"Queue time";static char *statdesc_outtimestats	=	"Response time";static char *statdesc_intarrstats	=	"Inter-arrival time";static char *statdesc_readintarrstats	=	"Read inter-arrival";static char *statdesc_writeintarrstats	=	"Write inter-arrival";static char *statdesc_idlestats	=	"Idle period length";static char *statdesc_infopenalty	=	"Sub-optimal mapping penalty";static char *statdesc_reqsizestats	=	"Request size";static char *statdesc_readsizestats	=	"Read request size";static char *statdesc_writesizestats	=	"Write request size";static char *statdesc_instqueuelen	=	"Instantaneous queue length";static char *statdesc_batchsizestats    =       "Batch size";void print_batch_fcfs_queue(subqueue *queue){  int i;  iobuf *tmp;  tmp = queue->list;  printf("blkno, batchno, state, complete, next, prev\n");  printf(" listlen = %d\n", queue->listlen);  printf(" iobufcnt = %d\n", queue->iobufcnt);  for (i = 0; i < queue->iobufcnt; i++) {    printf(" %d %d %d %d %d %d\n",	   tmp->blkno,	   tmp->batchno,	   tmp->state,	   tmp->batch_complete,	   tmp->next->blkno,	   tmp->prev->blkno);        if (tmp->batchno != -1) {      ioreq_event *event_ptr = tmp->batch_list;            printf("  batch_size = %d\n", tmp->batch_size);      while (event_ptr != NULL) {	printf("   %d\n", event_ptr->blkno);	event_ptr = event_ptr->batch_next;      }    }    tmp = tmp->next;  }}void ioqueue_print_contents (ioqueue *queue){   int i;   iobuf *tmp;   tmp = queue->base.list->next;   fprintf (outputfile, "Contents of base queue: listlen %d\n", queue->base.listlen);   for (i = 0; i < queue->base.iobufcnt; i++) {      fprintf(outputfile, "State: %d, blkno: %d\n", tmp->state, tmp->blkno);      tmp = tmp->next;   }   tmp = queue->timeout.list->next;   fprintf(outputfile, "Contents of timeout queue: listlen %d\n", queue->timeout.listlen);   for (i = 0; i < queue->timeout.iobufcnt; i++) {      fprintf(outputfile, "State: %d, blkno: %d\n", tmp->state, tmp->blkno);      tmp = tmp->next;   }   tmp = queue->priority.list->next;   fprintf(outputfile, "Contents of priority queue: listlen %d\n", queue->priority.listlen);   for (i = 0; i < queue->priority.iobufcnt; i++) {      fprintf(outputfile, "State: %d, blkno: %d\n", tmp->state, tmp->blkno);      tmp = tmp->next;   }}static void ioqueue_print_subqueue_state (subqueue *queue){   int i;   iobuf *tmp;   tmp = queue->list->next;   fprintf(outputfile, "\nContents of subqueue: listlen %d\n", queue->listlen);   fprintf(outputfile, "Subqueue state: lastblkno %d, lastcylno %d, lastsurface %d, dir %d\n", queue->lastblkno, queue->lastcylno, queue->lastsurface, queue->dir);   for (i = 0; i < queue->iobufcnt; i++) {      fprintf(outputfile, "State: %d, blkno: %d, cylno %d, surface %d\n", tmp->state, tmp->blkno, tmp->cylinder, tmp->surface);      tmp = tmp->next;   }}int ioqueue_get_number_in_queue (ioqueue *queue){   return(queue->base.listlen + queue->timeout.listlen + queue->priority.listlen);}int ioqueue_get_number_pending (ioqueue *queue){   int numpend = 0;   numpend += queue->base.listlen - queue->base.numoutstanding;   numpend += queue->timeout.listlen - queue->timeout.numoutstanding;   numpend += queue->priority.listlen - queue->priority.numoutstanding;   return(numpend);}int ioqueue_get_reqoutstanding (ioqueue *queue){   int numout = 0;   numout += queue->base.reqoutstanding;   numout += queue->timeout.reqoutstanding;   numout += queue->priority.reqoutstanding;   return(numout);}int ioqueue_get_number_of_requests (ioqueue *queue){   int numreqs = 0;   numreqs += queue->base.numcomplete + queue->base.listlen;   numreqs += queue->timeout.numcomplete + queue->timeout.listlen;   numreqs += queue->priority.numcomplete + queue->priority.listlen;   return(numreqs);}int ioqueue_get_number_of_requests_initiated (ioqueue *queue){   int numreqs = 0;   numreqs += queue->base.numcomplete + queue->base.numoutstanding;   numreqs += queue->timeout.numcomplete + queue->timeout.numoutstanding;   numreqs += queue->priority.numcomplete + queue->priority.numoutstanding;   return(numreqs);}int ioqueue_get_dist (ioqueue *queue, int blkno){   int lastblkno;   if (queue->lastsubqueue == IOQUEUE_BASE) {      lastblkno = queue->base.lastblkno;   } else if (queue->lastsubqueue == IOQUEUE_TIMEOUT) {      lastblkno = queue->timeout.lastblkno;   } else if (queue->lastsubqueue == IOQUEUE_PRIORITY) {      lastblkno = queue->priority.lastblkno;   } else {      fprintf(stderr, "Unknown queue identification at ioqueue_get_dist - %d\n", queue->lastsubqueue);      exit(1);   }   return(abs(blkno - lastblkno));}static void ioqueue_get_cylinder_mapping(ioqueue *queue, 			     iobuf *curr, 			     int blkno, 			     int *cylptr, 			     int *surfptr, 			     int cylmaptype){   cylmaptype = (cylmaptype == -1) ? queue->cylmaptype : cylmaptype;   switch (cylmaptype) {      case MAP_NONE:         *cylptr = 0;         *surfptr = 0;	 // fprintf (outputfile, "ioqueue_get_cylinder_mapping:  MAP_NONE\n");         break;      case MAP_IGNORESPARING:      case MAP_ZONEONLY:      case MAP_ADDSLIPS:      case MAP_FULL:	 device_get_mapping(cylmaptype,			    curr->iolist->devno, 			    blkno, 			    cylptr, 			    surfptr, 			    NULL);	 // fprintf (outputfile, "ioqueue_get_cylinder_mapping:  MAP_[%d]\n", cylmaptype);         break;      case MAP_FROMTRACE:	/* this yucky cast is being allowed for convenience.  We know	 * it can't really hurt us...  */         *cylptr = (int) curr->iolist->buf;	 *surfptr = 0;         break;      case MAP_AVGCYLMAP:         *cylptr = blkno / queue->sectpercyl;         *surfptr = 0;         break;      default:         fprintf(stderr, "Unknown cylinder mapping type: %d\n", queue->cylmaptype);         exit(1);   }   if ((cylptr != NULL) && (surfptr != NULL)) {     // fprintf (outputfile, "ioqueue_get_cylinder_mapping:  Mapped request for block %d to %d, %d\n",     // blkno, *cylptr, *surfptr);   } else {     // fprintf (outputfile, "ioqueue_get_cylinder_mapping:  cylptr or surfptr were NULL\n");   }}void ioqueue_set_concatok_function (ioqueue *queue, int (**concatok)(void *,int,int,int,int), void *concatokparam){   queue->concatok = concatok;   queue->concatokparam = concatokparam;}void ioqueue_set_idlework_function (ioqueue *queue, void (**idlework)(void *,int), void *idleworkparam, double idledelay){   queue->idlework = idlework;   queue->idleworkparam = idleworkparam;   queue->idledelay = idledelay;   queue->idledetect = NULL;}void ioqueue_set_enablement_function (ioqueue *queue, int (**enablement)(ioreq_event *)){   queue->base.enablement = enablement;   queue->timeout.enablement = enablement;   queue->priority.enablement = enablement;}static void ioqueue_idledetected (timer_event *timereq){   ioqueue *queue = (ioqueue *) timereq->ptr;   queue->idledetect = NULL;   (*queue->idlework)(queue->idleworkparam, queue->devno);   addtoextraq((event *)timereq);}void ioqueue_reset_idledetecter (ioqueue *queue, int timechange){   timer_event *idledetect = queue->idledetect;   int listlen = queue->base.listlen + queue->timeout.listlen + queue->priority.listlen;   if ((listlen) || ((idledetect) && (!timechange))) {      return;   }   if (idledetect) {      if (!(removefromintq((event *)idledetect))) {	 fprintf(stderr, "existing idledetect event not on intq in ioqueue_reset_idledetecter\n");	 exit(1);      }   } else {      idledetect = (timer_event *) getfromextraq();      idledetect->type = TIMER_EXPIRED;      idledetect->func = &disksim->timerfunc_ioqueue;      idledetect->ptr = queue;      queue->idledetect = idledetect;   }   idledetect->time = simtime + queue->idledelay;   addtointq((event *)idledetect);}static void ioqueue_update_arrival_stats (ioqueue *queue, ioreq_event *curr){   double tdiff;   if (queue->printintarrstats) {      tdiff = simtime - queue->lastarr;      queue->lastarr = simtime;      stat_update(&queue->intarrstats, tdiff);      if (curr->flags & READ) {         tdiff = simtime - queue->lastread;         queue->lastread = simtime;	 stat_update(&queue->readintarrstats, tdiff);      } else {         tdiff = simtime - queue->lastwrite;         queue->lastwrite = simtime;	 stat_update(&queue->writeintarrstats, tdiff);      }

⌨️ 快捷键说明

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