3

I have a C application that is using a function from the Gem5 operations called "m5_dumpreset_stats()".

So, I did the following, I included the header file of this function:

#include "../gem5-stable/util/m5/m5op.h"

then in my source file I called the function:

void foo()
{
   m5_dumpreset_stats(0,0);
   /* For loop */
   m5_dumpreset_stats(0,0);
}

To build my project I'm using a Makefile :

CC=arm-linux-gnueabi-gcc
CFLAGS=-g -c -Wall -O3 -mfpu=neon
LDFLAGS=-static

SOURCES=$ foo.c
OBJECTS=$(SOURCES:.c=.o)

EXECUTABLE=foo

all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
$(CC) $(LDFLAGS) $(OBJECTS) -lm -o $@

.c.o:
    $(CC) $(CFLAGS) $< -lm -o $@

 clean: 
    rm -fr $(OBJECTS) $(EXECUTABLE)

My first guess is that I have to link the library using the Makefile but honestly, I don't know how? Could someone show me the right way to do it?

P.S : m5_dumpreset_stats(delay,period): Save and reset simulation statistics to a file in delay nanoseconds; repeat this every period nanoseconds.

A.nechi
  • 521
  • 1
  • 5
  • 15

3 Answers3

2

Since your header is in a directory that's not normally searched, that's likely true of your library as well. So you'll need two flags: -l to reference the library and -L to add other library directory to search.

If my library was libm5op.a located in "../gem5-stable/util/m5", I might do:

$(CC) $(LDFLAGS) $(OBJECTS) -lm -L"../gem5-stable/util/m5" -lm5op -o $@

or some such as is appropriate to your situation.

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • 1
    In a makefile of mine, I'd use a macro like `M5_UTIL_DIR = ../gem5-stable/util/m5` with both the `-I` and `-L` options so that they can be relocated with a one-line change in the makefile (and can be changed for testing with `make M5_UTIL_DIR=/some/where/else/m5` on the command line). If the library and header are in different directories, I'd either use the common parent directory or two separate variables defining two separate locations. Of course, the source would have to be revised: see [What are the benefits of a relative path for a header](http://stackoverflow.com/questions/597318). – Jonathan Leffler Aug 14 '16 at 18:50
1

Thank you for your contributions. This was my solution: See that I'm using ARM core for simulation I used Makefile.arm to generate a library called "m5" then I had to do following changes in my own Makefile:

$(EXECUTABLE): $(OBJECTS) 
 $(CC) $(LDFLAGS) $(OBJECTS) -lm -L"/home/anoir/gem5-stable/util/m5" -lm5 -o $@

and I kept the inclusion in my header file to call m5op.h like this:

  #include "/home/anoir/gem5-stable/util/m5/m5op.h"

Finally, I've tested it in the simulator and checked the stats file and Works perfectly Thanks to you.

A.nechi
  • 521
  • 1
  • 5
  • 15
0

gem5 20 updated procedure

How to use m5 in gem5-20

Hardcode the assembly directly

Sometimes, it is just easier to hack it up and add the assembly inline. E.g. on aarch64, to dump stats you can do:

mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);

A list of some of those instructions is available here and how you can deduce them on your own is explained here.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44