Learning Gem5 Part I

Transcription

Learning gem5 – Part IGetting started with gem5Jason .engineering.ucdavis.edu/lowepower/ Jason Lowe-Power jason@lowepower.com 1

What is gem5?Michigan m5 Wisconsin GEMS gem5“The gem5 simulator is a modular platform for computersystem architecture research, encompassing system-levelarchitecture as well as processor microarchitecture.”Nathan Binkert, Bradford Beckmann, Gabriel Black, Steven K. Reinhardt, Ali Saidi, Arkaprava Basu, JoelHestness, Derek R. Hower, Tushar Krishna, Somayeh Sardashti, Rathijit Sen, Korey Sewell, Muhammad Shoaib,Nilay Vaish, Mark D. Hill, and David A. Wood. 2011. The gem5 simulator. SIGARCH Comput. Archit. News 39, 2(August 2011), 1-7. DOI http://dx.doi.org/10.1145/2024716.2024718 Jason Lowe-Power jason@lowepower.com 2

Tutorial and book are open /powerjg/learning gem5See a problem?Open a pull request or issueWant to add new material? Let me know!Creative commons licenseAttribution 4.0Want to do your own version of this? tations Jason Lowe-Power jason@lowepower.com 3

This tutorialThis is going to interactiveWork along with me for best resultsAsk questions!! Jason Lowe-Power jason@lowepower.com 4

ScheduleLearning Part IBreakLearning Part IILunchLearning Part IV & IIIBreakgem5 Best PracticesOpen forum8:30 – 10:00LearningPartPartI:III:LearningIntro to Ruby Buildinggem510:00 – 10:30SimplescriptsMSI protocol Config10:30 – 12:00Learning Part II:Configuring gem5outputRuby Event-driven simulation12:00 – 1:30DebuggingRuby SimpleSimObject SimObject parameters1:30 – 3:30Learning Part IV: MemoryBestPractices:system objects3:30 – 4:00 gem5 ISAs and CPU models Simpletocache Contributinggem5modelOverview of gem5’s CPUs4:00 – 5:00 Ryota:Visualizing the O3 CPUBuilding a simple CPU5:00 – 5:30 Éder:gem5 for Memory Research Jason Lowe-Power jason@lowepower.com 5

Building tml Jason Lowe-Power jason@lowepower.com 6

Let’s get started! git em5 cd gem5 git checkout –b asplos scons build/X86/gem5.opt –j5and now we wait (about 8 minutes) Jason Lowe-Power jason@lowepower.com 7

scons build/X86/gem5.opt –j5scons: the build systemthat gem5 uses (likemake). Seehttp://scons.org/build/X86/gem5.opt: “parameter”passed to scons. gem5’s Sconscriptinterprets this. Also, the patch tothe gem5 executable.X86: Specifies thedefault build options.See build opts/*opt: version of executableto compile (one of debug,opt, perf, fast) Jason Lowe-Power jason@lowepower.com 8

gem5 architecturegem5 consists of “SimObjects”Most C objects in gem5 inheritfrom class SimObjectRepresent physical systemcomponents Jason Lowe-Power jason@lowepower.com 9

gem5 architecturegem5 is a discrete event simulatorEvent Queue1) Event at head dequeued2) Event executed3) More events queuedEvent - 52Event - 50Event - 50Event - 20Event - 11Event - 10Event - 55We’ll cover moreafter the breakAll SimObjects can enqueueevents to the event queue Jason Lowe-Power jason@lowepower.com 10

gem5 configuration scriptshttp://learning.gem5.org/book/part1/simple he config.html Jason Lowe-Power jason@lowepower.com 11

gem5 user interfacegem5 completely controlled byPython scriptsScripts define system to modelAll (C ) SimObjects exposed toPythonSo let’s make one! Jason Lowe-Power jason@lowepower.com 12

Simple config scriptSingle CPU connected to amemory busSwitch! Jason Lowe-Power jason@lowepower.com 13

Simple config scriptconfigs/learning gem5/part1/simple.py Jason Lowe-Power jason@lowepower.com 14

Running gem5 X86/gem5.opt:the gem5 binary to runconfigs/ /simple.py:the configurationscript (config script) Jason Lowe-Power jason@lowepower.com 15

Port interface system.cpu.icache port system.membus.slavesystem.cpu.dcache port system.membus.slave.system.mem ctrl.port system.membus.masterPorts connect MemObjectsRequestsMasterSlaveTo register a connection betweenmaster and slave, use ‘ ’ in PythonResponses Jason Lowe-Power jason@lowepower.com 16

Syscall Emulation (SE) mode process Process()process.cmd [‘tests/./hello’]system.cpu.workload process.root Root(full system False)SE mode emulates the operatingsystem (Linux) syscalls. No OS runs.Full system mode runs a full OS as if gem5 isa “bare metal” system. Like full virtualization.process: an emulated processwith emulated page tables,file descriptors, etc. Jason Lowe-Power jason@lowepower.com 17

Going further: Adding cacheshttp://learning.gem5.org/book/part1/cache config.htmlExtending SimObjects in Python configSwitch!Object-oriented config filesAdding command-line parameters Jason Lowe-Power jason@lowepower.com 18

It’s just Python! class L1Cache(Cache): . class L1ICache(L1Cache): def connectCPU(self, cpu): self.cpu side cpu.icache port .Use good object-orienteddesign!See text for detailsDebugging config files iseasy. Just add some printstatements!Use Python builtins toprovide support forcommand line parameters. Jason Lowe-Power jason@lowepower.com 19

Understanding gem5 outputhttp://learning.gem5.org/book/part1/gem5 stats.html Jason Lowe-Power jason@lowepower.com 20

Understanding gem5 output ls m5outconfig.iniconfig.jsonstats.txtconfig.ini: Dumps all of thestats.txt: Detailed statisticparameters of all SimObjects.output. Each SimObjectThis shows exactly what youdefines and updates statistics.simulated.config.json: Same as They are printed here at theconfig.ini, but in json end of simulation.format. Jason Lowe-Power jason@lowepower.com 21

stats.txtSwitch!---------- Begin Simulation Statistics ---------sim seconds0.000346# Number of seconds simulatedsim ticks345518000# Number of ticks simulatedfinal tick345518000# Number of ticks from beginning .name of stat. Thissim freq1000000000000 # Frequency of simulatedsim seconds:ticks.shows simulated guest timesim insts5712# Number of instructions simulatedsim ops10314# Number of ops (including micro .EverySimObjectcanhaveitssystem.mem ctrl.bytes read::cpu.inst 58264 # Number of bytes .ownofstats.are what yousystem.mem ctrl.bytes read::cpu.data 7167# NumberbytesNames.used in the Python config filesystem.cpu.committedOps10314 # Number of ops (.system.cpu.num int alu accesses 10205 # Number of integer . Jason Lowe-Power jason@lowepower.com 22

Example scriptsSwitch! Jason Lowe-Power jason@lowepower.com 23

Questions?We coveredgem5 historyDownloading and building gem5gem5’s user interface: pythonHow to write a configuration scriptgem5’s outputUsing the example scripts Jason Lowe-Power jason@lowepower.com 24

What is gem5? Michigan m5 Wisconsin GEMS gem5 The gem5 simulator is a modular platform for compute