📄 cmdmain.c
字号:
c->cap_blockmiss[D4PREFETCH+D4XINSTRN], demand_cap_data, c->cap_blockmiss[D4PREFETCH+D4XREAD], c->cap_blockmiss[D4PREFETCH+D4XWRITE], c->cap_blockmiss[D4PREFETCH+D4XMISC]); printf( " PFB conf misses %12.0f %12.0f %12.0f %12.0f %12.0f %12.0f\n", demand_conf_alltype, c->conf_blockmiss[D4PREFETCH+D4XINSTRN], demand_conf_data, c->conf_blockmiss[D4PREFETCH+D4XREAD], c->conf_blockmiss[D4PREFETCH+D4XWRITE], c->conf_blockmiss[D4PREFETCH+D4XMISC]); printf( " PFB comp fract %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n", demand_comp_alltype / NONZERO(prefetch_alltype), c->comp_blockmiss[D4PREFETCH+D4XINSTRN] / NONZERO(c->blockmiss[D4PREFETCH+D4XINSTRN]), demand_comp_data / NONZERO(prefetch_data), c->comp_blockmiss[D4PREFETCH+D4XREAD] / NONZERO(c->blockmiss[D4PREFETCH+D4XREAD]), c->comp_blockmiss[D4PREFETCH+D4XWRITE] / NONZERO(c->blockmiss[D4PREFETCH+D4XWRITE]), c->comp_blockmiss[D4PREFETCH+D4XMISC] / NONZERO(c->blockmiss[D4PREFETCH+D4XMISC])); printf( " PFB cap fract %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n", demand_cap_alltype / NONZERO(prefetch_alltype), c->cap_blockmiss[D4PREFETCH+D4XINSTRN] / NONZERO(c->blockmiss[D4PREFETCH+D4XINSTRN]), demand_cap_data / NONZERO(prefetch_data), c->cap_blockmiss[D4PREFETCH+D4XREAD] / NONZERO(c->blockmiss[D4PREFETCH+D4XREAD]), c->cap_blockmiss[D4PREFETCH+D4XWRITE] / NONZERO(c->blockmiss[D4PREFETCH+D4XWRITE]), c->cap_blockmiss[D4PREFETCH+D4XMISC] / NONZERO(c->blockmiss[D4PREFETCH+D4XMISC])); printf( " PFB conf fract %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n", demand_conf_alltype / NONZERO(prefetch_alltype), c->conf_blockmiss[D4PREFETCH+D4XINSTRN] / NONZERO(c->blockmiss[D4PREFETCH+D4XINSTRN]), demand_conf_data / NONZERO(prefetch_data), c->conf_blockmiss[D4PREFETCH+D4XREAD] / NONZERO(c->blockmiss[D4PREFETCH+D4XREAD]), c->conf_blockmiss[D4PREFETCH+D4XWRITE] / NONZERO(c->blockmiss[D4PREFETCH+D4XWRITE]), c->conf_blockmiss[D4PREFETCH+D4XMISC] / NONZERO(c->blockmiss[D4PREFETCH+D4XMISC])); } printf( " Total Block Misses %12.0f %12.0f %12.0f %12.0f %12.0f %12.0f\n", demand_alltype + prefetch_alltype, c->blockmiss[D4XINSTRN] + c->blockmiss[D4PREFETCH+D4XINSTRN], demand_data + prefetch_data, c->blockmiss[D4XREAD] + c->blockmiss[D4PREFETCH+D4XREAD], c->blockmiss[D4XWRITE] + c->blockmiss[D4PREFETCH+D4XWRITE], c->blockmiss[D4XMISC] + c->blockmiss[D4PREFETCH+D4XMISC]); printf( " Tot blk miss rate %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f\n", (demand_alltype + prefetch_alltype) / NONZERO(demand_fetch_alltype + prefetch_fetch_alltype), (c->blockmiss[D4XINSTRN] + c->blockmiss[D4PREFETCH+D4XINSTRN]) / NONZERO(c->fetch[D4XINSTRN] + c->fetch[D4PREFETCH+D4XINSTRN]), (demand_data + prefetch_data) / NONZERO(demand_fetch_data + prefetch_fetch_data), (c->blockmiss[D4XREAD] + c->blockmiss[D4PREFETCH+D4XREAD]) / NONZERO(c->fetch[D4XREAD] + c->fetch[D4PREFETCH+D4XREAD]), (c->blockmiss[D4XWRITE] + c->blockmiss[D4PREFETCH+D4XWRITE]) / NONZERO(c->fetch[D4XWRITE] + c->fetch[D4PREFETCH+D4XWRITE]), (c->blockmiss[D4XMISC] + c->blockmiss[D4PREFETCH+D4XMISC]) / NONZERO(c->fetch[D4XMISC] + c->fetch[D4PREFETCH+D4XMISC])); } /* End of prefetch block misses */ printf("\n"); } /* End of block misses */ /* * End of Block Misses Numbers */ /* * Report multiblock and traffic to/from memory */ printf( " Multi-block refs %12.0f\n", c->multiblock); printf( " Bytes From Memory %12.0f\n", c->bytes_read); printf( " ( / Demand Fetches) %12.4f\n", c->bytes_read / NONZERO(demand_fetch_alltype)); printf( " Bytes To Memory %12.0f\n", c->bytes_written); printf( " ( / Demand Writes) %12.4f\n", c->bytes_written / NONZERO(c->fetch[D4XWRITE])); printf( " Total Bytes r/w Mem %12.0f\n", c->bytes_read + c->bytes_written); printf( " ( / Demand Fetches) %12.4f\n", (c->bytes_read + c->bytes_written) / NONZERO(demand_fetch_alltype)); printf("\n");}#undef NONZERO/* * Called to produce each address trace record */d4memrefnext_trace_item(){ d4memref r; static int once = 1; static int discard = 0; static int hastoggled = 0; if (once) { once = 0; if (on_trigger != 0) discard = 1; /* initially discard until trigger address seen */ if (skipcount > 0) { double tskipcount = skipcount; do { r = input_function(); if (r.accesstype == D4TRACE_END) { fprintf (stderr, "%s warning: input ended " "before -skipcount satisfied\n", progname); return r; } } while ((tskipcount -= 1) > 0); } } while (1) { r = input_function(); if (r.accesstype == D4TRACE_END) { if ((on_trigger != 0 || off_trigger != 0) && !hastoggled) fprintf (stderr, "%s warning: trace discard " "trigger addresses were not matched\n", progname); else if (discard == 0 && off_trigger != 0) fprintf (stderr, "%s warning: tail end of trace not discarded\n", progname); return r; } if (r.address != 0) { /* valid triggers must be != 0 */ if ((discard != 0 && on_trigger == r.address) || (discard == 0 && off_trigger == r.address)) { discard ^= 1; /* toggle */ hastoggled = 1; continue; /* discard the trigger itself */ } } if (!discard) return r; }}/* * Called to initialize all caches based on args * Die with an error message if there are serious problems. */voidinitialize_caches (d4cache **icachep, d4cache **dcachep){ static char memname[] = "memory"; int i, lev, idu; d4cache *c = NULL, /* avoid `may be used uninitialized' warning in gcc */ *ci, *cd; mem = cd = ci = d4new(NULL); if (ci == NULL) die ("cannot create simulated memory\n"); ci->name = memname; for (lev = maxlevel-1; lev >= 0; lev--) { for (idu = 0; idu < 3; idu++) { if (level_size[idu][lev] != 0) { switch (idu) { case 0: cd = ci = c = d4new (ci); break; /* u */ case 1: ci = c = d4new (ci); break; /* i */ case 2: cd = c = d4new (cd); break; /* d */ } if (c == NULL) die ("cannot create level %d %ccache\n", lev+1, idu==0?'u':(idu==1?'i':'d')); init_1cache (c, lev, idu); levcache[idu][lev] = c; } } } i = d4setup(); if (i != 0) die ("cannot complete cache initializations; d4setup = %d\n", i); *icachep = ci; *dcachep = cd;}#if !D4CUSTOM /* a customized version cannot be further customized *//* * Create a customized version of dineroIV. This is called after everything * is all set up and we would otherwise be ready to begin simulation. * * We create a temporary .c file, containing initializers for the * command line argument arrays (level_*, etc.), handled mostly by * args[].customf. We also call d4customize to add customized * d4ref code for all of our caches in the same file. * We rebuild dineroIV by running $D4_SRC/make with extra arguments, * and finally exec the new program. */voidcustomize_caches(){ FILE *f = NULL; char fname[100]; int pid = getpid(); struct arglist *adesc; struct stat st; char *cmdline = malloc(4096); /* XXX add overflow checking or make this more dynamic */ char *psrc, *plib; int x; if (cmdline == NULL) die ("no memory for custom make command line\n"); sprintf (fname, "/tmp/d4custom%d.c", pid); f = fopen (fname, "w"); if (f == NULL) die ("can't create file %s for writing (%s)\n", fname, strerror(errno)); d4customize(f); /* call all customf functions */ fprintf (f, "\n#include \"cmdargs.h\"\n"); for (adesc = args; adesc->optstring != NULL; adesc++) { if (adesc->customf != NULL) adesc->customf (adesc, f); } fprintf (f, "int maxlevel = %d;\n", maxlevel); fclose (f); /* run make */ psrc = getenv ("D4_SRC"); if (psrc == NULL || *psrc == 0) psrc = "."; plib = getenv ("D4_LIB"); if (plib == NULL || *plib == 0) { plib = malloc (strlen(psrc)+strlen("/libd4.a")+1); if (plib == NULL) die ("no memory for libd4.a pathname\n"); strcpy (plib, psrc); strcat (plib, "/libd4.a"); } /* try to catch common errors */ sprintf (cmdline, "%s/Makefile", psrc); if (stat (cmdline, &st) < 0) die ("There is no %s%s\n", cmdline, getenv("D4_SRC")==NULL ? "; try setting D4_SRC" : ""); sprintf (cmdline, "%s/d4.h", psrc); if (stat (cmdline, &st) < 0) die ("There is no %s%s\n", cmdline, getenv("D4_SRC")==NULL ? "; try setting D4_SRC" : ""); if (stat (plib, &st) < 0) die ("There is no %s%s\n", plib, getenv("D4_LIB")==NULL ? "; try setting D4_LIB" : ""); sprintf (cmdline, "make -s -f %s/Makefile %s CUSTOM_NAME=%s " "CUSTOM_C=%s D4_SRC=%s D4_LIB=%s\n", psrc, customname, customname, fname, psrc, plib); x = system (cmdline);#if 1 /* remove custom source file */ (void)unlink(fname);#endif if (x != 0) die ("can't make %s: %s returned %d\n", customname, cmdline, x); /* exec customname using cust_argc, cust_argv */ cust_argv[0] = customname; cust_argv[cust_argc++] = NULL; x = execv (customname, (char**)cust_argv); /* cast avoids warnings */ die ("cannot exec custom version %s: %s\n", customname, strerror(x));}#endif /* !D4CUSTOM *//* * Complain and terminate */voiddie (const char *fmt, ...){ va_list ap; fflush (stdout); fprintf (stderr, "%s: ", progname); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); exit (1);}/* * Produce short help message for improper usage, then terminate */voidshorthelp (const char *fmt, ...){ va_list ap; fflush (stdout); fprintf (stderr, "%s: ", progname); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); fprintf (stderr, "Consult Dinero IV documentation\n" "or run \"%s -help\" for usage information.\n", progname); exit (1);}/* * Ceiling of log base 2 * Return -1 for clog2(0) */intclog2 (unsigned int x){ int i; for (i = -1; x != 0; i++) x >>= 1; return i;}/* * Everything starts here */intmain (int argc, char **argv){ d4memref r; d4cache *ci, *cd; double tmaxcount = 0, tintcount; double flcount; if (argc > 0) { char *cp; progname = argv[0]; while ((cp = strrchr (progname, '/')) != NULL) { if (cp[1] == 0) cp[0] = 0; /* trim trailing '/' */ else progname = cp+1; } } doargs (argc, argv); verify_options(); initialize_caches (&ci, &cd);#if !D4CUSTOM if (customname != NULL) { customize_caches(); /* never returns */ }#endif if (cd == NULL) cd = ci; /* for unified L1 cache */ printf ("---Dinero IV cache simulator, version %s\n", D4VERSION); printf ("---Written by Jan Edler and Mark D. Hill\n"); printf ("---Copyright (C) 1997 NEC Research Institute, Inc. and Mark D. Hill.\n"); printf ("---All rights reserved.\n"); printf ("---Copyright (C) 1985, 1989 Mark D. Hill. All rights reserved.\n"); printf ("---See -copyright option for details\n"); summarize_caches (ci, cd); printf ("\n---Simulation begins.\n"); tintcount = stat_interval; flcount = flushcount; while (1) { r = next_trace_item(); if (r.accesstype == D4TRACE_END) goto done; if (maxcount != 0 && tmaxcount >= maxcount) { printf ("---Maximum address count exceeded.\n"); break; } switch (r.accesstype) { case D4XINSTRN: d4ref (ci, r); break; case D4XINVAL: d4ref (ci, r); /* fall through */ default: d4ref (cd, r); break; } tmaxcount += 1; if (tintcount > 0 && (tintcount -= 1) <= 0) { dostats(); tintcount = stat_interval; } if (flcount > 0 && (flcount -= 1) <= 0) { /* flush cache = copy back and invalidate */ r.accesstype = D4XCOPYB; r.address = 0; r.size = 0; d4ref (cd, r); r.accesstype = D4XINVAL; d4ref (ci, r); if (ci != cd) d4ref (cd, r); flcount = flushcount; } }done: /* copy everything back at the end -- is this really a good idea? XXX */ r.accesstype = D4XCOPYB; r.address = 0; r.size = 0; d4ref (cd, r); printf ("---Simulation complete.\n"); dostats(); printf ("---Execution complete.\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -