33
Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015 T04-1 http://csg.csail.mit.edu/6.175

Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Embed Size (px)

Citation preview

Page 1: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Constructive Computer ArchitectureTutorial 4

Debugging

Sizhuo Zhang6.175 TA

Oct 23, 2015 T04-1http://csg.csail.mit.edu/6.175

Page 2: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

BSV Debug -- $display

See a bug, not sure what causes itAdd $display statementsRecompileRunStill see bug, but you have narrowed it down to a smaller portion of codeRepeat with more display statements…Find bug, fix bug, and remove display statements

Oct 23, 2015 T04-2http://csg.csail.mit.edu/6.175

Page 3: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

BSV Display Statements

The $display() command is an action that prints statements to the simulation consoleExamples: $display(“Hello World!”); $display(“The value of x is %d”, x); $display(“The value of y is “, fshow(y));

Oct 23, 2015 T04-3http://csg.csail.mit.edu/6.175

Page 4: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Ways to Display ValuesFormat Specifiers

%d – decimal%b – binary%o – octal%h – hexadecimal%0d, %0b, %0o, %0h Show value without extra whitespace

padding

Oct 23, 2015 T04-4http://csg.csail.mit.edu/6.175

Page 5: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Ways to Display Valuesfshow

fshow is a function in the FShow typeclassIt can be derived for enumerations and structuresExample:

typedef emun {Red, Blue} Colors deriving(FShow);Color c = Red;$display(“c is “, fshow(c));

Oct 23, 2015 T04-5http://csg.csail.mit.edu/6.175

Prints “c is Red”

Page 6: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

BSV DebuggingWaveform Viewer

Simulation executables can dump VCD waveforms

./bsim_dut –V test.vcd

Produces test.vcd containing the values of all the signals used in the simulator

Not the same as normal BSV signals

VCD files can be viewed by a waveform viewer Such as gtkwave

The signal names and values in test.vcd can be hard to understand

Especially for structures and enumerations

Oct 23, 2015 T04-6http://csg.csail.mit.edu/6.175

Page 7: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Bluespec GUI Example

We use Bluespec GUI + gtkwave to view waveform of VCD files gtkwave Installed in vlsifarm matchines

SSH with -X ssh –X [email protected] Windows may need some tools

Cygwin/X

Use onecycle processor in lab5 as Example

Oct 23, 2015 T04-7http://csg.csail.mit.edu/6.175

Page 8: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Bluespec project

We have set SceMi to generate it when building the project project.bld: workstation-project-file

$ cd scemi/sim $ build –v onecycle onecycle.bspec is the project file

Oct 23, 2015 T04-8http://csg.csail.mit.edu/6.175

Page 9: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Simulation: generate VCD file

$ cp ../../programs/build/assembly/vmh/simple.riscv.vmh mem.vmh$ ./bsim_dut –V out.vcd > log.txt &$ ./tb

Oct 23, 2015 T04-9http://csg.csail.mit.edu/6.175

Page 10: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Open Bluespec GUI$ bluespec onecycle.bspec

Oct 23, 2015 T04-10http://csg.csail.mit.edu/6.175

Page 11: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Open Module Browser

Window Module Browser

Oct 23, 2015 T04-11http://csg.csail.mit.edu/6.175

Page 12: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Module Browser

Oct 23, 2015 T04-12http://csg.csail.mit.edu/6.175

Module Hierarchy

Signals

Methods

Top level module

Page 13: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Oct 23, 2015 T04-13http://csg.csail.mit.edu/6.175

Page 14: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Open Waveform Viewer

Oct 23, 2015 T04-14http://csg.csail.mit.edu/6.175

Page 15: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Load VCD

Oct 23, 2015 T04-15http://csg.csail.mit.edu/6.175

Page 16: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Waveform Viewer

Oct 23, 2015 T04-16http://csg.csail.mit.edu/6.175

Signalnames

Waveform

Page 17: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Add Signals to ViewAdd clock

Oct 23, 2015 T04-17http://csg.csail.mit.edu/6.175

Page 18: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Add Signals to View

Add PC

Oct 23, 2015 T04-18http://csg.csail.mit.edu/6.175

Page 19: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Add Signals to View

Add csrf.wr method

Oct 23, 2015 T04-19http://csg.csail.mit.edu/6.175

Page 20: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Add Signals to ViewAdd can_fire, will_filre for rule doProc

Oct 23, 2015 T04-20http://csg.csail.mit.edu/6.175

Page 21: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Waveforms

Oct 23, 2015 T04-21http://csg.csail.mit.edu/6.175

Readable value

Page 22: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Problem

No internal signals Optimized away during compilation But I want to see them for dubuggin

For example: dInst

Oct 23, 2015 T04-22http://csg.csail.mit.edu/6.175

Page 23: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Solution -- Probe

interface Probe#(type t); method Action _write(t x);endinterfacemodule mkProbe(Probe#(t)) provisos( Bits#(t, sz));

Write to mkProbe will be recorded in VCD file Instantiate mkProbe for each signal that we

want to record

Oct 23, 2015 T04-23http://csg.csail.mit.edu/6.175

Page 24: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Probe Exampleimport Probe::*;...module mkProc(Proc); mkProbe#(DecodedInst) dInstProbe <- mkProbe; ... rule doProc; ... let dInst = decode(inst); dInstProbe <= dInst; ... endrule ...endmodule

Oct 23, 2015 T04-24http://csg.csail.mit.edu/6.175

Page 25: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

After Adding Probe

Oct 23, 2015 T04-25http://csg.csail.mit.edu/6.175

Page 26: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Oct 23, 2015 T04-26http://csg.csail.mit.edu/6.175

Page 27: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Combine with Assembly

Assembly code of compiled tests are in programs/build/*/dump

Refer to the assembly code in debugging

Oct 23, 2015 T04-27http://csg.csail.mit.edu/6.175

Page 28: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Debugging SchedulingGUI: schedule Analysis The same as “-show-shedule” BSC flag

Oct 23, 2015 T04-28http://csg.csail.mit.edu/6.175

Page 29: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Select mkProc

Oct 23, 2015 T04-29http://csg.csail.mit.edu/6.175

Page 30: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Output of Schedule AnalysisRule order: execution order of rules and methods

From top to bottom

Oct 23, 2015 T04-30http://csg.csail.mit.edu/6.175

Page 31: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Alternative for Schedule Analysis

Add –show-schedule to project.bld

Generate info_dir/*.sched Contain same information as GUI outputs

Oct 23, 2015 T04-31http://csg.csail.mit.edu/6.175

Page 32: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

General Debugging AdviceDebugging is to guess what goes wrongCheck warnings in compiler outputs Scheduling warnings Understand all warnings in mkProc

Stare at your code – prove its correctnessAdd $display – convenient & very usefulLook at assembly code, locate positionDump VCD file and see waveform

Oct 23, 2015 T04-32http://csg.csail.mit.edu/6.175

Page 33: Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang 6.175 TA Oct 23, 2015T04-1

Note

Codes on the slide is a little different from our labsRead src/includes to be familiar with out lab setup.

Oct 23, 2015 T04-33http://csg.csail.mit.edu/6.175