Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3fc1274
feat: add build bash script and gitignore items
gtxzsxxk Mar 11, 2025
16787ba
refactor: remove the PIN in this world
gtxzsxxk Mar 11, 2025
f8440b2
deocder: feat: add risc-v integer instructions decode function
gtxzsxxk Mar 11, 2025
28b9733
decoder: feat: add risc-v immediate integer instructions support
gtxzsxxk Mar 11, 2025
8e5b081
decoder: feat: add risc-v load/store and branch and load imm integer …
gtxzsxxk Mar 11, 2025
c861083
decoder: feat: add risc-v atomi, system and fence instructions support
gtxzsxxk Mar 11, 2025
f3d066d
decoder: feat: add risc-v floating instruction modeling
gtxzsxxk Mar 11, 2025
7e3dadb
decoder: feat: add risc-v compressed and vector instruction modeling
gtxzsxxk Mar 12, 2025
63f32d4
decoder: refactor: adapt to the riscv's micro operation logics
gtxzsxxk Mar 12, 2025
1e197b4
decoder: refactor: use riscv micro-op emit function to support decode
gtxzsxxk Mar 12, 2025
3e0ffb0
decoder: fix: incorrect auipc opcode value
gtxzsxxk Mar 12, 2025
c5e2b08
decoder: fix: incorrect unwrapped switch-case statement
gtxzsxxk Mar 12, 2025
672ab1c
decoder: feat: finish instruction decode and ask the frontend for vec…
gtxzsxxk Mar 12, 2025
f6711e0
decoder: refactor: basic block decoding logics support risc-v instruc…
gtxzsxxk Mar 14, 2025
5f51863
refactor: remove the virt code which we will not use
gtxzsxxk Mar 16, 2025
36a07ac
refactor: remove the unused PinCmd code
gtxzsxxk Mar 16, 2025
c812803
refactor: remove the unused zsim_harness related code
gtxzsxxk Mar 16, 2025
25a0f1f
refactor: remove PIN related code and reimplement them
gtxzsxxk Mar 16, 2025
12f4d32
fix: compile error and solved by using correct header file
gtxzsxxk Mar 17, 2025
822676b
decoder: refactor: riscv has 32 general purposed registers
gtxzsxxk Mar 17, 2025
1ae0f16
fix: remove unused and compile-error-causing code
gtxzsxxk Mar 17, 2025
6dcd63e
fix: compile errors by reimplementing the buggy code
gtxzsxxk Mar 17, 2025
061ffd2
refactor: use debug option to compile
gtxzsxxk Mar 17, 2025
4dca22f
decoder: fix: instructions should be counted when not ooo decoding
gtxzsxxk Mar 17, 2025
aed3d32
feat: add test basic block traces for debugging
gtxzsxxk Mar 17, 2025
41f8696
refactor: use atomical bool to record thread activity and reimplement…
gtxzsxxk Mar 17, 2025
e25c4e5
fix: missing an invert when iterating bbl's instructions
gtxzsxxk Mar 17, 2025
75eaf48
feat: check per thread next basic block start address
gtxzsxxk Mar 17, 2025
ab389c1
feat: use c++ 20
gtxzsxxk Mar 18, 2025
dac877f
refactor: use a producer-consumer model to simulate in other threads
gtxzsxxk Mar 18, 2025
2b64507
feat: introduce IPCHandler to read trace data from client via unix do…
gtxzsxxk Mar 19, 2025
0f8320d
refactor: Basic Block data type to be compatible with C programs
gtxzsxxk Mar 19, 2025
a5d7591
feat: add deconstruction function for trace data structures
gtxzsxxk Mar 19, 2025
b5b0a79
zsim: refactor: read trace data from IPCHelper and reserve the test code
gtxzsxxk Mar 19, 2025
40d63ac
refactor: add virtual, midgard and physical types of address in struct
gtxzsxxk Mar 24, 2025
d0a0d46
refactor: reduce redundant data in structure branch information
gtxzsxxk Mar 24, 2025
b94df55
fix: do not assert the bbl end-to-start address because there might b…
gtxzsxxk Mar 24, 2025
6723476
refactor: PrepareNextInstruction needs the address of each instruction
gtxzsxxk Mar 24, 2025
006054e
refactor: load-stores should not be aligned with each instruction eve…
gtxzsxxk Mar 24, 2025
f24079c
decoder: feat: add a helper function to find the ldst instructions
gtxzsxxk Mar 24, 2025
d49aa2d
feat: support ending simulation when one unix domain socket breaks
gtxzsxxk Mar 24, 2025
4474ccb
feat: introduce trace acknowledge to synchronize the client and server
gtxzsxxk Mar 27, 2025
c0b6451
fix: incorrect linked list iterating of ldst data of each BBL
gtxzsxxk Apr 2, 2025
913de36
fix: ipc handler should receive ldst data according to BBL's loadstores
gtxzsxxk Apr 2, 2025
1be9ba9
fix: do not count for store conditional instructions
gtxzsxxk Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ zsim-ev.h5
zsim-cmp.h5
out.cfg
heartbeat
myPatchRoot/
myPatchRoot/
.cache/
pin.log
compile_commands.json
146 changes: 3 additions & 143 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def buildSim(cppFlags, dir, type, pgo=None):
versionFile = joinpath(buildDir, "version.h")
if os.path.exists(".git"):
env.Command(versionFile, allSrcs + [".git/index", "SConstruct"],
'printf "#define ZSIM_BUILDDATE \\"`date`\\"\\n#define ZSIM_BUILDVERSION \\"`python misc/gitver.py`\\"" >>' + versionFile)
'printf "#define ZSIM_BUILDDATE \\"`date`\\"\\n#define ZSIM_BUILDVERSION \\"`python3 misc/gitver.py`\\"" >>' + versionFile)
else:
env.Command(versionFile, allSrcs + ["SConstruct"],
'printf "#define ZSIM_BUILDDATE \\"`date`\\"\\n#define ZSIM_BUILDVERSION \\"no git repo\\"" >>' + versionFile)
Expand All @@ -33,23 +33,6 @@ def buildSim(cppFlags, dir, type, pgo=None):
env['CC'] = 'icc'
env['CXX'] = 'icpc -ipo'

# Required paths
if "PINPATH" in os.environ:
PINPATH = os.environ["PINPATH"]
else:
print("ERROR: You need to define the $PINPATH environment variable with Pin's path")
sys.exit(1)

# Pin 3 introduces PinCRT.
withPinCrt = os.path.exists(joinpath(PINPATH, "extras/crt"))
if withPinCrt:
pinCrtDir = joinpath(PINPATH, "extras/crt")
pinCrtLibDir = joinpath(PINPATH, "intel64/runtime/pincrt")
assert os.path.exists(pinCrtDir)
assert os.path.exists(pinCrtLibDir)
# Pin 3.24 starts to support most C++11
withPinCrtCXX11 = os.path.exists(joinpath(PINPATH, "extras/cxx"))

ROOT = Dir('.').abspath

# NOTE: These flags are for the 28/02/2011 2.9 PIN kit (rev39599). Older versions will not build.
Expand All @@ -58,49 +41,12 @@ def buildSim(cppFlags, dir, type, pgo=None):
# NOTE (dsm 16 Apr 2015): Update flags code to support Pin 2.14 while retaining backwards compatibility
# NOTE (gaomy May 2019): Set ABI version
# NOTE (gaomy Sept 2020): Add -Wno-unused-function for the template ilog2
env["CPPFLAGS"] += " -g -std=c++0x -Wall -Wno-unknown-pragmas -fomit-frame-pointer -fno-stack-protector"
env["CPPFLAGS"] += " -g -std=c++20 -Wall -Wno-unknown-pragmas -fomit-frame-pointer -fno-stack-protector"
env["CPPFLAGS"] += " -MMD -DBIGARRAY_MULTIPLIER=1 -DUSING_XED -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX"
env["CPPFLAGS"] += " -fabi-version=2"
env["CPPFLAGS"] += " -Wno-unused-function"

# Add more flags and system paths for pintool if with PinCRT.
if withPinCrt:
env["CPPFLAGS"] += " -D__PIN__=1 -DPIN_CRT=1"
env["CPPFLAGS"] += " -fno-exceptions -fno-rtti -funwind-tables -fasynchronous-unwind-tables"
env["CPPFLAGS"] += " -Ddynamic_cast=static_cast"
if withPinCrtCXX11:
env["CPPFLAGS"] += " -isystem " + joinpath(PINPATH, "extras/cxx/include")
else:
env["CPPFLAGS"] += " -isystem " + joinpath(PINPATH, "extras/stlport/include")
env["CPPFLAGS"] += " -isystem " + joinpath(PINPATH, "extras/libstdc++/include")
env["CPPFLAGS"] += " -isystem " + joinpath(PINPATH, "extras/libunwind/include")
env["CPPFLAGS"] += " -isystem " + joinpath(pinCrtDir, "include")
env["CPPFLAGS"] += " -isystem " + joinpath(pinCrtDir, "include/arch-x86_64")
env["CPPFLAGS"] += " -isystem " + joinpath(pinCrtDir, "include/kernel/uapi")
env["CPPFLAGS"] += " -isystem " + joinpath(pinCrtDir, "include/kernel/uapi/asm-x86")

# Pin 2.12+ kits have changed the layout of includes, detect whether we need
# source/include/ or source/include/pin/
pinInclDir = joinpath(PINPATH, "source/include/")
if not os.path.exists(joinpath(pinInclDir, "pin.H")):
pinInclDir = joinpath(pinInclDir, "pin")
assert os.path.exists(joinpath(pinInclDir, "pin.H"))

# Pin 2.14 changes location of XED
# Pin 3 changes location of XED again
xedName = "xed2" # used below
xedPath = joinpath(PINPATH, "extras/" + xedName + "-intel64/include")
if not os.path.exists(xedPath):
xedName = "xed"
xedPath = joinpath(PINPATH, "extras/" + xedName + "-intel64/include")
if os.path.exists(joinpath(xedPath, "xed")):
xedPath = joinpath(xedPath, "xed")
assert os.path.exists(xedPath)

env["CPPPATH"] = [xedPath,
pinInclDir, joinpath(pinInclDir, "gen"),
joinpath(PINPATH, "extras/components/include")]

env["CPPPATH"] = []
# Perform trace logging?
##env["CPPFLAGS"] += " -D_LOG_TRACE_=1"

Expand All @@ -110,47 +56,6 @@ def buildSim(cppFlags, dir, type, pgo=None):
# Be a Warning Nazi? (recommended)
# env["CPPFLAGS"] += " -Werror "

# Enables lib and harness to use the same info/log code,
# but only lib uses pin locks for thread safety
env["PINCPPFLAGS"] = " -DMT_SAFE_LOG "

# PIN-specific libraries
env["PINLINKFLAGS"] = " -Wl,--hash-style=sysv -Wl,-Bsymbolic -Wl,--version-script=" + joinpath(pinInclDir, "pintool.ver")

# To prime system libs, we include /usr/lib and /usr/lib/x86_64-linux-gnu
# first in lib path. In particular, this solves the issue that, in some
# systems, Pin's libelf takes precedence over the system's, but it does not
# include symbols that we need or it's a different variant (we need
# libelfg0-dev in Ubuntu systems)
# NOTE(gaomy May 2019): PinCRT use its own libs and the system libs are
# disallowed, so libelf dependency is removed.
env["PINLIBPATH"] = [joinpath(PINPATH, "extras/" + xedName + "-intel64/lib"),
joinpath(PINPATH, "intel64/lib"), joinpath(PINPATH, "intel64/lib-ext")]

# Libdwarf is provided in static and shared variants, Ubuntu only provides
# static, and I don't want to add -R<pin path/intel64/lib-ext> because
# there are some other old libraries provided there (e.g., libelf) and I
# want to use the system libs as much as possible. So link directly to the
# static version of libdwarf.

# Pin 2.14 uses unambiguous libpindwarf
# Pin 3 uses libpin3dwarf
# Pin 3.25 changes back to libpindwarf and changes its path
pindwarfPath = joinpath(PINPATH, "intel64/lib-ext/libdwarf.a")
pindwarfLib = File(pindwarfPath)
if not os.path.exists(pindwarfPath):
pindwarfPath = joinpath(PINPATH, "intel64/lib-ext/libpindwarf.a")
pindwarfLib = "pindwarf"
if not os.path.exists(pindwarfPath):
pindwarfPath = joinpath(PINPATH, "intel64/lib-ext/libpin3dwarf.so")
pindwarfLib = "pin3dwarf"
if not os.path.exists(pindwarfPath):
pindwarfPath = joinpath(PINPATH, "intel64/lib/libpindwarf.so")
pindwarfLib = "pindwarf"
assert os.path.exists(pindwarfPath)

env["PINLIBS"] = ["pin", "xed", pindwarfLib]

# Non-pintool libraries
env["LIBPATH"] = []
env["LIBS"] = ["config", "hdf5", "hdf5_hl"]
Expand All @@ -177,26 +82,20 @@ def buildSim(cppFlags, dir, type, pgo=None):
if "MBEDTLSPATH" in os.environ:
MBEDTLSPATH = os.environ["MBEDTLSPATH"]
env["LINKFLAGS"] += " -Wl,-R" + joinpath(MBEDTLSPATH, "lib")
env["PINLIBPATH"] += [joinpath(MBEDTLSPATH, "lib")]
env["CPPPATH"] += [joinpath(MBEDTLSPATH, "include")]
env["PINLIBS"] += ["mbedcrypto"]
env["CPPFLAGS"] += " -D_WITH_MBEDTLS_=1 "

if "POLARSSLPATH" in os.environ:
POLARSSLPATH = os.environ["POLARSSLPATH"]
env["LINKFLAGS"] += " -Wl,-R" + joinpath(POLARSSLPATH, "lib")
env["PINLIBPATH"] += [joinpath(POLARSSLPATH, "library")]
env["CPPPATH"] += [joinpath(POLARSSLPATH, "include")]
env["PINLIBS"] += ["polarssl"]
env["CPPFLAGS"] += " -D_WITH_POLARSSL_=1 "

# Only include DRAMSim if available
if "DRAMSIMPATH" in os.environ:
DRAMSIMPATH = os.environ["DRAMSIMPATH"]
env["LINKFLAGS"] += " -Wl,-R" + DRAMSIMPATH
env["PINLIBPATH"] += [DRAMSIMPATH]
env["CPPPATH"] += [DRAMSIMPATH]
env["PINLIBS"] += ["dramsim"]
env["CPPFLAGS"] += " -D_WITH_DRAMSIM_=1 "

# addr2line from GNU binutils is used as an independent third-party executable called by zsim when backtracing bugs.
Expand All @@ -208,47 +107,8 @@ def buildSim(cppFlags, dir, type, pgo=None):

env["CPPPATH"] += ["."]

# PinCRT libs. These libs are needed by both the shared lib pintool and the utilities.
if withPinCrt:
# PinCRT has issues, and we allow to apply our patches to it.
if "PINCRTPATCHPATH" in os.environ:
PINCRTPATCHPATH = os.environ["PINCRTPATCHPATH"]
env["LINKFLAGS"] += " -Wl,-R" + PINCRTPATCHPATH + " -Wl,--no-as-needed"
env["LIBPATH"] += [PINCRTPATCHPATH]
env["LIBS"] += ["pincrtpatch"]
env["LINKFLAGS"] += " -nostdlib -Wl,-R" + pinCrtLibDir
env["LIBPATH"] += [pinCrtLibDir]
if withPinCrtCXX11:
env["LIBS"] += ["dl-dynamic", "m-dynamic", "c-dynamic", "c++", "c++abi", "unwind-dynamic"]
else:
env["LIBS"] += ["dl-dynamic", "stlport-dynamic", "m-dynamic", "c-dynamic", "unwind-dynamic"]
env["CRTBEGIN"] = [joinpath(pinCrtLibDir, "crtbegin.o")]
env["CRTEND"] = [joinpath(pinCrtLibDir, "crtend.o")]
env["CRTBEGINS"] = [joinpath(pinCrtLibDir, "crtbeginS.o")]
env["CRTENDS"] = [joinpath(pinCrtLibDir, "crtendS.o")]
env["LINKCOM"] = "$LINK -o $TARGET $LINKFLAGS $CRTBEGIN $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $CRTEND"
env["SHLINKCOM"] = "$SHLINK -o $TARGET $SHLINKFLAGS $CRTBEGINS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $CRTENDS"

# Harness needs these defined
env["CPPFLAGS"] += ' -DPIN_PATH="' + joinpath(PINPATH, "intel64/bin/pinbin") + '" '
env["CPPFLAGS"] += ' -DZSIM_PATH="' + joinpath(ROOT, joinpath(buildDir, "libzsim.so")) + '" '
env["CPPFLAGS"] += ' -DLDLIB_PATH="' + ":".join(env["LIBPATH"] + env["PINLIBPATH"]) + '" '
if withPinCrt:
env["CPPFLAGS"] += ' -DPIN_CRT_TZDATA="' + joinpath(PINPATH, "extras/crt/tzdata") + '" '
# PinCRT header <functional> misses NULL declaration
env["CPPFLAGS"] += ' -DNULL=0 '

# Do PGO?
if pgo == "generate":
genFlags = " -prof-gen " if useIcc else " -fprofile-generate "
env["PINCPPFLAGS"] += genFlags
env["PINLINKFLAGS"] += genFlags
elif pgo == "use":
if useIcc: useFlags = " -prof-use "
else: useFlags = " -fprofile-use -fprofile-correction "
# even single-threaded sims use internal threads, so we need correction
env["PINCPPFLAGS"] += useFlags
env["PINLINKFLAGS"] += useFlags

env.SConscript("src/SConscript", variant_dir=buildDir, exports= {'env' : env.Clone()})

Expand Down
5 changes: 5 additions & 0 deletions make.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

export LIBCONFIGPATH=$HOME/.local
export HDF5PATH=$HOME/.local
bear -- scons --d -j64
28 changes: 9 additions & 19 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
Import("env")

commonSrcs = ["config.cpp", "galloc.cpp", "log.cpp", "pin_cmd.cpp"]
harnessSrcs = ["zsim_harness.cpp", "debug_harness.cpp"]
commonSrcs = ["config.cpp", "galloc.cpp", "log.cpp"]
harnessSrcs = ["debug_harness.cpp"]

# By default, we compile all cpp files in libzsim.so. List the cpp files that
# should be excluded below (one per line and in order, to ease merges)
Expand All @@ -16,22 +16,12 @@ excludeSrcs = [
excludeSrcs += harnessSrcs

libEnv = env.Clone()
libEnv["CPPFLAGS"] += libEnv["PINCPPFLAGS"]
libEnv["LINKFLAGS"] += libEnv["PINLINKFLAGS"]
libEnv["LIBPATH"] += libEnv["PINLIBPATH"]
libEnv["LIBS"] += libEnv["PINLIBS"]

# Build syscall name file
def getSyscalls(): return os.popen("python ../../misc/list_syscalls.py").read().strip()
syscallSrc = libEnv.Substfile("virt/syscall_name.cpp", "virt/syscall_name.cpp.in",
SUBST_DICT = {"SYSCALL_NAME_LIST" : getSyscalls()})

# Build libzsim.so
globSrcNodes = Glob("*.cpp") + Glob("virt/*.cpp")
globSrcNodes = Glob("*.cpp")
libSrcs = [str(x) for x in globSrcNodes if str(x) not in excludeSrcs]
libSrcs += [str(x) for x in syscallSrc]
libSrcs = list(set(libSrcs)) # ensure syscallSrc is not duplicated
libEnv.SharedLibrary("zsim.so", libSrcs)
libSrcs = list(set(libSrcs))
libEnv.Program("zsim", libSrcs)

# Build tracing utilities
traceEnv = env.Clone()
Expand All @@ -42,8 +32,8 @@ traceEnv.Program("sorttrace", ["sorttrace.cpp", "access_tracing.cpp"] + commonSr
# Build harness (static to make it easier to run across environments)
# NOTE(gaomy): with PinCRT we cannot build static as CRT only provides shared libs.
# env["LINKFLAGS"] += " --static "
env["LIBS"] += ["c"] # required by wordexp in zsim harness
env.Program("zsim", harnessSrcs + commonSrcs)
# env["LIBS"] += ["c"] # required by wordexp in zsim harness
# env.Program("zsim", commonSrcs)

# Build additional utilities below
env.Program("fftoggle", ["fftoggle.cpp"] + commonSrcs)
# # Build additional utilities below
# env.Program("fftoggle", ["fftoggle.cpp"] + commonSrcs)
6 changes: 3 additions & 3 deletions src/contention_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ bool ContentionSim::CompareDomains::operator()(DomainData* d1, DomainData* d2) c
}


void ContentionSim::SimThreadTrampoline(void* arg) {
ContentionSim* csim = static_cast<ContentionSim*>(arg);
void ContentionSim::SimThreadTrampoline(ContentionSim* arg) {
ContentionSim* csim = arg;
uint32_t thid = __sync_fetch_and_add(&csim->threadTicket, 1);
csim->simThreadLoop(thid);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ ContentionSim::ContentionSim(uint32_t _numDomains, uint32_t _numSimThreads) {
threadTicket = 0;
__sync_synchronize();
for (uint32_t i = 0; i < numSimThreads; i++) {
PIN_SpawnInternalThread(SimThreadTrampoline, this, 1024*1024, nullptr);
simThreadVec.emplace_back(SimThreadTrampoline, this);
}

lastCrossing = gm_calloc<CrossingEventInfo>(numDomains*numDomains*MAX_THREADS); //TODO: refine... this allocs too much
Expand Down
5 changes: 4 additions & 1 deletion src/contention_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <functional>
#include <stdint.h>
#include <vector>
#include <thread>
#include "bithacks.h"
#include "event_recorder.h"
#include "g_std/g_vector.h"
Expand Down Expand Up @@ -160,10 +161,12 @@ class ContentionSim : public GlobAlloc {
#endif

private:
std::vector<std::thread> simThreadVec;

void simThreadLoop(uint32_t thid);
void simulatePhaseThread(uint32_t thid);

static void SimThreadTrampoline(void* arg);
static void SimThreadTrampoline(ContentionSim* arg);
};

#endif // CONTENTION_SIM_H_
Loading