├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── README.stats ├── SConstruct ├── misc ├── Vagrantfile ├── cpplint.py ├── ffControl.py ├── fix_whitespace.sh ├── gitver.py ├── hooks │ ├── Makefile │ ├── README │ ├── fortran_hooks.c │ ├── test.c │ ├── test.cpp │ ├── test.f │ ├── test.java │ ├── zsim.java │ ├── zsim_hooks.h │ └── zsim_jni.cpp ├── lint_includes.py ├── list_syscalls.py ├── patchRoot │ ├── cpuinfo.template │ ├── genPatchRoot.py │ ├── nodeFiles │ │ ├── distance │ │ ├── meminfo │ │ ├── numastat │ │ ├── scan_unevictable_pages │ │ └── vmstat │ └── stat.template └── testProgs │ ├── Makefile │ └── test-affinity.cpp ├── src ├── SConscript ├── access_tracing.cpp ├── access_tracing.h ├── barrier.h ├── bithacks.h ├── breakdown_stats.h ├── cache.cpp ├── cache.h ├── cache_arrays.cpp ├── cache_arrays.h ├── coherence_ctrls.cpp ├── coherence_ctrls.h ├── config.cpp ├── config.h ├── constants.h ├── contention_sim.cpp ├── contention_sim.h ├── core.h ├── core_recorder.cpp ├── core_recorder.h ├── cpuenum.h ├── cpuid.h ├── ddr_mem.cpp ├── ddr_mem.h ├── debug.h ├── debug_harness.cpp ├── debug_harness.h ├── debug_zsim.cpp ├── debug_zsim.h ├── decoder.cpp ├── decoder.h ├── detailed_mem.cpp ├── detailed_mem.h ├── detailed_mem_params.cpp ├── detailed_mem_params.h ├── dramsim_mem_ctrl.cpp ├── dramsim_mem_ctrl.h ├── dumptrace.cpp ├── event_queue.h ├── event_recorder.h ├── fftoggle.cpp ├── filter_cache.h ├── g_heap │ └── dlmalloc.h.c ├── g_std │ ├── README.txt │ ├── g_list.h │ ├── g_multimap.h │ ├── g_string.h │ ├── g_unordered_map.h │ ├── g_unordered_set.h │ ├── g_vector.h │ └── stl_galloc.h ├── galloc.cpp ├── galloc.h ├── hash.cpp ├── hash.h ├── hdf5_stats.cpp ├── ideal_arrays.h ├── init.cpp ├── init.h ├── intrusive_list.h ├── locks.h ├── log.cpp ├── log.h ├── lookahead.cpp ├── mem_ctrls.cpp ├── mem_ctrls.h ├── memory_hierarchy.cpp ├── memory_hierarchy.h ├── monitor.cpp ├── mtrand.h ├── mutex.h ├── network.cpp ├── network.h ├── null_core.cpp ├── null_core.h ├── ooo_core.cpp ├── ooo_core.h ├── ooo_core_recorder.cpp ├── ooo_core_recorder.h ├── pad.h ├── parse_vdso.cpp ├── part_repl_policies.h ├── partition_mapper.cpp ├── partition_mapper.h ├── partitioner.h ├── pin_cmd.cpp ├── pin_cmd.h ├── prefetcher.cpp ├── prefetcher.h ├── prio_queue.h ├── proc_stats.cpp ├── proc_stats.h ├── process_stats.cpp ├── process_stats.h ├── process_tree.cpp ├── process_tree.h ├── profile_stats.h ├── rdtsc.h ├── repl_policies.h ├── scheduler.cpp ├── scheduler.h ├── simple_core.cpp ├── simple_core.h ├── slab_alloc.h ├── sorttrace.cpp ├── stats.h ├── stats_filter.cpp ├── stats_filter.h ├── str.h ├── text_stats.cpp ├── tick_event.h ├── timing_cache.cpp ├── timing_cache.h ├── timing_core.cpp ├── timing_core.h ├── timing_event.cpp ├── timing_event.h ├── trace_driver.cpp ├── trace_driver.h ├── tracing_cache.cpp ├── tracing_cache.h ├── utility_monitor.cpp ├── utility_monitor.h ├── virt │ ├── common.h │ ├── cpu.cpp │ ├── fs.cpp │ ├── patchdefs.h │ ├── port_virtualizer.h │ ├── ports.cpp │ ├── syscall_name.cpp.in │ ├── syscall_name.h │ ├── time.cpp │ ├── time_conv.h │ ├── timeout.cpp │ ├── virt.cpp │ └── virt.h ├── weave_md1_mem.h ├── zsim.cpp ├── zsim.h └── zsim_harness.cpp └── tests ├── affinity.cfg ├── het.cfg ├── hooks.cfg ├── pgo.cfg ├── ptree.cfg └── simple.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | pin-2.14 2 | *.out 3 | .sconsign.dblite 4 | build 5 | *.log 6 | *.h5 7 | heartbeat 8 | out.cfg 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | .phony: zsim clean 4 | 5 | zsim: 6 | @echo "Detecting whether pin directory exists..." 7 | @if [ -d "./pin-2.14" ]; then echo "Found pin-2.14"; else echo "You need pin-2.14 directory"; fi 8 | PINPATH=$(CURDIR)/pin-2.14 scons 9 | @echo "If compilation fails and says hdf5 cannot be found, run make clean and retry" 10 | 11 | release: 12 | @echo "Detecting whether pin directory exists..." 13 | @if [ -d "./pin-2.14" ]; then echo "Found pin-2.14"; else echo "You need pin-2.14 directory"; fi 14 | PINPATH=$(CURDIR)/pin-2.14 scons --r 15 | @echo "If compilation fails and says hdf5 cannot be found, run make clean and retry" 16 | 17 | clean: 18 | @rm ./.sconsign.dblite 19 | @rm -rf ./build 20 | -------------------------------------------------------------------------------- /README.stats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # zsim stats README 3 | # Author: Daniel Sanchez 4 | # Date: May 3 2011 5 | # 6 | # Stats are now saved in HDF5, and you should never need to write a stats 7 | # parser. This README explains how to access them in python using h5py. It 8 | # doubles as a python script, so you can just execute it with "python 9 | # README.stats" and see how everything works (after you have generated a stats 10 | # file). 11 | # 12 | 13 | import h5py # presents HDF5 files as numpy arrays 14 | import numpy as np 15 | 16 | # Open stats file 17 | f = h5py.File('zsim-ev.h5', 'r') 18 | 19 | # Get the single dataset in the file 20 | dset = f["stats"]["root"] 21 | 22 | # Each dataset is first indexed by record. A record is a snapshot of all the 23 | # stats taken at a specific time. All stats files have at least two records, 24 | # at beginning (dest[0])and end of simulation (dset[-1]). Inside each record, 25 | # the format follows the structure of the simulated objects. A few examples: 26 | 27 | # Phase count at end of simulation 28 | endPhase = dset[-1]['phase'] 29 | print endPhase 30 | 31 | # If your L2 has a single bank, this is all the L2 hits. Otherwise it's the 32 | # hits of the first L2 bank 33 | l2_0_hits = dset[-1]['l2'][0]['hGETS'] + dset[-1]['l2'][0]['hGETX'] 34 | print l2_0_hits 35 | 36 | # Hits into all L2s 37 | l2_hits = np.sum(dset[-1]['l2']['hGETS'] + dset[-1]['l2']['hGETX']) 38 | print l2_hits 39 | 40 | # Total number of instructions executed, counted by adding per-core counts 41 | # (you could also look at procInstrs) 42 | totalInstrs = np.sum(dset[-1]['simpleCore']['instrs']) 43 | print totalInstrs 44 | 45 | # You can also focus on one sample, or index over multiple steps, e.g., 46 | lastSample = dset[-1] 47 | allHitsS = lastSample['l2']['hGETS'] 48 | firstL2HitsS = allHitsS[0] 49 | print firstL2HitsS 50 | 51 | # There is a certain slack in the positions of numeric and non-numeric indices, 52 | # so the following are equivalent: 53 | print dset[-1]['l2'][0]['hGETS'] 54 | #print dset[-1][0]['l2']['hGETS'] # can't do 55 | print dset[-1]['l2']['hGETS'][0] 56 | print dset['l2']['hGETS'][-1,0] 57 | print dset['l2'][-1,0]['hGETS'] 58 | print dset['l2']['hGETS'][-1,0] 59 | 60 | # However, you can't do things like dset[-1][0]['l2']['hGETS'], because the [0] 61 | # indexes a specific element in array 'l2'. The rule of thumb seems to be that 62 | # numeric indices can "flow up", i.e., you can index them later than you should. 63 | # This introduces no ambiguities. 64 | 65 | # Slicing works as in numpy, e.g., 66 | print dset['l2']['hGETS'] # a 2D array with samples*per-cache data 67 | print dset['l2']['hGETS'][-1] # a 1D array with per-cache numbers, for the last sample 68 | print dset['l2']['hGETS'][:,0] # 1D array with all samples, for the first L2 cache 69 | 70 | # OK, now go bananas! 71 | 72 | -------------------------------------------------------------------------------- /misc/Vagrantfile: -------------------------------------------------------------------------------- 1 | #-*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant::Config.run do |config| 5 | config.vm.box = "precise64" 6 | config.vm.box_url = "http://files.vagrantup.com/precise64.box" 7 | 8 | config.vm.customize ["modifyvm", :id, "--memory", 4096] 9 | config.vm.customize ["modifyvm", :id, "--cpus", 4] 10 | 11 | config.vm.provision :shell, :inline => <<-SH 12 | # Packages 13 | export DEBIAN_FRONTEND=noninteractive 14 | apt-get -y update 15 | # apt-get -y dist-upgrade 16 | 17 | # zsim dependencies 18 | apt-get -y install build-essential g++ git scons 19 | apt-get -y install libelfg0-dev libhdf5-serial-dev libconfig++-dev 20 | 21 | # dependencies for zsim's Fortran and Java hooks (misc/hooks) 22 | apt-get -y install gfortran openjdk-7-jdk 23 | 24 | # other packages 25 | apt-get -y install vim 26 | 27 | # Get Pin & set PINPATH 28 | #PINVER="pin-2.12-58423-gcc.4.4.7-linux" 29 | PINVER="pin-2.13-62732-gcc.4.4.7-linux" 30 | if [ ! -d ~vagrant/${PINVER} ]; then 31 | echo "Downloading Pin version ${PINVER}" 32 | sudo -u vagrant wget -nc -nv http://software.intel.com/sites/landingpage/pintool/downloads/${PINVER}.tar.gz 33 | sudo -u vagrant tar xzf ${PINVER}.tar.gz 34 | echo "export PINPATH=~/${PINVER}" >> ~vagrant/.bashrc 35 | fi 36 | 37 | # Configure system flags 38 | sysctl -w kernel.shmmax=1073741824 39 | sysctl -w kernel.yama.ptrace_scope=0 40 | SH 41 | end 42 | -------------------------------------------------------------------------------- /misc/ffControl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (C) 2013-2015 by Massachusetts Institute of Technology 4 | # 5 | # This file is part of zsim. 6 | # 7 | # zsim is free software; you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, version 2. 10 | # 11 | # If you use this software in your research, we request that you reference 12 | # the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | # Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | # source of the simulator in any publications that use this software, and that 15 | # you send us a citation of your work. 16 | # 17 | # zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | # details. 21 | # 22 | # You should have received a copy of the GNU General Public License along with 23 | # this program. If not, see . 24 | 25 | import os, sys, subprocess 26 | from optparse import OptionParser 27 | 28 | parser = OptionParser() 29 | parser.add_option("--procIdx", type="int", default=0, dest="procIdx", help="Process index to signal") 30 | parser.add_option("--lineMatch", default=" ROI", dest="lineMatch", help="Matching line to stdin will trigger signal") 31 | parser.add_option("--maxMatches", type="int", default=0, dest="maxMatches", help="Exit after this many matches (0 to disable)") 32 | parser.add_option("--fftogglePath", default="./build/opt", dest="fftogglePath", help="") 33 | (opts, args) = parser.parse_args() 34 | 35 | targetShmid = -1 36 | matches = 0 37 | while matches < opts.maxMatches or opts.maxMatches <= 0: 38 | try: 39 | line = sys.stdin.readline() 40 | except: 41 | print "stdin done, exiting" 42 | break 43 | 44 | if line.startswith("[H] Global segment shmid = "): 45 | targetShmid = int(line.split("=")[1].lstrip().rstrip()) 46 | print "Target shmid is", targetShmid 47 | 48 | if line.find(opts.lineMatch) >= 0: 49 | if targetShmid >= 0: 50 | print "Match, calling fftoggle" 51 | matches += 1 52 | subprocess.call([os.path.join(opts.fftogglePath, "fftoggle"), str(targetShmid), str(opts.procIdx)]) 53 | else: 54 | print "Match but shmid is not valid, not sending signal (are you sure you specified procIdx correctly? it's not the PID)" 55 | print "Done, %d matches" % matches 56 | 57 | -------------------------------------------------------------------------------- /misc/fix_whitespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sed -i 's/[ \t]*$//' $@ # kill all trailing whitespace 3 | sed -i 's/\t/ /' $@ # turn each tab into 4 spaces 4 | -------------------------------------------------------------------------------- /misc/gitver.py: -------------------------------------------------------------------------------- 1 | # Return a pretty-printed short git version (like hg/svnversion) 2 | import os 3 | def cmd(c): return os.popen(c).read().strip() 4 | branch = cmd("git rev-parse --abbrev-ref HEAD") 5 | revnum = cmd("git log | grep ^commit | wc -l") 6 | rshort = cmd("git rev-parse --short HEAD") 7 | dfstat = cmd("git diff HEAD --shortstat") 8 | dfhash = cmd("git diff HEAD | md5sum")[:8] 9 | shstat = dfstat.replace(" files changed", "fc").replace(" file changed", "fc") \ 10 | .replace(" insertions(+)", "+").replace(" insertion(+)", "+") \ 11 | .replace(" deletions(-)", "-").replace(" deletion(-)", "-") \ 12 | .replace(",", "") 13 | diff = "clean" if len(dfstat) == 0 else shstat + " " + dfhash 14 | print ":".join([branch, revnum, rshort, diff]) 15 | -------------------------------------------------------------------------------- /misc/hooks/Makefile: -------------------------------------------------------------------------------- 1 | #JDK_PATH=../jdk1.5.0_22 2 | #JDK_PATH=/usr/lib/jvm/java-7-oracle 3 | # This should work regardless of the JDK flavor (OpenJDK/Oracle), at least on Ubuntu 4 | JDK_PATH=$(shell dirname $(shell dirname $(shell (readlink -f `which javac`)))) 5 | 6 | # Common deps 7 | DEPS=Makefile zsim_hooks.h 8 | 9 | default: test_c test_cpp test_fortran test.class 10 | 11 | libfortran_hooks.a: $(DEPS) 12 | gcc -O3 -g -fPIC -o fortran_hooks.o -c fortran_hooks.c 13 | ar rcs libfortran_hooks.a fortran_hooks.o 14 | ranlib libfortran_hooks.a 15 | 16 | zsim.class: $(DEPS) zsim_jni.cpp zsim.java 17 | $(JDK_PATH)/bin/javah -o zsim_jni.h zsim # generates header from zsim.java 18 | g++ -O3 -g -std=c++0x -shared -fPIC -o libzsim_jni.so zsim_jni.cpp -I$(JDK_PATH)/include -I$(JDK_PATH)/include/linux 19 | $(JDK_PATH)/bin/javac zsim.java 20 | #$(JDK_PATH)/bin/jar cf zsim.jar zsim.class # not needed 21 | 22 | test_c: $(DEPS) test.c 23 | gcc -O3 -g -o test_c test.c 24 | 25 | test_cpp: $(DEPS) test.cpp 26 | g++ -O3 -g -o test_cpp test.cpp 27 | 28 | test_fortran: $(DEPS) test.f libfortran_hooks.a 29 | gfortran -o test_fortran test.f -L. -lfortran_hooks 30 | 31 | test.class: $(DEPS) test.java zsim.class 32 | $(JDK_PATH)/bin/javac test.java 33 | 34 | run_tests: test_c test_cpp test_fortran test.class 35 | ./test_c 36 | ./test_cpp 37 | ./test_fortran 38 | java -Djava.library.path=. test 39 | 40 | clean: 41 | rm -f *.o *.so *.a *.jar *.class test_* zsim_jni.h 42 | -------------------------------------------------------------------------------- /misc/hooks/README: -------------------------------------------------------------------------------- 1 | zsim hooks for different programming languages. Use these to control simulation 2 | (e.g., fast-forwarding). C and C++ programs just need to include zsim-hooks.h. 3 | Fortran programs need to be linked with libfortran-hooks.a. Java programs can 4 | use the provided zsim JNI class. Run make run_tests and explore the Makefile 5 | for more info. 6 | -------------------------------------------------------------------------------- /misc/hooks/fortran_hooks.c: -------------------------------------------------------------------------------- 1 | #include "zsim_hooks.h" 2 | 3 | void zsim_roi_begin_() { 4 | zsim_roi_begin(); 5 | } 6 | 7 | void zsim_roi_end_() { 8 | zsim_roi_end(); 9 | } 10 | 11 | void zsim_heartbeat_() { 12 | zsim_heartbeat(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /misc/hooks/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "zsim_hooks.h" 3 | 4 | int main() { 5 | printf("C test\n"); 6 | zsim_roi_begin(); 7 | zsim_heartbeat(); 8 | zsim_roi_end(); 9 | printf("C test done\n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /misc/hooks/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "zsim_hooks.h" 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | cout << "C++ test" << endl; 8 | zsim_roi_begin(); 9 | zsim_heartbeat(); 10 | zsim_roi_end(); 11 | cout << "C++ test done" << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /misc/hooks/test.f: -------------------------------------------------------------------------------- 1 | print *, "Fortran test" 2 | call zsim_roi_begin() 3 | call zsim_heartbeat() 4 | call zsim_roi_end() 5 | print *, "Fortran test done" 6 | end 7 | -------------------------------------------------------------------------------- /misc/hooks/test.java: -------------------------------------------------------------------------------- 1 | 2 | public class test { 3 | public static void main(String[] args) { 4 | System.out.println("Java test"); 5 | zsim.roi_begin(); 6 | for (int i = 0; i < 42; i++) zsim.heartbeat(); 7 | zsim.roi_end(); 8 | System.out.println("Java test done"); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /misc/hooks/zsim.java: -------------------------------------------------------------------------------- 1 | // package zsim; 2 | 3 | public class zsim { 4 | public static native void roi_begin(); 5 | public static native void roi_end(); 6 | public static native void heartbeat(); 7 | static { 8 | System.loadLibrary("zsim_jni"); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /misc/hooks/zsim_hooks.h: -------------------------------------------------------------------------------- 1 | #ifndef __ZSIM_HOOKS_H__ 2 | #define __ZSIM_HOOKS_H__ 3 | 4 | #include 5 | #include 6 | 7 | //Avoid optimizing compilers moving code around this barrier 8 | #define COMPILER_BARRIER() { __asm__ __volatile__("" ::: "memory");} 9 | 10 | //These need to be in sync with the simulator 11 | #define ZSIM_MAGIC_OP_ROI_BEGIN (1025) 12 | #define ZSIM_MAGIC_OP_ROI_END (1026) 13 | #define ZSIM_MAGIC_OP_REGISTER_THREAD (1027) 14 | #define ZSIM_MAGIC_OP_HEARTBEAT (1028) 15 | #define ZSIM_MAGIC_OP_WORK_BEGIN (1029) //ubik 16 | #define ZSIM_MAGIC_OP_WORK_END (1030) //ubik 17 | 18 | #ifdef __x86_64__ 19 | #define HOOKS_STR "HOOKS" 20 | static inline void zsim_magic_op(uint64_t op) { 21 | COMPILER_BARRIER(); 22 | __asm__ __volatile__("xchg %%rcx, %%rcx;" : : "c"(op)); 23 | COMPILER_BARRIER(); 24 | } 25 | #else 26 | #define HOOKS_STR "NOP-HOOKS" 27 | static inline void zsim_magic_op(uint64_t op) { 28 | //NOP 29 | } 30 | #endif 31 | 32 | static inline void zsim_roi_begin() { 33 | printf("[" HOOKS_STR "] ROI begin\n"); 34 | zsim_magic_op(ZSIM_MAGIC_OP_ROI_BEGIN); 35 | } 36 | 37 | static inline void zsim_roi_end() { 38 | zsim_magic_op(ZSIM_MAGIC_OP_ROI_END); 39 | printf("[" HOOKS_STR "] ROI end\n"); 40 | } 41 | 42 | static inline void zsim_heartbeat() { 43 | zsim_magic_op(ZSIM_MAGIC_OP_HEARTBEAT); 44 | } 45 | 46 | static inline void zsim_work_begin() { zsim_magic_op(ZSIM_MAGIC_OP_WORK_BEGIN); } 47 | static inline void zsim_work_end() { zsim_magic_op(ZSIM_MAGIC_OP_WORK_END); } 48 | 49 | #endif /*__ZSIM_HOOKS_H__*/ 50 | -------------------------------------------------------------------------------- /misc/hooks/zsim_jni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "zsim_hooks.h" 3 | #include "zsim_jni.h" // generated by javah 4 | 5 | JNIEXPORT void JNICALL Java_zsim_roi_1begin(JNIEnv *env, jclass cls) { zsim_roi_begin(); } 6 | JNIEXPORT void JNICALL Java_zsim_roi_1end(JNIEnv *env, jclass cls) { zsim_roi_end(); } 7 | JNIEXPORT void JNICALL Java_zsim_heartbeat(JNIEnv *env, jclass cls) { zsim_heartbeat(); } 8 | -------------------------------------------------------------------------------- /misc/lint_includes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (C) 2013-2015 by Massachusetts Institute of Technology 4 | # 5 | # This file is part of zsim. 6 | # 7 | # zsim is free software; you can redistribute it and/or modify it under the 8 | # terms of the GNU General Public License as published by the Free Software 9 | # Foundation, version 2. 10 | # 11 | # If you use this software in your research, we request that you reference 12 | # the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | # Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | # source of the simulator in any publications that use this software, and that 15 | # you send us a citation of your work. 16 | # 17 | # zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | # details. 21 | # 22 | # You should have received a copy of the GNU General Public License along with 23 | # this program. If not, see . 24 | 25 | 26 | import os, sys 27 | 28 | #dryRun = True 29 | dryRun = False 30 | 31 | srcs = sys.argv[1:] 32 | 33 | def sortIncludes(lines, fname): 34 | def prefix(l): 35 | if l.find("<") >= 0: 36 | return "2" 37 | # if you want to differentiate... 38 | #if l.find(".h") >= 0: return "2" # C system headers 39 | #else: return "3" # C++ system headers 40 | else: 41 | if l.find('"' + fname + '.') >= 0: return "1" # Our own header 42 | return "4" # Program headers 43 | 44 | ll = [prefix(l) + l.strip() for l in lines if len(l.strip()) > 0] 45 | sl = [l[1:] for l in sorted(ll)] 46 | if lines[-1].strip() == "": sl += [""] 47 | #print sl 48 | return sl 49 | 50 | for src in srcs: 51 | f = open(src, 'r+') # we open for read/write here to fail early on read-only files 52 | txt = f.read() 53 | f.close() 54 | 55 | bName = os.path.basename(src).split(".")[0] 56 | print bName 57 | 58 | lines = [l for l in txt.split("\n")] 59 | 60 | includeBlocks = [] 61 | blockStart = -1 62 | for i in range(len(lines)): 63 | l = lines[i].strip() 64 | isInclude = l.startswith("#include") and l.find("NOLINT") == -1 65 | isEmpty = l == "" 66 | if blockStart == -1: 67 | if isInclude: blockStart = i # start block 68 | else: 69 | if not (isInclude or isEmpty): # close block 70 | includeBlocks.append((blockStart, i)) 71 | blockStart = -1 72 | 73 | print src, len(includeBlocks), "blocks" 74 | 75 | newIncludes = [(s , e, sortIncludes(lines[s:e], bName)) for (s, e) in includeBlocks] 76 | for (s , e, ii) in newIncludes: 77 | # Print? 78 | if ii == lines[s:e]: 79 | print "Block in lines %d-%d matches" % (s, e-1) 80 | continue 81 | for i in range(s, e): 82 | print "%3d: %s%s | %s" % (i, lines[i], " "*(40 - len(lines[i][:39])), ii[i-s] if i-s < len(ii) else "") 83 | print "" 84 | 85 | prevIdx = 0 86 | newLines = [] 87 | for (s , e, ii) in newIncludes: 88 | newLines += lines[prevIdx:s] + ii 89 | prevIdx = e 90 | newLines += lines[prevIdx:] 91 | 92 | if not dryRun and len(includeBlocks): 93 | outTxt = "\n".join(newLines) 94 | f = open(src, 'w') 95 | f.write(outTxt) 96 | f.close() 97 | 98 | print "Done!" 99 | -------------------------------------------------------------------------------- /misc/list_syscalls.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Produces a list of syscalls in the current system 3 | import os, re 4 | syscallCmd = "gcc -E -dD /usr/include/asm/unistd.h | grep __NR" 5 | syscallDefs = os.popen(syscallCmd).read() 6 | sysList = [(int(numStr), name) for (name, numStr) in re.findall("#define __NR_(.*?) (\d+)", syscallDefs)] 7 | denseList = ["INVALID"]*(max([num for (num, name) in sysList]) + 1) 8 | for (num, name) in sysList: denseList[num] = name 9 | print '"' + '",\n"'.join(denseList) + '"' 10 | -------------------------------------------------------------------------------- /misc/patchRoot/cpuinfo.template: -------------------------------------------------------------------------------- 1 | processor : $CPU 2 | vendor_id : GenuineIntel 3 | cpu family : 6 4 | model : 15 5 | model name : Intel(R) Xeon(R) CPU E5335 @ 2.00GHz 6 | stepping : 7 7 | cpu MHz : 1995.120 8 | cache size : 4096 KB 9 | physical id : $CPU 10 | siblings : $NCPUS 11 | core id : $CPU 12 | cpu cores : $NCPUS 13 | apicid : $CPU 14 | initial apicid : $CPU 15 | fpu : yes 16 | fpu_exception : yes 17 | cpuid level : 10 18 | wp : yes 19 | flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx tm2 ssse3 cx16 xtpr pdcm dca lahf_lm dtherm tpr_shadow 20 | bogomips : 3990.24 21 | clflush size : 64 22 | cache_alignment : 64 23 | address sizes : 36 bits physical, 48 bits virtual 24 | power management: 25 | 26 | -------------------------------------------------------------------------------- /misc/patchRoot/nodeFiles/distance: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /misc/patchRoot/nodeFiles/meminfo: -------------------------------------------------------------------------------- 1 | Node 0 MemTotal: 33525260 kB 2 | Node 0 MemFree: 7103752 kB 3 | Node 0 MemUsed: 26421508 kB 4 | Node 0 Active: 21111308 kB 5 | Node 0 Inactive: 2823820 kB 6 | Node 0 Active(anon): 18869284 kB 7 | Node 0 Inactive(anon): 601672 kB 8 | Node 0 Active(file): 2242024 kB 9 | Node 0 Inactive(file): 2222148 kB 10 | Node 0 Unevictable: 0 kB 11 | Node 0 Mlocked: 0 kB 12 | Node 0 Dirty: 108 kB 13 | Node 0 Writeback: 0 kB 14 | Node 0 FilePages: 4884048 kB 15 | Node 0 Mapped: 433856 kB 16 | Node 0 AnonPages: 19069344 kB 17 | Node 0 Shmem: 398052 kB 18 | Node 0 KernelStack: 4120 kB 19 | Node 0 PageTables: 74400 kB 20 | Node 0 NFS_Unstable: 8 kB 21 | Node 0 Bounce: 0 kB 22 | Node 0 WritebackTmp: 0 kB 23 | Node 0 Slab: 1386804 kB 24 | Node 0 SReclaimable: 1271048 kB 25 | Node 0 SUnreclaim: 115756 kB 26 | Node 0 AnonHugePages: 0 kB 27 | Node 0 HugePages_Total: 0 28 | Node 0 HugePages_Free: 0 29 | Node 0 HugePages_Surp: 0 30 | -------------------------------------------------------------------------------- /misc/patchRoot/nodeFiles/numastat: -------------------------------------------------------------------------------- 1 | numa_hit 17464111314 2 | numa_miss 0 3 | numa_foreign 0 4 | interleave_hit 15992 5 | local_node 17464079088 6 | other_node 0 7 | -------------------------------------------------------------------------------- /misc/patchRoot/nodeFiles/scan_unevictable_pages: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /misc/patchRoot/nodeFiles/vmstat: -------------------------------------------------------------------------------- 1 | nr_free_pages 1775938 2 | nr_inactive_anon 150418 3 | nr_active_anon 4717321 4 | nr_inactive_file 555537 5 | nr_active_file 560506 6 | nr_unevictable 0 7 | nr_mlock 0 8 | nr_anon_pages 4767336 9 | nr_mapped 108464 10 | nr_file_pages 1221012 11 | nr_dirty 27 12 | nr_writeback 0 13 | nr_slab_reclaimable 317762 14 | nr_slab_unreclaimable 28939 15 | nr_page_table_pages 18600 16 | nr_kernel_stack 515 17 | nr_unstable 2 18 | nr_bounce 0 19 | nr_vmscan_write 1418314 20 | nr_vmscan_immediate_reclaim 1404 21 | nr_writeback_temp 0 22 | nr_isolated_anon 0 23 | nr_isolated_file 0 24 | nr_shmem 99513 25 | nr_dirtied 218449153 26 | nr_written 216406104 27 | numa_hit 17464111314 28 | numa_miss 78421229 29 | numa_foreign 541191002 30 | numa_interleave 15992 31 | numa_local 17464079088 32 | numa_other 78453455 33 | nr_anon_transparent_hugepages 0 34 | -------------------------------------------------------------------------------- /misc/patchRoot/stat.template: -------------------------------------------------------------------------------- 1 | $CPUSTAT 2 | intr 126179179275 17876 3 0 0 0 0 0 0 1 0 0 0 4 0 0 0 61163008 0 0 0 0 0 0 290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 103771380 215532394 165622708 48561815 78921339 136273892 331572171 84723547 12593167 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | ctxt 1319718714527 4 | btime 1365356075 5 | processes 3878073 6 | procs_running 2 7 | procs_blocked 0 8 | softirq 73342466563 0 1689790758 12887572 2486080210 18121886 0 12593228 2445648220 3610928298 2936874247 9 | -------------------------------------------------------------------------------- /misc/testProgs/Makefile: -------------------------------------------------------------------------------- 1 | # Common deps 2 | DEPS=Makefile 3 | 4 | default: test_affinity 5 | 6 | test_affinity: $(DEPS) test-affinity.cpp 7 | g++ -O3 -g -o test_affinity test-affinity.cpp -pthread 8 | 9 | run_tests: default 10 | ./test_affinity 11 | 12 | clean: 13 | rm -f *.o *.so *.a test_* 14 | 15 | .PHONY: clean default 16 | 17 | -------------------------------------------------------------------------------- /misc/testProgs/test-affinity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "unistd.h" 4 | #include "pthread.h" 5 | #include "sched.h" 6 | #include "sys/syscall.h" 7 | #include "sys/types.h" 8 | 9 | static inline uint32_t get_cpuid() { 10 | return sched_getcpu(); 11 | } 12 | 13 | // Thread excutes different numbers of instructions based on its thread id. 14 | // Check zsim.out for instruction counts on the pinning cores. 15 | static uint64_t dummy_compute(uint64_t amount) { 16 | uint64_t ret = 0; 17 | const uint64_t amplify = 1uL << 23; 18 | for (uint64_t i = 0; i < amount * amplify; i++) ret += i; 19 | return ret; 20 | } 21 | 22 | struct thread_arg_t { 23 | pid_t* pids; 24 | pthread_barrier_t* bar; 25 | int tid; 26 | uint64_t ret; 27 | }; 28 | 29 | static void* thread_function(void* th_args) { 30 | thread_arg_t* args = (thread_arg_t*)th_args; 31 | int tid = args->tid; 32 | pid_t* pids = args->pids; 33 | pthread_barrier_t* bar = args->bar; 34 | 35 | printf("Thread %d: start on core %u\n", tid, get_cpuid()); 36 | 37 | pids[tid] = syscall(SYS_gettid); 38 | 39 | pthread_barrier_wait(bar); 40 | 41 | // syscall affinity API. 42 | cpu_set_t set; 43 | CPU_ZERO(&set); 44 | CPU_SET(tid + 4, &set); 45 | sched_setaffinity(0, sizeof(cpu_set_t), &set); 46 | 47 | CPU_ZERO(&set); 48 | sched_getaffinity(0, sizeof(cpu_set_t), &set); 49 | for (int i = 0; i < (int)sizeof(cpu_set_t)*8; i++) { 50 | if (CPU_ISSET(i, &set)) printf("Thread %d: could run on core %d\n", tid, i); 51 | } 52 | printf("Thread %d: actual running on core %u\n", tid, get_cpuid()); 53 | 54 | args->ret = dummy_compute(tid); 55 | 56 | if (pthread_barrier_wait(bar) == PTHREAD_BARRIER_SERIAL_THREAD) { 57 | printf("Round 1 done.\n"); 58 | } 59 | 60 | 61 | // Pthread affinity API. 62 | // Use dynamically sized cpu set. 63 | cpu_set_t* pset = CPU_ALLOC(2048); 64 | size_t size = CPU_ALLOC_SIZE(2048); 65 | CPU_ZERO_S(size, pset); 66 | CPU_SET_S(tid + 8, size, pset); 67 | pthread_setaffinity_np(pthread_self(), size, pset); 68 | 69 | CPU_ZERO_S(size, pset); 70 | pthread_getaffinity_np(pthread_self(), size, pset); 71 | for (int i = 0; i < (int)size*8; i++) { 72 | if (CPU_ISSET_S(i, size, pset)) printf("Thread %d: could run on core %d\n", tid, i); 73 | } 74 | printf("Thread %d: actual running on core %u\n", tid, get_cpuid()); 75 | CPU_FREE(pset); 76 | 77 | args->ret = dummy_compute(tid); 78 | 79 | if (pthread_barrier_wait(bar) == PTHREAD_BARRIER_SERIAL_THREAD) { 80 | printf("Round 2 done.\n"); 81 | } 82 | 83 | 84 | // Set affinity for others. 85 | CPU_ZERO(&set); 86 | CPU_SET(tid + 12, &set); 87 | sched_setaffinity(pids[(tid+2)%4], sizeof(cpu_set_t), &set); 88 | 89 | // Wait on barrier to ensure affinity has been set. 90 | pthread_barrier_wait(bar); 91 | 92 | CPU_ZERO(&set); 93 | sched_getaffinity(pids[(tid+2)%4], sizeof(cpu_set_t), &set); 94 | for (int i = 0; i < (int)sizeof(cpu_set_t)*8; i++) { 95 | if (CPU_ISSET(i, &set)) printf("Thread %d: could run on core %d\n", (tid+2)%4, i); 96 | } 97 | printf("Thread %d: actual running on core %u\n", tid, get_cpuid()); 98 | 99 | args->ret = dummy_compute(tid); 100 | 101 | if (pthread_barrier_wait(bar) == PTHREAD_BARRIER_SERIAL_THREAD) { 102 | printf("Round 3 done.\n"); 103 | } 104 | 105 | return NULL; 106 | } 107 | 108 | int main() { 109 | printf("zsim sched_get/setaffinity test\n"); 110 | printf("sizeof(cpu_set_t) == %lu\n", sizeof(cpu_set_t)); 111 | 112 | pthread_t threads[4]; 113 | pthread_barrier_t barrier; 114 | pthread_barrier_init(&barrier, NULL, 4); 115 | pid_t pids[4]; 116 | thread_arg_t thread_args[4]; 117 | for (uint32_t tid = 0; tid < 4; tid++) { 118 | thread_args[tid].pids = pids; 119 | thread_args[tid].bar = &barrier; 120 | thread_args[tid].tid = tid; 121 | pthread_create(&threads[tid], NULL, thread_function, &thread_args[tid]); 122 | } 123 | for (uint32_t tid = 0; tid < 4; tid++) { 124 | pthread_join(threads[tid], NULL); 125 | } 126 | pthread_barrier_destroy(&barrier); 127 | 128 | printf("zsim sched_get/setaffinity test done\n"); 129 | 130 | return 0; 131 | } 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/SConscript: -------------------------------------------------------------------------------- 1 | # -*- mode:python -*- 2 | 3 | import os 4 | Import("env") 5 | 6 | commonSrcs = ["config.cpp", "galloc.cpp", "log.cpp", "pin_cmd.cpp"] 7 | harnessSrcs = ["zsim_harness.cpp", "debug_harness.cpp"] 8 | 9 | # By default, we compile all cpp files in libzsim.so. List the cpp files that 10 | # should be excluded below (one per line and in order, to ease merges) 11 | excludeSrcs = [ 12 | "fftoggle.cpp", 13 | "dumptrace.cpp", 14 | "sorttrace.cpp", 15 | ] 16 | excludeSrcs += harnessSrcs 17 | 18 | libEnv = env.Clone() 19 | libEnv["CPPFLAGS"] += libEnv["PINCPPFLAGS"] 20 | libEnv["LINKFLAGS"] += libEnv["PINLINKFLAGS"] 21 | libEnv["LIBPATH"] += libEnv["PINLIBPATH"] 22 | libEnv["LIBS"] += libEnv["PINLIBS"] 23 | 24 | # Build syscall name file 25 | def getSyscalls(): return os.popen("python ../../misc/list_syscalls.py").read().strip() 26 | syscallSrc = libEnv.Substfile("virt/syscall_name.cpp", "virt/syscall_name.cpp.in", 27 | SUBST_DICT = {"SYSCALL_NAME_LIST" : getSyscalls()}) 28 | 29 | # Build libzsim.so 30 | globSrcNodes = Glob("*.cpp") + Glob("virt/*.cpp") 31 | libSrcs = [str(x) for x in globSrcNodes if str(x) not in excludeSrcs] 32 | libSrcs += [str(x) for x in syscallSrc] 33 | libSrcs = list(set(libSrcs)) # ensure syscallSrc is not duplicated 34 | libEnv.SharedLibrary("zsim.so", libSrcs) 35 | 36 | # Build tracing utilities (need hdf5 & dynamic linking) 37 | traceEnv = env.Clone() 38 | if "hdf5" in traceEnv["PINLIBS"]: 39 | traceEnv["LIBS"] += ["hdf5", "hdf5_hl"] 40 | else: 41 | assert "hdf5_serial" in traceEnv["PINLIBS"] 42 | traceEnv["LIBS"] += ["hdf5_serial", "hdf5_serial_hl"] 43 | traceEnv["OBJSUFFIX"] += "t" 44 | traceEnv.Program("dumptrace", ["dumptrace.cpp", "access_tracing.cpp", "memory_hierarchy.cpp"] + commonSrcs) 45 | traceEnv.Program("sorttrace", ["sorttrace.cpp", "access_tracing.cpp"] + commonSrcs) 46 | 47 | # Build harness (static to make it easier to run across environments) 48 | env["LINKFLAGS"] += " --static " 49 | env["LIBS"] += ["pthread"] 50 | env.Program("zsim", harnessSrcs + commonSrcs) 51 | 52 | # Build additional utilities below 53 | env.Program("fftoggle", ["fftoggle.cpp"] + commonSrcs) 54 | -------------------------------------------------------------------------------- /src/access_tracing.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef ACCESS_TRACING_H_ 27 | #define ACCESS_TRACING_H_ 28 | 29 | #include "g_std/g_string.h" 30 | #include "memory_hierarchy.h" 31 | 32 | /* HDF5-based classes read and write address traces in a consistent format */ 33 | 34 | struct AccessRecord { 35 | Address lineAddr; 36 | uint64_t reqCycle; 37 | uint32_t latency; 38 | uint32_t childId; 39 | AccessType type; 40 | }; 41 | 42 | struct PackedAccessRecord { 43 | uint64_t lineAddr; 44 | uint64_t reqCycle; 45 | uint32_t latency; 46 | uint16_t childId; 47 | uint16_t type; // could be uint8_t, but causes corruption in HDF5? (wtf...) 48 | } /*__attribute__((packed))*/; // 24 bytes --> no packing needed 49 | 50 | 51 | class AccessTraceReader { 52 | private: 53 | PackedAccessRecord* buf; 54 | uint32_t cur; 55 | uint32_t max; 56 | g_string fname; 57 | 58 | uint64_t curFrameRecord; 59 | uint64_t numRecords; 60 | uint32_t numChildren; //i.e., how many parallel streams does this file contain? 61 | 62 | public: 63 | AccessTraceReader(std::string fname); 64 | 65 | inline bool empty() const {return (cur == max);} 66 | uint32_t getNumChildren() const {return numChildren;} 67 | uint64_t getNumRecords() const {return numRecords;} 68 | 69 | inline AccessRecord read() { 70 | assert(cur < max); 71 | PackedAccessRecord& pr = buf[cur++]; 72 | AccessRecord rec = {pr.lineAddr, pr.reqCycle, pr.latency, pr.childId, (AccessType) pr.type}; 73 | if (unlikely(cur == max)) nextChunk(); 74 | return rec; 75 | } 76 | 77 | private: 78 | void nextChunk(); 79 | }; 80 | 81 | class AccessTraceWriter : public GlobAlloc { 82 | private: 83 | PackedAccessRecord* buf; 84 | uint32_t cur; 85 | uint32_t max; 86 | g_string fname; 87 | 88 | public: 89 | AccessTraceWriter(g_string fname, uint32_t numChildren); 90 | 91 | inline void write(AccessRecord& acc) { 92 | buf[cur++] = {acc.lineAddr, acc.reqCycle, acc.latency, (uint16_t) acc.childId, (uint8_t) acc.type}; 93 | if (unlikely(cur == max)) { 94 | dump(true); 95 | assert(cur < max); 96 | } 97 | } 98 | 99 | void dump(bool cont); 100 | }; 101 | 102 | #endif // _ACCESS_TRACING_H 103 | -------------------------------------------------------------------------------- /src/bithacks.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef BITHACKS_H_ 27 | #define BITHACKS_H_ 28 | 29 | #include 30 | 31 | /* Assortment of efficient implementations for required, "bithack" operations, see the bithacks 32 | * website, http://graphics.stanford.edu/~seander/bithacks.html 33 | */ 34 | 35 | /* Max and min: These work with side-effects, are type-safe, and gcc recognizes this pattern and uses 36 | * conditional moves (i.e., predication --> no unpredictable branches and great preformance) 37 | */ 38 | #ifdef MAX 39 | #undef MAX 40 | #endif 41 | #define MAX(x, y) ({ __typeof__(x) xx = (x); __typeof__(y) yy = (y); (xx > yy)? xx : yy;}) 42 | 43 | #ifdef MIN 44 | #undef MIN 45 | #endif 46 | #define MIN(x, y) ({ __typeof__(x) xx = (x); __typeof__(y) yy = (y); (xx < yy)? xx : yy;}) 47 | 48 | // Integer log2 --- called ilog2 because cmath defines log2 for floats/doubles, 49 | // and promotes int calls to use FP 50 | template static inline uint32_t ilog2(T val); 51 | // Only specializations of unsigned types (no calling these with ints) 52 | // __builtin_clz is undefined for 0 (internally, this uses bsr in x86-64) 53 | template<> uint32_t ilog2(uint32_t val) { 54 | return val? 31 - __builtin_clz(val) : 0; 55 | } 56 | template<> uint32_t ilog2(uint64_t val) { 57 | return val? 63 - __builtin_clzl(val) : 0; 58 | } 59 | 60 | template 61 | static inline bool isPow2(T val) { 62 | return val && !(val & (val - 1)); 63 | } 64 | 65 | /* Some variadic template magic for max/min with N args. 66 | * 67 | * Type-wise, you can compare multiple types (e.g., maxN(1, -7, 3.3)), but the 68 | * output type is the first arg's type (e.g., returns 3) 69 | */ 70 | template static inline T maxN(T a) { return a; } 71 | template static inline T maxN(T a, U b, V... c) { 72 | return maxN(((a > b)? a : b), c...); 73 | } 74 | 75 | template static inline T minN(T a) { return a; } 76 | template static inline T minN(T a, U b, V... c) { 77 | return minN(((a < b)? a : b), c...); 78 | } 79 | 80 | 81 | #endif // BITHACKS_H_ 82 | -------------------------------------------------------------------------------- /src/breakdown_stats.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef BREAKDOWN_STATS_H_ 27 | #define BREAKDOWN_STATS_H_ 28 | 29 | #include "bithacks.h" 30 | #include "stats.h" 31 | #include "zsim.h" 32 | 33 | /* Implements per-cycle breakdowns. Always starts at state 0. 34 | * count() accounts for cycles in current state; count() is used 35 | * because we extend VectorCounter (TODO: Move to VectorStat). 36 | */ 37 | class CycleBreakdownStat : public VectorCounter { 38 | private: 39 | uint32_t curState; 40 | uint64_t lastCycle; 41 | 42 | public: 43 | CycleBreakdownStat() : VectorCounter() {} 44 | 45 | virtual void init(const char* name, const char* desc, uint32_t size) { 46 | VectorCounter::init(name, desc, size); 47 | curState = 0; 48 | lastCycle = 0; 49 | } 50 | 51 | // I need to define this even though it is completely unnecessary, but only if I override init. gcc bug or C++ oddity? 52 | virtual void init(const char* name, const char* desc, uint32_t size, const char** names) { 53 | VectorCounter::init(name, desc, size, names); // will call our init(name, desc, size) 54 | } 55 | 56 | void transition(uint32_t newState, uint64_t cycle) { 57 | assert(curState < size()); 58 | assert(newState < size()); 59 | assert(lastCycle <= cycle); 60 | inc(curState, cycle - lastCycle); 61 | curState = newState; 62 | lastCycle = cycle; 63 | } 64 | 65 | // Accounts for time in current state, even if the last transition happened long ago 66 | inline virtual uint64_t count(uint32_t idx) const { 67 | uint64_t partial = VectorCounter::count(idx); 68 | uint64_t curCycle = MAX(lastCycle, zinfo->globPhaseCycles); 69 | return partial + ((idx == curState)? (curCycle - lastCycle) : 0); 70 | } 71 | }; 72 | 73 | #endif // BREAKDOWN_STATS_H_ 74 | -------------------------------------------------------------------------------- /src/cache.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef CACHE_H_ 27 | #define CACHE_H_ 28 | 29 | #include "cache_arrays.h" 30 | #include "coherence_ctrls.h" 31 | #include "g_std/g_string.h" 32 | #include "g_std/g_vector.h" 33 | #include "memory_hierarchy.h" 34 | #include "repl_policies.h" 35 | #include "stats.h" 36 | 37 | class Network; 38 | 39 | /* General coherent modular cache. The replacement policy and cache array are 40 | * pretty much mix and match. The coherence controller interfaces are general 41 | * too, but to avoid virtual function call overheads we work with MESI 42 | * controllers, since for now we only have MESI controllers 43 | */ 44 | class Cache : public BaseCache { 45 | protected: 46 | CC* cc; 47 | CacheArray* array; 48 | ReplPolicy* rp; 49 | 50 | uint32_t numLines; 51 | 52 | //Latencies 53 | uint32_t accLat; //latency of a normal access (could split in get/put, probably not needed) 54 | uint32_t invLat; //latency of an invalidation 55 | 56 | g_string name; 57 | 58 | public: 59 | Cache(uint32_t _numLines, CC* _cc, CacheArray* _array, ReplPolicy* _rp, uint32_t _accLat, uint32_t _invLat, const g_string& _name); 60 | 61 | const char* getName(); 62 | void setParents(uint32_t _childId, const g_vector& parents, Network* network); 63 | void setChildren(const g_vector& children, Network* network); 64 | void initStats(AggregateStat* parentStat); 65 | 66 | virtual uint64_t access(MemReq& req); 67 | 68 | //NOTE: reqWriteback is pulled up to true, but not pulled down to false. 69 | virtual uint64_t invalidate(const InvReq& req) { 70 | startInvalidate(); 71 | return finishInvalidate(req); 72 | } 73 | 74 | protected: 75 | void initCacheStats(AggregateStat* cacheStat); 76 | 77 | void startInvalidate(); // grabs cc's downLock 78 | uint64_t finishInvalidate(const InvReq& req); // performs inv and releases downLock 79 | }; 80 | 81 | #endif // CACHE_H_ 82 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef CONFIG_H_ 27 | #define CONFIG_H_ 28 | 29 | /* Thin wrapper around libconfig to: 30 | * - Reduce and simplify init code (tailored interface, not type BS, ...) 31 | * - Strict config: type errors, warnings on unused variables, panic on different defaults 32 | * - Produce a full configuration file with all the variables, including defaults (for config parsing, comparison, etc.) 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include "log.h" 39 | 40 | namespace libconfig { 41 | class Config; 42 | class Setting; 43 | }; 44 | 45 | 46 | class Config { 47 | private: 48 | libconfig::Config* inCfg; 49 | libconfig::Config* outCfg; 50 | 51 | public: 52 | explicit Config(const char* inFile); 53 | ~Config(); 54 | 55 | //Called when initialization ends. Writes output config, and emits warnings for unused input settings 56 | void writeAndClose(const char* outFile, bool strictCheck); 57 | 58 | bool exists(const char* key); 59 | bool exists(const std::string& key) {return exists(key.c_str());} 60 | 61 | //Access interface 62 | //T can be uint32_t, uint64_t, bool, or const char*. Instantiations are in the cpp file 63 | 64 | // Mandatory values (no default, panics if setting does not exist) 65 | template T get(const char* key); 66 | template T get(const std::string& key) {return get(key.c_str());} 67 | 68 | // Optional values (default) 69 | template T get(const char* key, T def); 70 | template T get(const std::string& key, T def) {return get(key.c_str(), def);} 71 | 72 | //Get subgroups in a specific key 73 | void subgroups(const char* key, std::vector& grps); 74 | void subgroups(const std::string& key, std::vector& grps) {subgroups(key.c_str(), grps);} 75 | 76 | private: 77 | template T genericGet(const char* key); 78 | template T genericGet(const char* key, T def); 79 | }; 80 | 81 | 82 | /* Parsing functions used for configuration */ 83 | 84 | std::vector ParseMask(const std::string& maskStr, uint32_t maskSize); 85 | 86 | /* Parses a delimiter-separated list of T's (typically ints, see/add specializtions in .cpp) 87 | * 0-elem lists are OK 88 | * panics on parsing and size-violation errors 89 | */ 90 | template std::vector ParseList(const std::string& listStr, const char* delimiters); 91 | 92 | template std::vector ParseList(const std::string& listStr) { return ParseList(listStr, " "); } 93 | 94 | // fills remaining elems till maxSize with fillValue 95 | template std::vector ParseList(const std::string& listStr, uint32_t maxSize, uint32_t fillValue) { 96 | std::vector res = ParseList(listStr); 97 | if (res.size() > maxSize) panic("ParseList: Too many elements, max %d, got %ld", maxSize, res.size()); 98 | while (res.size() < maxSize) res.push_back(fillValue); 99 | return res; 100 | } 101 | 102 | void Tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters); 103 | 104 | #endif // CONFIG_H_ 105 | -------------------------------------------------------------------------------- /src/constants.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef CONSTANTS_H_ 27 | #define CONSTANTS_H_ 28 | 29 | /* Simulator constants/limits go here, defined by macros */ 30 | 31 | // PIN 2.9 (rev39599) can't do more than 2048 threads... 32 | #define MAX_THREADS (2048) 33 | 34 | // How many children caches can each cache track? Note each bank is a separate child. This impacts sharer bit-vector sizes. 35 | #define MAX_CACHE_CHILDREN (256) 36 | //#define MAX_CACHE_CHILDREN (1024) 37 | 38 | // Complex multiprocess runs need multiple clocks, and multiple port domains 39 | #define MAX_CLOCK_DOMAINS (64) 40 | #define MAX_PORT_DOMAINS (64) 41 | 42 | //Maximum IPC of any implemented core. This is used for adaptive events and will not fail silently if you define new, faster processors. 43 | //If you use it, make sure it does not fail silently if violated. 44 | #define MAX_IPC (4) 45 | 46 | #endif // CONSTANTS_H_ 47 | -------------------------------------------------------------------------------- /src/core.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef CORE_H_ 27 | #define CORE_H_ 28 | 29 | #include 30 | #include "decoder.h" 31 | #include "g_std/g_string.h" 32 | #include "stats.h" 33 | 34 | struct BblInfo { 35 | uint32_t instrs; 36 | uint32_t bytes; 37 | DynBbl oooBbl[0]; //0 bytes, but will be 1-sized when we have an element (and that element has variable size as well) 38 | }; 39 | 40 | /* Analysis function pointer struct 41 | * As an artifact of having a shared code cache, we need these to be the same for different core types. 42 | */ 43 | struct InstrFuncPtrs { // NOLINT(whitespace) 44 | void (*loadPtr)(THREADID, ADDRINT); 45 | void (*storePtr)(THREADID, ADDRINT); 46 | void (*bblPtr)(THREADID, ADDRINT, BblInfo*); 47 | void (*branchPtr)(THREADID, ADDRINT, BOOL, ADDRINT, ADDRINT); 48 | // Same as load/store functions, but last arg indicated whether op is executing 49 | void (*predLoadPtr)(THREADID, ADDRINT, BOOL); 50 | void (*predStorePtr)(THREADID, ADDRINT, BOOL); 51 | uint64_t type; 52 | uint64_t pad[1]; 53 | //NOTE: By having the struct be a power of 2 bytes, indirect calls are simpler (w/ gcc 4.4 -O3, 6->5 instructions, and those instructions are simpler) 54 | }; 55 | 56 | 57 | //TODO: Switch type to an enum by using sizeof macros... 58 | #define FPTR_ANALYSIS (0L) 59 | #define FPTR_JOIN (1L) 60 | #define FPTR_NOP (2L) 61 | #define FPTR_RETRY (3L) 62 | 63 | //Generic core class 64 | 65 | class Core : public GlobAlloc { 66 | private: 67 | uint64_t lastUpdateCycles; 68 | uint64_t lastUpdateInstrs; 69 | 70 | protected: 71 | g_string name; 72 | 73 | public: 74 | explicit Core(g_string& _name) : lastUpdateCycles(0), lastUpdateInstrs(0), name(_name) {} 75 | 76 | virtual uint64_t getInstrs() const = 0; // typically used to find out termination conditions or dumps 77 | virtual uint64_t getPhaseCycles() const = 0; // used by RDTSC faking --- we need to know how far along we are in the phase, but not the total number of phases 78 | virtual uint64_t getCycles() const = 0; 79 | 80 | virtual void initStats(AggregateStat* parentStat) = 0; 81 | virtual void contextSwitch(int32_t gid) = 0; //gid == -1 means descheduled, otherwise this is the new gid 82 | 83 | //Called by scheduler on every leave and join action, before barrier methods are called 84 | virtual void leave() {} 85 | virtual void join() {} 86 | 87 | virtual InstrFuncPtrs GetFuncPtrs() = 0; 88 | }; 89 | 90 | #endif // CORE_H_ 91 | 92 | -------------------------------------------------------------------------------- /src/core_recorder.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef CORE_RECORDER_H_ 27 | #define CORE_RECORDER_H_ 28 | 29 | #include "event_recorder.h" 30 | #include "g_std/g_string.h" 31 | 32 | class TimingCoreEvent; 33 | 34 | class CoreRecorder { 35 | private: 36 | typedef enum { 37 | HALTED, //Not scheduled, no events left. Initial state. join() --> RUNNING 38 | RUNNING, //Scheduled. leave() --> DRAINING 39 | DRAINING //Not scheduled, but events remain. join() --> RUNNING; all events done --> HALTED 40 | } State; 41 | 42 | State state; 43 | 44 | /* There are 2 clocks: 45 | * - phase 1 clock = curCycle and is maintained by the bound phase contention-free core model 46 | * - phase 2 clock = curCycle - gapCycles is the zll clock 47 | * We maintain gapCycles, and only get curCycle on function calls. Some of those calls also 48 | * need to change curCycle, so they just return an updated version that the bound phase model 49 | * needs to take. However, **we have no idea about curCycle outside of those calls**. 50 | * Defend this invariant with your life or you'll find this horrible to reason about. 51 | */ 52 | uint64_t gapCycles; //phase 2 clock == curCycle - gapCycles 53 | 54 | //Event bookkeeping 55 | EventRecorder eventRecorder; 56 | uint64_t prevRespCycle; 57 | TimingEvent* prevRespEvent; 58 | uint64_t lastEventSimulatedStartCycle; 59 | uint64_t lastEventSimulatedOrigStartCycle; 60 | 61 | //Cycle accounting 62 | uint64_t totalGapCycles; //does not include gapCycles 63 | uint64_t totalHaltedCycles; //does not include cycles since last transition to HALTED 64 | uint64_t lastUnhaltedCycle; //set on transition to HALTED 65 | 66 | uint32_t domain; 67 | g_string name; 68 | 69 | public: 70 | CoreRecorder(uint32_t _domain, g_string& _name); 71 | 72 | //Methods called in the bound phase 73 | uint64_t notifyJoin(uint64_t curCycle); //returns th updated curCycle, if it needs updating 74 | void notifyLeave(uint64_t curCycle); 75 | 76 | //This better be inlined 100% of the time, it's called on EVERY access 77 | inline void record(uint64_t startCycle) { 78 | if (unlikely(eventRecorder.hasRecord())) recordAccess(startCycle); 79 | } 80 | 81 | //Methods called between the bound and weave phases 82 | uint64_t cSimStart(uint64_t curCycle); //returns updated curCycle 83 | uint64_t cSimEnd(uint64_t curCycle); //returns updated curCycle 84 | 85 | //Methods called in the weave phase 86 | inline void reportEventSimulated(TimingCoreEvent* ev); 87 | 88 | //Misc 89 | inline EventRecorder* getEventRecorder() {return &eventRecorder;} 90 | 91 | //Stats (called fully synchronized) 92 | uint64_t getUnhaltedCycles(uint64_t curCycle) const; 93 | uint64_t getContentionCycles() const; 94 | 95 | private: 96 | void recordAccess(uint64_t startCycle); 97 | }; 98 | 99 | #endif // CORE_RECORDER_H_ 100 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef DEBUG_H_ 27 | #define DEBUG_H_ 28 | 29 | //This header has common debugging datastructure defs. 30 | 31 | /* Describes the addresses at which libzsim.so is loaded. GDB needs this. */ 32 | struct LibInfo { 33 | void* textAddr; 34 | void* bssAddr; 35 | void* dataAddr; 36 | }; 37 | 38 | #endif // DEBUG_H_ 39 | -------------------------------------------------------------------------------- /src/debug_harness.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "debug_harness.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "log.h" 32 | #include "str.h" 33 | 34 | //For funky macro stuff 35 | #define QUOTED_(x) #x 36 | #define QUOTED(x) QUOTED_(x) 37 | 38 | /* This file is pretty much self-contained, and has minimal external dependencies. 39 | * Please keep it this way, and ESPECIALLY don't include Pin headers since there 40 | * seem to be conflicts between those and some system headers. 41 | */ 42 | 43 | int launchXtermDebugger(int targetPid, LibInfo* libzsimAddrs) { 44 | int childPid = fork(); 45 | if (childPid == 0) { 46 | std::string targetPidStr = Str(targetPid); 47 | char symbolCmdStr[2048]; 48 | snprintf(symbolCmdStr, sizeof(symbolCmdStr), "add-symbol-file %s %p -s .data %p -s .bss %p", QUOTED(ZSIM_PATH), libzsimAddrs->textAddr, libzsimAddrs->dataAddr, libzsimAddrs->bssAddr); 49 | 50 | const char* const args[] = {"xterm", "-e", "gdb", "-p", targetPidStr.c_str(), 51 | "-ex", "set confirm off", //we know what we're doing in the following 2 commands 52 | "-ex", symbolCmdStr, 53 | "-ex", "handle SIGTRAP nostop noprint", // For some reason we receive a lot of spurious sigtraps 54 | "-ex", "set confirm on", //reenable confirmations 55 | "-ex", "c", //start running 56 | nullptr}; 57 | execvp(args[0], (char* const*)args); 58 | panic("shouldn't reach this..."); 59 | } else { 60 | return childPid; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/debug_harness.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef DEBUG_HARNESS_H_ 27 | #define DEBUG_HARNESS_H_ 28 | 29 | #include "debug.h" 30 | 31 | /* Launch gdb automatically in a separate xterm window to debug the current process. 32 | * I'm doing this because I'm sick to death of debugging manually (wait 20 secs, attach 33 | * to PID, copy the libzsim.so symbol file command, etc etc). 34 | * Returns PID of children. Must be called from harness, since we can't fork from a pintool. 35 | */ 36 | int launchXtermDebugger(int targetPid, LibInfo* libzsimAddrs); 37 | 38 | #endif // DEBUG_HARNESS_H_ 39 | -------------------------------------------------------------------------------- /src/debug_zsim.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "debug_zsim.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "log.h" 36 | 37 | /* This file is pretty much self-contained, and has minimal external dependencies. 38 | * Please keep it this way, and ESPECIALLY don't include Pin headers since there 39 | * seem to be conflicts between those and some system headers. 40 | */ 41 | 42 | static int pp_callback(dl_phdr_info* info, size_t size, void* data) { 43 | if (strstr(info->dlpi_name, "libzsim.so")) { 44 | int fd; 45 | Elf* e; 46 | Elf_Scn* scn; 47 | if ((fd = open (info->dlpi_name, O_RDONLY , 0)) < 0) 48 | panic("Opening %s failed", info->dlpi_name); 49 | elf_version(EV_CURRENT); 50 | if ((e = elf_begin(fd, ELF_C_READ, nullptr)) == nullptr) 51 | panic("elf_begin() failed"); 52 | size_t shstrndx; //we need this to get the section names 53 | if (elf_getshdrstrndx(e, &shstrndx) != 0) 54 | panic("elf_getshdrstrndx() failed"); 55 | 56 | LibInfo* offsets = static_cast(data); 57 | offsets->textAddr = nullptr; 58 | offsets->dataAddr = nullptr; 59 | offsets->bssAddr = nullptr; 60 | 61 | scn = nullptr; 62 | while ((scn = elf_nextscn(e, scn)) != nullptr) { 63 | GElf_Shdr shdr; 64 | if (gelf_getshdr(scn, &shdr) != &shdr) 65 | panic("gelf_getshdr() failed"); 66 | char* name = elf_strptr(e, shstrndx , shdr.sh_name); 67 | //info("Section %s %lx %lx", name, shdr.sh_addr, shdr.sh_offset); 68 | //info("Section %s %lx %lx\n", name, info->dlpi_addr + shdr.sh_addr, info->dlpi_addr + shdr.sh_offset); 69 | void* sectionAddr = reinterpret_cast(info->dlpi_addr + shdr.sh_addr); 70 | if (strcmp(".text", name) == 0) { 71 | offsets->textAddr = sectionAddr; 72 | } else if (strcmp(".data", name) == 0) { 73 | offsets->dataAddr = sectionAddr; 74 | } else if (strcmp(".bss", name) == 0) { 75 | offsets->bssAddr = sectionAddr; 76 | } 77 | } 78 | elf_end(e); 79 | close(fd); 80 | 81 | //Check that we got all the section addresses; it'd be extremely weird if we didn't 82 | assert(offsets->textAddr && offsets->dataAddr && offsets->bssAddr); 83 | 84 | return 1; //stops iterating 85 | } 86 | return 0; //continues iterating 87 | } 88 | 89 | void getLibzsimAddrs(LibInfo* libzsimAddrs) { 90 | int ret = dl_iterate_phdr(pp_callback, libzsimAddrs); 91 | if (ret != 1) panic("libzsim.so not found"); 92 | } 93 | 94 | 95 | void notifyHarnessForDebugger(int harnessPid) { 96 | kill(harnessPid, SIGUSR1); 97 | sleep(1); //this is a bit of a hack, but ensures the debugger catches us 98 | } 99 | -------------------------------------------------------------------------------- /src/debug_zsim.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef DEBUG_ZSIM_H_ 27 | #define DEBUG_ZSIM_H_ 28 | 29 | #include "debug.h" 30 | 31 | /* Gather libzsim addresses and initialize a libinfo structure. 32 | * This is needed to essentially replicate the line that PIN prints when 33 | * called with pause_tool. It uses libelf, but PIN is linked to it already 34 | * (I bet that PIN does pretty much the same thing). 35 | */ 36 | void getLibzsimAddrs(LibInfo* libzsimAddrs); 37 | 38 | /* Signal the harness process that we're ready to be debugged */ 39 | void notifyHarnessForDebugger(int harnessPid); 40 | 41 | #endif // DEBUG_ZSIM_H_ 42 | -------------------------------------------------------------------------------- /src/dramsim_mem_ctrl.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef DRAMSIM_MEM_CTRL_H_ 27 | #define DRAMSIM_MEM_CTRL_H_ 28 | 29 | #include 30 | #include 31 | #include "g_std/g_string.h" 32 | #include "memory_hierarchy.h" 33 | #include "pad.h" 34 | #include "stats.h" 35 | 36 | namespace DRAMSim { 37 | class MultiChannelMemorySystem; 38 | }; 39 | 40 | class DRAMSimAccEvent; 41 | 42 | class DRAMSimMemory : public MemObject { //one DRAMSim controller 43 | private: 44 | g_string name; 45 | uint32_t minLatency; 46 | uint32_t domain; 47 | 48 | DRAMSim::MultiChannelMemorySystem* dramCore; 49 | 50 | std::multimap inflightRequests; 51 | 52 | uint64_t curCycle; //processor cycle, used in callbacks 53 | 54 | // R/W stats 55 | PAD(); 56 | Counter profReads; 57 | Counter profWrites; 58 | Counter profTotalRdLat; 59 | Counter profTotalWrLat; 60 | PAD(); 61 | 62 | public: 63 | DRAMSimMemory(std::string& dramTechIni, std::string& dramSystemIni, std::string& outputDir, std::string& traceName, uint32_t capacityMB, 64 | uint64_t cpuFreqHz, uint32_t _minLatency, uint32_t _domain, const g_string& _name); 65 | 66 | const char* getName() {return name.c_str();} 67 | 68 | void initStats(AggregateStat* parentStat); 69 | 70 | // Record accesses 71 | uint64_t access(MemReq& req); 72 | 73 | // Event-driven simulation (phase 2) 74 | uint32_t tick(uint64_t cycle); 75 | void enqueue(DRAMSimAccEvent* ev, uint64_t cycle); 76 | 77 | private: 78 | void DRAM_read_return_cb(uint32_t id, uint64_t addr, uint64_t returnCycle); 79 | void DRAM_write_return_cb(uint32_t id, uint64_t addr, uint64_t returnCycle); 80 | }; 81 | 82 | //DRAMSIM does not support non-pow2 channels, so: 83 | // - Encapsulate multiple DRAMSim controllers 84 | // - Fan out addresses interleaved across banks, and change the address to a "memory address" 85 | class SplitAddrMemory : public MemObject { 86 | private: 87 | const g_vector mems; 88 | const g_string name; 89 | public: 90 | SplitAddrMemory(const g_vector& _mems, const char* _name) : mems(_mems), name(_name) {} 91 | 92 | uint64_t access(MemReq& req) { 93 | Address addr = req.lineAddr; 94 | uint32_t mem = addr % mems.size(); 95 | Address ctrlAddr = addr/mems.size(); 96 | req.lineAddr = ctrlAddr; 97 | uint64_t respCycle = mems[mem]->access(req); 98 | req.lineAddr = addr; 99 | return respCycle; 100 | } 101 | 102 | const char* getName() { 103 | return name.c_str(); 104 | } 105 | 106 | void initStats(AggregateStat* parentStat) { 107 | for (auto mem : mems) mem->initStats(parentStat); 108 | } 109 | }; 110 | 111 | #endif // DRAMSIM_MEM_CTRL_H_ 112 | -------------------------------------------------------------------------------- /src/dumptrace.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | /* Simple program to dump a trace */ 27 | 28 | #include 29 | #include 30 | 31 | #include "access_tracing.h" 32 | #include "galloc.h" 33 | #include "memory_hierarchy.h" // to translate access type to strings 34 | 35 | int main(int argc, const char* argv[]) { 36 | InitLog(""); //no log header 37 | if (argc != 2) { 38 | info("Prints an access trace"); 39 | info("Usage: %s ", argv[0]); 40 | exit(1); 41 | } 42 | 43 | gm_init(32<<20 /*32 MB, should be enough*/); 44 | AccessTraceReader tr(argv[1]); 45 | 46 | info("%12s %6s %6s %20s %10s", "Cycle", "Src", "Type", "LineAddr", "Latency"); 47 | while(!tr.empty()) { 48 | AccessRecord acc = tr.read(); 49 | info("%12ld %6d %s %20p %10d", acc.reqCycle, acc.childId, AccessTypeName(acc.type), (uint64_t*)acc.lineAddr, acc.latency); 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/event_recorder.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef EVENT_RECORDER_H_ 27 | #define EVENT_RECORDER_H_ 28 | 29 | #include "g_std/g_vector.h" 30 | #include "memory_hierarchy.h" 31 | #include "pad.h" 32 | #include "slab_alloc.h" 33 | 34 | class TimingEvent; 35 | 36 | // Encodes an event that the core should capture for the contention simulation 37 | struct TimingRecord { 38 | Address addr; 39 | uint64_t reqCycle; 40 | uint64_t respCycle; 41 | AccessType type; 42 | TimingEvent* startEvent; 43 | TimingEvent* endEvent; 44 | 45 | bool isValid() const { return startEvent; } 46 | void clear() { startEvent = nullptr; } 47 | }; 48 | 49 | //class CoreRecorder; 50 | class CrossingEvent; 51 | typedef g_vector CrossingStack; 52 | 53 | class EventRecorder : public GlobAlloc { 54 | private: 55 | slab::SlabAlloc slabAlloc; 56 | TimingRecord tr; 57 | CrossingStack crossingStack; 58 | uint32_t srcId; 59 | 60 | volatile uint64_t lastGapCycles; 61 | PAD(); 62 | volatile uint64_t lastStartSlack; 63 | PAD(); 64 | 65 | public: 66 | EventRecorder() { 67 | tr.clear(); 68 | } 69 | 70 | //Alloc interface 71 | 72 | template 73 | T* alloc() { 74 | return slabAlloc.alloc(); 75 | } 76 | 77 | void* alloc(size_t sz) { 78 | return slabAlloc.alloc(sz); 79 | } 80 | 81 | //Event recording interface 82 | 83 | void pushRecord(const TimingRecord& rec) { 84 | assert(!tr.isValid()); 85 | tr = rec; 86 | assert(tr.isValid()); 87 | } 88 | 89 | // Inline to avoid extra copy 90 | inline TimingRecord popRecord() __attribute__((always_inline)) { 91 | TimingRecord rec = tr; 92 | tr.clear(); 93 | return rec; 94 | } 95 | 96 | inline size_t hasRecord() const { 97 | return tr.isValid(); 98 | } 99 | 100 | //Called by crossing events 101 | inline uint64_t getSlack(uint64_t origStartCycle) const { 102 | return origStartCycle + lastStartSlack; 103 | } 104 | 105 | inline uint64_t getGapCycles() const { 106 | return lastGapCycles; 107 | } 108 | 109 | //Called by the core's recorder 110 | //infrequently 111 | void setGapCycles(uint64_t gapCycles) { 112 | lastGapCycles = gapCycles; 113 | } 114 | 115 | //frequently 116 | inline void setStartSlack(uint64_t startSlack) { 117 | //Avoid a write, it can cost a bunch of coherence misses 118 | if (lastStartSlack != startSlack) lastStartSlack = startSlack; 119 | } 120 | 121 | uint32_t getSourceId() const {return srcId;} 122 | void setSourceId(uint32_t i) {srcId = i;} 123 | 124 | inline CrossingStack& getCrossingStack() { 125 | return crossingStack; 126 | } 127 | }; 128 | 129 | #endif // EVENT_RECORDER_H_ 130 | -------------------------------------------------------------------------------- /src/fftoggle.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | /* Small utility to control ff toggling. */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "galloc.h" 32 | #include "locks.h" 33 | #include "log.h" 34 | #include "zsim.h" 35 | 36 | int main(int argc, char *argv[]) { 37 | InitLog("[T] "); 38 | if (argc < 3 || argc > 4) { 39 | info("Usage: %s []", argv[0]); 40 | exit(1); 41 | } 42 | 43 | const char* cmd = argv[1]; 44 | int shmid = atoi(argv[2]); 45 | int procIdx = (argc == 4)? atoi(argv[3]) : -1; 46 | 47 | gm_attach(shmid); 48 | while (!gm_isready()) sched_yield(); //wait till proc idx 0 initializes everything; sched_yield to avoid livelock with lots of processes 49 | GlobSimInfo* zinfo = static_cast(gm_get_glob_ptr()); 50 | 51 | if (strcmp(cmd, "ff") == 0) { 52 | if (procIdx < 0) panic("ff needs procIdx"); 53 | futex_unlock(&zinfo->ffToggleLocks[procIdx]); 54 | info("Toggled fast-forward on process %d", procIdx); 55 | } else if (strcmp(argv[1], "pause") == 0) { 56 | if (procIdx < 0) panic("pause needs procIdx"); 57 | futex_unlock(&zinfo->pauseLocks[procIdx]); 58 | info("Unpaused process %d", procIdx); 59 | } else if (strcmp(argv[1], "globpause") == 0) { 60 | if (procIdx >= 0) warn("globpause pauses the whole simulation, you specified a procIdx"); 61 | zinfo->globalPauseFlag = !zinfo->globalPauseFlag; //you will not be stupid enough to run multiple fftoggles at the same time. 62 | __sync_synchronize(); 63 | } else if (strcmp(argv[1], "term") == 0) { 64 | if (procIdx >= 0) warn("term terminates the whole simulation, you specified a procIdx"); 65 | zinfo->externalTermPending = true; 66 | __sync_synchronize(); 67 | info("Marked simulation for termination"); 68 | } else { 69 | panic("Invalid command: %s", cmd); 70 | } 71 | exit(0); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/g_std/README.txt: -------------------------------------------------------------------------------- 1 | This folder simply has template spacializations of STL classes that use the 2 | global heap allocator. Feel free to define new specializations as needed. 3 | 4 | See g_vector.h for a brief discussion/pointers on how to do this. This should 5 | be more elegant when/if template typedefs get in C++2011. 6 | -------------------------------------------------------------------------------- /src/g_std/g_list.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_LIST_H_ 27 | #define G_LIST_H_ 28 | 29 | #include 30 | #include "g_std/stl_galloc.h" 31 | 32 | // Supposedly, this will work in C++2011 33 | //template typedef std::vector > g_vector; 34 | 35 | // Until GCC is compliant with this, just inherit: 36 | template class g_list : public std::list > {}; 37 | 38 | /* Some pointers on template typedefs: 39 | * http://www.gotw.ca/gotw/079.htm 40 | * http://drdobbs.com/cpp/184403850 41 | * http://gcc.gnu.org/ml/gcc-help/2007-04/msg00338.html 42 | */ 43 | 44 | #endif // G_LIST_H_ 45 | -------------------------------------------------------------------------------- /src/g_std/g_multimap.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_MULTIMAP_H_ 27 | #define G_MULTIMAP_H_ 28 | 29 | #include 30 | #include 31 | #include "g_std/stl_galloc.h" 32 | 33 | template class g_map : public std::map, StlGlobAlloc > > {}; 34 | template class g_multimap : public std::multimap, StlGlobAlloc > > {}; 35 | 36 | #endif // G_MULTIMAP_H_ 37 | -------------------------------------------------------------------------------- /src/g_std/g_string.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_STRING_H_ 27 | #define G_STRING_H_ 28 | // What? I'm just using consistent naming rules :) 29 | // Just be thankful that std::spot does not exist 30 | 31 | #include 32 | #include "g_std/stl_galloc.h" 33 | 34 | /* basic_string is actually an STL-mandated class, not an internal GCC thing. 35 | * This should work with other compilers 36 | */ 37 | typedef std::basic_string, StlGlobAlloc > g_string; 38 | 39 | #endif // G_STRING_H_ 40 | -------------------------------------------------------------------------------- /src/g_std/g_unordered_map.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_UNORDERED_MAP_H_ 27 | #define G_UNORDERED_MAP_H_ 28 | 29 | #include 30 | #include 31 | #include "g_std/stl_galloc.h" 32 | 33 | //template class g_unordered_map : public std::unordered_map > > {}; //this seems to work for TR1, not for final 34 | template class g_unordered_map : public std::unordered_map, std::equal_to, StlGlobAlloc > > {}; 35 | 36 | #endif // G_UNORDERED_MAP_H_ 37 | -------------------------------------------------------------------------------- /src/g_std/g_unordered_set.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_UNORDERED_SET_H_ 27 | #define G_UNORDERED_SET_H_ 28 | 29 | #include 30 | #include 31 | #include "g_std/stl_galloc.h" 32 | 33 | template class g_unordered_set : public std::unordered_set, std::equal_to, StlGlobAlloc > {}; 34 | 35 | #endif // G_UNORDERED_SET_H_ 36 | -------------------------------------------------------------------------------- /src/g_std/g_vector.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef G_VECTOR_H_ 27 | #define G_VECTOR_H_ 28 | 29 | #include 30 | #include "g_std/stl_galloc.h" 31 | 32 | // Supposedly, this will work in C++2011 33 | //template typedef std::vector > g_vector; 34 | 35 | // Until GCC is compliant with this, just inherit: 36 | template class g_vector : public std::vector >, public GlobAlloc { 37 | public: 38 | g_vector() = default; 39 | 40 | g_vector(const std::vector& v) { 41 | this->resize(v.size()); 42 | for (size_t i = 0; i < v.size(); i++) { 43 | (*this)[i] = v[i]; 44 | } 45 | } 46 | 47 | g_vector(std::initializer_list list) : std::vector>(list) {} 48 | g_vector(size_t n, const T& t = T()) : std::vector>(n, t) {} 49 | }; 50 | 51 | /* Some pointers on template typedefs: 52 | * http://www.gotw.ca/gotw/079.htm 53 | * http://drdobbs.com/cpp/184403850 54 | * http://gcc.gnu.org/ml/gcc-help/2007-04/msg00338.html 55 | */ 56 | 57 | #endif // G_VECTOR_H_ 58 | -------------------------------------------------------------------------------- /src/g_std/stl_galloc.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef STL_GALLOC_H_ 27 | #define STL_GALLOC_H_ 28 | 29 | #include 30 | #include "galloc.h" 31 | 32 | /* Follows interface of STL allocator, allocates and frees from the global heap */ 33 | 34 | template 35 | class StlGlobAlloc { 36 | public: 37 | typedef size_t size_type; 38 | typedef ptrdiff_t difference_type; 39 | typedef T* pointer; 40 | typedef const T* const_pointer; 41 | typedef T& reference; 42 | typedef const T& const_reference; 43 | typedef T value_type; 44 | 45 | StlGlobAlloc() {} 46 | StlGlobAlloc(const StlGlobAlloc&) {} 47 | 48 | pointer allocate(size_type n, const void * = 0) { 49 | T* t = gm_calloc(n); 50 | return t; 51 | } 52 | 53 | void deallocate(void* p, size_type) { 54 | if (p) gm_free(p); 55 | } 56 | 57 | pointer address(reference x) const { return &x; } 58 | const_pointer address(const_reference x) const { return &x; } 59 | StlGlobAlloc& operator=(const StlGlobAlloc&) { return *this; } 60 | 61 | 62 | // Construct/destroy 63 | // gcc keeps changing these interfaces. See /usr/include/c++/4.8/ext/new_allocator.h 64 | #if __cplusplus >= 201103L // >= 4.8 65 | template 66 | void construct(_Up* __p, _Args&&... __args) { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } 67 | 68 | template void destroy(_Up* __p) { __p->~_Up(); } 69 | #else // < 4.8 70 | void construct(pointer p, const T& val) { new (static_cast(p)) T(val); } 71 | void construct(pointer p) { construct(p, value_type()); } //required by gcc 4.6 72 | void destroy(pointer p) { p->~T(); } 73 | #endif 74 | 75 | size_type max_size() const { return size_t(-1); } 76 | 77 | template struct rebind { typedef StlGlobAlloc other; }; 78 | 79 | template StlGlobAlloc(const StlGlobAlloc&) {} 80 | 81 | template StlGlobAlloc& operator=(const StlGlobAlloc&) { return *this; } 82 | 83 | 84 | /* dsm: The == (and !=) operator in an allocator must be defined and, 85 | * per http://download.oracle.com/docs/cd/E19422-01/819-3703/15_3.htm : 86 | * 87 | * Returns true if allocators b and a can be safely interchanged. Safely 88 | * interchanged means that b could be used to deallocate storage obtained 89 | * through a, and vice versa. 90 | * 91 | * We can ALWAYS do this, as deallocate just calls gm_free() 92 | */ 93 | template bool operator==(const StlGlobAlloc&) const { return true; } 94 | 95 | template bool operator!=(const StlGlobAlloc&) const { return false; } 96 | }; 97 | 98 | #endif // STL_GALLOC_H_ 99 | -------------------------------------------------------------------------------- /src/galloc.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef GALLOC_H_ 27 | #define GALLOC_H_ 28 | 29 | #include 30 | #include 31 | 32 | int gm_init(size_t segmentSize); 33 | 34 | void gm_attach(int shmid); 35 | 36 | // C-style interface 37 | void* gm_malloc(size_t size); 38 | void* __gm_calloc(size_t num, size_t size); //deprecated, only used internally 39 | void* __gm_memalign(size_t blocksize, size_t bytes); // deprecated, only used internally 40 | char* gm_strdup(const char* str); 41 | void gm_free(void* ptr); 42 | 43 | // C++-style alloc interface (preferred) 44 | template T* gm_malloc() {return static_cast(gm_malloc(sizeof(T)));} 45 | template T* gm_malloc(size_t objs) {return static_cast(gm_malloc(sizeof(T)*objs));} 46 | template T* gm_calloc() {return static_cast(__gm_calloc(1, sizeof(T)));} 47 | template T* gm_calloc(size_t objs) {return static_cast(__gm_calloc(objs, sizeof(T)));} 48 | template T* gm_memalign(size_t blocksize) {return static_cast(__gm_memalign(blocksize, sizeof(T)));} 49 | template T* gm_memalign(size_t blocksize, size_t objs) {return static_cast(__gm_memalign(blocksize, sizeof(T)*objs));} 50 | template T* gm_dup(T* src, size_t objs) { 51 | T* dst = gm_malloc(objs); 52 | memcpy(dst, src, sizeof(T)*objs); 53 | return dst; 54 | } 55 | 56 | void gm_set_glob_ptr(void* ptr); 57 | void* gm_get_glob_ptr(); 58 | 59 | void gm_set_secondary_ptr(void* ptr); 60 | void* gm_get_secondary_ptr(); 61 | 62 | void gm_stats(); 63 | 64 | bool gm_isready(); 65 | void gm_detach(); 66 | 67 | 68 | class GlobAlloc { 69 | public: 70 | virtual ~GlobAlloc() {} 71 | 72 | inline void* operator new (size_t sz) { 73 | return gm_malloc(sz); 74 | } 75 | 76 | //Placement new 77 | inline void* operator new (size_t sz, void* ptr) { 78 | return ptr; 79 | } 80 | 81 | inline void operator delete(void *p, size_t sz) { 82 | gm_free(p); 83 | } 84 | 85 | //Placement delete... make ICC happy. This would only fire on an exception 86 | void operator delete (void* p, void* ptr) {} 87 | }; 88 | 89 | #endif // GALLOC_H_ 90 | -------------------------------------------------------------------------------- /src/hash.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef HASH_H_ 27 | #define HASH_H_ 28 | 29 | #include 30 | #include "galloc.h" 31 | 32 | class HashFamily : public GlobAlloc { 33 | public: 34 | HashFamily() {} 35 | virtual ~HashFamily() {} 36 | 37 | virtual uint64_t hash(uint32_t id, uint64_t val) = 0; 38 | }; 39 | 40 | class H3HashFamily : public HashFamily { 41 | private: 42 | const uint32_t numFuncs; 43 | uint32_t resShift; 44 | uint64_t* hMatrix; 45 | public: 46 | H3HashFamily(uint32_t numFunctions, uint32_t outputBits, uint64_t randSeed = 123132127); 47 | virtual ~H3HashFamily(); 48 | uint64_t hash(uint32_t id, uint64_t val); 49 | }; 50 | 51 | class SHA1HashFamily : public HashFamily { 52 | private: 53 | int numFuncs; 54 | int numPasses; 55 | 56 | //SHA1 is quite expensive and returns large blocks, so we use memoization and chunk the block to implement hash function families. 57 | uint64_t memoizedVal; 58 | uint32_t* memoizedHashes; 59 | public: 60 | explicit SHA1HashFamily(int numFunctions); 61 | uint64_t hash(uint32_t id, uint64_t val); 62 | }; 63 | 64 | /* Used when we don't want hashing, just return the value */ 65 | class IdHashFamily : public HashFamily { 66 | public: 67 | inline uint64_t hash(uint32_t id, uint64_t val) {return val;} 68 | }; 69 | 70 | #endif // HASH_H_ 71 | -------------------------------------------------------------------------------- /src/init.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef INIT_H_ 27 | #define INIT_H_ 28 | 29 | #include 30 | 31 | /* Read configuration options, configure system */ 32 | void SimInit(const char* configFile, const char* outputDir, uint32_t shmid); 33 | 34 | #endif // INIT_H_ 35 | -------------------------------------------------------------------------------- /src/log.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "log.h" 27 | #include 28 | #include 29 | #include "locks.h" 30 | 31 | const char* logHeader = ""; 32 | 33 | const char* logTypeNames[] = {"Harness", "Config", "Process", "Cache", "Mem", "Sched", "FSVirt", "TimeVirt"}; 34 | 35 | FILE* logFdOut = stdout; 36 | FILE* logFdErr = stderr; 37 | 38 | static lock_t log_printLock; 39 | 40 | 41 | void InitLog(const char* header, const char* file) { 42 | logHeader = strdup(header); 43 | futex_init(&log_printLock); 44 | 45 | if (file) { 46 | FILE* fd = fopen(file, "a"); 47 | if (fd == nullptr) { 48 | perror("fopen() failed"); 49 | panic("Could not open logfile %s", file); //we can panic in InitLog (will dump to stderr) 50 | } 51 | logFdOut = fd; 52 | logFdErr = fd; 53 | //NOTE: We technically never close this fd, but always flush it 54 | } 55 | } 56 | 57 | void __log_lock() {futex_lock(&log_printLock);} 58 | void __log_unlock() {futex_unlock(&log_printLock);} 59 | 60 | -------------------------------------------------------------------------------- /src/mem_ctrls.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef MEM_CTRLS_H_ 27 | #define MEM_CTRLS_H_ 28 | 29 | #include "g_std/g_string.h" 30 | #include "memory_hierarchy.h" 31 | #include "pad.h" 32 | #include "stats.h" 33 | 34 | /* Simple memory (or memory bank), has a fixed latency */ 35 | class SimpleMemory : public MemObject { 36 | private: 37 | g_string name; 38 | uint32_t latency; 39 | 40 | public: 41 | uint64_t access(MemReq& req); 42 | 43 | const char* getName() {return name.c_str();} 44 | 45 | SimpleMemory(uint32_t _latency, g_string& _name) : name(_name), latency(_latency) {} 46 | }; 47 | 48 | 49 | /* Implements a memory controller with limited bandwidth, throttling latency 50 | * using an M/D/1 queueing model. 51 | */ 52 | class MD1Memory : public MemObject { 53 | private: 54 | uint64_t lastPhase; 55 | double maxRequestsPerCycle; 56 | double smoothedPhaseAccesses; 57 | uint32_t zeroLoadLatency; 58 | uint32_t curLatency; 59 | 60 | PAD(); 61 | 62 | Counter profReads; 63 | Counter profWrites; 64 | Counter profTotalRdLat; 65 | Counter profTotalWrLat; 66 | Counter profLoad; 67 | Counter profUpdates; 68 | Counter profClampedLoads; 69 | uint32_t curPhaseAccesses; 70 | 71 | g_string name; //barely used 72 | lock_t updateLock; 73 | PAD(); 74 | 75 | public: 76 | MD1Memory(uint32_t lineSize, uint32_t megacyclesPerSecond, uint32_t megabytesPerSecond, uint32_t _zeroLoadLatency, g_string& _name); 77 | 78 | void initStats(AggregateStat* parentStat) { 79 | AggregateStat* memStats = new AggregateStat(); 80 | memStats->init(name.c_str(), "Memory controller stats"); 81 | profReads.init("rd", "Read requests"); memStats->append(&profReads); 82 | profWrites.init("wr", "Write requests"); memStats->append(&profWrites); 83 | profTotalRdLat.init("rdlat", "Total latency experienced by read requests"); memStats->append(&profTotalRdLat); 84 | profTotalWrLat.init("wrlat", "Total latency experienced by write requests"); memStats->append(&profTotalWrLat); 85 | profLoad.init("load", "Sum of load factors (0-100) per update"); memStats->append(&profLoad); 86 | profUpdates.init("ups", "Number of latency updates"); memStats->append(&profUpdates); 87 | profClampedLoads.init("clampedLoads", "Number of updates where the load was clamped to 95%"); memStats->append(&profClampedLoads); 88 | parentStat->append(memStats); 89 | } 90 | 91 | //uint32_t access(Address lineAddr, AccessType type, uint32_t childId, MESIState* state /*both input and output*/, MESIState initialState, lock_t* childLock); 92 | uint64_t access(MemReq& req); 93 | 94 | const char* getName() {return name.c_str();} 95 | 96 | private: 97 | void updateLatency(); 98 | }; 99 | 100 | #endif // MEM_CTRLS_H_ 101 | -------------------------------------------------------------------------------- /src/memory_hierarchy.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "memory_hierarchy.h" 27 | 28 | static const char* accessTypeNames[] = {"GETS", "GETX", "PUTS", "PUTX"}; 29 | static const char* invTypeNames[] = {"INV", "INVX"}; 30 | static const char* mesiStateNames[] = {"I", "S", "E", "M"}; 31 | 32 | const char* AccessTypeName(AccessType t) { 33 | assert_msg(t >= 0 && (size_t)t < sizeof(accessTypeNames)/sizeof(const char*), "AccessTypeName got an out-of-range input, %d", t); 34 | return accessTypeNames[t]; 35 | } 36 | 37 | const char* InvTypeName(InvType t) { 38 | assert_msg(t >= 0 && (size_t)t < sizeof(invTypeNames)/sizeof(const char*), "InvTypeName got an out-of-range input, %d", t); 39 | return invTypeNames[t]; 40 | } 41 | 42 | const char* MESIStateName(MESIState s) { 43 | assert_msg(s >= 0 && (size_t)s < sizeof(mesiStateNames)/sizeof(const char*), "MESIStateName got an out-of-range input, %d", s); 44 | return mesiStateNames[s]; 45 | } 46 | 47 | #include 48 | 49 | static inline void CompileTimeAsserts() { 50 | static_assert(std::is_pod::value, "MemReq not POD!"); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/network.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "network.h" 27 | #include 28 | #include 29 | #include "log.h" 30 | 31 | using std::ifstream; 32 | using std::string; 33 | 34 | Network::Network(const char* filename) { 35 | ifstream inFile(filename); 36 | 37 | if (!inFile) { 38 | panic("Could not open network description file %s", filename); 39 | } 40 | 41 | while (inFile.good()) { 42 | string src, dst; 43 | uint32_t delay; 44 | inFile >> src; 45 | inFile >> dst; 46 | inFile >> delay; 47 | 48 | if (inFile.eof()) break; 49 | 50 | string s1 = src + " " + dst; 51 | string s2 = dst + " " + src; 52 | 53 | assert((delayMap.find(s1) == delayMap.end())); 54 | assert((delayMap.find(s2) == delayMap.end())); 55 | 56 | delayMap[s1] = delay; 57 | delayMap[s2] = delay; 58 | 59 | //info("Parsed %s %s %d", src.c_str(), dst.c_str(), delay); 60 | } 61 | 62 | inFile.close(); 63 | } 64 | 65 | uint32_t Network::getRTT(const char* src, const char* dst) { 66 | string key(src); 67 | key += " "; 68 | key += dst; 69 | /* dsm: Be sloppy, deadline deadline deadline 70 | assert_msg(delayMap.find(key) != delayMap.end(), "%s and %s cannot communicate, according to the network description file", src, dst); 71 | return 2*delayMap[key]; 72 | */ 73 | 74 | if (delayMap.find(key) != delayMap.end()) { 75 | return 2*delayMap[key]; 76 | } else { 77 | warn("%s and %s have no entry in network description file, returning 0 latency", src, dst); 78 | return 0; 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/network.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef NETWORK_H_ 27 | #define NETWORK_H_ 28 | 29 | /* Very simple fixed-delay network model. Parses a list of delays between 30 | * entities, then accepts queries for roundtrip times between these entities. 31 | * There is no contention modeling or even support for serialization latency. 32 | * This is a basic model that should be extended as appropriate. 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | class Network { 39 | private: 40 | std::unordered_map delayMap; 41 | 42 | public: 43 | explicit Network(const char* filename); 44 | uint32_t getRTT(const char* src, const char* dst); 45 | }; 46 | 47 | #endif // NETWORK_H_ 48 | 49 | -------------------------------------------------------------------------------- /src/null_core.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "null_core.h" 27 | #include "zsim.h" 28 | 29 | NullCore::NullCore(g_string& _name) : Core(_name), instrs(0), curCycle(0), phaseEndCycle(0) {} 30 | 31 | void NullCore::initStats(AggregateStat* parentStat) { 32 | AggregateStat* coreStat = new AggregateStat(); 33 | coreStat->init(name.c_str(), "Core stats"); 34 | ProxyStat* cyclesStat = new ProxyStat(); 35 | cyclesStat->init("cycles", "Simulated cycles", &instrs); //simulated instrs == simulated cycles; curCycle can be skewed forward 36 | ProxyStat* instrsStat = new ProxyStat(); 37 | instrsStat->init("instrs", "Simulated instructions", &instrs); 38 | coreStat->append(cyclesStat); 39 | coreStat->append(instrsStat); 40 | parentStat->append(coreStat); 41 | } 42 | 43 | uint64_t NullCore::getPhaseCycles() const { 44 | return curCycle - zinfo->globPhaseCycles; 45 | } 46 | 47 | void NullCore::bbl(BblInfo* bblInfo) { 48 | instrs += bblInfo->instrs; 49 | curCycle += bblInfo->instrs; 50 | } 51 | 52 | void NullCore::contextSwitch(int32_t gid) {} 53 | 54 | void NullCore::join() { 55 | curCycle = MAX(curCycle, zinfo->globPhaseCycles); 56 | phaseEndCycle = zinfo->globPhaseCycles + zinfo->phaseLength; 57 | } 58 | 59 | //Static class functions: Function pointers and trampolines 60 | 61 | InstrFuncPtrs NullCore::GetFuncPtrs() { 62 | return {LoadFunc, StoreFunc, BblFunc, BranchFunc, PredLoadFunc, PredStoreFunc, FPTR_ANALYSIS, {0}}; 63 | } 64 | 65 | void NullCore::LoadFunc(THREADID tid, ADDRINT addr) {} 66 | void NullCore::StoreFunc(THREADID tid, ADDRINT addr) {} 67 | void NullCore::PredLoadFunc(THREADID tid, ADDRINT addr, BOOL pred) {} 68 | void NullCore::PredStoreFunc(THREADID tid, ADDRINT addr, BOOL pred) {} 69 | 70 | void NullCore::BblFunc(THREADID tid, ADDRINT bblAddr, BblInfo* bblInfo) { 71 | NullCore* core = static_cast(cores[tid]); 72 | core->bbl(bblInfo); 73 | 74 | while (unlikely(core->curCycle > core->phaseEndCycle)) { 75 | assert(core->phaseEndCycle == zinfo->globPhaseCycles + zinfo->phaseLength); 76 | core->phaseEndCycle += zinfo->phaseLength; 77 | 78 | uint32_t cid = getCid(tid); 79 | //NOTE: TakeBarrier may take ownership of the core, and so it will be used by some other thread. If TakeBarrier context-switches us, 80 | //the *only* safe option is to return inmmediately after we detect this, or we can race and corrupt core state. If newCid == cid, 81 | //we're not at risk of racing, even if we were switched out and then switched in. 82 | uint32_t newCid = TakeBarrier(tid, cid); 83 | if (newCid != cid) break; /*context-switch*/ 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/null_core.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef NULL_CORE_H_ 27 | #define NULL_CORE_H_ 28 | 29 | //A core model with IPC=1 and no hooks into the memory hierarchy. Useful to isolate threads that need to be run for simulation purposes. 30 | 31 | #include "core.h" 32 | #include "pad.h" 33 | 34 | class NullCore : public Core { 35 | protected: 36 | uint64_t instrs; 37 | uint64_t curCycle; 38 | uint64_t phaseEndCycle; //next stopping point 39 | 40 | public: 41 | explicit NullCore(g_string& _name); 42 | void initStats(AggregateStat* parentStat); 43 | 44 | uint64_t getInstrs() const {return instrs;} 45 | uint64_t getPhaseCycles() const; 46 | uint64_t getCycles() const {return instrs; /*IPC=1*/ } 47 | 48 | void contextSwitch(int32_t gid); 49 | virtual void join(); 50 | 51 | InstrFuncPtrs GetFuncPtrs(); 52 | 53 | protected: 54 | inline void bbl(BblInfo* bblInstrs); 55 | 56 | static void LoadFunc(THREADID tid, ADDRINT addr); 57 | static void StoreFunc(THREADID tid, ADDRINT addr); 58 | static void BblFunc(THREADID tid, ADDRINT bblAddr, BblInfo* bblInfo); 59 | static void PredLoadFunc(THREADID tid, ADDRINT addr, BOOL pred); 60 | static void PredStoreFunc(THREADID tid, ADDRINT addr, BOOL pred); 61 | 62 | static void BranchFunc(THREADID, ADDRINT, BOOL, ADDRINT, ADDRINT) {} 63 | } ATTR_LINE_ALIGNED; //This needs to take up a whole cache line, or false sharing will be extremely frequent 64 | 65 | #endif // NULL_CORE_H_ 66 | 67 | -------------------------------------------------------------------------------- /src/pad.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PAD_H_ 27 | #define PAD_H_ 28 | 29 | /* Padding macros to remove false sharing */ 30 | 31 | //Line size, in chars (bytes). We could make it configurable through a define 32 | #define CACHE_LINE_BYTES 64 33 | 34 | #define _PAD_CONCAT(x, y) x ## y 35 | #define PAD_CONCAT(x, y) _PAD_CONCAT(x, y) 36 | 37 | #define PAD() unsigned char PAD_CONCAT(pad_line, __LINE__)[CACHE_LINE_BYTES] //assuming classes are defined over one file, this should generate unique names 38 | 39 | //Pad remainder to line size, use as e.g. PAD(sizeof(uint32)) will produce 60B of padding 40 | #define PAD_SZ(sz) unsigned char PAD_CONCAT(pad_sz_line, __LINE__)[CACHE_LINE_BYTES - ((sz) % CACHE_LINE_BYTES)] 41 | 42 | #define ATTR_LINE_ALIGNED __attribute__((aligned(CACHE_LINE_BYTES))) 43 | 44 | #endif // PAD_H_ 45 | -------------------------------------------------------------------------------- /src/partition_mapper.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "partition_mapper.h" 27 | #include "log.h" 28 | #include "process_tree.h" 29 | #include "zsim.h" 30 | 31 | uint32_t CorePartMapper::getPartition(const MemReq& req) { 32 | return req.srcId; 33 | } 34 | 35 | uint32_t InstrDataPartMapper::getPartition(const MemReq& req) { 36 | return req.flags & MemReq::IFETCH; 37 | } 38 | 39 | uint32_t InstrDataCorePartMapper::getPartition(const MemReq& req) { 40 | bool instr = req.flags & MemReq::IFETCH; 41 | return req.srcId + (instr ? numCores : 0); //all instruction partitions come after data partitions 42 | } 43 | 44 | uint32_t ProcessPartMapper::getPartition(const MemReq& req) { 45 | assert(procIdx < numProcs); 46 | return procIdx; 47 | } 48 | 49 | uint32_t InstrDataProcessPartMapper::getPartition(const MemReq& req) { 50 | assert(procIdx < numProcs); 51 | bool instr = req.flags & MemReq::IFETCH; 52 | return procIdx + (instr ? numProcs : 0); 53 | } 54 | 55 | uint32_t ProcessGroupPartMapper::getNumPartitions() { 56 | return zinfo->numProcGroups; 57 | } 58 | 59 | uint32_t ProcessGroupPartMapper::getPartition(const MemReq& req) { 60 | uint32_t groupIdx = zinfo->procArray[procIdx]->getGroupIdx(); 61 | assert(groupIdx < zinfo->numProcGroups); 62 | return groupIdx; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/partition_mapper.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PARTITION_MAPPER_H_ 27 | #define PARTITION_MAPPER_H_ 28 | 29 | #include 30 | #include "galloc.h" 31 | #include "memory_hierarchy.h" 32 | 33 | //Interface 34 | class PartMapper : public GlobAlloc { 35 | public: 36 | virtual uint32_t getNumPartitions()=0; 37 | virtual uint32_t getPartition(const MemReq& req)=0; 38 | }; 39 | 40 | class CorePartMapper : public PartMapper { 41 | private: 42 | uint32_t numCores; 43 | public: 44 | explicit CorePartMapper(uint32_t _numCores) : numCores(_numCores) {} 45 | virtual uint32_t getNumPartitions() {return numCores;} 46 | virtual uint32_t getPartition(const MemReq& req); 47 | }; 48 | 49 | class InstrDataPartMapper : public PartMapper { 50 | public: 51 | virtual uint32_t getNumPartitions() {return 2;} 52 | virtual uint32_t getPartition(const MemReq& req); 53 | }; 54 | 55 | class InstrDataCorePartMapper : public PartMapper { 56 | private: 57 | uint32_t numCores; 58 | public: 59 | explicit InstrDataCorePartMapper(uint32_t _numCores) : numCores(_numCores) {} 60 | virtual uint32_t getNumPartitions() {return 2*numCores;} 61 | virtual uint32_t getPartition(const MemReq& req); 62 | }; 63 | 64 | class ProcessPartMapper : public PartMapper { 65 | private: 66 | uint32_t numProcs; 67 | public: 68 | explicit ProcessPartMapper(uint32_t _numProcs) : numProcs(_numProcs) {} 69 | virtual uint32_t getNumPartitions() {return numProcs;} 70 | virtual uint32_t getPartition(const MemReq& req); 71 | }; 72 | 73 | class InstrDataProcessPartMapper : public PartMapper { 74 | private: 75 | uint32_t numProcs; 76 | public: 77 | explicit InstrDataProcessPartMapper(uint32_t _numProcs) : numProcs(_numProcs) {} 78 | virtual uint32_t getNumPartitions() {return 2*numProcs;} 79 | virtual uint32_t getPartition(const MemReq& req); 80 | }; 81 | 82 | class ProcessGroupPartMapper : public PartMapper { 83 | public: 84 | ProcessGroupPartMapper() {} 85 | virtual uint32_t getNumPartitions(); 86 | virtual uint32_t getPartition(const MemReq& req); 87 | }; 88 | 89 | #endif // PARTITION_MAPPER_H_ 90 | 91 | 92 | -------------------------------------------------------------------------------- /src/pin_cmd.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PIN_CMD_H_ 27 | #define PIN_CMD_H_ 28 | 29 | /* Interface to get pin command line */ 30 | 31 | #include 32 | #include "g_std/g_string.h" 33 | #include "g_std/g_vector.h" 34 | #include "galloc.h" 35 | 36 | class Config; 37 | 38 | class PinCmd : public GlobAlloc { 39 | private: 40 | g_vector args; 41 | 42 | struct ProcCmdInfo { 43 | g_string cmd; 44 | g_string input; 45 | g_string loader; 46 | g_string env; 47 | }; 48 | 49 | g_vector procInfo; //one entry for each process that the harness launches (not for child procs) 50 | 51 | public: 52 | PinCmd(Config* conf, const char* configFile, const char* outputDir, uint64_t shmid); 53 | g_vector getPinCmdArgs(uint32_t procIdx); 54 | g_vector getFullCmdArgs(uint32_t procIdx, const char** inputFile); 55 | void setEnvVars(uint32_t procIdx); 56 | 57 | uint32_t getNumCmdProcs() {return procInfo.size();} 58 | }; 59 | 60 | #endif // PIN_CMD_H_ 61 | -------------------------------------------------------------------------------- /src/prefetcher.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PREFETCHER_H_ 27 | #define PREFETCHER_H_ 28 | 29 | #include 30 | #include "bithacks.h" 31 | #include "g_std/g_string.h" 32 | #include "memory_hierarchy.h" 33 | #include "stats.h" 34 | 35 | /* Prefetcher models: Basic operation is to interpose between cache levels, issue additional accesses, 36 | * and keep a small table with delays; when the demand access comes, we do it and account for the 37 | * latency as when it was first fetched (to avoid hit latencies on partial latency overlaps). 38 | */ 39 | 40 | template // max value, threshold, initial 41 | class SatCounter { 42 | private: 43 | int32_t count; 44 | public: 45 | SatCounter() : count(I) {} 46 | void reset() { count = I; } 47 | void dec() { count = MAX(count - 1, 0); } 48 | void inc() { count = MIN(count + 1, M); } 49 | bool pred() const { return count >= T; } 50 | uint32_t counter() const { return count; } 51 | }; 52 | 53 | /* This is basically a souped-up version of the DLP L2 prefetcher in Nehalem: 16 stream buffers, 54 | * but (a) no up/down distinction, and (b) strided operation based on dominant stride detection 55 | * to try to subsume as much of the L1 IP/strided prefetcher as possible. 56 | * 57 | * FIXME: For now, mostly hardcoded; 64-line entries (4KB w/64-byte lines), fixed granularities, etc. 58 | * TODO: Adapt to use weave models 59 | */ 60 | class StreamPrefetcher : public BaseCache { 61 | private: 62 | struct Entry { 63 | // Two competing strides; at most one active 64 | int32_t stride; 65 | SatCounter<3, 2, 1> conf; 66 | 67 | struct AccessTimes { 68 | uint64_t startCycle; // FIXME: Dead for now, we should use it for profiling 69 | uint64_t respCycle; 70 | 71 | void fill(uint32_t s, uint64_t r) { startCycle = s; respCycle = r; } 72 | }; 73 | 74 | AccessTimes times[64]; 75 | std::bitset<64> valid; 76 | 77 | uint32_t lastPos; 78 | uint32_t lastLastPos; 79 | uint32_t lastPrefetchPos; 80 | uint64_t lastCycle; // updated on alloc and hit 81 | uint64_t ts; 82 | 83 | void alloc(uint64_t curCycle) { 84 | stride = 1; 85 | lastPos = 0; 86 | lastLastPos = 0; 87 | lastPrefetchPos = 0; 88 | conf.reset(); 89 | valid.reset(); 90 | lastCycle = curCycle; 91 | } 92 | }; 93 | 94 | uint64_t timestamp; // for LRU 95 | Address tag[16]; 96 | Entry array[16]; 97 | 98 | Counter profAccesses, profPrefetches, profDoublePrefetches, profPageHits, profHits, profShortHits, profStrideSwitches, profLowConfAccs; 99 | 100 | MemObject* parent; 101 | BaseCache* child; 102 | uint32_t childId; 103 | g_string name; 104 | 105 | public: 106 | explicit StreamPrefetcher(const g_string& _name) : timestamp(0), name(_name) {} 107 | void initStats(AggregateStat* parentStat); 108 | const char* getName() { return name.c_str();} 109 | void setParents(uint32_t _childId, const g_vector& parents, Network* network); 110 | void setChildren(const g_vector& children, Network* network); 111 | 112 | uint64_t access(MemReq& req); 113 | uint64_t invalidate(const InvReq& req); 114 | }; 115 | 116 | #endif // PREFETCHER_H_ 117 | -------------------------------------------------------------------------------- /src/proc_stats.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PROC_STATS_H_ 27 | #define PROC_STATS_H_ 28 | 29 | #include "galloc.h" 30 | #include "stats.h" 31 | 32 | class ProcStats : public GlobAlloc { 33 | private: 34 | 35 | class ProcessCounter; 36 | class ProcessVectorCounter; 37 | 38 | uint64_t lastUpdatePhase; 39 | 40 | AggregateStat* coreStats; // each member must be a regular aggregate with numCores elems 41 | AggregateStat* procStats; // stats produced 42 | 43 | uint64_t* buf; 44 | uint64_t* lastBuf; 45 | uint64_t bufSize; 46 | 47 | public: 48 | explicit ProcStats(AggregateStat* parentStat, AggregateStat* _coreStats); //includes initStats, called post-system init 49 | 50 | // Must be called by scheduler when descheduling; core must be quiesced 51 | void notifyDeschedule(); 52 | 53 | private: 54 | Stat* replStat(Stat* s, const char* name = nullptr, const char* desc = nullptr); 55 | 56 | void update(); // transparent 57 | }; 58 | 59 | #endif // PROCESS_STATS_H_ 60 | -------------------------------------------------------------------------------- /src/process_stats.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "process_stats.h" 27 | #include "process_tree.h" 28 | #include "scheduler.h" 29 | #include "zsim.h" 30 | 31 | ProcessStats::ProcessStats(AggregateStat* parentStat) { 32 | uint32_t maxProcs = zinfo->lineSize; 33 | processCycles.resize(maxProcs, 0); 34 | processInstrs.resize(maxProcs, 0); 35 | lastCoreCycles.resize(zinfo->numCores, 0); 36 | lastCoreInstrs.resize(zinfo->numCores, 0); 37 | lastUpdatePhase = 0; 38 | 39 | auto procCyclesLambda = [this](uint32_t p) { return getProcessCycles(p); }; 40 | auto procCyclesStat = makeLambdaVectorStat(procCyclesLambda, maxProcs); 41 | procCyclesStat->init("procCycles", "Per-process unhalted core cycles"); 42 | 43 | auto procInstrsLambda = [this](uint32_t p) { return getProcessInstrs(p); }; 44 | auto procInstrsStat = makeLambdaVectorStat(procInstrsLambda, maxProcs); 45 | procInstrsStat->init("procInstrs", "Per-process instructions"); 46 | 47 | parentStat->append(procCyclesStat); 48 | parentStat->append(procInstrsStat); 49 | } 50 | 51 | uint64_t ProcessStats::getProcessCycles(uint32_t p) { 52 | if (unlikely(lastUpdatePhase != zinfo->numPhases)) update(); 53 | assert(p < processCycles.size()); 54 | return processCycles[p]; 55 | } 56 | 57 | uint64_t ProcessStats::getProcessInstrs(uint32_t p) { 58 | if (unlikely(lastUpdatePhase != zinfo->numPhases)) update(); 59 | assert(p < processInstrs.size()); 60 | return processInstrs[p]; 61 | } 62 | 63 | void ProcessStats::notifyDeschedule(uint32_t cid, uint32_t outgoingPid) { 64 | assert(cid < lastCoreCycles.size()); 65 | assert(outgoingPid < processCycles.size()); 66 | updateCore(cid, outgoingPid); 67 | } 68 | 69 | /* Private */ 70 | 71 | void ProcessStats::updateCore(uint32_t cid, uint32_t p) { 72 | p = zinfo->procArray[p]->getGroupIdx(); 73 | 74 | uint64_t cCycles = zinfo->cores[cid]->getCycles(); 75 | uint64_t cInstrs = zinfo->cores[cid]->getInstrs(); 76 | 77 | assert(cCycles >= lastCoreCycles[cid] && cInstrs >= lastCoreInstrs[cid]); 78 | processCycles[p] += cCycles - lastCoreCycles[cid]; 79 | processInstrs[p] += cInstrs - lastCoreInstrs[cid]; 80 | 81 | lastCoreCycles[cid] = cCycles; 82 | lastCoreInstrs[cid] = cInstrs; 83 | } 84 | 85 | void ProcessStats::update() { 86 | assert(lastUpdatePhase < zinfo->numPhases); 87 | for (uint32_t cid = 0; cid < lastCoreCycles.size(); cid++) { 88 | uint32_t p = zinfo->sched->getScheduledPid(cid); 89 | if (p == (uint32_t)-1) continue; 90 | assert(p < processCycles.size()); 91 | updateCore(cid, p); 92 | } 93 | lastUpdatePhase = zinfo->numPhases; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/process_stats.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PROCESS_STATS_H_ 27 | #define PROCESS_STATS_H_ 28 | 29 | #include "galloc.h" 30 | #include "stats.h" 31 | 32 | /* Maintains, queries, and transparently updates per-process instruction and cycle counts. 33 | * You'd think it'd make sense to include this in ProcTreeNode, but those are dynamic, and 34 | * stats must be static (and zeros compress great) 35 | */ 36 | class ProcessStats : public GlobAlloc { 37 | private: 38 | g_vector processCycles, processInstrs; 39 | g_vector lastCoreCycles, lastCoreInstrs; 40 | uint64_t lastUpdatePhase; 41 | 42 | public: 43 | explicit ProcessStats(AggregateStat* parentStat); //includes initStats, called post-system init 44 | 45 | // May trigger a global update, should call ONLY when quiesced 46 | uint64_t getProcessCycles(uint32_t p); 47 | uint64_t getProcessInstrs(uint32_t p); 48 | 49 | // Must be called by scheduler when descheduling; core must be quiesced 50 | void notifyDeschedule(uint32_t cid, uint32_t outgoingPid); 51 | 52 | private: 53 | void updateCore(uint32_t cid, uint32_t p); 54 | void update(); //transparent 55 | }; 56 | 57 | #endif // PROCESS_STATS_H_ 58 | -------------------------------------------------------------------------------- /src/profile_stats.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef PROFILE_STATS_H_ 27 | #define PROFILE_STATS_H_ 28 | 29 | /* Stats used to profile the simulator */ 30 | 31 | #include 32 | #include "stats.h" 33 | 34 | //Helper function 35 | inline uint64_t getNs() { 36 | struct timespec ts; 37 | //guaranteed synchronized across processors, averages 20ns/call on Ubuntu 12.04... Linux hrtimers have gotten really good! In comparison, rdtsc is 9ns. 38 | clock_gettime(CLOCK_REALTIME, &ts); 39 | return 1000000000L*ts.tv_sec + ts.tv_nsec; 40 | } 41 | 42 | /* Implements a single stopwatch-style cumulative clock. Useful to profile isolated events. 43 | * get() accounts for current interval if clock is running. 44 | */ 45 | class ClockStat : public ScalarStat { 46 | private: 47 | uint64_t startNs; 48 | uint64_t totalNs; 49 | 50 | public: 51 | ClockStat() : ScalarStat(), startNs(0), totalNs(0) {} 52 | 53 | void start() { 54 | assert(!startNs); 55 | startNs = getNs(); 56 | } 57 | 58 | void end() { 59 | assert(startNs); 60 | uint64_t endNs = getNs(); 61 | assert(endNs >= startNs) 62 | totalNs += (endNs - startNs); 63 | startNs = 0; 64 | } 65 | 66 | uint64_t get() const { 67 | return totalNs + (startNs? (getNs() - startNs) : 0); 68 | } 69 | }; 70 | 71 | /* Implements multi-state time profiling. Always starts at state 0. 72 | * Using this with an enum will help retain your sanity. Does not stop, 73 | * so just transition to a dummy state if you want to stop profiling. 74 | * count() accounts for partial time in current state; count() is used 75 | * because we extend VectorCounter (TODO: we should have a VectorStat) 76 | */ 77 | class TimeBreakdownStat : public VectorCounter { 78 | private: 79 | uint32_t curState; 80 | uint64_t startNs; 81 | 82 | public: 83 | TimeBreakdownStat() : VectorCounter() {} 84 | 85 | virtual void init(const char* name, const char* desc, uint32_t size) { 86 | VectorCounter::init(name, desc, size); 87 | curState = 0; 88 | startNs = getNs(); 89 | } 90 | 91 | //I need to define this even though it is completely unnecessary, but only if I override init. gcc bug or C++ oddity? 92 | virtual void init(const char* name, const char* desc, uint32_t size, const char** names) { 93 | VectorCounter::init(name, desc, size, names); //will call our init(name, desc, size) 94 | } 95 | 96 | void transition(uint32_t newState) { 97 | assert(curState < size()); 98 | assert(newState < size()); 99 | 100 | uint64_t curNs = getNs(); 101 | assert(curNs >= startNs); 102 | 103 | inc(curState, curNs - startNs); 104 | //info("%d: %ld / %ld", curState, curNs - startNs, VectorCounter::count(curState)); 105 | curState = newState; 106 | startNs = curNs; 107 | } 108 | 109 | inline virtual uint64_t count(uint32_t idx) const { 110 | uint64_t partial = VectorCounter::count(idx); 111 | return partial + ((idx == curState)? (getNs() - startNs) : 0); 112 | } 113 | }; 114 | 115 | #endif // PROFILE_STATS_H_ 116 | -------------------------------------------------------------------------------- /src/rdtsc.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef RDTSC_H_ 27 | #define RDTSC_H_ 28 | 29 | /* Functions to read the timestamp counter */ 30 | 31 | #include 32 | 33 | #if defined(__x86_64__) 34 | static inline uint64_t rdtsc() { 35 | uint32_t hi, lo; 36 | __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi)); 37 | return ((uint64_t)lo) | (((uint64_t)hi) << 32); 38 | } 39 | #else 40 | #error "No rdtsc() available for this arch" 41 | #endif 42 | 43 | #endif // RDTSC_H_ 44 | -------------------------------------------------------------------------------- /src/simple_core.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef SIMPLE_CORE_H_ 27 | #define SIMPLE_CORE_H_ 28 | 29 | //A simple core model with IPC=1 except on memory accesses 30 | 31 | #include "core.h" 32 | #include "memory_hierarchy.h" 33 | #include "pad.h" 34 | 35 | class FilterCache; 36 | 37 | class SimpleCore : public Core { 38 | protected: 39 | FilterCache* l1i; 40 | FilterCache* l1d; 41 | 42 | uint64_t instrs; 43 | uint64_t curCycle; 44 | uint64_t phaseEndCycle; //next stopping point 45 | uint64_t haltedCycles; 46 | 47 | public: 48 | SimpleCore(FilterCache* _l1i, FilterCache* _l1d, g_string& _name); 49 | void initStats(AggregateStat* parentStat); 50 | 51 | uint64_t getInstrs() const {return instrs;} 52 | uint64_t getPhaseCycles() const; 53 | uint64_t getCycles() const {return curCycle - haltedCycles;} 54 | 55 | void contextSwitch(int32_t gid); 56 | virtual void join(); 57 | 58 | InstrFuncPtrs GetFuncPtrs(); 59 | 60 | protected: 61 | //Simulation functions 62 | inline void load(Address addr); 63 | inline void store(Address addr); 64 | inline void bbl(Address bblAddr, BblInfo* bblInstrs); 65 | 66 | static void LoadFunc(THREADID tid, ADDRINT addr); 67 | static void StoreFunc(THREADID tid, ADDRINT addr); 68 | static void BblFunc(THREADID tid, ADDRINT bblAddr, BblInfo* bblInfo); 69 | static void PredLoadFunc(THREADID tid, ADDRINT addr, BOOL pred); 70 | static void PredStoreFunc(THREADID tid, ADDRINT addr, BOOL pred); 71 | 72 | static void BranchFunc(THREADID, ADDRINT, BOOL, ADDRINT, ADDRINT) {} 73 | } ATTR_LINE_ALIGNED; //This needs to take up a whole cache line, or false sharing will be extremely frequent 74 | 75 | #endif // SIMPLE_CORE_H_ 76 | 77 | -------------------------------------------------------------------------------- /src/stats_filter.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "stats_filter.h" 27 | #include 28 | #include 29 | #include 30 | 31 | using std::regex; using std::regex_match; using std::string; using std::vector; 32 | 33 | // FilterStats operates recursively, building up a filtered hierarchy of aggregates 34 | 35 | AggregateStat* FilterStatsLevel(const AggregateStat* src, const regex& filter, const char* prefix) { 36 | string base = prefix? (string(prefix) + src->name() + ".") : ""; //if nullptr prefix, omit our name (we're root) 37 | vector children; 38 | for (uint32_t i = 0; i < src->curSize(); i++) { 39 | Stat* child = src->get(i); 40 | if (AggregateStat* as = dynamic_cast(child)) { 41 | AggregateStat* fs = FilterStatsLevel(as, filter, base.c_str()); 42 | if (fs) children.push_back(fs); 43 | } else { 44 | string name = base + child->name(); 45 | if (regex_match(name, filter)) children.push_back(child); 46 | } 47 | } 48 | 49 | if (children.size()) { 50 | AggregateStat* res = new AggregateStat(src->isRegular()); 51 | res->init(src->name(), src->desc()); 52 | for (Stat* c : children) res->append(c); 53 | return res; 54 | } else { 55 | return nullptr; 56 | } 57 | } 58 | 59 | AggregateStat* FilterStats(const AggregateStat* rootStat, const char* regexStr) { 60 | regex filter(regexStr); 61 | AggregateStat* res = FilterStatsLevel(rootStat, filter, nullptr /*root*/); 62 | if (res) res->makeImmutable(); 63 | return res; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/stats_filter.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef STATS_FILTER_H_ 27 | #define STATS_FILTER_H_ 28 | 29 | #include "stats.h" 30 | 31 | /* Produces a filtered stats tree, where only the base stats whose names match the regex are retained. 32 | * Base stats are NOT copied, they are either kept or ommitted. Aggregate stats are created as needed. 33 | * The returned tree can be passed to any backend to produce filtered dumps. Returns nullptr if nothing 34 | * matches the regex. 35 | */ 36 | AggregateStat* FilterStats(const AggregateStat* srcStat, const char* regex); 37 | 38 | #endif // STATS_FILTER_H_ 39 | -------------------------------------------------------------------------------- /src/str.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef STR_H_ 27 | #define STR_H_ 28 | 29 | /* Turn anything stringstream can grok into a string */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "g_std/g_vector.h" 35 | 36 | template std::string Str(T v) { 37 | std::stringstream ss; 38 | ss << v; 39 | return ss.str(); 40 | } 41 | 42 | template std::string Str(const std::vector& v) { 43 | std::stringstream ss; 44 | ss << "["; 45 | for (auto& x : v) ss << " " << x; 46 | ss << " ]"; 47 | return ss.str(); 48 | } 49 | 50 | template std::string Str(const g_vector& v) { 51 | std::stringstream ss; 52 | ss << "["; 53 | for (auto& x : v) ss << " " << x; 54 | ss << "]"; 55 | return ss.str(); 56 | } 57 | 58 | #endif // STR_H_ 59 | -------------------------------------------------------------------------------- /src/text_stats.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include 27 | #include 28 | #include "galloc.h" 29 | #include "log.h" 30 | #include "stats.h" 31 | #include "zsim.h" 32 | 33 | using std::endl; 34 | 35 | class TextBackendImpl : public GlobAlloc { 36 | private: 37 | const char* filename; 38 | AggregateStat* rootStat; 39 | 40 | void dumpStat(Stat* s, uint32_t level, std::ofstream* out) { 41 | for (uint32_t i = 0; i < level; i++) *out << " "; 42 | *out << s->name() << ": "; 43 | if (AggregateStat* as = dynamic_cast(s)) { 44 | *out << "# " << as->desc() << endl; 45 | for (uint32_t i = 0; i < as->size(); i++) { 46 | dumpStat(as->get(i), level+1, out); 47 | } 48 | } else if (ScalarStat* ss = dynamic_cast(s)) { 49 | *out << ss->get() << " # " << ss->desc() << endl; 50 | } else if (VectorStat* vs = dynamic_cast(s)) { 51 | *out << "# " << vs->desc() << endl; 52 | for (uint32_t i = 0; i < vs->size(); i++) { 53 | for (uint32_t j = 0; j < level+1; j++) *out << " "; 54 | if (vs->hasCounterNames()) { 55 | *out << vs->counterName(i) << ": " << vs->count(i) << endl; 56 | } else { 57 | *out << i << ": " << vs->count(i) << endl; 58 | } 59 | } 60 | } else { 61 | panic("Unrecognized stat type"); 62 | } 63 | } 64 | 65 | public: 66 | TextBackendImpl(const char* _filename, AggregateStat* _rootStat) : 67 | filename(_filename), rootStat(_rootStat) 68 | { 69 | std::ofstream out(filename, std::ios_base::out); 70 | out << "# zsim stats" << endl; 71 | out << "===" << endl; 72 | } 73 | 74 | void dump(bool buffered) { 75 | std::ofstream out(filename, std::ios_base::app); 76 | dumpStat(rootStat, 0, &out); 77 | out << "===" << endl; 78 | } 79 | }; 80 | 81 | TextBackend::TextBackend(const char* filename, AggregateStat* rootStat) { 82 | backend = new TextBackendImpl(filename, rootStat); 83 | } 84 | 85 | void TextBackend::dump(bool buffered) { 86 | backend->dump(buffered); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/tick_event.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef TICK_EVENT_H_ 27 | #define TICK_EVENT_H_ 28 | 29 | #include "contention_sim.h" 30 | #include "timing_event.h" 31 | #include "zsim.h" 32 | 33 | //FIXME: Rearchitect this SENSIBLY 34 | template 35 | class TickEvent : public TimingEvent, public GlobAlloc { //this one should be allocated from glob mem 36 | private: 37 | T* obj; 38 | bool active; 39 | 40 | public: 41 | TickEvent(T* _obj, int32_t domain) : TimingEvent(0, 0, domain), obj(_obj), active(false) { 42 | setMinStartCycle(0); 43 | } 44 | 45 | void parentDone(uint64_t startCycle) { 46 | panic("This is queued directly"); 47 | } 48 | 49 | void queue(uint64_t startCycle) { 50 | assert(!active); 51 | active = true; 52 | zinfo->contentionSim->enqueueSynced(this, startCycle); 53 | } 54 | 55 | void simulate(uint64_t startCycle) { 56 | uint32_t delay = obj->tick(startCycle); 57 | if (delay) { 58 | requeue(startCycle+delay); 59 | } else { 60 | active = false; 61 | } 62 | } 63 | 64 | using GlobAlloc::operator new; //grrrrrrrrr 65 | using GlobAlloc::operator delete; 66 | }; 67 | 68 | #endif // TICK_EVENT_H_ 69 | -------------------------------------------------------------------------------- /src/timing_cache.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef TIMING_CACHE_H_ 27 | #define TIMING_CACHE_H_ 28 | 29 | #include "breakdown_stats.h" 30 | #include "cache.h" 31 | 32 | class HitEvent; 33 | class MissStartEvent; 34 | class MissResponseEvent; 35 | class MissWritebackEvent; 36 | class ReplAccessEvent; 37 | class TimingEvent; 38 | 39 | class TimingCache : public Cache { 40 | private: 41 | uint64_t lastAccCycle, lastFreeCycle; 42 | uint32_t numMSHRs, activeMisses; 43 | g_vector pendingQueue; 44 | 45 | // Stats 46 | CycleBreakdownStat profOccHist; 47 | Counter profHitLat, profMissRespLat, profMissLat; 48 | 49 | uint32_t domain; 50 | 51 | // For zcache replacement simulation (pessimistic, assumes we walk the whole tree) 52 | uint32_t tagLat, ways, cands; 53 | 54 | PAD(); 55 | lock_t topLock; 56 | PAD(); 57 | 58 | public: 59 | TimingCache(uint32_t _numLines, CC* _cc, CacheArray* _array, ReplPolicy* _rp, uint32_t _accLat, uint32_t _invLat, uint32_t mshrs, 60 | uint32_t tagLat, uint32_t ways, uint32_t cands, uint32_t _domain, const g_string& _name); 61 | void initStats(AggregateStat* parentStat); 62 | 63 | uint64_t access(MemReq& req); 64 | 65 | void simulateHit(HitEvent* ev, uint64_t cycle); 66 | void simulateMissStart(MissStartEvent* ev, uint64_t cycle); 67 | void simulateMissResponse(MissResponseEvent* ev, uint64_t cycle, MissStartEvent* mse); 68 | void simulateMissWriteback(MissWritebackEvent* ev, uint64_t cycle, MissStartEvent* mse); 69 | void simulateReplAccess(ReplAccessEvent* ev, uint64_t cycle); 70 | 71 | private: 72 | uint64_t highPrioAccess(uint64_t cycle); 73 | uint64_t tryLowPrioAccess(uint64_t cycle); 74 | }; 75 | 76 | #endif // TIMING_CACHE_H_ 77 | -------------------------------------------------------------------------------- /src/timing_core.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef TIMING_CORE_H_ 27 | #define TIMING_CORE_H_ 28 | 29 | #include "core.h" 30 | #include "core_recorder.h" 31 | #include "event_recorder.h" 32 | #include "memory_hierarchy.h" 33 | #include "pad.h" 34 | 35 | class FilterCache; 36 | 37 | class TimingCore : public Core { 38 | private: 39 | FilterCache* l1i; 40 | FilterCache* l1d; 41 | 42 | uint64_t instrs; 43 | 44 | uint64_t curCycle; //phase 1 clock 45 | uint64_t phaseEndCycle; //phase 1 end clock 46 | 47 | CoreRecorder cRec; 48 | 49 | public: 50 | TimingCore(FilterCache* _l1i, FilterCache* _l1d, uint32_t domain, g_string& _name); 51 | void initStats(AggregateStat* parentStat); 52 | 53 | uint64_t getInstrs() const {return instrs;} 54 | uint64_t getPhaseCycles() const; 55 | uint64_t getCycles() const {return cRec.getUnhaltedCycles(curCycle);} 56 | 57 | void contextSwitch(int32_t gid); 58 | virtual void join(); 59 | virtual void leave(); 60 | 61 | InstrFuncPtrs GetFuncPtrs(); 62 | 63 | //Contention simulation interface 64 | inline EventRecorder* getEventRecorder() {return cRec.getEventRecorder();} 65 | void cSimStart() {curCycle = cRec.cSimStart(curCycle);} 66 | void cSimEnd() {curCycle = cRec.cSimEnd(curCycle);} 67 | 68 | private: 69 | inline void loadAndRecord(Address addr); 70 | inline void storeAndRecord(Address addr); 71 | inline void bblAndRecord(Address bblAddr, BblInfo* bblInstrs); 72 | inline void record(uint64_t startCycle); 73 | 74 | static void LoadAndRecordFunc(THREADID tid, ADDRINT addr); 75 | static void StoreAndRecordFunc(THREADID tid, ADDRINT addr); 76 | static void BblAndRecordFunc(THREADID tid, ADDRINT bblAddr, BblInfo* bblInfo); 77 | static void PredLoadAndRecordFunc(THREADID tid, ADDRINT addr, BOOL pred); 78 | static void PredStoreAndRecordFunc(THREADID tid, ADDRINT addr, BOOL pred); 79 | 80 | static void BranchFunc(THREADID, ADDRINT, BOOL, ADDRINT, ADDRINT) {} 81 | } ATTR_LINE_ALIGNED; 82 | 83 | #endif // TIMING_CORE_H_ 84 | -------------------------------------------------------------------------------- /src/trace_driver.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef __TRACE_DRIVER_H__ 27 | #define __TRACE_DRIVER_H__ 28 | 29 | #include 30 | #include 31 | #include "access_tracing.h" 32 | #include "g_std/g_string.h" 33 | #include "stats.h" 34 | 35 | /* Basic class for trace-driven simulation. Shares the cache interface (invalidate), but it is not a cache in any sense --- it just reads in a single trace and replays it */ 36 | 37 | class TraceDriverProxyCache; 38 | 39 | class TraceDriver { 40 | private: 41 | struct ChildInfo { 42 | std::unordered_map cStore; //holds current sets of lines for each child. Needs to support an arbitrary set, hence the hash table 43 | int64_t skew; 44 | uint64_t lastReqCycle; 45 | //Counter bypassedGETS; 46 | //Counter bypassedGETX; 47 | Counter profLat; 48 | Counter profSelfInv; //invalidations in response to our own access 49 | Counter profCrossInv; //invalidations in response to another access 50 | Counter profInvx; 51 | }; 52 | 53 | ChildInfo* children; 54 | lock_t lock; //NOTE: not needed for now 55 | AccessTraceReader tr; 56 | uint32_t numChildren; 57 | bool useSkews; //If false, replays the trace using its request cycles. If true, it skews the simulated child. Can only be true with a single child. 58 | bool playPuts; //If true, issues PUTS/PUTX requests as they appear in the trace. If false, it just issues the GETS/X requests, leaving it up to the parent to decide when to evict something (NOTE: if the parent is running OPT, it knows better!) 59 | bool playAllGets; //If true, if we have a get to an address that we already have, issue a put immediately before. 60 | MemObject* parent; 61 | 62 | AccessTraceWriter* atw; 63 | 64 | //Last access, childId == -1 if invalid, acts as 1-elem buffer 65 | AccessRecord lastAcc; 66 | 67 | public: 68 | TraceDriver(std::string filename, std::string retracefile, std::vector& proxies, bool _useSkews, bool _playPuts, bool _playAllGets); 69 | void initStats(AggregateStat* parentStat); 70 | void setParent(MemObject* _parent); 71 | 72 | uint64_t invalidate(uint32_t childId, Address lineAddr, InvType type, bool* reqWriteback, uint64_t reqCycle, uint32_t srcId); 73 | 74 | //Returns false if done, true otherwise 75 | bool executePhase(); 76 | 77 | private: 78 | inline void executeAccess(AccessRecord acc); 79 | }; 80 | 81 | 82 | class TraceDriverProxyCache : public BaseCache { 83 | private: 84 | TraceDriver* drv; 85 | uint32_t id; 86 | g_string name; 87 | MemObject* parent; 88 | public: 89 | TraceDriverProxyCache(g_string& _name) : drv(nullptr), id(-1), name(_name) {} 90 | const char* getName() {return name.c_str();} 91 | 92 | void setParents(uint32_t _childId, const g_vector& parents, Network* network) {id = _childId; assert(parents.size() == 1); parent = parents[0];}; //FIXME: Support multi-banked caches... 93 | void setChildren(const g_vector& children, Network* network) {panic("Should not be called, this must be terminal");}; 94 | 95 | MemObject* getParent() const {return parent;} 96 | void setDriver(TraceDriver* driver) {drv = driver;} 97 | 98 | uint64_t access(MemReq& req) {panic("Should never be called");} 99 | uint64_t invalidate(const InvReq& req) { 100 | return drv->invalidate(id, req.lineAddr, req.type, req.writeback, req.cycle, req.srcId); 101 | } 102 | }; 103 | 104 | #endif /*__TRACE_DRIVER_H__*/ 105 | -------------------------------------------------------------------------------- /src/tracing_cache.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #include "tracing_cache.h" 27 | #include "zsim.h" 28 | 29 | TracingCache::TracingCache(uint32_t _numLines, CC* _cc, CacheArray* _array, ReplPolicy* _rp, uint32_t _accLat, uint32_t _invLat, g_string& _tracefile, g_string& _name) : 30 | Cache(_numLines, _cc, _array, _rp, _accLat, _invLat, _name), tracefile(_tracefile) 31 | { 32 | futex_init(&traceLock); 33 | } 34 | 35 | void TracingCache::setChildren(const g_vector& children, Network* network) { 36 | Cache::setChildren(children, network); 37 | //We need to initialize the trace writer here because it needs the number of children 38 | atw = new AccessTraceWriter(tracefile, children.size()); 39 | zinfo->traceWriters->push_back(atw); //register it so that it gets flushed when the simulation ends 40 | } 41 | 42 | uint64_t TracingCache::access(MemReq& req) { 43 | uint64_t respCycle = Cache::access(req); 44 | futex_lock(&traceLock); 45 | uint32_t lat = respCycle - req.cycle; 46 | AccessRecord acc = {req.lineAddr, req.cycle, lat, req.childId, req.type}; 47 | atw->write(acc); 48 | futex_unlock(&traceLock); 49 | return respCycle; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/tracing_cache.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef __TRACING_CACHE_H__ 27 | #define __TRACING_CACHE_H__ 28 | 29 | #include "access_tracing.h" 30 | #include "cache.h" 31 | 32 | class TracingCache : public Cache { 33 | private: 34 | g_string tracefile; 35 | AccessTraceWriter* atw; 36 | lock_t traceLock; 37 | 38 | public: 39 | TracingCache(uint32_t _numLines, CC* _cc, CacheArray* _array, ReplPolicy* _rp, uint32_t _accLat, uint32_t _invLat, g_string& _tracefile, g_string& _name); 40 | void setChildren(const g_vector& children, Network* network); 41 | uint64_t access(MemReq& req); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/utility_monitor.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef UTILITY_MONITOR_H_ 27 | #define UTILITY_MONITOR_H_ 28 | 29 | #include "galloc.h" 30 | #include "memory_hierarchy.h" 31 | #include "stats.h" 32 | 33 | //Print some information regarding utility monitors and partitioning 34 | #define UMON_INFO 0 35 | //#define UMON_INFO 1 36 | 37 | class HashFamily; 38 | 39 | class UMon : public GlobAlloc { 40 | private: 41 | uint32_t umonLines; 42 | uint32_t samplingFactor; //Size of sampled cache (lines)/size of umon. Should be power of 2 43 | uint32_t buckets; //umon ways 44 | uint32_t sets; //umon sets. Should be power of 2. 45 | 46 | //Used in masks for set indices and sampling factor descisions 47 | uint64_t samplingFactorBits; 48 | uint64_t setsBits; 49 | 50 | uint64_t* curWayHits; 51 | uint64_t curMisses; 52 | 53 | Counter profHits; 54 | Counter profMisses; 55 | VectorCounter profWayHits; 56 | 57 | //Even for high associativity/number of buckets, performance of this is not important because we downsample so much (so this is a LL) 58 | struct Node { 59 | Address addr; 60 | struct Node* next; 61 | }; 62 | Node** array; 63 | Node** heads; 64 | 65 | HashFamily* hf; 66 | 67 | public: 68 | UMon(uint32_t _bankLines, uint32_t _umonLines, uint32_t _buckets); 69 | void initStats(AggregateStat* parentStat); 70 | 71 | void access(Address lineAddr); 72 | 73 | uint64_t getNumAccesses() const; 74 | void getMisses(uint64_t* misses); 75 | void startNextInterval(); 76 | 77 | uint32_t getBuckets() const { return buckets; } 78 | }; 79 | 80 | #endif // UTILITY_MONITOR_H_ 81 | 82 | -------------------------------------------------------------------------------- /src/virt/common.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef VIRT_COMMON_H_ 27 | #define VIRT_COMMON_H_ 28 | 29 | // Typedefs and common functions for Virt implementation 30 | // This is internal to virt, and should only be included withing virt/ files 31 | 32 | #include 33 | #include "log.h" 34 | #include "pin.H" 35 | #include "virt/virt.h" 36 | 37 | struct PrePatchArgs { 38 | uint32_t tid; 39 | CONTEXT* ctxt; 40 | SYSCALL_STANDARD std; 41 | const char* patchRoot; 42 | bool isNopThread; 43 | }; 44 | 45 | struct PostPatchArgs { 46 | uint32_t tid; 47 | CONTEXT* ctxt; 48 | SYSCALL_STANDARD std; 49 | }; 50 | 51 | typedef std::function PostPatchFn; 52 | typedef PostPatchFn (*PrePatchFn)(PrePatchArgs); 53 | 54 | extern const PostPatchFn NullPostPatch; // defined in virt.cpp 55 | 56 | // PIN_SafeCopy wrapper. We expect the default thing to be correct access 57 | template 58 | static inline bool safeCopy(const T* src, T* dst, const char* file = __FILE__, int line = __LINE__) { 59 | size_t copiedBytes = PIN_SafeCopy(dst, src, sizeof(T)); 60 | if (copiedBytes != sizeof(T)) { 61 | warn("[%d] %s:%d Failed app<->tool copy (%ld/%ld bytes copied)", PIN_ThreadId(), file, line, copiedBytes, sizeof(T)); 62 | return false; 63 | } 64 | return true; 65 | } 66 | 67 | #endif // VIRT_COMMON_H_ 68 | -------------------------------------------------------------------------------- /src/virt/patchdefs.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | // Definitions of which patch functions handle which syscalls 27 | // Uses macros, assumes you'll include this from somewhere else 28 | 29 | // Unconditional patches 30 | 31 | // File system -- fs.cpp 32 | PF(SYS_open, PatchOpen); 33 | PF(SYS_openat, PatchOpen); 34 | 35 | // Port virtualization -- ports.cpp 36 | PF(SYS_bind, PatchBind); 37 | PF(SYS_getsockname, PatchGetsockname); 38 | PF(SYS_connect, PatchConnect); 39 | 40 | // CPU virtualization -- cpu.cpp 41 | PF(SYS_getcpu, PatchGetcpu); 42 | PF(SYS_sched_getaffinity, PatchSchedGetaffinity); 43 | PF(SYS_sched_setaffinity, PatchSchedSetaffinity); 44 | 45 | 46 | // Conditional patches, only when not fast-forwarded 47 | 48 | // Time virtualization -- time.cpp 49 | PF(SYS_gettimeofday, PatchGettimeofday); 50 | PF(SYS_time, PatchTime); 51 | PF(SYS_clock_gettime, PatchClockGettime); 52 | PF(SYS_nanosleep, PatchNanosleep); 53 | PF(SYS_clock_nanosleep, PatchNanosleep); 54 | 55 | // Timeout virtualization -- timeout.cpp 56 | PF(SYS_futex, PatchTimeoutSyscall); 57 | PF(SYS_epoll_wait, PatchTimeoutSyscall); 58 | PF(SYS_epoll_pwait, PatchTimeoutSyscall); 59 | PF(SYS_poll, PatchTimeoutSyscall); 60 | 61 | -------------------------------------------------------------------------------- /src/virt/port_virtualizer.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef VIRT_PORT_VIRTUALIZER_H_ 27 | #define VIRT_PORT_VIRTUALIZER_H_ 28 | 29 | /* Simple class to keep tabs on virtualized ports */ 30 | 31 | #include "g_std/g_unordered_map.h" 32 | #include "galloc.h" 33 | #include "locks.h" 34 | 35 | class PortVirtualizer : public GlobAlloc { 36 | private: 37 | g_unordered_map realToVirt; 38 | g_unordered_map virtToReal; 39 | 40 | lock_t pvLock; 41 | 42 | public: 43 | PortVirtualizer() { 44 | futex_init(&pvLock); 45 | } 46 | 47 | //Must always lock before any operation, and unlock after! 48 | //lock() unlock() are external because bind() spans multiple methods 49 | void lock() { futex_lock(&pvLock); } 50 | void unlock() { futex_unlock(&pvLock); } 51 | 52 | //Note there's no error checking for a bind that binds on a previous one. 53 | //If someone previous bound to that port, the virtualization code should just go ahead with that mapping and 54 | //either let bind() fail (if the previous bind is stil active) or succeed (if the previous bind ended) 55 | void registerBind(int virt, int real) { 56 | realToVirt[real] = virt; 57 | virtToReal[virt] = real; 58 | } 59 | 60 | //Returns -1 if not in map. For connect() and bind() 61 | int lookupReal(int virt) { 62 | g_unordered_map::iterator it = virtToReal.find(virt); 63 | return (it == virtToReal.end())? -1 : it->second; 64 | } 65 | 66 | //Returns -1 if not in map. For getsockname(), where the OS returns real and we need virt 67 | int lookupVirt(int real) { 68 | g_unordered_map::iterator it = realToVirt.find(real); 69 | return (it == realToVirt.end())? -1 : it->second; 70 | } 71 | }; 72 | 73 | #endif // VIRT_PORT_VIRTUALIZER_H_ 74 | -------------------------------------------------------------------------------- /src/virt/syscall_name.cpp.in: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2014 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | static const char* syscallNames[] = { 27 | // Auto-generated at build time 28 | SYSCALL_NAME_LIST 29 | }; 30 | 31 | #include 32 | 33 | const char* GetSyscallName(uint32_t syscall) { 34 | return (syscall >= sizeof(syscallNames)/sizeof(syscallNames[0]))? "INVALID" : syscallNames[syscall]; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/virt/syscall_name.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of zsim. 6 | * 7 | * zsim is free software; you can redistribute it and/or modify it under the 8 | * terms of the GNU General Public License as published by the Free Software 9 | * Foundation, version 2. 10 | * 11 | * If you use this software in your research, we request that you reference 12 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 13 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 14 | * source of the simulator in any publications that use this software, and that 15 | * you send us a citation of your work. 16 | * 17 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20 | * details. 21 | * 22 | * You should have received a copy of the GNU General Public License along with 23 | * this program. If not, see . 24 | */ 25 | 26 | #ifndef VIRT_SYSCALL_NAME_H_ 27 | #define VIRT_SYSCALL_NAME_H_ 28 | 29 | const char* GetSyscallName(uint32_t syscall); 30 | 31 | #endif // VIRT_SYSCALL_NAME_H_ 32 | -------------------------------------------------------------------------------- /src/virt/time_conv.h: -------------------------------------------------------------------------------- 1 | /** $glic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * Copyright (C) 2011 Google Inc. 5 | * 6 | * This file is part of zsim. 7 | * 8 | * zsim is free software; you can redistribute it and/or modify it under the 9 | * terms of the GNU General Public License as published by the Free Software 10 | * Foundation, version 2. 11 | * 12 | * If you use this software in your research, we request that you reference 13 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 14 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 15 | * source of the simulator in any publications that use this software, and that 16 | * you send us a citation of your work. 17 | * 18 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 19 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 | * details. 22 | * 23 | * You should have received a copy of the GNU General Public License along with 24 | * this program. If not, see . 25 | */ 26 | 27 | #ifndef VIRT_TIME_CONV_H_ 28 | #define VIRT_TIME_CONV_H_ 29 | 30 | #include 31 | 32 | // Helper functions to translate between ns, timespec/timeval, and cycles 33 | 34 | // ns per s :) 35 | #define NSPS (1000*1000*1000L) 36 | 37 | static inline uint64_t timevalToNs(struct timeval tv) { 38 | return tv.tv_sec*NSPS + tv.tv_usec*1000L; 39 | } 40 | 41 | static inline uint64_t timespecToNs(struct timespec ts) { 42 | return ts.tv_sec*NSPS + ts.tv_nsec; 43 | } 44 | 45 | static inline struct timeval nsToTimeval(uint64_t ns) { 46 | struct timeval res; 47 | res.tv_sec = ns/NSPS; 48 | res.tv_usec = (ns % NSPS)/1000; 49 | return res; 50 | } 51 | 52 | static inline struct timespec nsToTimespec(uint64_t ns) { 53 | struct timespec res; 54 | res.tv_sec = ns/NSPS; 55 | res.tv_nsec = (ns % NSPS); 56 | return res; 57 | } 58 | 59 | static inline uint64_t cyclesToNs(uint64_t cycles) { 60 | return cycles*1000/zinfo->freqMHz; 61 | } 62 | 63 | static inline uint64_t nsToCycles(uint64_t cycles) { 64 | return cycles*zinfo->freqMHz/1000; 65 | } 66 | 67 | #endif // VIRT_TIME_CONV_H_ 68 | -------------------------------------------------------------------------------- /src/virt/virt.cpp: -------------------------------------------------------------------------------- 1 | /** $glic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * Copyright (C) 2011 Google Inc. 5 | * 6 | * This file is part of zsim. 7 | * 8 | * zsim is free software; you can redistribute it and/or modify it under the 9 | * terms of the GNU General Public License as published by the Free Software 10 | * Foundation, version 2. 11 | * 12 | * If you use this software in your research, we request that you reference 13 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 14 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 15 | * source of the simulator in any publications that use this software, and that 16 | * you send us a citation of your work. 17 | * 18 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 19 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 | * details. 22 | * 23 | * You should have received a copy of the GNU General Public License along with 24 | * this program. If not, see . 25 | */ 26 | 27 | #include 28 | #include "constants.h" 29 | #include "log.h" 30 | #include "virt/common.h" 31 | #include "virt/syscall_name.h" 32 | #include "virt/virt.h" 33 | 34 | #define MAX_SYSCALLS 350 // doesn't need to be accurate 35 | 36 | PrePatchFn prePatchFunctions[MAX_SYSCALLS]; 37 | PostPatchFn postPatchFunctions[MAX_THREADS]; 38 | 39 | const PostPatchFn NullPostPatch = [](PostPatchArgs) {return PPA_NOTHING;}; 40 | 41 | // Common prepatch functions 42 | PostPatchFn NullPatch(PrePatchArgs) { 43 | return NullPostPatch; 44 | } 45 | 46 | PostPatchFn WarnTimingRelated(PrePatchArgs args) { 47 | uint32_t syscall = PIN_GetSyscallNumber(args.ctxt, args.std); 48 | warn("[%d] Executing unvirtualized potentially timing-sensitive syscall: %s (%d)", args.tid, GetSyscallName(syscall), syscall); 49 | return NullPostPatch; 50 | } 51 | 52 | // Define all patch functions 53 | #define PF(syscall, pfn) PostPatchFn pfn(PrePatchArgs args); 54 | #include "virt/patchdefs.h" 55 | #undef PF 56 | 57 | void VirtInit() { 58 | for (uint32_t i = 0; i < MAX_SYSCALLS; i++) prePatchFunctions[i] = NullPatch; 59 | 60 | // Issue warnings on timing-sensitive syscalls 61 | for (uint32_t syscall : {SYS_select, SYS_getitimer, SYS_alarm, SYS_setitimer, SYS_semop, 62 | SYS_gettimeofday, SYS_times, SYS_rt_sigtimedwait, SYS_time, SYS_futex, SYS_mq_timedsend, 63 | SYS_mq_timedreceive, SYS_pselect6, SYS_ppoll}) { 64 | prePatchFunctions[syscall] = WarnTimingRelated; 65 | } 66 | 67 | // Bind all patch functions 68 | #define PF(syscall, pfn) prePatchFunctions[syscall] = pfn; 69 | #include "virt/patchdefs.h" 70 | #undef PF 71 | } 72 | 73 | 74 | // Dispatch methods 75 | void VirtSyscallEnter(THREADID tid, CONTEXT *ctxt, SYSCALL_STANDARD std, const char* patchRoot, bool isNopThread) { 76 | uint32_t syscall = PIN_GetSyscallNumber(ctxt, std); 77 | if (syscall >= MAX_SYSCALLS) { 78 | warn("syscall %d out of range", syscall); 79 | postPatchFunctions[tid] = NullPostPatch; 80 | } else { 81 | postPatchFunctions[tid] = prePatchFunctions[syscall]({tid, ctxt, std, patchRoot, isNopThread}); 82 | } 83 | } 84 | 85 | PostPatchAction VirtSyscallExit(THREADID tid, CONTEXT *ctxt, SYSCALL_STANDARD std) { 86 | return postPatchFunctions[tid]({tid, ctxt, std}); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/virt/virt.h: -------------------------------------------------------------------------------- 1 | /** $glic$ 2 | * Copyright (C) 2012-2015 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2013 by The Board of Trustees of Stanford University 4 | * Copyright (C) 2011 Google Inc. 5 | * 6 | * This file is part of zsim. 7 | * 8 | * zsim is free software; you can redistribute it and/or modify it under the 9 | * terms of the GNU General Public License as published by the Free Software 10 | * Foundation, version 2. 11 | * 12 | * If you use this software in your research, we request that you reference 13 | * the zsim paper ("ZSim: Fast and Accurate Microarchitectural Simulation of 14 | * Thousand-Core Systems", Sanchez and Kozyrakis, ISCA-40, June 2013) as the 15 | * source of the simulator in any publications that use this software, and that 16 | * you send us a citation of your work. 17 | * 18 | * zsim is distributed in the hope that it will be useful, but WITHOUT ANY 19 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 | * details. 22 | * 23 | * You should have received a copy of the GNU General Public License along with 24 | * this program. If not, see . 25 | */ 26 | 27 | #ifndef VIRT_VIRT_H_ 28 | #define VIRT_VIRT_H_ 29 | 30 | // External virt interface 31 | 32 | #include "pin.H" 33 | 34 | enum PostPatchAction { 35 | PPA_NOTHING, 36 | PPA_USE_RETRY_PTRS, 37 | PPA_USE_JOIN_PTRS, 38 | }; 39 | 40 | void VirtInit(); // per-process, not global 41 | void VirtSyscallEnter(THREADID tid, CONTEXT *ctxt, SYSCALL_STANDARD std, const char* patchRoot, bool isNopThread); 42 | PostPatchAction VirtSyscallExit(THREADID tid, CONTEXT *ctxt, SYSCALL_STANDARD std); 43 | 44 | // VDSO / external virt functions 45 | void VirtGettimeofday(uint32_t tid, ADDRINT arg0); 46 | void VirtTime(uint32_t tid, REG* retVal, ADDRINT arg0); 47 | void VirtClockGettime(uint32_t tid, ADDRINT arg0, ADDRINT arg1); 48 | void VirtGetcpu(uint32_t tid, uint32_t cpu, ADDRINT arg0, ADDRINT arg1); 49 | 50 | // Time virtualization direct functions 51 | void VirtCaptureClocks(bool isDeffwd); // called on start and ffwd to get all clocks together 52 | uint64_t VirtGetPhaseRDTSC(); 53 | 54 | #endif // VIRT_VIRT_H_ 55 | -------------------------------------------------------------------------------- /tests/affinity.cfg: -------------------------------------------------------------------------------- 1 | // Tests zsim APIs. 2 | 3 | sys = { 4 | cores = { 5 | c = { 6 | cores = 16; 7 | type = "Timing"; 8 | dcache = "l1d"; 9 | icache = "l1i"; 10 | }; 11 | }; 12 | 13 | lineSize = 64; 14 | 15 | caches = { 16 | l1d = { 17 | caches = 16; 18 | size = 65536; 19 | }; 20 | l1i = { 21 | caches = 16; 22 | size = 32768; 23 | }; 24 | l2 = { 25 | size = 2097152; 26 | children = "l1d|l1i"; 27 | }; 28 | }; 29 | }; 30 | 31 | process0 = { 32 | command = "./misc/testProgs/test_affinity"; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /tests/het.cfg: -------------------------------------------------------------------------------- 1 | // This system is similar to a 6-core, 2.4GHz Westmere with 10 Niagara-like cores attached to the L3 2 | sys = { 3 | lineSize = 64; 4 | frequency = 2400; 5 | 6 | cores = { 7 | beefy = { 8 | type = "OOO"; 9 | cores = 6; 10 | icache = "l1i_beefy"; 11 | dcache = "l1d_beefy"; 12 | }; 13 | 14 | wimpy = { 15 | type = "Simple"; 16 | cores = 10; 17 | icache = "l1i_wimpy"; 18 | dcache = "l1d_wimpy"; 19 | }; 20 | }; 21 | 22 | caches = { 23 | l1d_beefy = { 24 | caches = 6; 25 | size = 32768; 26 | array = { 27 | type = "SetAssoc"; 28 | ways = 8; 29 | }; 30 | latency = 4; 31 | }; 32 | 33 | l1i_beefy = { 34 | caches = 6; 35 | size = 32768; 36 | array = { 37 | type = "SetAssoc"; 38 | ways = 4; 39 | }; 40 | latency = 3; 41 | }; 42 | 43 | l2_beefy = { 44 | caches = 6; 45 | size = 262144; 46 | latency = 7; 47 | array = { 48 | type = "SetAssoc"; 49 | ways = 8; 50 | }; 51 | children = "l1i_beefy|l1d_beefy"; 52 | }; 53 | 54 | 55 | l1d_wimpy = { 56 | caches = 10; 57 | size = 8192; 58 | latency = 2; 59 | array = { 60 | type = "SetAssoc"; 61 | ways = 4; 62 | }; 63 | }; 64 | 65 | l1i_wimpy = { 66 | caches = 10; 67 | size = 16384; 68 | latency = 3; 69 | array = { 70 | type = "SetAssoc"; 71 | ways = 8; 72 | }; 73 | }; 74 | 75 | 76 | l3 = { 77 | caches = 1; 78 | banks = 6; 79 | size = 12582912; 80 | latency = 27; 81 | 82 | array = { 83 | type = "SetAssoc"; 84 | hash = "H3"; 85 | ways = 16; 86 | }; 87 | children = "l2_beefy l1i_wimpy|l1d_wimpy"; 88 | }; 89 | }; 90 | 91 | mem = { 92 | type = "DDR"; 93 | controllers = 4; 94 | tech = "DDR3-1066-CL8"; 95 | }; 96 | }; 97 | 98 | sim = { 99 | phaseLength = 10000; 100 | maxTotalInstrs = 5000000000L; 101 | statsPhaseInterval = 1000; 102 | printHierarchy = true; 103 | // attachDebugger = True; 104 | }; 105 | 106 | process0 = { 107 | command = "$ZSIMAPPSPATH/build/speccpu2006/401.bzip2/401.bzip2 $ZSIMAPPSPATH/inputs/speccpu2006/401.bzip2/ref/input.source 64"; 108 | }; 109 | 110 | process1 = { 111 | command = "$ZSIMAPPSPATH/build/parsec/blackscholes/blackscholes 15 2000000"; 112 | startFastForwarded = True; 113 | }; 114 | 115 | -------------------------------------------------------------------------------- /tests/hooks.cfg: -------------------------------------------------------------------------------- 1 | // Tests zsim hooks for different programming languages To build tests, run 2 | // make -j -C misc/hooks You can run the real tests with make -C misc/hooks 3 | // run_tests This uses logToFile because some JVMs need transparency (they fork 4 | // and use pipes, and writing to stdout/stderr breaks those pipes) 5 | 6 | sys = { 7 | cores = { 8 | c = { 9 | type = "Simple"; 10 | dcache = "l1d"; 11 | icache = "l1i"; 12 | }; 13 | }; 14 | 15 | lineSize = 64; 16 | 17 | caches = { 18 | l1d = { 19 | size = 65536; 20 | }; 21 | l1i = { 22 | size = 32768; 23 | }; 24 | l2 = { 25 | size = 2097152; 26 | children = "l1d|l1i"; 27 | }; 28 | }; 29 | }; 30 | 31 | sim = { 32 | logToFile = true; 33 | }; 34 | 35 | process0 = { 36 | command = "./misc/hooks/test_c"; 37 | startFastForwarded = True; 38 | syncedFastForward = False; 39 | }; 40 | 41 | process1 = { 42 | command = "./misc/hooks/test_cpp"; 43 | startFastForwarded = True; 44 | syncedFastForward = False; 45 | }; 46 | 47 | process2 = { 48 | command = "./misc/hooks/test_fortran"; 49 | startFastForwarded = True; 50 | syncedFastForward = False; 51 | }; 52 | 53 | process3 = { 54 | command = "java -cp ./misc/hooks -Djava.library.path=./misc/hooks test"; 55 | startFastForwarded = True; 56 | syncedFastForward = False; 57 | }; 58 | -------------------------------------------------------------------------------- /tests/pgo.cfg: -------------------------------------------------------------------------------- 1 | // Used for the PGO compile flow 2 | // based on zephyr3 L5640@2.27GHz 3 | 4 | process0 = { 5 | command = "$ZSIMAPPSPATH/build/speccpu2006/447.dealII/447.dealII 23"; 6 | }; 7 | 8 | sim = { 9 | maxTotalInstrs = 100000000L; 10 | phaseLength = 10000; 11 | statsPhaseInterval = 1; 12 | }; 13 | 14 | sys = { 15 | caches = { 16 | l1d = { 17 | array = { 18 | type = "SetAssoc"; 19 | ways = 8; 20 | }; 21 | caches = 1; 22 | latency = 4; 23 | size = 32768; 24 | }; 25 | 26 | l1i = { 27 | array = { 28 | type = "SetAssoc"; 29 | ways = 4; 30 | }; 31 | caches = 1; 32 | latency = 3; 33 | size = 32768; 34 | }; 35 | 36 | l2 = { 37 | array = { 38 | type = "SetAssoc"; 39 | ways = 8; 40 | }; 41 | caches = 1; 42 | latency = 7; 43 | children = "l1i|l1d"; 44 | size = 262144; 45 | }; 46 | 47 | l3 = { 48 | array = { 49 | hash = "H3"; 50 | type = "Z"; 51 | ways = 4; 52 | candidates = 52; 53 | }; 54 | banks = 6; 55 | caches = 1; 56 | latency = 27; 57 | children = "l2"; 58 | size = 12582912; 59 | }; 60 | }; 61 | 62 | cores = { 63 | westmere = { 64 | cores = 1; 65 | dcache = "l1d"; 66 | icache = "l1i"; 67 | type = "OOO"; 68 | }; 69 | }; 70 | 71 | frequency = 2270; 72 | lineSize = 64; 73 | mem = { 74 | controllers = 3; 75 | type = "DDR"; 76 | controllerLatency = 40; 77 | }; 78 | }; 79 | 80 | -------------------------------------------------------------------------------- /tests/ptree.cfg: -------------------------------------------------------------------------------- 1 | // Test nested processes 2 | 3 | sys = { 4 | cores = { 5 | nehalem = { 6 | type = "OOO"; 7 | cores = 2; 8 | //icache and dcache can be the same group, but are still split. 9 | //Even ones are i (l1-0 and 2), odd are d (l1-1 and 3) 10 | icache = "l1"; 11 | dcache = "l1"; 12 | }; 13 | }; 14 | 15 | caches = { 16 | l1 = { 17 | size = 65536; 18 | caches = 4; 19 | }; 20 | 21 | l2 = { 22 | caches = 1; 23 | size = 2097152; 24 | array = { 25 | ways = 16; 26 | hash = "H3"; 27 | }; 28 | children = "l1"; 29 | }; 30 | }; 31 | }; 32 | 33 | sim = { 34 | phaseLength = 10000; 35 | //attachDebugger = True; //this would be madness :) 36 | }; 37 | 38 | // NOTE: This is useful when you spawn multiple processes that create other 39 | // processes --- they are assigned in tree order. However, at this point if you 40 | // don't specify any subprocesses, the simulation will work (but process ids 41 | // are assigned in FCFS order, which is non-deterministic, and the children will 42 | // inherit the parent's configuration). 43 | process0 = { //bash 44 | command = "bash -c \"bash -c '/bin/echo Foo | cat; sleep 2 ; echo Bar' | cat | cat \""; 45 | process0 = { //bash 46 | process0 = { // /bin/echo 47 | }; 48 | process1 = { //cat 49 | }; 50 | process2 = { //sleep 51 | }; 52 | process3 = { //echo (actually, when you call echo in bash, it's just a fork, it doesn't exec echo) 53 | }; 54 | }; 55 | process1 = { //cat 56 | }; 57 | process2 = { //cat 58 | }; 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /tests/simple.cfg: -------------------------------------------------------------------------------- 1 | // As simple as it gets: 1-core system with 2 short processes 2 | 3 | sys = { 4 | cores = { 5 | simpleCore = { 6 | type = "Simple"; 7 | dcache = "l1d"; 8 | icache = "l1i"; 9 | }; 10 | }; 11 | 12 | lineSize = 64; 13 | 14 | caches = { 15 | l1d = { 16 | size = 65536; 17 | }; 18 | l1i = { 19 | size = 32768; 20 | }; 21 | l2 = { 22 | caches = 1; 23 | size = 2097152; 24 | children = "l1i|l1d"; // interleave 25 | }; 26 | }; 27 | }; 28 | 29 | sim = { 30 | phaseLength = 10000; 31 | // attachDebugger = True; 32 | schedQuantum = 50; // switch threads frequently 33 | procStatsFilter = "l1.*|l2.*"; 34 | pinOptions = "-injection child -ifeellucky"; 35 | }; 36 | 37 | process0 = { 38 | command = "ls -alh --color tests/"; 39 | }; 40 | 41 | 42 | process1 = { 43 | command = "cat tests/simple.cfg"; 44 | }; 45 | 46 | --------------------------------------------------------------------------------