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

📄 disksim_synthio.c

📁 目前最精确的磁盘模拟器的第3版
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * DiskSim Storage Subsystem Simulation Environment (Version 3.0) * Revision Authors: John Bucy, Greg Ganger * Contributors: John Griffin, Jiri Schindler, Steve Schlosser * * Copyright (c) of Carnegie Mellon University, 2001, 2002, 2003. * * 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_global.h"#include "disksim_synthio.h"#include "disksim_pfsim.h"#include "disksim_iotrace.h"#include "config.h"#include "disksim_device.h"#include "disksim_iodriver.h"#define SYNTHIO_UNIFORM		0#define SYNTHIO_NORMAL		1#define SYNTHIO_EXPONENTIAL	2#define SYNTHIO_POISSON		3#define SYNTHIO_TWOVALUE	4typedef struct dist {   double base;   double mean;   double var;   int    type;} synthio_distr;typedef struct gen {   FILE          *tracefile;   double         probseq;   double         probloc;   double         probread;   double         probtmcrit;   double         probtmlim;   int            number;   ioreq_event *  pendio;   sleep_event *  limits;   int            numdisks;   int            *devno;   int            numblocks;   int            sectsperdisk;   int            blksperdisk;   int            blocksize;   synthio_distr  tmlimit;   synthio_distr  genintr;   synthio_distr  seqintr;   synthio_distr  locintr;   synthio_distr  locdist;   synthio_distr  sizedist;} synthio_generator;typedef struct synthio_info {   synthio_generator **synthio_gens;   int    synthio_gencnt;   int    synthio_gens_len; /* allocated size of array */   int    synthio_iocnt;   int    synthio_endiocnt;   double synthio_endtime;   int    synthio_syscalls;   double synthio_syscall_time;   double synthio_sysret_time;} synthio_info_t;/* one remapping #define for each variable in synthio_info_t */#define synthio_gens            (disksim->synthio_info->synthio_gens)#define synthio_gencnt          (disksim->synthio_info->synthio_gencnt)#define synthio_iocnt           (disksim->synthio_info->synthio_iocnt)#define synthio_endiocnt        (disksim->synthio_info->synthio_endiocnt)#define synthio_endtime         (disksim->synthio_info->synthio_endtime)#define synthio_syscalls        (disksim->synthio_info->synthio_syscalls)#define synthio_syscall_time    (disksim->synthio_info->synthio_syscall_time)#define synthio_sysret_time     (disksim->synthio_info->synthio_sysret_time)static double synthio_get_uniform (synthio_distr *fromdistr){   return(((fromdistr->var - fromdistr->base) * DISKSIM_drand48()) + fromdistr->base);}static double synthio_get_normal (synthio_distr *fromdistr){   double y1, y2;   double y = 0;   while (y <= 0.0) {      y2 = - log((double) 1.0 - DISKSIM_drand48());      y1 = - log((double) 1.0 - DISKSIM_drand48());      y = y2 - ((y1 - (double) 1.0) * (y1 - (double) 1.0)) / 2;   }   if (DISKSIM_drand48() < 0.5) {      y1 = -y1;   }   return((fromdistr->var * y1) + fromdistr->mean);}static double synthio_get_exponential (synthio_distr *fromdistr){   double dtmp;   dtmp = log((double) 1.0 - DISKSIM_drand48());   return((fromdistr->base - (fromdistr->mean * dtmp)));}static double synthio_get_poisson (synthio_distr *fromdistr){   double dtmp = 1.0;   int count = 0;   double stop;   stop = exp(-fromdistr->mean);   while (dtmp >= stop) {      dtmp *= DISKSIM_drand48();      count++;   }   count--;   return((double) count + fromdistr->base);}static double synthio_get_twovalue (synthio_distr *fromdistr){   if (DISKSIM_drand48() < fromdistr->var) {      return(fromdistr->mean);   } else {      return(fromdistr->base);   }}static double synthio_getrand (synthio_distr *fromdistr){   switch (fromdistr->type) {      case SYNTHIO_UNIFORM:	                return(synthio_get_uniform(fromdistr));      case SYNTHIO_NORMAL:                        return(synthio_get_normal(fromdistr));      case SYNTHIO_EXPONENTIAL:			return(synthio_get_exponential(fromdistr));      case SYNTHIO_POISSON:			return(synthio_get_poisson(fromdistr));      case SYNTHIO_TWOVALUE:			return(synthio_get_twovalue(fromdistr));      default:	                fprintf(stderr, "Unrecognized distribution type - %d\n", fromdistr->type);	                exit(1);   }}static void synthio_appendio (process *procp, ioreq_event *tmp){   synthio_generator *gen = (synthio_generator *) procp->space;   sleep_event *limittmp = NULL;   event *prev = NULL;   sleep_event *newsleep = NULL;   sleep_event *callsleep = NULL;   sleep_event *retsleep = NULL;   ioreq_event *new;   int blocksize;   int gennum;   blocksize = gen->blocksize;   gennum = gen->number;   new = (ioreq_event *) getfromextraq();   new->type = IOREQ_EVENT;   new->time = tmp->time;   new->devno = tmp->devno;   new->blkno = tmp->blkno * blocksize;   new->bcount = tmp->bcount * blocksize;   new->flags = tmp->flags;   new->cause = tmp->cause;   new->opid = (synthio_endiocnt * gennum) + synthio_iocnt;   /* this is being considered "ok" under the assumption that opid will */   /* never exceed 2^32.....                                            */   new->buf = (void *) new->opid;   if(synthio_syscalls){      retsleep = (sleep_event *) getfromextraq();      retsleep->type = SLEEP_EVENT;      retsleep->time = synthio_sysret_time;      retsleep->chan = new->buf;      retsleep->iosleep = 1;      callsleep = (sleep_event *) getfromextraq();      callsleep->type = SLEEP_EVENT;      callsleep->time = synthio_syscall_time;      callsleep->chan = new->buf;      callsleep->iosleep = 1;   }   if (new->flags & (TIME_CRITICAL|TIME_LIMITED)) {      newsleep = (sleep_event *) getfromextraq();      newsleep->type = SLEEP_EVENT;      newsleep->time = 0.0;      newsleep->chan = new->buf;      newsleep->iosleep = 1;      if (new->flags & TIME_CRITICAL) {	if(synthio_syscalls){	  retsleep->next = procp->eventlist;	  new->next = (ioreq_event *) retsleep;	  callsleep->next = (event *) new;	  new = (ioreq_event *) callsleep;	  newsleep = NULL;	}else{	  newsleep->next = procp->eventlist;	  new->next = (ioreq_event *) newsleep;	}      } else {	new->next = (ioreq_event *) procp->eventlist;	newsleep->time = -1.0;	while (newsleep->time < 0.0) {	  newsleep->time = synthio_getrand (&gen->tmlimit);	}	newsleep->time += new->time;	limittmp = gen->limits;	if ((limittmp == NULL) || (newsleep->time < limittmp->time)) {	  newsleep->next = (event *) gen->limits;	  gen->limits = (sleep_event *) newsleep;	  if (limittmp) {	    limittmp->time -= newsleep->time;	  }	} else {	  newsleep->time -= limittmp->time;	  while ((limittmp->next) && (newsleep->time >= limittmp->next->time)) {	    limittmp = (sleep_event *) limittmp->next;	    newsleep->time -= limittmp->time;	  }	  newsleep->next = limittmp->next;	  limittmp->next = (event *) newsleep;	  if (newsleep->next) {	    newsleep->next->time -= newsleep->time;	  }	}	newsleep = NULL;      }   } else {     new->next = (ioreq_event *) procp->eventlist;   }      procp->eventlist = (event *) new;synthio_check_genlimits:   limittmp = gen->limits;   while ((limittmp) && (limittmp->time < new->time)) {      gen->limits = (sleep_event *) limittmp->next;      new->time -= limittmp->time;      limittmp->next = (event *) new;      if (prev) {         prev->next = (event *) limittmp;      } else {         procp->eventlist = (event *) limittmp;      }      prev = (event *) limittmp;      limittmp = gen->limits;   }   if ((newsleep) && (gen->limits)) {      prev = (event *) new;      new = (ioreq_event *) newsleep;      newsleep = NULL;      goto synthio_check_genlimits;   }   //fprintf (stderr, "New request %d, time %f, devno %d, blkno %d, bcount %d, flags %x\n", synthio_iocnt, new->time, new->devno, new->blkno, new->bcount, new->flags);}void synthio_initialize_generator (process *procp){   ioreq_event *tmp;   synthio_generator *gen;   event *evptr;   double reqclass;   evptr = getfromextraq();   evptr->time = 0.0;   evptr->type = SYNTHIO_EVENT;   evptr->next = NULL;   procp->eventlist = evptr;   gen = (synthio_generator *) procp->space;   if (gen == NULL) {      fprintf(stderr, "Process with no synthetic generator in synthio_initialize\n");      exit(1);   }   tmp = (ioreq_event *) getfromextraq();   tmp->time = -1.0;   while (tmp->time < 0.0) {      tmp->time = synthio_getrand(&gen->genintr);   }   tmp->flags = 0;   tmp->cause = gen->number;   tmp->devno = gen->devno[(int) (DISKSIM_drand48() * (double) gen->numdisks)];   tmp->blkno = tmp->bcount = gen->blksperdisk;   while (((tmp->blkno + tmp->bcount) >= gen->blksperdisk) || (tmp->bcount == 0)) {      tmp->blkno = (int) (DISKSIM_drand48() * (double) gen->blksperdisk);      tmp->bcount = ((int) synthio_getrand(&gen->sizedist) + gen->blocksize - 1) / gen->blocksize;   }   if (DISKSIM_drand48() < gen->probread) {      tmp->flags |= READ;   }   reqclass = DISKSIM_drand48() - gen->probtmcrit;   if (reqclass < 0.0) {      tmp->flags |= TIME_CRITICAL;   } else if (reqclass < gen->probtmlim) {      tmp->flags |= TIME_LIMITED;   }   gen->pendio = tmp;   synthio_appendio(procp, tmp);fprintf (outputfile, "Initialized synthio process #%d, first event at time %f\n", procp->pid, procp->eventlist->time);}static int synthio_generatenextio (synthio_generator *gen){   double type;   double reqclass;   int blkno;   ioreq_event *tmp;   if ((simtime >= synthio_endtime) || (synthio_iocnt >= synthio_endiocnt))      return 0;   tmp = gen->pendio;   if (gen->tracefile) {      gen->pendio = 	(ioreq_event *)iotrace_get_ioreq_event(gen->tracefile, 					       disksim->traceformat, 					       tmp);      if (gen->pendio) {	 tmp->cause = gen->number;	 /* tmp->time = 0; */      } else {	 fprintf(stderr, "Returning NULL event in synthio_generatenextio\n");	 return 0;      }      return 1;   }   type = DISKSIM_drand48();   if ((type < gen->probseq) &&        ((tmp->blkno + 2*tmp->bcount) < gen->blksperdisk)) {     tmp->time = -1.0;     while (tmp->time < 0.0) {       tmp->time = synthio_getrand(&gen->seqintr);     }     tmp->flags = SEQ | (tmp->flags & READ);     tmp->cause = gen->number;     tmp->blkno += tmp->bcount;   }    else if ((type < (gen->probseq + gen->probloc)) && 	    (type >= gen->probseq)) {     tmp->time = -1.0;     while (tmp->time < 0.0) {       tmp->time = synthio_getrand(&gen->locintr);     }     tmp->flags = LOCAL;     tmp->cause = gen->number;     blkno = gen->blksperdisk;     while (((blkno + tmp->bcount) >= gen->blksperdisk) 	    || (blkno < 0) 	    || (tmp->bcount <= 0))        {	 blkno = tmp->blkno + 	   (int)synthio_getrand(&gen->locdist) / gen->blocksize;	 tmp->bcount = ((int) synthio_getrand(&gen->sizedist) + 			gen->blocksize - 1) / gen->blocksize;       }     tmp->blkno = blkno;     if (DISKSIM_drand48() < gen->probread) {       tmp->flags |= READ;     }   }    else {      tmp->time = -1.0;      while (tmp->time < 0.0) {	tmp->time = synthio_getrand(&gen->genintr);      }      tmp->flags = 0;      tmp->cause = gen->number;      tmp->devno = gen->devno[(int)(DISKSIM_drand48() * 				    (double)gen->numdisks)];      tmp->blkno = tmp->bcount = gen->blksperdisk;      while (((tmp->blkno + tmp->bcount) >= gen->blksperdisk) || 

⌨️ 快捷键说明

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