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

📄 disksim_pfsim.c

📁 目前最精确的磁盘模拟器的第3版
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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_stat.h"#include "disksim_pfface.h"#include "disksim_pfsim.h"#include "disksim_ioface.h"#include "disksim_synthio.h"#include "config.h"int pf_how_many_cpus(){   return (numcpus);}static void pf_allocate_process_structs(){   int i;   process *temp = (process *) DISKSIM_malloc(ALLOCSIZE);   ASSERT(temp != NULL);   for (i=0; i<((ALLOCSIZE/sizeof(process))-1); i++) {      temp[i].next = &temp[i+1];   }   temp[((ALLOCSIZE/sizeof(process))-1)].next = NULL;   extra_process_q = temp;   extra_process_qlen = ALLOCSIZE/sizeof(process);}#if 0static void pf_addtoextra_process_q(temp)process *temp;{   temp->next = extra_process_q;   extra_process_q = temp;   extra_process_qlen++;}#endifprocess *pf_getfromextra_process_q(){   process *temp = extra_process_q;   if (extra_process_qlen == 0) {      pf_allocate_process_structs();      temp = extra_process_q;      extra_process_q = extra_process_q->next;   } else if (extra_process_qlen == 1) {      extra_process_q = NULL;   } else {      extra_process_q = extra_process_q->next;   }   extra_process_qlen--;   temp->pfflags = 0;   temp->stat = PROC_RUN;   temp->idler = 0;   temp->runcpu = 0;   temp->flags = 0;   temp->chan = 0;   temp->ios = 0;   temp->ioreads = 0;   temp->cswitches = 0;   temp->active = 0;   temp->sleeps = 0;   temp->iosleep = 0;   temp->iosleeps = 0;   temp->runiosleep = 0.0;   temp->lastsleep = 0.0;   temp->runsleep = 0.0;   temp->runtime = 0.0;   temp->falseidletime = 0.0;   temp->lasteventtime = -1.0;   stat_initialize(statdeffile, "Time limit duration", &temp->readtimelimitstats);   stat_initialize(statdeffile, "Time limit duration", &temp->writetimelimitstats);   stat_initialize(statdeffile, "Time limit duration", &temp->readmisslimitstats);   stat_initialize(statdeffile, "Time limit duration", &temp->writemisslimitstats);   temp->ioreq = NULL;   temp->eventlist = NULL;   temp->space = NULL;   temp->link = NULL;   temp->next = NULL;   return(temp);}/* This is NOT general.  It is basically only used by synthio.c during *//* synthio_readparams.                                                 */process * pf_new_process(){   process *procp = pf_getfromextra_process_q();   procp->pid = (synthlist) ? (synthlist->pid + 1) : 0;   procp->next = synthlist;   synthlist = procp;   return(procp);}#if 0static event * pf_remove_from_process_eventlist (process *procp){   event *old = procp->eventlist;   procp->eventlist = old->next;   return(old);}#endifstatic void pf_add_to_process_eventlist (process *procp, event *new){   new->next = procp->eventlist;   procp->eventlist = new;}static void pf_add_to_intrp_eventlist (intr_event *intrp, event *new){   new->next = intrp->eventlist;   intrp->eventlist = new;}static double pf_add_false_idle_time (double length){   double ret = 0.0;   process *procp = process_livelist;   while (procp != NULL) {      if ((procp->stat == PROC_SLEEP) && (procp->iosleep)) {         procp->falseidletime += length;         ret = length;      } else if ((procp->stat == PROC_RUN) && (procp->pfflags & PF_SLEEP_FLAG) && (procp->iosleep)) {         procp->falseidletime += length;         ret = length;      } else if ((procp->stat == PROC_ONPROC) && (cpus[procp->runcpu].state == CPU_IDLE) && (procp->pfflags & PF_SLEEP_FLAG) && (procp->iosleep)) {         procp->falseidletime += length;         ret = length;      }      procp = procp->livelist;   }   return(ret);}static void pf_add_to_pendiolist (process *procp, ioreq_event *curr){   ioreq_event *new = (ioreq_event *)getfromextraq();   new->time = simtime;   new->devno = curr->devno;   new->blkno = curr->blkno;   new->buf = curr->buf;   new->opid = curr->opid;   new->tempptr1 = procp;   new->tempint2 = -1;   new->flags = curr->flags & ~PF_BUF_WANTED;   new->prev = NULL;   new->next = pendiolist;   pendiolist = new;}event * pf_io_done_notify (ioreq_event *curr){   ioreq_event *tmp = pendiolist;   ioreq_event *tmp2;   wakeup_event *tmpwake = NULL;   if(disksim->external_control){     disksim->external_io_done_notify (curr);   }   if (pf_printhack) {     fprintf (outputfile, "pf_io_done_notify: curr->buf %p, curr->opid %x, curr->blkno %d\n", curr->buf, curr->opid, curr->blkno);   }   ASSERT(pendiolist != NULL);   if ((tmp->buf == curr->buf) && (tmp->opid == curr->opid)) {      pendiolist = tmp->next;   }    else {     while ((tmp->next) && 	    ((tmp->next->buf != curr->buf) || 	     (tmp->next->opid != curr->opid)))        {         tmp = tmp->next;       }          ASSERT(tmp->next != NULL);     tmp2 = tmp->next;     tmp->next = tmp2->next;     tmp = tmp2;   }   if (tmp->flags & PF_BUF_WANTED) {      tmpwake = (wakeup_event *) getfromextraq();      tmpwake->type = WAKEUP_EVENT;      /* tmpwake->time = PF_IO_WAKEUP_TIME;         gets overridden anyway */      tmpwake->next = NULL;      tmpwake->chan = tmp->buf;      tmpwake->dropit = 0;   }   if (curr->flags & TIME_CRITICAL) {      stat_update(&timecritrespstats, (simtime - tmp->time));   }    else if (curr->flags & TIME_LIMITED) {      stat_update(&timelimitrespstats, (simtime - tmp->time));   }    else {      stat_update(&timenoncritrespstats, (simtime - tmp->time));   }   if (!(curr->flags & TIME_LIMITED) || (tmpwake)) {      addtoextraq((event *) tmp);   }    else {      tmp->next = doneiolist;      doneiolist = tmp;   }   return((event *) tmpwake);}static int pf_iowait (void *chan, process *procp){   double tmptime;   ioreq_event *tmp = pendiolist;   while ((tmp) && (tmp->buf != chan)) {      tmp = tmp->next;   }   if (tmp == NULL) {      ioreq_event *prev = 0;      tmp = doneiolist;      while ((tmp) && (tmp->buf != chan)) {         prev = tmp;         tmp = tmp->next;      }      if (tmp) {         if (doneiolist == tmp) {            doneiolist = tmp->next;         } else {            prev->next = tmp->next;         }         if (tmp->flags & READ) {            stat_update(&procp->readtimelimitstats, (simtime - tmp->time));         } else {            stat_update(&procp->writetimelimitstats, (simtime - tmp->time));         }         addtoextraq((event *) tmp);      }      return(FALSE);   }if (pf_printhack)fprintf (outputfile, "pf_iowait: chan %p, read %d, crit %d, opid %d, blkno %x\n", tmp->buf, (tmp->flags & READ), (tmp->flags & (TIME_LIMITED|TIME_CRITICAL)), tmp->opid, tmp->blkno);   if (tmp->flags & TIME_LIMITED) {      if (tmp->flags & READ) {         stat_update(&procp->readtimelimitstats, (simtime - tmp->time));         stat_update(&procp->readmisslimitstats, (simtime - tmp->time));      } else {         stat_update(&procp->writetimelimitstats, (simtime - tmp->time));         stat_update(&procp->writemisslimitstats, (simtime - tmp->time));      }   }   tmp->flags |= PF_BUF_WANTED;   tmptime = io_raise_priority(tmp->opid, tmp->devno, tmp->blkno, tmp->buf);   if (tmptime != 0.0) {      fprintf(stderr, "Haven't handled non-zero bufferwait time yet\n");      exit(1);   }   return(TRUE);}static void pf_add_cswitch_event (process *procp, process *newprocp, cpu_event *cpu_ev){   cpu *currcpu = &cpus[(cpu_ev->cpunum)];   cswitch_event *new = (cswitch_event *) getfromextraq();   new->type = CSWITCH_EVENT;   new->newprocp = newprocp;   if (procp != newprocp) {      new->time = PF_CSWITCH_TIME;      currcpu->cswitches++;   } else {      new->time = 0.0;   }   currcpu->runswitchtime += new->time;   if (procp) {      pf_add_to_process_eventlist(procp, (event *) new);   } else {      new->next = currcpu->idleevents;      currcpu->idleevents = (event *) new;   }}static double pf_get_time_to_next_process_event (process *procp){   double tmptime;   if (procp->eventlist == NULL) {      fprintf (outputfile, "Active process at end of eventlist: %d\n", procp->pid);      disksim_simstop();      return(0.0);   }   tmptime = procp->eventlist->time;   procp->eventlist->time = simtime;   return(tmptime);}static double pf_get_time_to_next_intr_event (intr_event *intrp){   double tmptime;   ASSERT(intrp->eventlist != NULL);   tmptime = intrp->eventlist->time;   intrp->eventlist->time = simtime;   return(tmptime);}/* called when a process is enabled by another CPU while this CPU is idle */void pf_idle_cpu_recheck_dispq (int cpunum){  ASSERT(cpus[cpunum].current->procp == NULL);   if (cpus[cpunum].idleevents == NULL) {      event *new = getfromextraq();      new->type = IDLELOOP_EVENT;      new->time = PF_IDLE_CHECK_DISPQ_TIME;      new->next = cpus[cpunum].idleevents;      cpus[cpunum].idleevents = new;      if (cpus[cpunum].current->intrp == NULL) {	cpus[cpunum].idletime += simtime - cpus[cpunum].idlestart;	cpus[cpunum].falseidletime += pf_add_false_idle_time(simtime - cpus[cpunum].idlestart);	cpus[cpunum].current->time = simtime + (cpus[cpunum].scale * new->time);	new->time = simtime;	cpus[cpunum].state = CPU_IDLE_WORK;	addtointq((event *) cpus[cpunum].current);      }   }}static void pf_handle_cswitch_event (cswitch_event *curr, cpu_event *cpu_ev){

⌨️ 快捷键说明

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