├── .clang-format ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── SConstruct ├── Vagrantfile.sample ├── doc ├── DevGuide.mdown └── UserGuide.mdown ├── misc ├── build_compilation_db.py ├── flatten_tree.sh ├── gitver.py ├── lint_includes.py └── report_coverage.sh ├── provenance ├── provision.sh ├── sample.cfg ├── scripts ├── anl.py ├── configs.py ├── genConfigs.py ├── graphEnqueues.py ├── loadProfile.py ├── mt_anl.py ├── parseTrace.py ├── simConfig.py ├── taskTimeline.py └── trace.py ├── sim ├── SConscript ├── alloc │ ├── alloc.cpp │ ├── alloc.h │ ├── dlmalloc.h.c │ ├── untracked.cpp │ └── untracked.h ├── assert.h ├── atomic_port.h ├── bit_window.h ├── bithacks.h ├── bloom │ ├── bf_partitioned.h │ ├── bloom_filter.h │ ├── custom_hash.h │ └── h3array.h ├── canary.h ├── collections │ ├── enum.h │ ├── ordered_set.h │ └── prio_queue.h ├── commitqueue.cpp ├── commitqueue.h ├── conflicts │ ├── abort_handler.cpp │ ├── abort_handler.h │ ├── address_accessors.h │ ├── bloom_address_accessors.cpp │ ├── bloom_address_accessors.h │ ├── conflict_detection.h │ ├── conflict_resolution.h │ ├── llc_cd.cpp │ ├── llc_cd.h │ ├── precise_address_accessors.cpp │ ├── precise_address_accessors.h │ ├── stallers.h │ ├── sticky_directory.h │ ├── terminal_cd.cpp │ ├── terminal_cd.h │ ├── tile_cd.cpp │ ├── tile_cd.h │ └── unstallers.h ├── core │ ├── core.cpp │ ├── core.h │ ├── core_context.cpp │ ├── core_context.h │ ├── core_structures.h │ ├── decoder.cpp │ ├── decoder.h │ ├── ooo_core.cpp │ ├── ooo_core.h │ ├── sbcore.cpp │ ├── sbcore.h │ └── task_to_core_stats_profiler.h ├── domainprofiler.cpp ├── domainprofiler.h ├── driver.cpp ├── driver.h ├── event.h ├── ff_queue.cpp ├── ff_queue.h ├── gvt_arbiter.cpp ├── gvt_arbiter.h ├── harness │ ├── debug.in │ └── sim.in ├── init │ ├── build_cache.cpp │ ├── build_conflicts.cpp │ ├── build_memory_controller.cpp │ ├── builders.h │ ├── config.cpp │ ├── config.h │ ├── configure_stream_prefetchers.cpp │ ├── init.cpp │ └── init.h ├── interactive.cpp ├── interactive.h ├── load.h ├── loadstatssummary.cpp ├── loadstatssummary.h ├── locks.h ├── log.cpp ├── log.h ├── make_unique.h ├── match.h ├── memory │ ├── cache.cpp │ ├── cache.h │ ├── cache_arrays.cpp │ ├── cache_arrays.h │ ├── coherence_ctrls.cpp │ ├── coherence_ctrls.h │ ├── constants.h │ ├── filter_cache.h │ ├── hash.cpp │ ├── hash.h │ ├── mem_ctrls.cpp │ ├── mem_ctrls.h │ ├── memory_hierarchy.cpp │ ├── memory_hierarchy.h │ ├── memory_partition.h │ ├── repl_policies.h │ ├── stream_prefetcher.cpp │ └── stream_prefetcher.h ├── network.cpp ├── network.h ├── network_msg_types.h ├── object.h ├── overflow_watcher.h ├── pad.h ├── performance_metrics.h ├── port.h ├── rob.cpp ├── rob.h ├── rob_stats_collector.h ├── robtypes.h ├── run_condition.h ├── sim.cpp ├── sim.h ├── spin_cv.cpp ├── spin_cv.h ├── stack.h ├── stats │ ├── breakdown_stat.h │ ├── clock_stat.h │ ├── hdf5_stats.cpp │ ├── set_stat.h │ ├── stats.h │ ├── table_stat.cpp │ ├── table_stat.h │ └── text_stats.cpp ├── str.h ├── task.cpp ├── task.h ├── task_balancer.h ├── task_mapper.cpp ├── task_mapper.h ├── taskloadprofiler.cpp ├── taskloadprofiler.h ├── taskobserver.h ├── taskprofiler.h ├── taskprofilingsummary.cpp ├── taskprofilingsummary.h ├── taskptr.h ├── test │ ├── SConscript │ ├── address_accessors_test.cpp │ ├── aligned_uint64_t_test.cpp │ ├── bf_partitioned_test.cpp │ ├── gvt_arbiter_epoch_test.cpp │ ├── memory_hierarchy_test.cpp │ ├── ordered_set_intp_test.cpp │ ├── stack_segments_test.cpp │ ├── table_stat_test.cpp │ └── timestamp_test.cpp ├── thread.cpp ├── thread.h ├── thread_count_controller.cpp ├── thread_count_controller.h ├── thread_throttler.cpp ├── thread_throttler.h ├── timestamp.cpp ├── timestamp.h ├── trace.cpp ├── trace.h ├── tsarray.h ├── tsb.h ├── types.h ├── undo_log.cpp ├── undo_log.h ├── virt │ ├── virt.cpp │ └── virt.h ├── watchdog.cpp ├── watchdog.h ├── zoom_requester.cpp └── zoom_requester.h └── tests ├── SConscript ├── bfs.cpp ├── busy_waiting_after_roi.cpp ├── call_nullptr.cpp ├── childless_after_exception.cpp ├── common.h ├── concurrent_malloc.cpp ├── counter.cpp ├── counter.h ├── counter_spatial.cpp ├── counter_spatial_collide.cpp ├── cps.cpp ├── deadlock.cpp ├── deepen_chain.cpp ├── deepen_fanout_serial.cpp ├── dereference_ffff.cpp ├── enqueue_all_whints.cpp ├── enqueue_race.cpp ├── enqueue_to_parent.cpp ├── exception.cpp ├── fill.cpp ├── fractal.cpp ├── fractal_deadlock.cpp ├── get_ts.cpp ├── get_ts_super.cpp ├── heartbeats.cpp ├── in_ff.c ├── interleave.cpp ├── invalid_ts.cpp ├── large_heap.cpp ├── list.cpp ├── load_balance ├── .gitignore ├── SConscript ├── chain.cpp ├── hash.cpp └── hash.h ├── malloc.cpp ├── malloc_unimplemented.cpp ├── many_read_syscalls.cpp ├── memalign.cpp ├── multi_hint_rw_mayspec.cpp ├── nohint_cas_mayspec.cpp ├── notimestamp.cpp ├── overwrite.h ├── overwrite_dlmalloc_metadata.cpp ├── overwrite_spill_buffers.cpp ├── overwrite_undologs.cpp ├── pingpong.cpp ├── precede_stallers.cpp ├── precede_waiters.cpp ├── priv.cpp ├── rand.cpp ├── read_file.cpp ├── realloc.cpp ├── reduce.cpp ├── reducible_counter.cpp ├── reduction.cpp ├── reduction.h ├── reduction_hint.cpp ├── register_end_handler.cpp ├── roi_exit.cpp ├── run_all.py ├── segfault.cpp ├── serialize.cpp ├── set_gvt.cpp ├── simguard.cpp ├── snprintf.cpp ├── some_non_serializing_hints.cpp ├── statscheck.py ├── stream.cpp ├── syscall.cpp ├── taskbomb.cpp ├── taskbomb_deepen.cpp ├── taskbomb_tied.cpp ├── threadlocal.cpp ├── tileId.cpp ├── transform.cpp ├── undeepen.cpp ├── undo_after_exception.cpp └── variadic.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 4 3 | AccessModifierOffset: -2 4 | AlwaysBreakTemplateDeclarations: false 5 | 6 | # Mark liked to have two blank lines between functions 7 | MaxEmptyLinesToKeep: 2 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | 9 | # Compiled Static libraries 10 | *.lai 11 | *.la 12 | *.a 13 | 14 | # LLVM IR 15 | *.ll 16 | *.bc 17 | 18 | # Compiled Python bytecode 19 | *.pyc 20 | 21 | # index files generated by Ctags or Etags 22 | tags 23 | TAGS 24 | 25 | # User's custom project- or directory-specific editor configs 26 | .vimrc 27 | .vscode 28 | 29 | # The user is epected to customize their own Vagrantfile 30 | Vagrantfile 31 | 32 | # Output files from local simulation runs 33 | *.out 34 | *.h5 35 | *.log 36 | heartbeat 37 | out.cfg 38 | # Simulator may generate the following files in the event of a failure 39 | memory_map 40 | perf.data 41 | 42 | # Additional output files generated by scripts based on simulation data 43 | *.png 44 | enqueue_graph.gv 45 | 46 | *.svn 47 | 48 | /.sconf_temp/ 49 | /.sconsign.dblite 50 | 51 | # build, which is generated by scons 52 | /build 53 | 54 | # Generated by /misc/build_compilation_database.py 55 | /compile_commands.json 56 | 57 | # Configs directory generated by /scripts/configs.py 58 | /configs/ 59 | # Also ignore manually moved or edited configs in the root directory 60 | /*configs*/ 61 | /*.cfg 62 | !/sample.cfg 63 | 64 | # Temp files created by most text editors. 65 | *~ 66 | # vim swap files 67 | .*.sw? 68 | .sw? 69 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libspin"] 2 | path = libspin 3 | url = https://github.com/SwarmArch/libspin.git 4 | [submodule "plsalloc"] 5 | path = plsalloc 6 | url = https://github.com/SwarmArch/plsalloc.git 7 | [submodule "runtime"] 8 | path = runtime 9 | url = https://github.com/SwarmArch/runtime.git 10 | [submodule "googletest"] 11 | path = googletest 12 | url = https://github.com/SwarmArch/googletest.git 13 | branch = v1.10.x 14 | -------------------------------------------------------------------------------- /Vagrantfile.sample: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.require_version ">= 2.1.3" 5 | 6 | VAGRANTFILE_API_VERSION = "2" 7 | 8 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 9 | # From the docs, use bento boxes 10 | # https://www.vagrantup.com/docs/boxes.html 11 | # "It is often a point of confusion, but Canonical (the company that makes the 12 | # Ubuntu operating system) publishes boxes under the "ubuntu" namespace on 13 | # Atlas. These boxes only support Virtualbox and do not provide an ideal 14 | # experience for most users. If you encounter issues with these boxes, please 15 | # try the Bento boxes instead." 16 | config.vm.box = "bento/ubuntu-18.04" 17 | config.vm.hostname = "swarm" 18 | 19 | config.vm.provider "hyperv" do |hv, override| 20 | #hv.cpus = 6 21 | #hv.maxmemory = 12288 22 | end 23 | 24 | config.vm.provider "virtualbox" do |vb, override| 25 | #vb.cpus = 6 26 | #vb.memory = 12288 27 | # While recent versions of VirtualBox enable SSE4 passthrough by default, 28 | # explicitly enabling it is required for older versions 29 | vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"] 30 | vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"] 31 | # If you see issues with guest additions needed for shared folders, uncomment this line: 32 | #override.vagrant.plugins = ["vagrant-vbguest"] 33 | end 34 | 35 | config.vm.provision :shell, path: 'provision.sh' 36 | 37 | # Write lines like this to make directories on your host machine accessible 38 | # within the VM: 39 | #config.vm.synced_folder "/path/on/host/to/benchmarks/", "/benchmarks" 40 | end 41 | -------------------------------------------------------------------------------- /misc/build_compilation_db.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Builds a clang compilation database from the output of scons. Use with: 4 | # scons -n --clang | ./misc/build_compilation_db.py 5 | # 6 | # CAVEAT: Trivial, but tuned to our build process. So for now don't expect 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | import json, os, sys 10 | 11 | directory = os.path.abspath(".") 12 | db = [] 13 | 14 | for line in sys.stdin: 15 | if line.startswith("clang") and ' -c ' in line: 16 | line = line.strip() 17 | entry = { "directory" : directory, "command" : line, "file" : line.split(" ")[-1] } 18 | db.append(entry) 19 | 20 | dbfilename = "compile_commands.json" 21 | dbfile = open(dbfilename, "w") 22 | print(json.dumps(db, indent=1), file=dbfile) 23 | dbfile.close() 24 | -------------------------------------------------------------------------------- /misc/flatten_tree.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # dsm: Flatten the source tree... I'm tired of the extra keystrokes and this org messes up with my muscle memory 3 | 4 | mkdir -p src/ 5 | find sim -name "*.h" | sort | xargs -n1 -IX ln -s `pwd`/X src/ 6 | find sim -name "*.cpp" | sort | xargs -n1 -IX ln -s `pwd`/X src/ 7 | -------------------------------------------------------------------------------- /misc/gitver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Return a pretty-printed short git version (like hg/svnversion) 3 | from __future__ import (absolute_import, division, print_function) 4 | import os 5 | def cmd(c): return os.popen(c).read().strip() 6 | branch = cmd("git rev-parse --abbrev-ref HEAD") 7 | revnum = cmd("git log | grep ^commit | wc -l") 8 | rshort = cmd("git rev-parse --short HEAD") 9 | dfstat = cmd("git diff HEAD --shortstat") 10 | dfhash = cmd("git diff HEAD | md5sum")[:8] 11 | shstat = dfstat.replace(" files changed", "fc").replace(" file changed", "fc") \ 12 | .replace(" insertions(+)", "+").replace(" insertion(+)", "+") \ 13 | .replace(" deletions(-)", "-").replace(" deletion(-)", "-") \ 14 | .replace(",", "") 15 | diff = "clean" if len(dfstat) == 0 else shstat + " " + dfhash 16 | print(":".join([branch, revnum, rshort, diff])) 17 | -------------------------------------------------------------------------------- /misc/report_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Prereqs: gcov and lcov installed 4 | 5 | # Usage: 6 | # 1. Compile simulator with scons mode=cov 7 | # 2. Run lcov --base-directory . --directory . --zerocounters to clear all gcov files 8 | # 3. Run tests (preferably with several config files); gcov is multiprocess-safe 9 | # 4. Run this script 10 | 11 | lcov --rc lcov_branch_coverage=1 --base-directory . --directory build/cov/sim/ -c -o coverage.info 12 | lcov --rc lcov_branch_coverage=1 --remove coverage.info "/data/sanchez/*" -o coverage.info 13 | lcov --rc lcov_branch_coverage=1 --remove coverage.info "/usr*" -o coverage.info 14 | genhtml --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 -o lcov_html -t "simulator coverage" --num-spaces 4 coverage.info 15 | rm coverage.info 16 | -------------------------------------------------------------------------------- /provenance: -------------------------------------------------------------------------------- 1 | public-github:5380:cee2b129:clean 2 | -------------------------------------------------------------------------------- /provision.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | apt-get -yq update 6 | 7 | apt-get -yq install software-properties-common # for add-apt-repository 8 | apt-get -yq install build-essential 9 | apt-get -yq install make g++ 10 | apt-get -yq install python 11 | apt-get -yq install libreadline-dev 12 | apt-get -yq install pypy pypy-six 13 | apt-get -yq install git 14 | apt-get -yq install gdb 15 | apt-get -yq install linux-tools-common # for perf 16 | apt-get -yq install cmake ninja-build # for building SCC 17 | 18 | apt-get -yq install libconfig++-dev 19 | apt-get -yq install libhdf5-serial-dev 20 | apt-get -yq install libboost-dev 21 | apt-get -yq install libarmadillo-dev 22 | 23 | apt-get -yq install python3-pip 24 | pip3 install SCons 25 | 26 | # Benchmarks/tests can be linked with other allocators, like tcmalloc 27 | apt-get -yq install libtcmalloc-minimal4 28 | # The following symlink is not part of the libtcmalloc-minimal4 Debian package, 29 | # but is in libgoogle-perftools-dev. We don't need the rest of perftools, so 30 | # let's just create this symlink ourselves. 31 | # This is how we can get GCC to find -ltcmalloc_minimal 32 | ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so 33 | 34 | # Make multiple versions of GCC available for testing 35 | # Ubuntu 14.04 LTS shipped with GCC 4.8, which may give you a better 36 | # chance of ABI compatibility with Pin 2.14. 37 | apt-get -yq install g++-4.8 38 | # Ubuntu 16.04 LTS shipped with GCC 5 39 | apt-get -yq install g++-5 40 | # Ubuntu 18.04 LTS shipped with GCC 7 41 | apt-get -yq install g++-7 # Should be already be installed as dependency of g++ 42 | # Ubuntu 20.04 LTS shipped with GCC 9 43 | add-apt-repository -y ppa:ubuntu-toolchain-r/test 44 | apt-get -yq update 45 | apt-get -yq install g++-9 46 | 47 | VMUSER="vagrant" 48 | HOME="/home/${VMUSER}" 49 | 50 | PINDIR="pin-2.14-71313-gcc.4.4.7-linux" 51 | wget --no-verbose --no-clobber http://software.intel.com/sites/landingpage/pintool/downloads/${PINDIR}.tar.gz 52 | tar zxf ${PINDIR}.tar.gz -C /opt/ 53 | chown -R ${VMUSER} /opt/${PINDIR} 54 | # If in a VM that is only used for Swarm experiments, no need to be paranoid 55 | # about security, so globally enable classic (lax) ptrace permissions 56 | echo 0 > /proc/sys/kernel/yama/ptrace_scope 57 | echo "kernel.yama.ptrace_scope = 0" > /etc/sysctl.d/90-ptrace.conf 58 | 59 | function appendToFileUniquely { 60 | STRING=$1 61 | FILE=$2 62 | #http://stackoverflow.com/a/13027535 63 | if ! grep -qe "^${STRING}$" ${FILE}; then 64 | echo ${STRING} >> $FILE 65 | fi 66 | } 67 | 68 | appendToFileUniquely "export PINPATH=/opt/${PINDIR}" ${HOME}/.bashrc 69 | 70 | # Install enough to run microbenchmarks with run_all.py under Python 2 71 | apt-get -yq install python-pip 72 | pip install 'numpy<1.17' # NumPy supported Python 2 through 1.16.x 73 | pip install h5py 74 | pip install libconf 75 | 76 | # To run orig_silo from the simulator's VM, install db++-dev 77 | # (but unfortunately orig_silo still doesn't run to completion in the VM) 78 | apt-get -yq install libdb++-dev 79 | -------------------------------------------------------------------------------- /scripts/graphEnqueues.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/pypy -u 2 | from __future__ import (absolute_import, division, print_function) 3 | 4 | import argparse 5 | import collections 6 | try: 7 | import graphviz as gv 8 | except ImportError: 9 | gv = None 10 | 11 | import parseTrace 12 | 13 | 14 | if __name__ == "__main__": 15 | parser = argparse.ArgumentParser() 16 | parser.add_argument("-t", "--trace", type=str, default="trace.out", 17 | help="trace file") 18 | parser.add_argument("--aborted", default=False, action='store_true', 19 | help="graph aborted tasks instead of committed ones (helps analyze aborts)") 20 | args = parser.parse_args() 21 | 22 | tasks, _ = parseTrace.getTasks(args.trace) 23 | print("Trace read") 24 | 25 | # Build enqueue graph 26 | taskFns = set() 27 | taskEnqueues = {} 28 | for t in tasks[1:]: 29 | if t.outcomeCycle == -1: continue # partial trace 30 | taskFns.add(t.taskFn) 31 | isCommit = t.outcome[0] == "Commit" 32 | if isCommit == args.aborted: continue 33 | parentFn = tasks[t.parent].taskFn if t.parent else None 34 | if parentFn not in taskEnqueues: 35 | taskEnqueues[parentFn] = collections.Counter() 36 | taskEnqueues[parentFn][t.taskFn] += 1 37 | taskFns = sorted(taskFns) 38 | 39 | print("\nEnqueues") 40 | print("%16s %s" % ("Parent\Child PC", ' '.join("%16x" % child for child in taskFns))) 41 | print("%16s %s" % ("No parent", ' '.join( 42 | "%16d" % taskEnqueues[None][child] for child in taskFns))) 43 | for parent in taskFns: 44 | if parent in taskEnqueues: 45 | print("%16s %s" % ("%16x" % parent, ' '.join( 46 | "%16d" % taskEnqueues[parent][child] for child in taskFns))) 47 | 48 | if gv: 49 | graph = gv.Digraph(format="png") 50 | for child in taskFns: 51 | if taskEnqueues[None][child]: 52 | graph.edge("No parent", format(child, 'x'), 53 | label=str(taskEnqueues[0][child])) 54 | for parent in taskFns: 55 | if parent in taskEnqueues: 56 | for child in taskFns: 57 | if taskEnqueues[parent][child]: 58 | graph.edge(format(parent, 'x'), format(child, 'x'), 59 | label=str(taskEnqueues[parent][child])) 60 | graph.render("enqueue_graph.gv", view=False) 61 | print("enqueue_graph.gv.png written.") 62 | else: 63 | print("graphviz not found") 64 | -------------------------------------------------------------------------------- /sim/alloc/untracked.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/alloc/alloc.h" 27 | #include 28 | #include 29 | #include 30 | #include "sim/assert.h" 31 | #include "sim/log.h" 32 | #include "sim/pad.h" 33 | #include "sim/sim.h" 34 | 35 | #define DLMALLOC_BASEADDR (ALLOC_UNTRACKED_BASEADDR) 36 | #include "sim/alloc/dlmalloc.h.c" 37 | 38 | #undef DEBUG 39 | #define DEBUG(args...) //info(args) 40 | 41 | static std::vector allocPools; 42 | 43 | void InitUntrackedAllocPools(uint32_t numCores) { 44 | allocPools.resize(numCores); 45 | DEBUG("[alloc] allocPools.data()=%p", allocPools.data()); 46 | for (uint32_t i = 0; i < numCores; i++) { 47 | allocPools[i] = create_mspace(0, 0); 48 | DEBUG("[alloc] allocPools[%d]=%p", i, allocPools[i]); 49 | } 50 | } 51 | 52 | // Memory always cleared & cache-aligned, so we can route malloc, calloc, and memalign variants thru 53 | void* untracked_alloc(size_t minSz) { 54 | // Select pool based on current core, or 0 if invalid 55 | uint32_t tid = GetCurTid(); 56 | uint32_t pool = (tid == INVALID_TID)? 0 : GetCoreIdx(tid); 57 | assert(pool < allocPools.size()); 58 | 59 | // [mcj] if minSz is a multiple of CACHE_LINE_BYTES, then doesn't this 60 | // allocate one cache line too many? 61 | size_t sz = minSz + CACHE_LINE_BYTES - ((minSz) % CACHE_LINE_BYTES); 62 | void* ptr = mspace_memalign(allocPools[pool], CACHE_LINE_BYTES, sz); 63 | assert(ptr); 64 | memset(ptr, 0, sz); 65 | assert(isUntrackedAddress(ptr)); 66 | //info("[alloc] pool %4d size %8ld - %p", pool, sz, ptr); 67 | return ptr; 68 | } 69 | 70 | void untracked_dealloc(void* ptr) { 71 | assert(isUntrackedAddress(ptr)); 72 | mspace_free(allocPools[0], ptr); 73 | } 74 | -------------------------------------------------------------------------------- /sim/alloc/untracked.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | // NOTE(dsm): This file should not be included by anything other than 28 | // alloc.cpp. These are raw methods for the untracked pool. 29 | 30 | #include 31 | #include 32 | 33 | void InitUntrackedAllocPools(uint32_t numCores); 34 | void* untracked_alloc(size_t minSz); 35 | void untracked_dealloc(void* ptr); 36 | -------------------------------------------------------------------------------- /sim/atomic_port.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | /* General request-reply port interface */ 31 | template class AtomicPort { 32 | public: 33 | typedef T req_type; 34 | typedef R resp_type; 35 | // Returns response cycle 36 | // FIXME(mcj) a very cache-centric name. 37 | virtual uint64_t access(T& req, R& resp, uint64_t cycle) = 0; 38 | }; 39 | 40 | 41 | -------------------------------------------------------------------------------- /sim/bloom/bloom_filter.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | namespace bloom { 31 | 32 | using hash_t = uint32_t; 33 | 34 | template 35 | class BloomFilter { 36 | public: 37 | virtual void insert(T val) = 0; 38 | virtual bool contains(T val) const = 0; 39 | virtual bool union(const BloomFilter& rhs) = 0; 40 | virtual void clear() = 0; 41 | }; 42 | 43 | } // namespace bloom 44 | -------------------------------------------------------------------------------- /sim/bloom/custom_hash.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | class Custom64To32Hash { 31 | public: 32 | Custom64To32Hash() {} 33 | 34 | __attribute__((always_inline)) 35 | uint32_t operator()(uint64_t key) const { 36 | return hashint(fullAvalanche(hash6432shift(key))); 37 | } 38 | 39 | private: 40 | // Source: https://gist.github.com/badboy/6267743 41 | uint32_t hash6432shift(uint64_t key) const { 42 | key = (~key) + (key << 18); // key = (key << 18) - key - 1; 43 | key = key ^ (key >> 31); 44 | key = key * 21; // key = (key + (key << 2)) + (key << 4); 45 | key = key ^ (key >> 11); 46 | key = key + (key << 6); 47 | key = key ^ (key >> 22); 48 | return (uint32_t) key; 49 | } 50 | 51 | // Source: http://burtleburtle.net/bob/hash/integer.html 52 | uint32_t fullAvalanche(uint32_t a) const { 53 | a = (a+0x7ed55d16) + (a<<12); 54 | a = (a^0xc761c23c) ^ (a>>19); 55 | a = (a+0x165667b1) + (a<<5); 56 | a = (a+0xd3a2646c) ^ (a<<9); 57 | a = (a+0xfd7046c5) + (a<<3); 58 | a = (a^0xb55a4f09) ^ (a>>16); 59 | return a; 60 | } 61 | 62 | uint32_t hashint(uint32_t a) const { 63 | a -= (a<<6); 64 | a ^= (a>>17); 65 | a -= (a<<9); 66 | a ^= (a<<4); 67 | a -= (a<<3); 68 | a ^= (a<<10); 69 | a ^= (a>>15); 70 | return a; 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /sim/commitqueue.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/commitqueue.h" 27 | #include "sim/assert.h" 28 | #include "sim/log.h" 29 | 30 | #undef DEBUG 31 | #define DEBUG(args...) //infos(args) 32 | 33 | CommitQueueAdmissionPolicy stringToCQAdmissionPolicy(std::string str) { 34 | if (str == "Any") return CommitQueueAdmissionPolicy::ANY; 35 | if (str == "All") return CommitQueueAdmissionPolicy::ALL; 36 | if (str == "Half") return CommitQueueAdmissionPolicy::HALF; 37 | 38 | panic("Invalid CommitQueueAdmissionPolicy config %s", str.c_str()); 39 | } 40 | 41 | CommitQueue::CommitQueue(uint32_t capacity, CommitQueueAdmissionPolicy policy) 42 | : CommitQ_ty(capacity), admission(policy, *this), eviction(*this) { } 43 | 44 | 45 | TaskPtr CommitQueue::replacementCandidateFor(const Task& incoming) const { 46 | if (admission.accepts(incoming)) { 47 | return eviction.candidate(incoming); 48 | } else { 49 | return nullptr; 50 | } 51 | } 52 | 53 | bool Admission::accepts(const Task& incoming) const { 54 | assert(!cq.empty()); 55 | const Task* incumbent; 56 | switch(policy) { 57 | case CommitQueueAdmissionPolicy::ANY: 58 | incumbent = cq.max().get(); break; 59 | case CommitQueueAdmissionPolicy::ALL: 60 | incumbent = cq.min().get(); break; 61 | case CommitQueueAdmissionPolicy::HALF: 62 | { 63 | auto median = std::next(cq.cbegin(), cq.size() / 2); 64 | incumbent = (*median).get(); break; 65 | } 66 | default: 67 | panic("Invalid CommitQueueAdmission policy"); 68 | } 69 | DEBUG("CQ admission incoming %s incumbent %s", 70 | incoming.toString().c_str(), incumbent->toString().c_str()); 71 | return incoming.ts < incumbent->ts; 72 | } 73 | -------------------------------------------------------------------------------- /sim/conflicts/conflict_resolution.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | #include "sim/atomic_port.h" 31 | #include "sim/taskptr.h" 32 | 33 | // Start with child aborts. They are always in the network. 34 | // The corrective writes of the undo log are difficult for two reasons: 35 | // 1) The invalidations for a write that happens from the core 36 | // are already in the network via the memory hierarchy. 37 | // 2) The corrective writer may already have the line cached, which would 38 | // greatly reduce the latency and bandwidth requirement. Do I probe the 39 | // nearby L2? 40 | 41 | struct AbortReq { 42 | TaskPtr task; 43 | uint32_t tileIdx; 44 | uint32_t depth; // Depth in the abort cascade 45 | 46 | // * Child's Task Queue index: 8 to 10 bits, 47 | // plus some way to uniquely identify the child (in case it committed) 48 | // * Parent's Task Queue index: 8 to 10 bits, 49 | // since the receiving tile must send an AbortAck to the right tile, and 50 | // the child doesn't store its parent's TQ index, only an isTied bit. 51 | uint32_t bytes() const { 52 | return 2 /* child TQ */ 53 | + 2; /* parent TQ */ 54 | } 55 | }; 56 | 57 | struct AbortAck { 58 | // Parent's Task Queue index: 8 to 10 bits. 59 | uint32_t bytes() const { return 2; } 60 | uint32_t bytes(const AbortReq&) const { return bytes(); } 61 | }; 62 | 63 | using ChildAbortPort = AtomicPort; 64 | -------------------------------------------------------------------------------- /sim/conflicts/llc_cd.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/assert.h" 27 | 28 | #include "sim/conflicts/llc_cd.h" 29 | 30 | LLCCD::LLCCD() : sdReaders_("llc-sd-readers"), sdWriters_("llc-sd-writers") {} 31 | 32 | uint64_t LLCCD::access(const MemReq& req, uint64_t cycle) { 33 | if (IsPut(req.type)) { 34 | if (req.is(MemReq::TRACKREAD)) { 35 | sdReaders_.add(req.lineAddr, req.childId); 36 | } else { 37 | sdReaders_.remove(req.lineAddr, req.childId); 38 | } 39 | if (req.is(MemReq::TRACKWRITE)) { 40 | sdWriters_.add(req.lineAddr, req.childId); 41 | } else { 42 | sdWriters_.remove(req.lineAddr, req.childId); 43 | } 44 | } 45 | return cycle; 46 | } 47 | 48 | uint64_t LLCCD::invalidated(uint32_t childId, const InvReq& req, 49 | const InvResp& resp, uint64_t cycle) { 50 | if (resp.is(InvResp::TRACKREAD)) { 51 | sdReaders_.add(req.lineAddr, childId); 52 | } else { 53 | sdReaders_.remove(req.lineAddr, childId); 54 | } 55 | if (resp.is(InvResp::TRACKWRITE)) { 56 | sdWriters_.add(req.lineAddr, childId); 57 | } else { 58 | sdWriters_.remove(req.lineAddr, childId); 59 | } 60 | return cycle; 61 | } 62 | 63 | std::bitset LLCCD::sharers(Address lineAddr, bool checkReaders) const { 64 | auto s = sdWriters_.getSharers(lineAddr); 65 | if (checkReaders) s |= sdReaders_.getSharers(lineAddr); 66 | return s; 67 | } 68 | 69 | bool LLCCD::giveExclusive(const MemReq& req) const { 70 | auto stickySharers = sharers(req.lineAddr, true); 71 | stickySharers[req.childId] = 0; 72 | return stickySharers.none(); 73 | } 74 | -------------------------------------------------------------------------------- /sim/conflicts/llc_cd.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include "sim/conflicts/conflict_detection.h" 29 | #include "sim/conflicts/sticky_directory.h" 30 | 31 | class StickyDirectory; 32 | 33 | class LLCCD : public ConflictDetectionTop, public ConflictDetectionBottom { 34 | StickyDirectory sdReaders_; 35 | StickyDirectory sdWriters_; 36 | 37 | public: 38 | LLCCD(); 39 | 40 | // Top interface 41 | uint64_t invalidated(uint32_t, const InvReq&, const InvResp&, 42 | uint64_t) override; 43 | std::bitset sharers(Address, bool) const override; 44 | bool giveExclusive(const MemReq& req) const override; 45 | 46 | // Bottom interface: silences incoming conflict-checked MemReqs 47 | uint64_t access(const MemReq&, uint64_t cycle) override; 48 | }; 49 | -------------------------------------------------------------------------------- /sim/domainprofiler.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/domainprofiler.h" 27 | #include "sim/stats/set_stat.h" 28 | #include "sim/task.h" 29 | #include "sim/taskobserver.h" 30 | 31 | static bool initialized = false; 32 | static SetStat created, started, committed; 33 | 34 | void InitDomainProfiling(AggregateStat* rootStat, uint32_t minBits, 35 | uint32_t maxBits, uint32_t bitsPerStep) { 36 | initialized = true; 37 | AggregateStat* dp = new AggregateStat(false); 38 | dp->init("domains", "System-wide domain stats"); 39 | 40 | auto initSetStat = [&](SetStat& s, const char* name, 41 | const char* desc) { 42 | s.init(name, desc, minBits, maxBits, bitsPerStep); 43 | dp->append(&s); 44 | }; 45 | initSetStat(created, "created", "Domains of created tasks"); 46 | initSetStat(started, "started", "Domains of started tasks"); 47 | initSetStat(committed, "committed", "Domains of committed tasks"); 48 | 49 | rootStat->append(dp); 50 | } 51 | 52 | bool profileDomains() { return initialized; } 53 | 54 | class DomainProfiler : public TaskObserver { 55 | private: 56 | uint64_t id; 57 | public: 58 | DomainProfiler(uint64_t id) : id(id) {} 59 | void start(ThreadID tid) override { started.push(id); } 60 | void commit() override { committed.push(id); } 61 | }; 62 | 63 | std::unique_ptr createDomainProfiler(const Task& task) { 64 | assert(initialized); 65 | uint64_t id = task.lts().domainId(); 66 | created.push(id); 67 | return std::make_unique(id); 68 | } 69 | -------------------------------------------------------------------------------- /sim/domainprofiler.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | class AggregateStat; 31 | class Task; 32 | class TaskObserver; 33 | 34 | // Need not be called; stats only dumped if this is called 35 | void InitDomainProfiling(AggregateStat* rootStat, uint32_t minBits, 36 | uint32_t maxBits, uint32_t bitsPerStep); 37 | 38 | bool profileDomains(); 39 | std::unique_ptr createDomainProfiler(const Task& task); 40 | -------------------------------------------------------------------------------- /sim/driver.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | 28 | #include "sim/sim.h" 29 | #include "sim/thread.h" 30 | #include "spin.h" 31 | 32 | // NOTE: Include this from sim.cpp only. driver.cpp and sim.cpp are fairly 33 | // tightly integrated (they started as a single file), but only a tiny fraction 34 | // of the driver code is visible to other entities. 35 | 36 | spin::ThreadId NextThread(); 37 | std::tuple SwitchThread(spin::ThreadId tid); 38 | spin::ThreadId PreventFfStarvation(spin::ThreadId tid); 39 | 40 | void Capture(spin::ThreadId tid, bool runsNext); 41 | spin::ThreadId Uncapture(spin::ThreadId tid, spin::ThreadContext* tc); 42 | void BlockThreadAfterSwitch(ExecState state); 43 | void BlockThread(uint32_t tid, ExecState state); // works for curThread too 44 | void UnblockThread(uint32_t tid, uint64_t cycle); 45 | 46 | void ThreadStart(spin::ThreadId tid); 47 | void ThreadFini(spin::ThreadId tid); 48 | 49 | uint32_t GetCurTid(); 50 | ThreadState* GetCurThread(); 51 | ThreadState* GetThreadState(uint32_t tid); 52 | uint32_t GetCoreIdx(uint32_t tid); 53 | 54 | bool IsInFastForward(); 55 | void ExitFastForward(); 56 | void EnterFastForward(); 57 | 58 | void InitDriver(); 59 | -------------------------------------------------------------------------------- /sim/ff_queue.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/object.h" 27 | #include "sim/taskptr.h" 28 | #include "sim/gvt_arbiter.h" 29 | 30 | class TSB; 31 | 32 | // Interfaces to a TimeStamp-ordered priority queue structure 33 | // for tasks created while fast-forwarding (e.g., initial tasks 34 | // enqueued before the ROI, or all tasks that are created during 35 | // heartbeats-based fast-forwarding). 36 | 37 | // Interface during steady-state fast-forwarding 38 | void EnqueueFfTask(TaskPtr&& t); 39 | TaskPtr DequeueFfTask(); 40 | bool IsFfQueueEmpty(); 41 | 42 | // For transitioning out of fast-forwarding into full simulation. 43 | void DrainFfTaskQueue(); // Begins draining tasks to TSB #0 44 | void FfTaskQueueNotifyZoomIn(uint32_t newFrameBaseDepth); 45 | void FfTaskQueueSetPort(LVTUpdatePort* port); 46 | void FfTaskQueueSendLvt(uint64_t epoch); // analogous to ROB::sendLvt() 47 | 48 | // Dummy network object so we can send LVTUpdateMsgs to GVTArbiter 49 | class FfTaskQueue : public SimObject { 50 | public: 51 | FfTaskQueue() : SimObject("ffTaskQueue") { } 52 | }; 53 | -------------------------------------------------------------------------------- /sim/harness/debug.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # FIXME(dsm): Lots of duplication with run. May want to merge into a single harness script. 4 | 5 | pipe=$(mktemp -u) 6 | mkfifo $pipe 7 | exec 9<>$pipe 8 | rm $pipe 9 | 10 | 11 | PIN_ARGS=$@ 12 | APP_ARGS_TOKEN="--" 13 | SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 14 | 15 | if [ "${PIN_ARGS/$APP_ARGS_TOKEN}" = "$PIN_ARGS" ] ; then 16 | : 17 | else 18 | APP_ARGS_TOKEN="" 19 | fi 20 | 21 | 22 | @SCONS_ENV_VARS $PINPATH/intel64/bin/pinbin $PIN_OPTIONS @SCONS_PIN_OPTIONS -pause_tool 5 -t $SCRIPTDIR/speculator.so $APP_ARGS_TOKEN $@ 1>&9 & 23 | pid=$! 24 | dbgSymbolAddrs=`head -n3 <&9 | tail -1` 25 | #echo $pid $dbgSymbolAddrs 26 | # See zsim/src/debug_harness.cpp 27 | xterm -e gdb -p $pid -ex "set confirm off" -ex "$dbgSymbolAddrs" -ex "handle SIGTRAP nostop noprint" -ex "set confirm on" -ex c & 28 | dbgPid=$! 29 | 30 | cat <&9 & 31 | catPid=$! 32 | 33 | wait $pid 34 | wait $dbgPid 35 | 36 | kill $catPid 37 | -------------------------------------------------------------------------------- /sim/harness/sim.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PIN_ARGS=$@ 4 | APP_ARGS_TOKEN="--" 5 | SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6 | SIM_PID=0 7 | 8 | onSig() { 9 | exec 1>&2 10 | echo "[sim] Harness received termination signal" 11 | trap - SIGINT SIGTERM # avoid infinite recursive loop if we TERM ourself 12 | kill -SIGTERM $SIM_PID # if 0, TERMs the whole process group including self, which is OK 13 | 14 | # Make sure sim is dead; otherwise, hard-kill 15 | sleep 1 # Allow time for simulator to print some info and die cleanly 16 | let NUM_CHILDREN=`ps --no-headers -o pid --ppid=$$ | wc -w`-1 17 | if [ $NUM_CHILDREN != 0 ]; then 18 | echo "[sim] Simulator is not responsive, hard-killing" 19 | kill -9 $SIM_PID 20 | pkill -9 -P $$ 21 | sleep 1 22 | let NUM_CHILDREN=`ps --no-headers -o pid --ppid=$$ | wc -w`-1 23 | echo "[sim] Children left: $NUM_CHILDREN" 24 | else 25 | echo "[sim] Cleanly terminated child processes" 26 | fi 27 | 28 | exit 1 29 | } 30 | 31 | trap onSig SIGINT SIGTERM 32 | 33 | echo "[sim] Invoked with arguments: ${PIN_ARGS}" 34 | 35 | # http://askubuntu.com/questions/299710/how-to-determine-if-a-string-is-a-substring-of-another-in-bash 36 | if [ "${PIN_ARGS/$APP_ARGS_TOKEN}" = "$PIN_ARGS" ] ; then 37 | # No token found 38 | : 39 | else 40 | # Token found in the string, so don't use it in the command 41 | APP_ARGS_TOKEN="" 42 | fi 43 | 44 | if [ -f $SCRIPTDIR/pinbin ] ; then 45 | # Condor jobs use a symlink to the pin binary instead of depending on the 46 | # PINPATH environment variable 47 | PINBIN=$SCRIPTDIR/pinbin 48 | else 49 | # [victory] On a clean Ubuntu 18.04 install, I hit a segfault when running 50 | # the `pin` launcher, which is a 32-bit executable. To avoid a dependence 51 | # on old i386 (32-bit) components, directly invoke the x86_64 Pin binary. 52 | PINBIN="${PINPATH}/intel64/bin/pinbin" 53 | fi 54 | 55 | @SCONS_ENV_VARS $PINBIN $PIN_OPTIONS @SCONS_PIN_OPTIONS -t $SCRIPTDIR/speculator.so $APP_ARGS_TOKEN $@ <&0 & 56 | SIM_PID=$! 57 | 58 | # Wait in a loop (because wait returns any time we receive a signal for which 59 | # a trap has been set) until the simulator is actually finished. 60 | while kill -0 $SIM_PID &>/dev/null 61 | do 62 | wait $SIM_PID 63 | EXIT_STATUS=$? 64 | done 65 | exit $EXIT_STATUS 66 | -------------------------------------------------------------------------------- /sim/init/init.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #pragma once 30 | 31 | // Top-level initialization function 32 | void SimInit(const char* configFile); 33 | -------------------------------------------------------------------------------- /sim/interactive.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | void InteractivePrompt(); 29 | bool AtInteractivePrompt(); 30 | -------------------------------------------------------------------------------- /sim/loadstatssummary.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "loadstatssummary.h" 27 | #include "taskloadprofiler.h" 28 | 29 | std::unique_ptr createTaskLoadProfiler(LoadStatsSummary* summary) { 30 | if (summary) return std::make_unique(*summary); 31 | 32 | //return nullptr; 33 | // GCC 11 (Ubuntu 22.04) has a bug in the libstdc++ implementation of 34 | // std::unique_ptr's default constructor as well as the converting 35 | // constructor from std::nullptr_t, if you pass --fabi-version=2 to g++, as 36 | // we must do here for our simulator Pintool. The workaround is to do this 37 | // explicit construction: 38 | return std::unique_ptr((TaskLoadProfiler*)nullptr); 39 | } 40 | -------------------------------------------------------------------------------- /sim/make_unique.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | // Bringing a limited version of C++14's std::make_unique to C++11 27 | // https://herbsutter.com/gotw/_102/ 28 | 29 | #pragma once 30 | 31 | #include 32 | 33 | namespace std { 34 | template 35 | std::unique_ptr make_unique(Args&&... args) { 36 | return std::unique_ptr(new T(std::forward(args)...)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sim/match.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | template 29 | static inline bool matchAny(T val, U arg0) { 30 | return (val == arg0); 31 | } 32 | 33 | template 34 | static inline bool matchAny(T val, U arg0, Args... args) { 35 | return (val == arg0) || matchAny(val, args...); 36 | } 37 | -------------------------------------------------------------------------------- /sim/memory/constants.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #ifndef CONSTANTS_H_ 30 | #define CONSTANTS_H_ 31 | 32 | /* Simulator constants/limits go here, defined by macros */ 33 | 34 | // PIN 2.9 (rev39599) can't do more than 2048 threads... 35 | #define MAX_THREADS (2048) 36 | 37 | // How many children caches can each cache track? Note each bank is a separate child. This impacts sharer bit-vector sizes. 38 | #define MAX_CACHE_CHILDREN (256) 39 | //#define MAX_CACHE_CHILDREN (1024) 40 | 41 | // Complex multiprocess runs need multiple clocks, and multiple port domains 42 | #define MAX_CLOCK_DOMAINS (64) 43 | #define MAX_PORT_DOMAINS (64) 44 | 45 | //Maximum IPC of any implemented core. This is used for adaptive events and will not fail silently if you define new, faster processors. 46 | //If you use it, make sure it does not fail silently if violated. 47 | #define MAX_IPC (4) 48 | 49 | #endif // CONSTANTS_H_ 50 | -------------------------------------------------------------------------------- /sim/memory/hash.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #ifndef HASH_H_ 30 | #define HASH_H_ 31 | 32 | #include 33 | 34 | class HashFamily { 35 | public: 36 | HashFamily() {} 37 | virtual ~HashFamily() {} 38 | 39 | virtual uint64_t hash(uint32_t id, uint64_t val) const = 0; 40 | }; 41 | 42 | class H3HashFamily : public HashFamily { 43 | private: 44 | const uint32_t numFuncs; 45 | uint32_t resShift; 46 | uint64_t* hMatrix; 47 | public: 48 | H3HashFamily(uint32_t numFunctions, uint32_t outputBits, uint64_t randSeed = 123132127); 49 | ~H3HashFamily() override; 50 | uint64_t hash(uint32_t id, uint64_t val) const override; 51 | }; 52 | 53 | /* Used when we don't want hashing, just return the value */ 54 | class IdHashFamily : public HashFamily { 55 | public: 56 | inline uint64_t hash(uint32_t id, uint64_t val) const override {return val;} 57 | }; 58 | 59 | #endif // HASH_H_ 60 | -------------------------------------------------------------------------------- /sim/object.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | /* All simulator objects that wish to be networked and have ports should 31 | * inherit from this class. For now, the only needed property is its name. 32 | */ 33 | 34 | class SimObject { 35 | private: 36 | const std::string name_; 37 | 38 | public: 39 | explicit SimObject(const std::string& name) : name_(name) {} 40 | virtual ~SimObject() {} // allow dynamic_cast 41 | inline const std::string& nameStr() const { return name_; } 42 | inline const char* name() const { return name_.c_str(); } 43 | }; 44 | -------------------------------------------------------------------------------- /sim/pad.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #pragma once 30 | 31 | /* Padding macros to remove false sharing */ 32 | 33 | // Line size, in chars (bytes). We could make it configurable through a define 34 | #define CACHE_LINE_BYTES (64) 35 | 36 | #define _PAD_CONCAT(x, y) x ## y 37 | #define PAD_CONCAT(x, y) _PAD_CONCAT(x, y) 38 | 39 | // One-line pad 40 | // Assuming classes are defined over one file, this should generate unique names 41 | #define PAD() unsigned char PAD_CONCAT(pad_line, __LINE__)[CACHE_LINE_BYTES] 42 | 43 | // Pad remainder to line size, use as e.g. PAD(sizeof(uint32)) will produce 60B of padding 44 | #define PAD_SZ(sz) unsigned char PAD_CONCAT(pad_sz_line, __LINE__)[CACHE_LINE_BYTES - ((sz) % CACHE_LINE_BYTES)] 45 | 46 | #define ATTR_LINE_ALIGNED __attribute__((aligned CACHE_LINE_BYTES )) 47 | -------------------------------------------------------------------------------- /sim/port.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | /* General one-sided port interface */ 31 | template class Port { 32 | public: 33 | typedef T msg_type; 34 | 35 | class Receiver { 36 | public: 37 | virtual void receive(const T& msg, uint64_t cycle) = 0; 38 | }; 39 | 40 | virtual void send(const T& msg, uint64_t cycle) = 0; 41 | }; 42 | -------------------------------------------------------------------------------- /sim/run_condition.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | enum class RunCondition : uint8_t { 29 | MUSTSPEC, // Run speculatively at any time. 30 | CANTSPEC, // Run non-speculatively, only after parent commits and GVT has matching app timestamp. 31 | MAYSPEC, // Run at any time, non-speculatively if possible if it were CANTSPEC, otherwise run speculatively 32 | ANYTIME, // Run non-speculatively at any time (for spillers and (some) requeuers) 33 | }; 34 | -------------------------------------------------------------------------------- /sim/spin_cv.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/spin_cv.h" 27 | #include "sim/assert.h" 28 | #include "sim/log.h" 29 | #include "sim/sim.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #undef DEBUG 36 | #define DEBUG(args...) //info(args) 37 | 38 | static std::mt19937 PRNG(0); 39 | 40 | void SPinConditionVariable::addWaiter(ThreadID tid) { 41 | DEBUG("spin_cv[%p] add tid %d", this, tid); 42 | auto result = waiters.insert(tid); 43 | assert(result.second); 44 | } 45 | 46 | // If tid is not in the waiters set, exit gracefully 47 | void SPinConditionVariable::notify(ThreadID tid) { 48 | if (waiters.erase(tid)) { 49 | DEBUG("spin_cv[%p] wake tid %d", this, tid); 50 | UnblockThread(tid, getCurCycle()); 51 | } 52 | } 53 | 54 | void SPinConditionVariable::notifyOne() { 55 | if (!waiters.empty()) { 56 | // Random selection (unfortunately O(n) in the number of watiers). 57 | std::uniform_int_distribution randomIdx(0, waiters.size()-1); 58 | auto it = std::next(waiters.cbegin(), randomIdx(PRNG)); 59 | const ThreadID tid = *it; 60 | waiters.erase(it); 61 | DEBUG("spin_cv[%p] wake tid %d", this, tid); 62 | // FIXME(dsm): What cycle? 63 | UnblockThread(tid, getCurCycle()); 64 | } 65 | } 66 | 67 | void SPinConditionVariable::notifyAll() { 68 | // Randomize the wakeup order to avoid systemic bias in access to resources 69 | std::vector randomized(waiters.begin(), waiters.end()); 70 | std::shuffle(randomized.begin(), randomized.end(), PRNG); 71 | for (const ThreadID tid : randomized) { 72 | DEBUG("spin_cv[%p] Wake waiter %d", this, tid); 73 | UnblockThread(tid, getCurCycle()); 74 | } 75 | waiters.clear(); 76 | } 77 | -------------------------------------------------------------------------------- /sim/spin_cv.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include "sim/types.h" 30 | 31 | /** 32 | * This class implements something resembling a condition variable around the 33 | * libspin/sim.cpp blocking mechanism. Note that the caller does not actually 34 | * block on SPinConditionVariable::addWaiter, as the flow currently requires: 35 | * 36 | * SPinConditionVariable::addWaiter(tid) 37 | * curThread->transition(BLOCKED); 38 | * spin::blockAfterSwitch(); 39 | * # tell the caller of the pin routine what is the NextThread(); 40 | */ 41 | 42 | class SPinConditionVariable { 43 | std::set waiters; 44 | public: 45 | void addWaiter(ThreadID); 46 | // NOP if tid is not in the waiters set 47 | void notify(ThreadID); 48 | void notifyOne(); 49 | void notifyAll(); 50 | inline uint64_t getNumWaiters() { return waiters.size(); } 51 | bool hasWaiters() const { return !waiters.empty(); } 52 | }; 53 | -------------------------------------------------------------------------------- /sim/stats/clock_stat.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include "sim/stats/stats.h" 30 | 31 | // Helper function 32 | inline uint64_t getNs() { 33 | struct timespec ts; 34 | // Guaranteed synchronized across processors, ~20ns/call on Ubuntu 12.04. 35 | // Linux hrtimers have gotten really good! In comparison, rdtsc is 9ns. 36 | clock_gettime(CLOCK_REALTIME, &ts); 37 | return 1000000000L * ts.tv_sec + ts.tv_nsec; 38 | } 39 | 40 | /* Implements a single stopwatch-style cumulative clock. Useful to profile 41 | * isolated events. get() accounts for current interval if clock is running. 42 | */ 43 | class ClockStat : public ScalarStat { 44 | private: 45 | uint64_t startNs; 46 | uint64_t totalNs; 47 | 48 | public: 49 | ClockStat() : ScalarStat(), startNs(0), totalNs(0) {} 50 | 51 | void start() { 52 | assert(!startNs); 53 | startNs = getNs(); 54 | } 55 | 56 | void end() { 57 | assert(startNs); 58 | uint64_t endNs = getNs(); 59 | assert(endNs >= startNs) totalNs += (endNs - startNs); 60 | startNs = 0; 61 | } 62 | 63 | uint64_t get() const { 64 | return totalNs + (startNs ? (getNs() - startNs) : 0); 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /sim/stats/table_stat.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "table_stat.h" 27 | 28 | void TableStat::init(const char* name, const char* desc, 29 | std::vector rowNames, 30 | std::vector columnNames) { 31 | initStat(name, desc); 32 | _nrows = rowNames.size(); 33 | _ncols = columnNames.size(); 34 | _rowStats.resize(_nrows); 35 | _values = new uint64_t[_nrows * _ncols]; 36 | for (size_t r = 0; r < _nrows; r++) { 37 | _rowStats[r].init(strdup(rowNames[r].c_str()), columnNames, 38 | &_values[r * _ncols]); 39 | this->append(&_rowStats[r]); 40 | } 41 | std::fill(_values, _values + _nrows * _ncols, 0ul); 42 | } 43 | 44 | 45 | TableStat operator+(const TableStat& lhs, const TableStat& rhs) { 46 | TableStat result(lhs); 47 | result += rhs; 48 | return result; 49 | } 50 | 51 | TableStat operator-(const TableStat& lhs, const TableStat& rhs) { 52 | TableStat result(lhs); 53 | result -= rhs; 54 | return result; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /sim/str.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | /* Turn anything stringstream can grok into a string */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | template std::string Str(T v) { 35 | std::stringstream ss; 36 | ss << v; 37 | return ss.str(); 38 | } 39 | 40 | template std::string Str(const std::vector& v) { 41 | std::stringstream ss; 42 | ss << "["; 43 | for (auto& x : v) ss << " " << x; 44 | ss << "]"; 45 | return ss.str(); 46 | } 47 | -------------------------------------------------------------------------------- /sim/taskloadprofiler.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/taskloadprofiler.h" 27 | #include "sim/sim.h" 28 | #include "sim/driver.h" 29 | #include "sim/core/core.h" 30 | 31 | extern LoadMetricConfig loadMetricConfig; 32 | 33 | uint64_t getCount(ThreadID tid) { 34 | if (loadMetricConfig.metric == LoadMetricConfig::LoadMetric::CYCLES) return getCurCycle(); 35 | else return ossinfo->cores[GetCoreIdx(tid)]->getInstructionCount(); 36 | } 37 | -------------------------------------------------------------------------------- /sim/taskobserver.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include "make_unique.h" 30 | #include "types.h" 31 | 32 | /** 33 | * A TaskObserver is a class that needs notifications when a Task object 34 | * invokes one of its start, finish, commit, and abort methods. The creator of 35 | * the TaskObserver registers with some task. 36 | */ 37 | class TaskObserver { 38 | public: 39 | virtual ~TaskObserver() {} 40 | virtual void start(ThreadID tid=INVALID_TID) {}; 41 | virtual void finish() {}; 42 | virtual void commit() {}; 43 | virtual void abort(bool requeue) {}; 44 | }; 45 | -------------------------------------------------------------------------------- /sim/taskprofilingsummary.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include "sim/taskprofiler.h" 30 | 31 | void InitTaskProfiling(bool profileByPc); 32 | 33 | std::unique_ptr createTaskProfiler(void* pc); 34 | const TaskCyclesSummary& taskCyclesSummary(); 35 | void printTaskProfilingInfo(); 36 | -------------------------------------------------------------------------------- /sim/taskptr.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | 30 | class Task; 31 | 32 | typedef std::shared_ptr TaskPtr; 33 | typedef std::shared_ptr ConstTaskPtr; 34 | -------------------------------------------------------------------------------- /sim/test/SConscript: -------------------------------------------------------------------------------- 1 | from __future__ import (absolute_import, division, print_function) 2 | 3 | Import('env') 4 | 5 | localenv = env.Clone() 6 | 7 | simObjs = [localenv.Object(f + '.o', '../' + f + '.cpp') 8 | for f in ( 9 | 'timestamp', 10 | 'conflicts/precise_address_accessors', 11 | 'conflicts/bloom_address_accessors', 12 | 'memory/hash', 13 | 'memory/memory_hierarchy', 14 | 'stats/table_stat', 15 | )] 16 | 17 | localenv.Append(CPPDEFINES = {'SWARM_CACHE_LINE' : '64', 18 | 'SWARM_SIM_NO_LOG' : '1', 19 | }) 20 | localenv.Append(CPPFLAGS = ['-std=c++11']) 21 | 22 | gtest_include_path, libgtest, libgtest_main = SConscript( 23 | '#googletest/SConscript', 24 | exports={'env': localenv}, 25 | variant_dir='googletest', 26 | duplicate=0) 27 | #localenv.Append(CPPPATH = gtest_include_path) 28 | localenv.Append(CPPFLAGS = ['-isystem', gtest_include_path]) 29 | # Use libgtest_main until a custom int main() is necessary 30 | localenv.Append(LIBS=[libgtest_main, 'pthread']) 31 | 32 | localenv.Program( 33 | target = 'runTests', 34 | # Add all sim objects so that we can unit test classes with cpp components 35 | source = Glob('*.cpp') + [simObjs] 36 | ) 37 | -------------------------------------------------------------------------------- /sim/test/aligned_uint64_t_test.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/aligned.h" 29 | 30 | class AlignedUint64Test : public ::testing::Test { 31 | protected: 32 | swarm::aligned n; 33 | }; 34 | 35 | 36 | TEST_F(AlignedUint64Test, PrimitiveAssignmentTest) { 37 | n = 3ul; 38 | 39 | ASSERT_EQ(3ul, n); 40 | ASSERT_EQ(n, 3ul); 41 | } 42 | 43 | TEST_F(AlignedUint64Test, AlignedAssignmentTest) { 44 | n = swarm::aligned(3ul); 45 | 46 | ASSERT_EQ(3ul, n); 47 | ASSERT_EQ(n, 3ul); 48 | } 49 | 50 | TEST_F(AlignedUint64Test, AlignedEqualityTest) { 51 | n = 4ul; 52 | swarm::aligned other(4); 53 | ASSERT_TRUE(n == other); 54 | ASSERT_EQ(n, other); 55 | } 56 | 57 | TEST_F(AlignedUint64Test, AlignedNotEqualTest) { 58 | n = 4; 59 | swarm::aligned other(3); 60 | ASSERT_TRUE(n != other); 61 | ASSERT_NE(n, other); 62 | } 63 | 64 | TEST_F(AlignedUint64Test, PrimitiveNotEqualTest) { 65 | n = 4; 66 | uint64_t other = 3; 67 | ASSERT_TRUE(n != other); 68 | ASSERT_NE(n, other); 69 | } 70 | -------------------------------------------------------------------------------- /sim/test/bf_partitioned_test.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/bloom/bf_partitioned.h" 28 | 29 | class BFPartitionedWithH3Test : public ::testing::Test { 30 | protected: 31 | bloom::BloomFilterPartitioned bf; 32 | uint64_t item; 33 | 34 | BFPartitionedWithH3Test() : bf(4096, 16), item(3ul) {} 35 | }; 36 | 37 | 38 | TEST_F(BFPartitionedWithH3Test, EmptyFilterIsEmpty) { 39 | ASSERT_FALSE(bf.contains(item)); 40 | } 41 | 42 | TEST_F(BFPartitionedWithH3Test, InsertedItemIsContained) { 43 | bf.insert(item); 44 | ASSERT_TRUE(bf.contains(item)); 45 | } 46 | 47 | TEST_F(BFPartitionedWithH3Test, ClearLeavesAnEmptyFilter) { 48 | bf.insert(item); 49 | bf.clear(); 50 | // TODO [mcj] implement empty()? 51 | ASSERT_FALSE(bf.contains(item)); 52 | } 53 | -------------------------------------------------------------------------------- /sim/test/gvt_arbiter_epoch_test.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/gvt_arbiter.h" 29 | 30 | class GVTArbiterEpochTest : public ::testing::Test { 31 | }; 32 | 33 | 34 | TEST_F(GVTArbiterEpochTest, PrioOf2Is1) { 35 | GVTArbiter::Epoch e(2, 0); 36 | ASSERT_EQ(1U, e.prio()); 37 | } 38 | 39 | TEST_F(GVTArbiterEpochTest, PrioOf8Is3) { 40 | GVTArbiter::Epoch e(8, 0); 41 | ASSERT_EQ(3U, e.prio()); 42 | } 43 | 44 | TEST_F(GVTArbiterEpochTest, PrioOf7Is0) { 45 | GVTArbiter::Epoch e(7, 0); 46 | ASSERT_EQ(0U, e.prio()); 47 | } 48 | 49 | TEST_F(GVTArbiterEpochTest, PrioOf7IsLessThan8) { 50 | GVTArbiter::Epoch l(7, 0); 51 | GVTArbiter::Epoch r(8, 0); 52 | ASSERT_LT(l.prio(), r.prio()); 53 | } 54 | 55 | TEST_F(GVTArbiterEpochTest, PrioOf8Exceeds9) { 56 | GVTArbiter::Epoch l(8, 0); 57 | GVTArbiter::Epoch r(9, 0); 58 | ASSERT_GT(l.prio(), r.prio()); 59 | } 60 | 61 | TEST_F(GVTArbiterEpochTest, PrioOf796Exceeds797) { 62 | GVTArbiter::Epoch l(796, 0); 63 | GVTArbiter::Epoch r(797, 0); 64 | ASSERT_GT(l.prio(), r.prio()); 65 | } 66 | -------------------------------------------------------------------------------- /sim/test/stack_segments_test.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #if 0 // dsm: doesn't compile, as this requires Pin now 27 | #include 28 | #include "stack.h" 29 | 30 | class StackSegmentsTest : public ::testing::Test { 31 | protected: 32 | static const uint32_t nthreads = 8; 33 | static const uint32_t logSegSize = 10; 34 | static const uint32_t totalSize = nthreads << logSegSize; 35 | const StackSegments stack; 36 | const Address base; 37 | 38 | StackSegmentsTest() : stack(nthreads, logSegSize), base(stack.base()) {} 39 | }; 40 | 41 | TEST_F(StackSegmentsTest, AddressLessThanBaseNotInSegment) { 42 | ASSERT_EQ(-1, stack.segment(base - 1)); 43 | } 44 | 45 | TEST_F(StackSegmentsTest, AddressInBaseSegmentIsZero) { 46 | ASSERT_EQ(0, stack.segment(base + 1)); 47 | } 48 | 49 | TEST_F(StackSegmentsTest, AddressInTopSegmentIsTop) { 50 | Address addr = base + totalSize - 1; 51 | ASSERT_EQ(nthreads - 1, stack.segment(addr)); 52 | } 53 | 54 | TEST_F(StackSegmentsTest, AddressJustAboveTopNotInSegment) { 55 | ASSERT_EQ(-1, stack.segment(base + totalSize)); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /sim/thread_count_controller.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include 30 | #include "sim/sim.h" 31 | #include "sim/types.h" 32 | #include "sim/spin_cv.h" 33 | #include "sim/stats/stats.h" 34 | #include "sim/str.h" 35 | 36 | class ThreadCountController { 37 | public: 38 | ThreadCountController(uint32_t _idx) 39 | : name_("tcc-" + Str(_idx)), lastThreadCountUpdateCycle(0) {} 40 | 41 | bool handleDequeue(ThreadID tid); 42 | void addCore(Core* core); 43 | void notifyOne(); 44 | void notifyAll(); 45 | 46 | inline uint64_t getNumBlockedThreads() const { return numBlockedThreads; } 47 | inline void setROB(ROB* r) { rob = r; } 48 | 49 | void initStats(AggregateStat* parentStat); 50 | 51 | uint32_t increaseThreads(uint32_t); 52 | uint32_t decreaseThreads(uint32_t); 53 | 54 | private: 55 | const std::string name_; 56 | 57 | ROB* rob; 58 | std::unordered_map coreMap; // cid -> Core* map 59 | std::vector cores; 60 | SPinConditionVariable blockedThreads; 61 | uint32_t numBlockedThreads; 62 | 63 | uint64_t lastThreadCountUpdateCycle; 64 | 65 | inline const char* name() const { return name_.c_str(); } 66 | 67 | // Stats 68 | Counter numAvailableThreads; 69 | RunningStat threadCount; 70 | }; 71 | -------------------------------------------------------------------------------- /sim/types.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | typedef uint32_t ThreadID; 32 | typedef uint64_t Address; 33 | typedef uint32_t TileId; 34 | 35 | static const uint32_t MAX32_T = ((uint32_t)-1); 36 | static const uint64_t MAX64_T = ((uint64_t)-1); 37 | static const double MAX_DOUBLE = (std::numeric_limits::max()-1); 38 | static const ThreadID INVALID_TID = ((ThreadID)-1); 39 | static const uint32_t INVALID_CID = ((uint32_t)-1); 40 | static const uint32_t INVALID_DEPTH = ((uint32_t)-1); 41 | 42 | static const uint64_t INDEFINITE = ((uint64_t)-1); 43 | static const uint64_t INVALID_INT = ((uint64_t)-1); 44 | 45 | #define __MAX_TS (~((uint64_t)0)) 46 | -------------------------------------------------------------------------------- /sim/undo_log.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "sim/undo_log.h" 27 | 28 | std::array UndoLog::freeLists; 29 | -------------------------------------------------------------------------------- /sim/virt/virt.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #pragma once 30 | 31 | #include "spin.h" 32 | 33 | namespace virt { 34 | void init(); 35 | bool syscallEnter(spin::ThreadId tid, spin::ThreadContext* ctxt); 36 | void syscallExit(spin::ThreadId tid, spin::ThreadContext* ctxt); 37 | }; 38 | -------------------------------------------------------------------------------- /sim/watchdog.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | 28 | #include "sim/timestamp.h" 29 | 30 | /* Launch this thread at the beginning of simulation. It will periodically wake 31 | * up & print a hearbeat file. This file keeps us alive. 32 | */ 33 | void WatchdogThread(void*); 34 | void StopWatchdogThread(); 35 | 36 | /* Non-thread interface */ 37 | void InitWatchdog(time_t cycleTimeout, time_t taskTimeout, time_t gvtTimeout, time_t ffTimeout); 38 | void TickWatchdog(); 39 | 40 | // Thread-safe method to inform the watchdog of a GVT update. 41 | void UpdateWatchdogGvt(TimeStamp newGvt); 42 | -------------------------------------------------------------------------------- /tests/busy_waiting_after_roi.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "common.h" 27 | #include "swarm/api.h" 28 | #include "swarm/hooks.h" 29 | #include 30 | 31 | constexpr int MAX_THREADS = 2048; 32 | 33 | int counters[MAX_THREADS]; 34 | 35 | #define DO_PTHREAD 1 36 | 37 | #if DO_PTHREAD 38 | void *barrier_then_loop(void *args) { 39 | sim_barrier(); 40 | sim_barrier(); 41 | 42 | counters[(long)args] = (long)args; 43 | 44 | sim_barrier(); 45 | sim_barrier(); 46 | while (true); 47 | } 48 | #else 49 | void barrier_then_loop(int tid) { 50 | sim_barrier(); 51 | sim_barrier(); 52 | 53 | counters[tid] = tid; 54 | 55 | sim_barrier(); 56 | sim_barrier(); 57 | while (true); 58 | } 59 | #endif 60 | 61 | int main(int argc, const char** argv) { 62 | const int numThreads = swarm::num_threads(); 63 | assert(numThreads <= MAX_THREADS); 64 | #if DO_PTHREAD 65 | pthread_t t; 66 | for (long i = 1; i < numThreads; i++) 67 | pthread_create(&t, NULL, barrier_then_loop, (void *)i); 68 | #else 69 | std::thread* threads = new std::thread[numThreads]; 70 | for (int i = 1; i < numThreads; i++) 71 | threads[i] = std::thread(barrier_then_loop, i); 72 | #endif 73 | 74 | sim_barrier(); 75 | zsim_roi_begin(); 76 | sim_barrier(); 77 | 78 | sim_barrier(); 79 | zsim_roi_end(); 80 | sim_barrier(); 81 | 82 | int total = 0; 83 | for (int i = 0; i < numThreads; i++) 84 | total += counters[i]; 85 | 86 | tests::assert_eq(numThreads * (numThreads - 1) / 2, total); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /tests/call_nullptr.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /* 27 | * Speculatively call a function pointer that is null. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "common.h" 34 | #include "swarm/api.h" 35 | 36 | bool success = false; 37 | void (*fcnptr)(void) = nullptr; 38 | 39 | void beSuccessful() { success = true; } 40 | 41 | static inline void pauser(swarm::Timestamp ts) { 42 | for (uint32_t i = 0; i < 5000; i++) _mm_pause(); 43 | fcnptr = &beSuccessful; 44 | } 45 | 46 | static inline void exceptioner(swarm::Timestamp) { 47 | (*fcnptr)(); 48 | } 49 | 50 | int main() { 51 | swarm::enqueue(pauser, 0, EnqFlags::NOHINT); 52 | swarm::enqueue(exceptioner, 1, EnqFlags::NOHINT); 53 | swarm::run(); 54 | tests::assert_eq(success, true); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/counter.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "counter.h" 27 | 28 | int main(int argc, const char** argv) { 29 | return counter(argc, argv); 30 | } 31 | -------------------------------------------------------------------------------- /tests/counter_spatial.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #define PLS_SPATIAL 27 | #include "counter.h" 28 | 29 | int main(int argc, const char** argv) { 30 | return counter(argc, argv); 31 | } 32 | -------------------------------------------------------------------------------- /tests/counter_spatial_collide.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #define PLS_SPATIAL_COLLIDE 27 | #include "counter.h" 28 | 29 | int main(int argc, const char** argv) { 30 | return counter(argc, argv); 31 | } 32 | -------------------------------------------------------------------------------- /tests/deadlock.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | 28 | static void deadlockTask(swarm::Timestamp ts) { 29 | while (true) 30 | ; 31 | } 32 | 33 | int main(int argc, const char** argv) { 34 | swarm::enqueue(deadlockTask, 42, EnqFlags::NOHINT); 35 | swarm::run(); 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tests/deepen_chain.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | #include "common.h" 32 | 33 | #include "swarm/api.h" 34 | #include "swarm/algorithm.h" 35 | 36 | #define INITIAL (3) 37 | 38 | using namespace std; 39 | 40 | uint64_t v = 0; 41 | 42 | inline void deepenTask(swarm::Timestamp ts, uint64_t level) { 43 | level--; 44 | v += level; 45 | if (level == 0) return; 46 | else { 47 | swarm::deepen(); 48 | swarm::enqueue(deepenTask, ts, EnqFlags::NOHINT, level); 49 | } 50 | } 51 | 52 | inline void startTask(swarm::Timestamp ts, uint64_t level) { 53 | for (uint32_t i = 0; i < INITIAL; ++i) { 54 | swarm::enqueue(deepenTask, ts, EnqFlags::NOHINT, level); 55 | } 56 | } 57 | 58 | int main(int argc, const char** argv) { 59 | if (argc != 2) { 60 | cerr << "Usage: " << argv[0] << " " << endl; 61 | return -1; 62 | } 63 | 64 | uint64_t nlevels = atoi(argv[1]); 65 | 66 | swarm::enqueue(startTask, 0, EnqFlags::NOHINT, nlevels); 67 | swarm::run(); 68 | 69 | uint64_t expected = (INITIAL * nlevels * (nlevels - 1)) / 2; 70 | tests::assert_eq(expected, v); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /tests/deepen_fanout_serial.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | #include 32 | #include "common.h" 33 | 34 | #include "swarm/api.h" 35 | #include "swarm/algorithm.h" 36 | 37 | #define FANOUT (3) 38 | 39 | using namespace std; 40 | 41 | uint64_t v = 0; 42 | 43 | // Forward declaration 44 | inline void startTask(swarm::Timestamp ts, uint64_t level); 45 | 46 | inline void deepenTask(swarm::Timestamp ts, uint64_t level) { 47 | v = v + level; 48 | level--; 49 | if (level == 0) return; 50 | else { 51 | swarm::deepen(); 52 | swarm::enqueue(startTask, ts, EnqFlags::NOHINT, level); 53 | } 54 | } 55 | 56 | inline void startTask(swarm::Timestamp ts, uint64_t level) { 57 | for (uint32_t i = 0; i < FANOUT; ++i) { 58 | swarm::enqueue(deepenTask, ts, EnqFlags::NOHINT, level); 59 | } 60 | } 61 | 62 | int main(int argc, const char** argv) { 63 | if (argc != 2) { 64 | cerr << "Usage: " << argv[0] << " " << endl; 65 | return -1; 66 | } 67 | 68 | uint64_t nlevels = atoi(argv[1]); 69 | 70 | swarm::enqueue(startTask, 0, EnqFlags::NOHINT, nlevels); 71 | swarm::run(); 72 | 73 | uint64_t expected = 0; 74 | for (uint32_t i = 0; i <= nlevels; ++i) { 75 | expected += (nlevels - i) * std::pow(FANOUT, i+1); 76 | } 77 | 78 | tests::assert_eq(expected, v); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /tests/dereference_ffff.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /* 27 | * Speculatively dereference address 0xffffffffffffffff. 28 | * This tests for sim bugs involving wraparound/overflow in address-related 29 | * computations. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | #include "common.h" 36 | #include "swarm/api.h" 37 | 38 | bool success = false; 39 | bool* success_ptr = (bool*)0xffffffffffffffff; 40 | 41 | uint32_t answer32 = 0; 42 | uint32_t* answer32_ptr = (uint32_t*)0xfffffffffffffffc; 43 | 44 | uint64_t answer64 = 0; 45 | uint64_t* answer64_ptr = (uint64_t*)0xffffffffffffffff; 46 | 47 | static inline void slowlySetPointers(swarm::Timestamp ts) { 48 | for (uint32_t i = 0; i < 5000; i++) _mm_pause(); 49 | 50 | success_ptr = &success; 51 | answer32_ptr = &answer32; 52 | answer64_ptr = &answer64; 53 | } 54 | 55 | static inline void dereferenceSuccess(swarm::Timestamp) { 56 | *success_ptr = true; 57 | } 58 | 59 | static inline void dereferenceAnswer32(swarm::Timestamp) { 60 | *answer32_ptr = 7; 61 | } 62 | 63 | static inline void dereferenceAnswer64(swarm::Timestamp) { 64 | *answer64_ptr = 42; 65 | } 66 | 67 | int main() { 68 | swarm::enqueue(slowlySetPointers, 0, EnqFlags::NOHINT); 69 | swarm::enqueue(dereferenceSuccess, 1, EnqFlags::NOHINT); 70 | swarm::enqueue(dereferenceAnswer32, 1, EnqFlags::NOHINT); 71 | swarm::enqueue(dereferenceAnswer64, 1, EnqFlags::NOHINT); 72 | swarm::run(); 73 | tests::assert_eq(success, true); 74 | tests::assert_eq(answer32, 7U); 75 | tests::assert_eq(answer64, 42UL); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /tests/enqueue_all_whints.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include "swarm/algorithm.h" 31 | #include "common.h" 32 | #include "swarm/api.h" 33 | 34 | std::vector counters; 35 | 36 | inline swarm::Hint hint(uint64_t c) { 37 | return {swarm::Hint::cacheLine(&counters[c]), MAYSPEC}; 38 | } 39 | 40 | void task(swarm::Timestamp, uint64_t c) { 41 | counters[c] = c; 42 | } 43 | 44 | int main(int argc, const char** argv) { 45 | if (argc < 2) { 46 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 47 | return -1; 48 | } 49 | 50 | counters.resize(atoi(argv[1]), 0ul); 51 | assert(counters.size() > 0); 52 | 53 | // counters is a vector of randomly-shuffled integers from 0 -> ncounters-1. 54 | std::iota(counters.begin(), counters.end(), 0ul); 55 | std::random_shuffle(counters.begin(), counters.end()); 56 | 57 | swarm::enqueue_all( 58 | counters.begin(), counters.end(), 59 | [] (uint64_t c) { swarm::enqueue(task, 1, hint(c), c); }, 60 | 0); 61 | swarm::run(); 62 | 63 | std::vector expected(counters.size(), 0ul); 64 | std::iota(expected.begin(), expected.end(), 0ul); 65 | 66 | tests::assert_eq(expected, counters); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /tests/enqueue_race.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | // On 1-core systems, this test demonstrates a race between a task enqueue and 27 | // a task dequeue. This can cause correctness issues on 1-core systems, where 28 | // we must be careful to avoid irrevocably running tasks in the wrong order. 29 | 30 | #include 31 | #include 32 | 33 | #include "common.h" 34 | #include "swarm/api.h" 35 | 36 | bool success = false; 37 | 38 | static void pessimist(swarm::Timestamp) { 39 | success = false; 40 | } 41 | 42 | static void optimist(swarm::Timestamp) { 43 | success = true; 44 | } 45 | 46 | static void start(swarm::Timestamp) { 47 | swarm::enqueue(optimist, 42, EnqFlags::NOHINT); 48 | 49 | // This delay helps to reproduce the desired issue. 50 | for (uint32_t i = 0; i < 100; i++) _mm_pause(); 51 | 52 | // spawn a task that will take at least a cycle to make it out of the TSB. 53 | swarm::enqueue(pessimist, 0, EnqFlags::NOHINT); 54 | 55 | // Immediately dequeue the next task w/o using a ret instruction. 56 | // Depending on the core model, this might run while pessimist is still 57 | // waiting to pass through the TSB! 58 | __asm__ __volatile__ (" xchg %rdx, %rdx"); 59 | } 60 | 61 | int main() { 62 | swarm::enqueue(start, 0, EnqFlags::NOHINT); 63 | swarm::run(); 64 | tests::assert_eq(success, true); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /tests/exception.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /* Causes null-pointer dereferences when run speculatively. 27 | * Used to test the Swarm exception model. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "common.h" 36 | #include "swarm/api.h" 37 | #include "swarm/algorithm.h" 38 | 39 | std::vector ptrs; 40 | 41 | uint64_t count; 42 | 43 | inline void task(swarm::Timestamp ts) { 44 | *ptrs[ts] += ts; 45 | ptrs[ts+1] = ptrs[ts]; 46 | } 47 | 48 | int main(int argc, const char** argv) { 49 | if (argc != 2) { 50 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 51 | return -1; 52 | } 53 | 54 | uint64_t size = atoi(argv[1]); 55 | 56 | // one extra elem, written but not read 57 | ptrs.resize(size + 1); 58 | count = 0; 59 | ptrs[0] = &count; 60 | std::fill(ptrs.begin()+1, ptrs.end(), nullptr); 61 | 62 | swarm::enqueue_all( 63 | swarm::u64it(0), swarm::u64it(size), [] (uint64_t i) { 64 | swarm::enqueue(task, i, NOHINT); 65 | }, 0ul); 66 | 67 | swarm::run(); 68 | 69 | tests::assert_eq(size*(size-1)/2, count); 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /tests/fill.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | 30 | #define PLS_APP_MAX_ARGS 3 // swarm::fill's internal tasks require 3 args 31 | #include "swarm/api.h" 32 | #include "swarm/algorithm.h" 33 | #include "common.h" 34 | 35 | constexpr size_t ZEROS = 5u; 36 | constexpr uint16_t FILLER = 0xf00d; 37 | 38 | int main(int argc, const char** argv) { 39 | if (argc != 2) { 40 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 41 | return -1; 42 | } 43 | size_t size = atoi(argv[1]); 44 | assert(size >= ZEROS); 45 | 46 | std::vector actual; 47 | std::vector expected; 48 | actual.resize(size); 49 | expected.resize(actual.size()); 50 | 51 | swarm::fill(actual.begin() + ZEROS, actual.end() - ZEROS, FILLER, 14ul); 52 | swarm::fill(actual.begin(), actual.end(), 0ul, 13ul); 53 | swarm::run(); 54 | 55 | std::fill(expected.begin(), expected.end(), 0ul); 56 | std::fill(expected.begin() + ZEROS, expected.end() - ZEROS, FILLER); 57 | tests::assert_eq(expected, actual); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /tests/fractal.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | #include "common.h" 32 | 33 | #include "swarm/api.h" 34 | #include "swarm/algorithm.h" 35 | 36 | 37 | using namespace std; 38 | 39 | uint64_t v = 0; 40 | 41 | inline void task(swarm::Timestamp ts, uint64_t level, uint64_t prefix) { 42 | uint64_t val = (prefix << 1) + ts; 43 | if (level == 0) { 44 | assert(v == val); 45 | v = val + 1; 46 | } else { 47 | swarm::deepen(); 48 | swarm::enqueue(task, 0, EnqFlags::NOHINT, level-1, val); 49 | swarm::enqueue(task, 1, EnqFlags::NOHINT, level-1, val); 50 | } 51 | } 52 | 53 | int main(int argc, const char** argv) { 54 | if (argc != 2) { 55 | cerr << "Usage: " << argv[0] << " " << endl; 56 | return -1; 57 | } 58 | 59 | uint64_t nlevels = atoi(argv[1]); 60 | 61 | swarm::enqueue(task, 0, EnqFlags::NOHINT, nlevels, 0); 62 | swarm::run(); 63 | 64 | tests::assert_eq(v, 1ul<. 24 | */ 25 | 26 | #include "common.h" 27 | 28 | #include "swarm/api.h" 29 | 30 | #include 31 | #include 32 | 33 | static void task(swarm::Timestamp ts, int depthRemaining) { 34 | if (!ts && depthRemaining) { 35 | swarm::deepen(); 36 | swarm::enqueue(task, 0, EnqFlags::NOHINT, depthRemaining - 1); 37 | swarm::enqueue(task, 1, EnqFlags::NOHINT, depthRemaining - 1); 38 | } 39 | } 40 | 41 | 42 | int main(int argc, const char** argv) { 43 | 44 | if (argc != 2) { 45 | std::cerr << "Usage: " << argv[0] 46 | << " " << std::endl; 47 | std::abort(); 48 | } 49 | 50 | swarm::enqueue(task, 0, EnqFlags::NOHINT, atoi(argv[1])); 51 | swarm::run(); 52 | 53 | // Print the verification string so that our test scripts don't complain 54 | tests::assert_true(true); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/get_ts.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 test for swarm::timestamp() */ 27 | 28 | #include 29 | #include "swarm/api.h" 30 | #include "swarm/algorithm.h" 31 | 32 | #include "common.h" 33 | 34 | #define NP (1024ul) 35 | 36 | std::array incorrect = {0}; 37 | 38 | inline void task(swarm::Timestamp ts) { 39 | swarm::Timestamp answer = swarm::timestamp(); 40 | if (answer != ts) { 41 | swarm::info("swarm::timestamp() returned %d, when the timestamp was %d", 42 | answer, ts); 43 | incorrect[ts] = 1; 44 | } 45 | swarm::deepen(); 46 | answer = swarm::timestamp(); 47 | if (answer != 0UL) { 48 | swarm::info("swarm::timestamp() returned %d after deepen instead of 0", 49 | answer); 50 | incorrect[ts] = 1; 51 | } 52 | swarm::undeepen(); 53 | answer = swarm::timestamp(); 54 | if (answer != ts) { 55 | swarm::info("swarm::timestamp() returned %d after undeepen, " 56 | "when the timestamp was %d", 57 | answer, ts); 58 | incorrect[ts] = 1; 59 | } 60 | } 61 | 62 | int main(int argc, const char** argv) { 63 | assert(swarm::timestamp() == UINT64_MAX); 64 | std::fill(incorrect.begin(), incorrect.end(), 0ul); 65 | 66 | swarm::enqueue_all(swarm::u64it(0), swarm::u64it(NP), 67 | [] (uint64_t i) { 68 | swarm::enqueue(task, i, NOHINT); 69 | }, 0ul); 70 | 71 | swarm::run(); 72 | 73 | assert(swarm::timestamp() == UINT64_MAX); 74 | 75 | std::array expected; 76 | std::fill(expected.begin(), expected.end(), 0ul); 77 | tests::assert_eq(expected, incorrect); 78 | return 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /tests/heartbeats.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | #include "swarm/algorithm.h" 28 | #include "common.h" 29 | 30 | /* Used for testing early program termination using heartbeats. Should not be 31 | * an automated test. You should manually check that the number of committed 32 | * heartbeatTasks() + 2 matches maxHeartbeats. The +2 comes from (a) the last 33 | * commit not being counted, and (b) the program calling zsim_heartbeat outside 34 | * of a task. The test is designed to make aborts frequent. Note there are also 35 | * enqueuer tasks, so run with sim.profileByPc == True. 36 | */ 37 | 38 | #define NC (128ul) 39 | static std::array counters; 40 | 41 | static void task(uint64_t ts) { 42 | zsim_heartbeat(); 43 | counters[ts % NC]++; 44 | } 45 | 46 | int main(int argc, const char** argv) { 47 | if (argc != 2) { 48 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 49 | std::abort(); 50 | } 51 | uint64_t nupdates = atoi(argv[1]); 52 | std::fill(counters.begin(), counters.end(), 0ul); 53 | 54 | zsim_heartbeat(); 55 | 56 | swarm::enqueue_all( 57 | swarm::u64it(0), swarm::u64it(nupdates), 58 | [](uint64_t i) { swarm::enqueue(task, i, NOHINT); }, 0ul); 59 | swarm::run(); 60 | } 61 | -------------------------------------------------------------------------------- /tests/in_ff.c: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/hooks.h" 27 | #include 28 | 29 | int main(int argc, char* argv[]) { 30 | assert(sim_in_ff()); 31 | zsim_roi_begin(); 32 | // N.B. This assertion will fail for configs that set ffHeartbeats so that 33 | // we fast-forward through the whole ROI. 34 | assert(!sim_in_ff()); 35 | zsim_roi_end(); 36 | assert(sim_in_ff()); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tests/interleave.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | 31 | #include "swarm/api.h" 32 | #include "common.h" 33 | 34 | volatile uint64_t counter; 35 | 36 | void reader(uint64_t ts, uint64_t upsLeft); 37 | void writer(uint64_t ts, uint64_t upsLeft); 38 | 39 | void reader(uint64_t ts, uint64_t upsLeft) { 40 | const uint64_t sample1 = counter; 41 | 42 | swarm::enqueue(writer, ts+1, EnqFlags::NOHINT, upsLeft); 43 | for (uint32_t i = 0; i < 1000; i++) _mm_pause(); 44 | 45 | const uint64_t sample2 = counter; 46 | 47 | if (sample1 != sample2) throw std::runtime_error("Two reads aren't equal"); 48 | if (sample2 != ts) throw std::runtime_error("Read not as expected"); 49 | } 50 | 51 | void writer(uint64_t ts, uint64_t upsLeft) { 52 | if (!upsLeft) return; 53 | counter = ts + 1; 54 | swarm::enqueue(reader, ts + 1, EnqFlags::NOHINT, upsLeft - 1); 55 | } 56 | 57 | int main(int argc, const char** argv) { 58 | if (argc != 2) { 59 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 60 | return -1; 61 | } 62 | const uint64_t nupdates = atoi(argv[1]); 63 | 64 | counter = 0; 65 | swarm::enqueue(reader, 0, EnqFlags::NOHINT, nupdates); 66 | swarm::run(); 67 | 68 | tests::assert_eq(counter, 2 * nupdates); 69 | return 0; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /tests/invalid_ts.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /* 27 | * Speculatively enqueue a task with an illegal timestamp. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "common.h" 34 | #include "swarm/api.h" 35 | 36 | bool success = false; 37 | swarm::Timestamp successTs = UINT64_MAX; 38 | 39 | void beSuccessful(swarm::Timestamp) { success = true; } 40 | 41 | void pauser(swarm::Timestamp ts) { 42 | for (uint32_t i = 0; i < 5000; i++) _mm_pause(); 43 | successTs = 42; 44 | } 45 | 46 | void exceptioner(swarm::Timestamp) { 47 | swarm::enqueue(beSuccessful, successTs, EnqFlags::NOHINT); 48 | } 49 | 50 | int main() { 51 | swarm::enqueue(pauser, 0, EnqFlags::NOHINT); 52 | swarm::enqueue(exceptioner, 1, EnqFlags::NOHINT); 53 | swarm::run(); 54 | tests::assert_true(success); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/large_heap.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | #include "swarm/api.h" 32 | #include "swarm/rand.h" 33 | #include "common.h" 34 | 35 | int main(int argc, const char** argv) { 36 | // No need to run this inside tasks. This is a functional plsalloc test. 37 | struct Alloc { 38 | uint64_t* ptr; 39 | size_t sz; 40 | }; 41 | Alloc allocs[256]; 42 | for (auto& a : allocs) a.ptr = nullptr; 43 | for (uint32_t n = 0; n < 100000; n++) { 44 | uint32_t i = swarm::rand64() % 256; 45 | if (allocs[i].ptr) { 46 | uint64_t* first = allocs[i].ptr; 47 | uint64_t* last = first + (allocs[i].sz / sizeof(uint64_t)) - 1; 48 | // Check first and last words haven't been overwritten 49 | assert(*first == allocs[i].sz); 50 | assert(*last == allocs[i].sz); 51 | assert(malloc_usable_size(allocs[i].ptr) >= allocs[i].sz); 52 | free(allocs[i].ptr); 53 | allocs[i].ptr = nullptr; 54 | } else { 55 | size_t sz = (16 * 1024) + (swarm::rand64() % (256 * 1024)); 56 | allocs[i] = {(uint64_t*) malloc(sz), sz}; 57 | *allocs[i].ptr = sz; 58 | *(allocs[i].ptr + sz/sizeof(uint64_t) - 1) = sz; 59 | } 60 | } 61 | 62 | swarm::run(); 63 | tests::assert_true(true); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tests/load_balance/.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | -------------------------------------------------------------------------------- /tests/load_balance/SConscript: -------------------------------------------------------------------------------- 1 | from __future__ import (absolute_import, division, print_function) 2 | 3 | import os 4 | Import('env') 5 | 6 | env = env.Clone() 7 | 8 | programs = [os.path.splitext(f.name)[0] for f in Glob("*.cpp")] 9 | 10 | for program in programs: 11 | if program == 'chain': 12 | ipenv = env.Clone() 13 | spenv = env.Clone() 14 | # sufficient parallelism 15 | spenv.Program(target=program+"_sp", 16 | source=[program + '.cpp'] + ['hash.cpp']) 17 | 18 | # insufficient parallleism 19 | ipenv["OBJSUFFIX"] = ".oip" 20 | ipenv.Append(CPPDEFINES = 'INSUFFICIENT_PARALLELISM') 21 | ipenv.Program(target=program+"_ip", 22 | source=[program + '.cpp'] + ['hash.cpp']) 23 | -------------------------------------------------------------------------------- /tests/load_balance/hash.h: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2012-2021 by Massachusetts Institute of Technology 3 | * Copyright (C) 2010-2012 by The Board of Trustees of Stanford University 4 | * 5 | * This file is part of the Swarm simulator. 6 | * 7 | * This simulator is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation, version 2. 10 | * 11 | * This simulator was developed as part of the Swarm architecture project. If 12 | * you use this software in your research, we request that you reference the 13 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 14 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 15 | * MICRO-51, 2018) as the source of this simulator in any publications that use 16 | * this software, and that you send us a citation of your work. 17 | * 18 | * This simulator is distributed in the hope that it will be useful, but 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 21 | * more 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 | /* This file was adapted from zsim. */ 28 | 29 | #ifndef HASH_H_ 30 | #define HASH_H_ 31 | 32 | #include 33 | 34 | class HashFamily { 35 | public: 36 | HashFamily() {} 37 | virtual ~HashFamily() {} 38 | 39 | virtual uint64_t hash(uint32_t id, uint64_t val) const = 0; 40 | }; 41 | 42 | class H3HashFamily : public HashFamily { 43 | private: 44 | const uint32_t numFuncs; 45 | uint32_t resShift; 46 | uint64_t* hMatrix; 47 | public: 48 | H3HashFamily(uint32_t numFunctions, uint32_t outputBits, uint64_t randSeed = 123132127); 49 | ~H3HashFamily() override; 50 | uint64_t hash(uint32_t id, uint64_t val) const override; 51 | }; 52 | 53 | /* Used when we don't want hashing, just return the value */ 54 | class IdHashFamily : public HashFamily { 55 | public: 56 | inline uint64_t hash(uint32_t id, uint64_t val) const override {return val;} 57 | }; 58 | 59 | #endif // HASH_H_ 60 | -------------------------------------------------------------------------------- /tests/malloc.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include "swarm/algorithm.h" 31 | #include "swarm/api.h" 32 | #include "common.h" 33 | 34 | 35 | inline void allocTask(swarm::Timestamp ts, uint64_t alloc_size) { 36 | long* tm = (long*) malloc(alloc_size*sizeof(long)); 37 | const int WRITES = 100000; /*some large number sufficient to fill up bloom filters */ 38 | for (int i=0;i 3) { 48 | std::cerr << "Usage: " << argv[0] 49 | << " []" << std::endl; 50 | std::abort(); 51 | } 52 | uint64_t alloc_size = atoi(argv[1]); 53 | uint64_t ntasks = (argc == 3)? atoi(argv[2]) : 128; 54 | 55 | 56 | swarm::enqueue_all( 57 | swarm::u32it(0), 58 | swarm::u32it(ntasks), 59 | [=] (int a) { 60 | swarm::enqueue(allocTask, 0, NOHINT, alloc_size); 61 | }, 0); 62 | 63 | swarm::run(); 64 | tests::assert_true(true); 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /tests/malloc_unimplemented.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 28 | 29 | void mallocTask(swarm::Timestamp timestamp) { 30 | void* p = pvalloc(8192); // should fail 31 | (void)p; 32 | } 33 | 34 | int main() { 35 | swarm::enqueue(mallocTask, 0, EnqFlags::NOHINT); 36 | swarm::run(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tests/many_read_syscalls.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /** 27 | * Lots of short unordered system-calling tasks. Each task 28 | * 1) induces a dependence on a random element of an array 29 | * 2) make a syscall 30 | * 3) induces another dependence on a random element of the array 31 | * As of commit 7b86b37332cacc1, this reproduces the error seen in 470.lbm 32 | * [sim] Panic on sim/sim.cpp:1089: Task [0x7f8c140cc5f8 (ts=0:114177 softTs=0 fcn=0x401f90 state=1 tid=8 untied irrevocable)] became non-speculative while taking exception (reason: syscall #0) 33 | */ 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "swarm/api.h" 41 | #include "swarm/algorithm.h" 42 | #include "swarm/rand.h" 43 | #include "common.h" 44 | 45 | constexpr uint64_t NC = 256; 46 | 47 | std::array counters; 48 | 49 | inline void task(swarm::Timestamp, int filedes) { 50 | counters[swarm::rand64() % NC]++; 51 | uint8_t c; 52 | ssize_t x = read(filedes, &c, 1); 53 | if (x == 1) counters[c]++; 54 | } 55 | 56 | int main(int argc, const char** argv) { 57 | if (argc != 2) { 58 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 59 | return -1; 60 | } 61 | uint64_t nreads = atoi(argv[1]); 62 | 63 | int f = open("/dev/urandom", O_RDONLY); 64 | 65 | swarm::enqueue_all( 66 | swarm::u64it(0), swarm::u64it(nreads), 67 | [f] (uint64_t) { swarm::enqueue(task, 0ul, NOHINT, f); }, 68 | 0ul); 69 | swarm::run(); 70 | 71 | close(f); 72 | 73 | uint64_t actual = std::accumulate(counters.begin(), counters.end(), 0ul); 74 | tests::assert_eq(2 * nreads, actual); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /tests/nohint_cas_mayspec.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /** 27 | * This tests the mutation of the same data on different tiles while irrevocable 28 | * 29 | * At its inception, on the master branch, this test passes just fine. 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include "swarm/api.h" 35 | #include "swarm/algorithm.h" 36 | #include "common.h" 37 | 38 | std::atomic counter; 39 | 40 | void increment(swarm::Timestamp) { counter++; } 41 | 42 | int main(int argc, const char** argv) { 43 | if (argc != 2) { 44 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 45 | return -1; 46 | } 47 | const uint64_t nincrements = atoi(argv[1]); 48 | counter = 0; 49 | 50 | swarm::enqueue_all( 51 | swarm::u32it(0), swarm::u32it(nincrements), [] (uint32_t i) { 52 | swarm::enqueue(increment, 0ul, NOHINT | MAYSPEC); 53 | }, 0ul); 54 | swarm::run(); 55 | 56 | tests::assert_eq(nincrements, counter.load()); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /tests/notimestamp.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /** 27 | * Fill one tile with non-timestamped tasks to trigger non-timestamped 28 | * spillers and requeuers. This probably duplicates aspects of 29 | * enqueue_all_whints, but oh well. 30 | */ 31 | 32 | #include "swarm/api.h" 33 | #include "swarm/algorithm.h" 34 | #include "common.h" 35 | 36 | #include 37 | #include 38 | 39 | constexpr uint64_t NC = 1024; 40 | std::array, NC> counters; 41 | 42 | static void task(swarm::Timestamp, uint64_t c) { 43 | counters[c]++; 44 | } 45 | 46 | int main(int argc, const char** argv) { 47 | std::fill(counters.begin(), counters.end(), 0ul); 48 | 49 | if (argc < 2) { 50 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 51 | return -1; 52 | } 53 | uint64_t nupdates = atoi(argv[1]); 54 | 55 | // Flood one tile with NOTIMESTAMP tasks 56 | swarm::enqueue_all( 57 | swarm::u64it(0), swarm::u64it(nupdates), 58 | [] (uint64_t i) { 59 | swarm::enqueue(task, 0ul, {0ul, NOTIMESTAMP | CANTSPEC}, i % NC); 60 | }, 61 | 1ul); 62 | swarm::run(); 63 | 64 | uint64_t sum = std::accumulate(counters.begin(), counters.end(), 0ul); 65 | tests::assert_eq(nupdates, sum); 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tests/overwrite_dlmalloc_metadata.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "overwrite.h" 27 | 28 | int main(int argc, const char** argv) { 29 | return overwrite(argc, argv); 30 | } 31 | -------------------------------------------------------------------------------- /tests/overwrite_spill_buffers.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | #define OVERFLOW_ZEROTH_TILE 27 | #include "overwrite.h" 28 | 29 | int main(int argc, const char** argv) { 30 | return overwrite(argc, argv); 31 | } 32 | -------------------------------------------------------------------------------- /tests/pingpong.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include "swarm/api.h" 30 | #include "common.h" 31 | #include 32 | 33 | using namespace std; 34 | 35 | uint64_t __pad0[32]; 36 | uint64_t counter1; 37 | uint64_t __pad1[32]; 38 | uint64_t counter2; 39 | uint64_t __pad2[32]; 40 | 41 | 42 | void ping(uint64_t ts, uint64_t upsLeft) { 43 | if (!upsLeft) return; 44 | counter2 = counter1 + 1; 45 | for (uint32_t i = 0; i < 1000; i++) _mm_pause(); 46 | swarm::enqueue(ping, ts+2, EnqFlags::NOHINT, upsLeft-1); 47 | } 48 | 49 | void pong(uint64_t ts, uint64_t upsLeft) { 50 | if (!upsLeft) return; 51 | counter1 = counter2 + 1; 52 | swarm::enqueue(pong, ts+2, EnqFlags::NOHINT, upsLeft-1); 53 | } 54 | 55 | int main(int argc, const char** argv) { 56 | if (argc != 2) { 57 | cerr << "Usage: " << argv[0] << " " << endl; 58 | return -1; 59 | } 60 | 61 | uint32_t nupdates = atoi(argv[1]); 62 | 63 | counter1 = counter2 = 0; 64 | swarm::enqueue(ping, 0, EnqFlags::NOHINT, nupdates - nupdates/2); 65 | swarm::enqueue(pong, 1, EnqFlags::NOHINT, nupdates/2); 66 | 67 | swarm::run(); 68 | 69 | if (nupdates % 2 == 0) tests::assert_eq(counter1, counter2 + 1); 70 | else tests::assert_eq(counter2, counter1 + 1); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /tests/priv.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "common.h" 27 | #include "swarm/api.h" 28 | #include "swarm/algorithm.h" 29 | #include "swarm/hooks.h" 30 | #include 31 | 32 | typedef std::array Counters; 33 | #define NC (1ul << 12) 34 | 35 | // NOTE(dsm): Ignore provided timestamp, which simulator takes ownership of to 36 | // execute abort handlers ars early as possible 37 | void compensation(uint64_t, uint64_t ts, volatile uint64_t* counter) { 38 | __sync_fetch_and_sub(counter, ts); 39 | } 40 | 41 | void task(uint64_t ts, Counters* tracked, Counters* untracked) { 42 | size_t idx = ts % tracked->size(); 43 | (*tracked)[idx] += ts; 44 | sim_priv_call(); 45 | volatile uint64_t* counter = &(*untracked)[idx]; 46 | // NOTE: We're in multithreaded land now, atomics are a must 47 | __sync_fetch_and_add(counter, ts); 48 | swarm::enqueue(compensation, ts, (EnqFlags)(EnqFlags::SAMEHINT | EnqFlags::CANTSPEC | EnqFlags::RUNONABORT), ts, counter); 49 | sim_priv_ret(); 50 | } 51 | 52 | int main(int argc, const char** argv) { 53 | Counters* tracked = new Counters; 54 | void* ubuf = sim_zero_cycle_untracked_malloc(sizeof(Counters)); 55 | Counters* untracked = new(ubuf) Counters; 56 | 57 | swarm::enqueue_all( 58 | swarm::u64it(0), swarm::u64it(NC), [tracked, untracked](uint64_t i) { 59 | swarm::enqueue(task, i, EnqFlags::NOHINT, tracked, untracked); 60 | }, 0ul); 61 | 62 | swarm::run(); 63 | for (size_t idx = 0; idx < tracked->size(); idx++) { 64 | uint64_t ct = (*tracked)[idx]; 65 | uint64_t cu = (*untracked)[idx]; 66 | if (ct != cu) printf("Mismatch @ %ld %ld != %ld\n", idx, ct, cu); 67 | } 68 | 69 | tests::assert_eq(*tracked, *untracked); 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /tests/rand.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | #include "swarm/rand.h" 28 | 29 | /* Test to see that sim & native patch both return random-looking numbers */ 30 | 31 | int main(int argc, const char** argv) { 32 | for (uint32_t i = 0; i < 128; i++) { 33 | printf("rand64() = %lx\n", swarm::rand64()); 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/read_file.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | 31 | #include "swarm/api.h" 32 | #include "common.h" 33 | 34 | inline void readTask(swarm::Timestamp ts) { 35 | std::ifstream input("heartbeat"); 36 | if (input) { 37 | std::string firstLine; 38 | std::getline(input, firstLine); 39 | assert(firstLine.compare(0, 7, "Running") == 0); 40 | } 41 | } 42 | 43 | int main(int argc, const char** argv) { 44 | swarm::enqueue(readTask, 42, EnqFlags::NOHINT); 45 | swarm::run(); 46 | tests::assert_true(true); 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /tests/realloc.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/algorithm.h" 29 | #include "swarm/api.h" 30 | #include "common.h" 31 | 32 | static void readTask(swarm::Timestamp ts, uint64_t **p) { 33 | if (**p != ts) { 34 | swarm::info("Incorrect value %ld != %ld.", **p, ts); 35 | std::abort(); 36 | } 37 | } 38 | 39 | static void writeTask(swarm::Timestamp ts, uint64_t **p) { 40 | **p = ts; 41 | swarm::enqueue(readTask, ts, NOHINT, p); 42 | } 43 | 44 | static void reallocTask(swarm::Timestamp ts, uint64_t **p) { 45 | size_t sz = malloc_usable_size(*p); 46 | *p = (uint64_t*)realloc(*p, 4 * sz); 47 | } 48 | 49 | static void freeTask(swarm::Timestamp ts, uint64_t **p) { 50 | free(*p); 51 | free(p); 52 | } 53 | 54 | static void allocTask(swarm::Timestamp ts) { 55 | uint64_t *val = (uint64_t*)malloc(sizeof(*val)); 56 | uint64_t **p = (uint64_t**)malloc(sizeof(*p)); 57 | *p = val; 58 | swarm::enqueue(writeTask, ts, NOHINT, p); 59 | swarm::enqueue(reallocTask, ts, NOHINT, p); 60 | swarm::enqueue(freeTask, ts+1, NOHINT, p); 61 | } 62 | 63 | int main(int argc, const char** argv) { 64 | if (argc != 2) { 65 | std::cerr << "Usage: " << argv[0] 66 | << " " << std::endl; 67 | std::abort(); 68 | } 69 | uint64_t numallocs = atoi(argv[1]); 70 | 71 | swarm::enqueue_all( 72 | swarm::u32it(0), 73 | swarm::u32it(numallocs), 74 | [=] (int i) { 75 | swarm::enqueue(allocTask, i, NOHINT); 76 | }, 0); 77 | 78 | swarm::run(); 79 | tests::assert_true(true); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /tests/reduce.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | // This tests the swarm::reduce API. It should have better scalability than 27 | // the reduction.cpp test, whose purpose is to create noisy memory traffic. 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "swarm/api.h" 34 | #include "swarm/numeric.h" 35 | #include "common.h" 36 | 37 | uint64_t sum; 38 | std::vector values; 39 | 40 | int main(int argc, const char** argv) { 41 | if (argc != 2) { 42 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 43 | return -1; 44 | } 45 | size_t size = atoi(argv[1]); 46 | assert(size >= 1); 47 | 48 | values.resize(size); 49 | std::iota(values.begin(), values.end(), 0); 50 | 51 | swarm::reduce(values.begin(), values.end(), 0ul, std::plus(), 52 | 0ul, [] (swarm::Timestamp, uint64_t r) { sum = r; }); 53 | swarm::run(); 54 | 55 | uint64_t blockSize = UINT16_MAX + 1ul; 56 | uint64_t blocks = size / blockSize; 57 | uint64_t lastBlock = size - blocks * blockSize; 58 | uint64_t expected = blocks * (blockSize * (blockSize - 1)) / 2 + 59 | (lastBlock * (lastBlock - 1) / 2); 60 | tests::assert_eq(expected, sum); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /tests/reducible_counter.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include "swarm/api.h" 30 | #include "swarm/algorithm.h" 31 | #include "common.h" 32 | #include "swarm/counter.h" 33 | 34 | using namespace std; 35 | typedef boost::counting_iterator u32it; 36 | 37 | uint64_t __pad0[32]; 38 | volatile uint64_t scounter; 39 | uint64_t __pad1[32]; 40 | swarm::ParallelCounter pcounter; 41 | 42 | 43 | void increment(uint64_t ts) { 44 | uint64_t r = scounter; 45 | pcounter += 1; 46 | scounter = r + 1; 47 | } 48 | 49 | int main(int argc, const char** argv) { 50 | if (argc != 2) { 51 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 52 | return -1; 53 | } 54 | uint32_t nupdates = atoi(argv[1]); 55 | 56 | scounter = 0; 57 | 58 | swarm::enqueue_all(u32it(0), u32it(nupdates), 59 | [](uint32_t i) { 60 | swarm::enqueue(increment, 0, NOHINT); 61 | }, 0ul); 62 | 63 | swarm::run(); 64 | 65 | printf("Counters: s %ld p %ld\n", scounter, pcounter.reduce()); 66 | tests::assert_true( 67 | (scounter == nupdates) && (pcounter.reduce() == nupdates)); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /tests/reduction.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | 29 | #include "reduction.h" 30 | #include "common.h" 31 | 32 | std::vector counters; 33 | 34 | template void enqueuer(swarm::Timestamp, uint32_t, uint32_t); 35 | 36 | int main(int argc, const char** argv) { 37 | setup(argc, argv); 38 | int expected = std::accumulate(counters.begin(), counters.end(), 0); 39 | 40 | swarm::enqueue(enqueuer, 0, EnqFlags::NOHINT, 0, counters.size() - 1); 41 | swarm::run(); 42 | 43 | dump(); 44 | tests::assert_eq(expected, counters[0]); 45 | } 46 | -------------------------------------------------------------------------------- /tests/reduction_hint.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | 29 | #include "reduction.h" 30 | #include "common.h" 31 | 32 | std::vector counters; 33 | 34 | template void enqueuer(swarm::Timestamp, uint32_t, uint32_t); 35 | 36 | int main(int argc, const char** argv) { 37 | setup(argc, argv); 38 | int expected = std::accumulate(counters.begin(), counters.end(), 0); 39 | 40 | swarm::enqueue(enqueuer, 0, EnqFlags::NOHINT, 0, counters.size() - 1); 41 | swarm::run(); 42 | 43 | dump(); 44 | tests::assert_eq(expected, counters[0]); 45 | } 46 | -------------------------------------------------------------------------------- /tests/register_end_handler.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/hooks.h" 27 | #include "common.h" 28 | #include 29 | 30 | static unsigned i; 31 | 32 | void foo() { 33 | printf("Stopped after iteration %d.\n", i); 34 | tests::assert_true(true); 35 | } 36 | 37 | int main() { 38 | sim_register_end_handler(foo); 39 | zsim_roi_begin(); 40 | for (i = 0; i < 1024; i++) zsim_heartbeat(); 41 | zsim_roi_end(); 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /tests/roi_exit.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | 30 | #include "swarm/api.h" 31 | #include "common.h" 32 | 33 | inline void exitTask(swarm::Timestamp ts) { 34 | #if defined(TRY_SYS_EXIT) 35 | syscall(SYS_exit, 1); 36 | #elif defined(TRY_SYS_EXIT_GROUP) 37 | syscall(SYS_exit_group, 1); 38 | #else 39 | exit(1); 40 | #endif 41 | } 42 | 43 | int main(int argc, const char** argv) { 44 | swarm::enqueue(exitTask, 42, EnqFlags::NOHINT); 45 | swarm::run(); 46 | tests::assert_true(true); 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /tests/segfault.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | 32 | #include "common.h" 33 | #include "swarm/api.h" 34 | #include "swarm/algorithm.h" 35 | 36 | /* Causes a null-pointer dereference, both speculatively 37 | * and non-speculatively. Program should end with a 38 | * SIGSEGV. Used to test the Swarm exception model. 39 | */ 40 | 41 | #define NC (4) 42 | 43 | uint64_t count; 44 | bool success = false; 45 | 46 | inline void countTask(swarm::Timestamp ts) { 47 | for (uint32_t i = 0; i < 1000; i++) _mm_pause(); 48 | count++; 49 | } 50 | 51 | inline void exceptionTask(swarm::Timestamp ts) { 52 | //FIXME(victory): Clang is is too smart, it sees this null-pointer dereference, 53 | // gives a warning, and, depending on version, gets rid of it. 54 | if (count < NC) *((volatile uint64_t*)nullptr) = 17; 55 | else success = true; 56 | } 57 | 58 | int main(int argc, const char** argv) { 59 | count = 0; 60 | swarm::enqueue_all( 61 | swarm::u64it(0), swarm::u64it(NC), [](uint64_t i) { 62 | swarm::enqueue(countTask, i, NOHINT); 63 | }, 0ul); 64 | swarm::enqueue(exceptionTask, NC, NOHINT); 65 | 66 | swarm::run(); 67 | 68 | // Should never be reached 69 | tests::assert_eq(success, true); 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /tests/serialize.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | 28 | /* Simple test for swarm::serialize() (hard to do automatically, since PLS 29 | * serializes side-effects automatically). 30 | * 31 | * If serialize() call is not commented, numbers will be printed out in order 32 | * (this relies on the fact that swarm::info from speculative tasks is permitted. 33 | * 34 | * Needs to run on a system with enough task queue entries. 35 | */ 36 | 37 | #define NP (1024ul) 38 | 39 | inline void task(swarm::Timestamp ts) { 40 | swarm::serialize(); 41 | swarm::info("%ld", ts); 42 | } 43 | 44 | int main(int argc, const char** argv) { 45 | for (uint64_t i = 0; i < NP; i++) { 46 | swarm::enqueue(task, i, EnqFlags::NOHINT); 47 | } 48 | 49 | swarm::run(); 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/simguard.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /** 27 | * Used to tests the simulator's gurad against tasks that overwrite its own 28 | * memory. No way to test systematically... 29 | */ 30 | #include 31 | #include "swarm/api.h" 32 | 33 | int main(int argc, const char** argv) { 34 | bool done1 = false; 35 | bool done2 = false; 36 | swarm::enqueueLambda([&done1](swarm::Timestamp ts) { 37 | for (uint32_t i = 0; i < 10000; i++) _mm_pause(); 38 | done1 = true; 39 | }, 0ul, EnqFlags::NOHINT); 40 | swarm::enqueueLambda([&done1, &done2](swarm::Timestamp ts) { 41 | if (!done1) { 42 | // First address in range 43 | *(uint64_t*)(0x0d0000000000ul) = 0xDEADBEEF; 44 | } 45 | done2 = true; 46 | }, 1ul, EnqFlags::NOHINT); 47 | swarm::enqueueLambda([&done2](swarm::Timestamp ts) { 48 | if (!done2) { 49 | // Last address in range 50 | *(uint64_t*)(0x0dfffffffff0ul) = 0xCAFEBABE; 51 | } 52 | }, 2ul, EnqFlags::NOHINT); 53 | swarm::run(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/snprintf.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | #include 31 | #include "swarm/api.h" 32 | #include "swarm/algorithm.h" 33 | #include "common.h" 34 | 35 | typedef boost::counting_iterator u32it; 36 | 37 | using swarm::Timestamp; 38 | 39 | static inline void test(Timestamp ts) { 40 | char buf[1024]; 41 | snprintf(buf, sizeof(buf)-1, "%s\n", "hello world!"); 42 | } 43 | 44 | int main(int argc, const char** argv) { 45 | swarm::enqueue_all( 46 | u32it(0), u32it(32), 47 | [](uint32_t i) { swarm::enqueue(test, 0, NOHINT); }, 48 | 0ul); 49 | 50 | swarm::run(); 51 | 52 | // Print the verification string so that our test scripts don't complain 53 | tests::assert_true(true); 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /tests/stream.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include "swarm/api.h" 30 | #include "swarm/algorithm.h" 31 | 32 | using swarm::u64it; 33 | 34 | // A bunch of stores write to a large array; tests store buffers 35 | 36 | volatile uint64_t* array; 37 | uint64_t passes; 38 | uint64_t elems; 39 | uint64_t strands; 40 | 41 | #define N (1024ul) 42 | #define STRIDE (8ul) // one cache line 43 | 44 | void task(swarm::Timestamp ts, uint64_t strand, uint64_t pass, uint64_t i) { 45 | auto sstart = strand * elems / strands; 46 | auto ssup = (strand + 1) * elems / strands; 47 | 48 | auto start = sstart + i * N * STRIDE; 49 | auto sup = std::min(ssup, start + N * STRIDE); 50 | 51 | for (auto n = start; n < sup; n += STRIDE) { 52 | // Should just be a store 53 | array[n] = n; 54 | } 55 | 56 | if (sup < ssup) { 57 | swarm::enqueue(task, ts, NOHINT, strand, pass, i + 1); 58 | } else if (pass < passes - 1) { 59 | swarm::enqueue(task, ts + 1, NOHINT, strand, pass + 1, 0); 60 | } 61 | } 62 | 63 | int main(int argc, const char** argv) { 64 | if (argc != 3) { 65 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 66 | return -1; 67 | } 68 | 69 | uint64_t memBytes = atoi(argv[1]) * 1024ul * 1024ul; 70 | passes = atol(argv[2]); 71 | 72 | array = (volatile uint64_t*)memalign(64, memBytes); 73 | elems = memBytes / sizeof(array[0]); 74 | strands = swarm::num_threads() * 8; 75 | 76 | swarm::enqueue_all(u64it(0), u64it(strands), 77 | [](uint64_t s) { 78 | swarm::enqueue(task, 0, NOHINT, s, 0, 0); 79 | }, 0ul); 80 | 81 | swarm::run(); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /tests/syscall.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 29 | #include 30 | 31 | #include "swarm/api.h" 32 | #include "common.h" 33 | 34 | const char* words[] = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}; 35 | uint64_t count; 36 | 37 | inline void printTask(swarm::Timestamp ts) { 38 | printf("%s\n", words[/*count++*/ ts]); 39 | fflush(stdout); 40 | } 41 | 42 | int main(int argc, const char** argv) { 43 | count = 0; 44 | for (uint64_t i = 0; i < sizeof(words)/sizeof(const char*); i++) { 45 | swarm::enqueue(printTask, i, EnqFlags::NOHINT); 46 | } 47 | 48 | swarm::run(); 49 | tests::assert_true(true); 50 | return 0; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/threadlocal.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | #include "swarm/algorithm.h" 28 | #include "common.h" 29 | 30 | // Tests whether thread-local data is correctly versioned 31 | 32 | static __thread uint64_t pre = 0; 33 | static __thread uint64_t post = 0; 34 | 35 | static void task(uint64_t ts) { 36 | pre++; 37 | swarm::serialize(); 38 | post++; 39 | // dsm: Because post is only increases post-serialize, a mismatch indicates 40 | // the TLS segment is not versioned. 41 | if (pre != post) { 42 | std::cerr << "Mismatched counters " << pre << " " << post << std::endl; 43 | std::abort(); 44 | } 45 | } 46 | 47 | int main(int argc, const char** argv) { 48 | if (argc != 2) { 49 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 50 | std::abort(); 51 | } 52 | uint64_t nupdates = atoi(argv[1]); 53 | 54 | swarm::enqueue_all( 55 | swarm::u64it(0), swarm::u64it(nupdates), 56 | [](uint64_t c) { 57 | swarm::enqueue(task, c, NOHINT); 58 | }, 0ul); 59 | swarm::run(); 60 | 61 | // dsm: If it hasn't made it to this point 62 | tests::assert_true(true); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /tests/tileId.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 test for swarm::tileId() and swarm::numTiles() */ 27 | 28 | #include 29 | #include "swarm/api.h" 30 | #include "swarm/algorithm.h" 31 | 32 | #include "common.h" 33 | 34 | constexpr unsigned NP = 1024u; 35 | 36 | std::array counters = {0}; 37 | 38 | static void checkSameHint(swarm::Timestamp, unsigned tileId) { 39 | assert(tileId == swarm::tileId()); 40 | } 41 | 42 | static void task(swarm::Timestamp ts, int i) { 43 | const unsigned tileId = swarm::tileId(); 44 | assert(tileId < swarm::numTiles()); 45 | assert(i % swarm::numTiles() == swarm::tileId()); 46 | counters[tileId] += i; 47 | swarm::enqueue(checkSameHint, ts, SAMEHINT | NONSERIALHINT, tileId); 48 | } 49 | 50 | int main(int argc, const char** argv) { 51 | assert(swarm::tileId() == 0); 52 | assert(swarm::tid() == 0); 53 | std::fill(counters.begin(), counters.end(), 0ul); 54 | 55 | const auto numTiles = swarm::numTiles(); 56 | assert(numTiles < NP); 57 | 58 | swarm::enqueue_all(swarm::u64it(0), swarm::u64it(numTiles * 2), 59 | [] (uint64_t i) { 60 | swarm::enqueue(task, i, {i, NOHASH | NONSERIALHINT}, i); 61 | }, 0ul); 62 | 63 | swarm::run(); 64 | 65 | std::array expected = {0}; 66 | for (unsigned i = 0; i < numTiles; i++) expected[i] = 2 * i + numTiles; 67 | tests::assert_eq(expected, counters); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /tests/transform.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | // This tests the swarm::transform API task 27 | // It should suffer zero aborts, but it took careful changes to cps.h to make 28 | // that happen. 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "swarm/api.h" 35 | // TODO(mcj) move swarm::transform to algorithm.h to mimic 36 | // That isn't possible right now because 37 | // transform.h #includes cps.h which #includes algorithm.h 38 | // We should move enqueue_all out of algorithm.h 39 | #include "swarm/impl/transform.h" 40 | #include "common.h" 41 | 42 | int main(int argc, const char** argv) { 43 | if (argc != 2) { 44 | std::cerr << "Usage: " << argv[0] << " " << std::endl; 45 | return -1; 46 | } 47 | size_t size = atoi(argv[1]); 48 | assert(size >= 1); 49 | 50 | std::vector input, output, expected; 51 | input.resize(size); 52 | output.resize(size); 53 | expected.resize(size); 54 | 55 | std::iota(input.begin(), input.end(), 0); 56 | std::iota(expected.begin(), expected.end(), 1); 57 | 58 | swarm::transform(input.cbegin(), input.cend(), output.begin(), 59 | [] (uint16_t i) { return i + 1; }, 60 | 0ul); 61 | swarm::run(); 62 | 63 | tests::assert_eq(expected, output); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tests/undeepen.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 "swarm/api.h" 27 | #include "swarm/algorithm.h" 28 | #include "common.h" 29 | 30 | static void incrementTask(swarm::Timestamp, uint64_t *x) { ++*x; } 31 | static void doubleTask(swarm::Timestamp, uint64_t *x) { *x *= 2; } 32 | static void finalTask(swarm::Timestamp, uint64_t *x) { 33 | if (*x != 4) 34 | std::abort(); 35 | delete x; 36 | } 37 | 38 | static void rootTask(swarm::Timestamp ts) { 39 | uint64_t *x = new uint64_t; 40 | *x = 1; 41 | swarm::deepen(); 42 | swarm::enqueue(incrementTask, ts+42, EnqFlags::NOHINT, x); 43 | swarm::undeepen(); 44 | ts = swarm::timestamp(); 45 | swarm::enqueue(doubleTask, ts, EnqFlags::NOHINT, x); 46 | swarm::enqueue(finalTask, ts+1, EnqFlags::NOHINT, x); 47 | } 48 | 49 | 50 | int main(int argc, const char** argv) { 51 | if (argc != 2) { 52 | std::cerr << "Usage: " << argv[0] 53 | << " " << std::endl; 54 | std::abort(); 55 | } 56 | 57 | swarm::enqueue_all(swarm::u64it(0), swarm::u64it(atoi(argv[1])), 58 | [] (uint64_t i) { 59 | swarm::enqueue(rootTask, i, EnqFlags::NOHINT); 60 | }, 0ul); 61 | swarm::run(); 62 | 63 | tests::assert_true(true); 64 | 65 | return 0; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /tests/undo_after_exception.cpp: -------------------------------------------------------------------------------- 1 | /** $lic$ 2 | * Copyright (C) 2014-2021 by Massachusetts Institute of Technology 3 | * 4 | * This file is part of the Swarm simulator. 5 | * 6 | * This simulator is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation, version 2. 9 | * 10 | * This simulator was developed as part of the Swarm architecture project. If 11 | * you use this software in your research, we request that you reference the 12 | * Swarm MICRO 2018 paper ("Harmonizing Speculative and Non-Speculative 13 | * Execution in Architectures for Ordered Parallelism", Jeffrey et al., 14 | * MICRO-51, 2018) as the source of this simulator in any publications that use 15 | * this software, and that you send us a citation of your work. 16 | * 17 | * This simulator is distributed in the hope that it will be useful, but 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 | * more 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 | /* A task that hits an exception must undo its speculative writes before it 27 | * proceeds to execute a second time. 28 | * 29 | * The 'exception' task transitions the 'finished' variable from false to true. 30 | * However it should read a value of false first. If it does not undo its 31 | * speculative writes before executing a second time, the exception task will 32 | * read true. 33 | * 34 | * The 'delayer' task exists to hold back the GVT so that the exception task 35 | * does trigger an exception. 36 | */ 37 | 38 | #include 39 | #include "swarm/api.h" 40 | #include "common.h" 41 | #include "swarm/aligned.h" 42 | 43 | 44 | swarm::aligned finished = false; 45 | swarm::aligned success = false; 46 | 47 | void exception(swarm::Timestamp) { 48 | success = !finished; 49 | finished = true; 50 | 51 | // Trigger an exception 52 | swarm::serialize(); 53 | } 54 | 55 | void delayer(swarm::Timestamp ts) { 56 | swarm::enqueue(exception, ts, EnqFlags::NOHINT); 57 | 58 | // Artificially delay commit 59 | for (uint32_t i = 0; i < 10000; i++) _mm_pause(); 60 | } 61 | 62 | int main(int argc, const char** argv) { 63 | swarm::enqueue(delayer, 0, EnqFlags::NOHINT); 64 | swarm::run(); 65 | 66 | tests::assert_true(success); 67 | return 0; 68 | } 69 | --------------------------------------------------------------------------------