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

📄 disksim_logorg.c

📁 目前最精确的磁盘模拟器的第3版
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * 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 <errno.h>#include <string.h>#include "disksim_global.h"#include "disksim_stat.h"#include "disksim_iosim.h"#include "disksim_orgface.h"#include "disksim_logorg.h"#include "disksim_ioqueue.h"#include "config.h"#define MAX_QUEUE_LENGTH 10000/* read-only globals used during readparams phase */static char *statdesc_intarr =      "Inter-arrival time";static char *statdesc_readintarr =  "Read inter-arrival";static char *statdesc_writeintarr = "Write inter-arrival";static char *statdesc_reqsize =     "Request size";static char *statdesc_readsize =    "Read request size";static char *statdesc_writesize =   "Write request size";static char *statdesc_idles =       "Idle period length";static char *statdesc_resptime =    "Response time";static char *statdesc_streak =      "Streak length";static char *statdesc_locality =    "Inter-request distance";static int logorg_overlap (logorg *currlogorg, int devno, ioreq_event *curr, int blksperpart){   int calc;   calc = curr->blkno - currlogorg->devs[devno].startblkno;   if ((calc >= 0) && (calc < blksperpart)) {      curr->devno = devno;      curr->blkno = calc;      return(TRUE);   }   return(FALSE);}static void logorg_streakstat (logorg *currlogorg, int diskno){   int last = currlogorg->lastdiskaccessed;   logorgdev *devs = currlogorg->devs;   if (currlogorg->printstreakstats == FALSE) {      return;   }   ASSERT1((diskno >= 0) && (diskno <= currlogorg->actualnumdisks), "diskno", diskno);   if (diskno == last) {      if (diskno != currlogorg->actualnumdisks) {         devs[diskno].curstreak++;      }      return;   }   if (last != currlogorg->actualnumdisks) {      stat_update(&devs[last].streakstats, (double) devs[last].curstreak);      devs[last].curstreak = 0;   }   currlogorg->lastdiskaccessed = diskno;   if (diskno != currlogorg->actualnumdisks) {      devs[diskno].curstreak = 1;   }}static void logorg_update_intarr_stats (logorg *currlogorg, ioreq_event *curr){   double tdiff;   if (currlogorg->printintarrstats == FALSE) {      return;   }   tdiff = simtime - currlogorg->stat.lastarr;   stat_update(&currlogorg->stat.intarrstats, tdiff);   currlogorg->stat.lastarr = simtime;   if (curr->flags & READ) {      tdiff = simtime - currlogorg->stat.lastread;      stat_update(&currlogorg->stat.readintarrstats, tdiff);      currlogorg->stat.lastread = simtime;   } else {      tdiff = simtime - currlogorg->stat.lastwrite;      stat_update(&currlogorg->stat.writeintarrstats, tdiff);      currlogorg->stat.lastwrite = simtime;   }}static void logorg_update_interfere_stats (logorg *currlogorg, ioreq_event *curr){   int i;   int first;   int *lastreq = currlogorg->stat.lastreq;   int diffblkno;   if (currlogorg->printinterferestats == FALSE) {      return;   }   first = stat_get_count(&currlogorg->stat.intarrstats) % INTERFEREMAX;   first = (INTERFEREMAX - first) % INTERFEREMAX;   for (i=0; i<INTERFEREMAX; i++) {      if (curr->devno == lastreq[(((i+first)%INTERFEREMAX) << 1)]) {         diffblkno = curr->blkno - lastreq[((((i+first)%INTERFEREMAX) << 1) + 1)];         if (!diffblkno) {            currlogorg->stat.intdist[(i*INTDISTMAX)]++;            i = -1;            break;         }      }   }   if (i != -1) {      for (i=0; i<INTERFEREMAX; i++) {         if (curr->devno == lastreq[(((i+first)%INTERFEREMAX) << 1)]) {            diffblkno = curr->blkno - lastreq[((((i+first)%INTERFEREMAX) << 1) + 1)];            if ((diffblkno <= 64) && (diffblkno >= -64)) {               if (diffblkno < 0) {                  if (diffblkno >= -4) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+1)]++;                  } else if (diffblkno >= -8) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+2)]++;                  } else if (diffblkno >= -16) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+3)]++;                  } else if (diffblkno >= -64) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+4)]++;                  }               } else {                  if (diffblkno <= 8) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+5)]++;                  } else if (diffblkno <= 16) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+6)]++;                  } else if (diffblkno <= 64) {                     currlogorg->stat.intdist[((i*INTDISTMAX)+7)]++;                  }               }               break;            }         }      }   }   first = ((first - 1) % INTERFEREMAX) << 1;/*     assert(first >= 0); */   if(first >= 0) {     lastreq[first] = curr->devno;     lastreq[(first + 1)] = curr->blkno + curr->bcount;   }}static void logorg_update_blocking_stats (logorg *currlogorg, ioreq_event *curr){   int i;   int maxval;   if (currlogorg->printblockingstats == FALSE) {      return;   }   maxval = min(BLOCKINGMAX, curr->bcount);   for (i=0; i<maxval; i++) {      if ((curr->bcount % (i+1)) == 0) {         currlogorg->stat.blocked[i]++;      }   }   maxval = min(BLOCKINGMAX, curr->blkno);   for (i=0; i<maxval; i++) {      if ((curr->blkno % (i+1)) == 0) {         currlogorg->stat.aligned[i]++;      }   }}static void logorg_numoutdist (int numout, int *dist){   int i = min(numout, 9);   ASSERT(numout >= 0);   dist[i]++;}static void logorg_diffdist (double mydiff, int *dist){   int i;   if (mydiff < (double) 0.5) {      i = 0;   } else if (mydiff < (double) 1.0) {      i = 1;   } else if (mydiff < (double) 1.5) {      i = 2;   } else if (mydiff < (double) 2.0) {      i = 3;   } else if (mydiff < (double) 2.5) {      i = 4;   } else if (mydiff < (double) 3.0) {      i = 5;   } else if (mydiff < (double) 4.0) {      i = 6;   } else if (mydiff < (double) 5.0) {      i = 7;   } else if (mydiff < (double) 6.0) {      i = 8;   } else {      i = 9;   }   dist[i]++;}static void logorg_maprequest_update_stats (logorg *currlogorg, ioreq_event *curr, outstand *req, int numreqs){   int i;   ioreq_event *temp;   int gen;   double tpass;   logorgdev *currdev;   int orgdevno = curr->devno - currlogorg->devs[0].devno;/*fprintf (outputfile, "Entering logorg_maprequest_update_stats - numreqs %d, orgdevno %d\n", numreqs, orgdevno);*/   currdev = &currlogorg->devs[orgdevno];   logorg_update_interfere_stats(currlogorg, curr);   logorg_update_intarr_stats(currlogorg, curr);   logorg_update_blocking_stats(currlogorg, curr);      if (currlogorg->printsizestats) {      stat_update(&currlogorg->stat.sizestats, (double) curr->bcount);      if (curr->flags & READ) {         stat_update(&currlogorg->stat.readsizestats, (double) curr->bcount);      } else {         stat_update(&currlogorg->stat.writesizestats, (double) curr->bcount);      }   }   if (curr->flags & TIME_CRITICAL) {      if (curr->flags & READ) {         currlogorg->stat.critreads++;      } else {         currlogorg->stat.critwrites++;      }   }   stat_update(&currdev->localitystats, (double) (currdev->lastblkno - curr->blkno));   if ((curr->blkno > currdev->lastblkno) && (curr->blkno <= currdev->lastblkno2)) {      if (curr->flags & READ) {         currdev->intreads++;      } else {         currdev->intwrites++;      }   }   currdev->lastblkno2 = curr->blkno + curr->bcount + 16;   if (curr->blkno == currdev->lastblkno) {      if (curr->flags & READ) {         currdev->seqreads++;      } else {         currdev->seqwrites++;      }   }   currdev->lastblkno = curr->blkno + curr->bcount;   gen = curr->cause;   if (curr->flags & SEQ) {      if (curr->flags & READ) {         currlogorg->stat.seqreads++;      } else {         currlogorg->stat.seqwrites++;      }      if (currlogorg->stat.gens[gen] != curr->devno) {         currlogorg->stat.seqdiskswitches++;         curr->flags &= ~SEQ;      }   }   if (curr->flags & LOCAL) {      currlogorg->stat.numlocal++;      if (currlogorg->stat.gens[gen] != curr->devno) {         currlogorg->stat.locdiskswitches++;         curr->flags &= ~LOCAL;      }   }   currlogorg->stat.gens[gen] = curr->devno;   logorg_streakstat(currlogorg, orgdevno);/*fprintf (outputfile, "Midway through stats\n");*/   temp = curr;   for (i=0; i<numreqs; i++) {      currlogorg->devs[(temp->devno - currlogorg->devs[0].devno)].numout++;      temp = temp->next;   }   if (currlogorg->stat.outstanding > 0) {      currlogorg->stat.nonzeroouttime += simtime - currlogorg->stat.outtime;   } else {      tpass = simtime - currlogorg->stat.idlestart;      stat_update(&currlogorg->stat.idlestats, tpass);   }   currlogorg->stat.idlestart = simtime;   currlogorg->stat.runouttime += (double) currlogorg->stat.outstanding * (simtime - currlogorg->stat.outtime);   currlogorg->stat.outstanding++;   if (currlogorg->stat.outstanding >= MAX_QUEUE_LENGTH) {      fprintf(stderr,"Stopping simulation because of saturation: simtime %f, totalreqs %d\n", simtime, disksim->totalreqs);      fflush(stderr);      fprintf (outputfile, "Stopping simulation because of saturation: simtime %f, totalreqs %d\n", simtime, disksim->totalreqs);      fprintf (outputfile, "last request:  dev=%d, blk=%d, cnt=%d, %d (R==1)\n",curr->devno, curr->blkno, curr->bcount, (curr->flags & READ));      disksim_simstop();   }   if (req->flags & READ) {      currlogorg->stat.readoutstanding++;   }   if (currlogorg->stat.outstanding > currlogorg->stat.maxoutstanding) {      currlogorg->stat.maxoutstanding = currlogorg->stat.outstanding;   }   currlogorg->stat.outtime = simtime;/*fprintf (outputfile, "Leaving maprequest_stats\n");*/}static void logorg_mapcomplete_update_stats (logorg *currlogorg, ioreq_event *curr, outstand *req){

⌨️ 快捷键说明

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