forked from travisdowns/uarch-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
189 lines (139 loc) · 5.46 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
include config.mk
# rebuild when makefile changes
-include dummy.rebuild
.PHONY: all clean libpfc libpfc-clean
CXX ?= g++
CC ?= gcc
ASM ?= nasm
ASM_FLAGS ?= -DNASM_ENABLE_DEBUG=$(NASM_DEBUG) -w+all
# make submakes use the specified compiler also
export CXX
export CC
ifeq ($(PORTABLE),1)
$(info uarch-bench is being compiled in PORTABLE=1 mode, most x86-specific tests disabled)
endif
# The target to build when building libpfc (if we build it at all). By default, we are going
# to build the userspace shared lib and the kernel module, but TravisCI, for example, would
# (usually) like to skip building the kernel module. Note that we don't build the demo, see #issue 71
LIBPFC_TARGET ?= libpfc.so pfc.ko
PFM_DIR ?= libpfm4
PFM_LIBDIR ?= $(PFM_DIR)/lib
JEVENTS_DIR ?= pmu-tools/jevents
JEVENTS_LIB ?= $(JEVENTS_DIR)/libjevents.a
PSNIP_DIR ?= portable-snippets
# all the psnip source files we want to compile into uarch-bench
PSNIP_SRC := cpu.c
BOOST_DIR := boost_1_70_0
FMT_DIR := fmt-7.1.3
GIT_VERSION := $(shell git describe --dirty --always)
ifneq ($(CPU_ARCH),)
ARCH_FLAGS := -march=$(CPU_ARCH)
endif
O_LEVEL ?= -O2
COMMON_FLAGS := -MMD -Wall $(ARCH_FLAGS) -g $(O_LEVEL) -DGIT_VERSION=\"$(GIT_VERSION)\" \
-DUSE_LIBPFC=$(USE_LIBPFC) -DUSE_BACKWARD_CPP=$(USE_BACKWARD_CPP) -DBACKWARD_HAS_BFD=$(BACKWARD_HAS_BFD) \
-DBACKWARD_HAS_DW=$(BACKWARD_HAS_DW) -DUSE_PERF_TIMER=$(USE_PERF_TIMER) -I$(PSNIP_DIR) -I$(BOOST_DIR) \
-I$(FMT_DIR)/include \
-DUARCH_BENCH_PORTABLE=$(if $(PORTABLE),1,0)
CPPFLAGS := $(COMMON_FLAGS)
CFLAGS := $(COMMON_FLAGS)
# files that should only be compiled if USE_LIBPFC is enabled
PFC_SRC := libpfc-timer.cpp libpfm4-support.cpp
SRC_FILES := $(wildcard *.cpp) $(wildcard *.c) nasm-utils/nasm-utils-helper.c $(PSNIP_SRC) $(FMT_DIR)/src/format.cc
SRC_FILES := $(filter-out $(PFC_SRC), $(SRC_FILES))
ASM_FILES := $(if $(PORTABLE),,$(wildcard *.asm))
# on most compilers we should use no-pie since the nasm stuff isn't position independent
# but since old compilers don't support it, you can override it with PIE= on the command line
PIE ?= -no-pie
LDFLAGS += $(PIE)
EXTRA_DEPS :=
ifeq ($(USE_LIBPFC),1)
LDFLAGS += -Llibpfc '-Wl,-rpath=$$ORIGIN/libpfc/' -L$(PFM_LIBDIR) '-Wl,-rpath=$$ORIGIN/$(PFM_LIBDIR)/'
LDLIBS += -lpfc -lpfm
EXTRA_DEPS += libpfc/libpfc.so libpfc/pfc.ko $(PFM_LIBDIR)/libpfm.so
CLEAN_TARGETS += libpfc-clean libpfm4-clean
SRC_FILES += $(PFC_SRC)
endif
ifeq ($(USE_PERF_TIMER),1)
EXTRA_DEPS += $(JEVENTS_LIB) download_events.touch
LDLIBS += $(JEVENTS_LIB)
SEQTEST := util/seqtest
endif
ifeq ($(BACKWARD_HAS_BFD),1)
LDFLAGS += -lbfd -ldl
endif
ifeq ($(BACKWARD_HAS_DW),1)
LDFLAGS += -ldw
endif
OBJECTS := $(SRC_FILES:.cpp=.o) $(ASM_FILES:.asm=.o)
OBJECTS := $(OBJECTS:.cc=.o)
OBJECTS := $(OBJECTS:.c=.o)
DEPFILES = $(OBJECTS:.o=.d)
# $(info OBJECTS=$(OBJECTS))
$(info USE_LIBPFC=${USE_LIBPFC} USE_PERF_TIMER=${USE_PERF_TIMER})
VPATH = test:$(PSNIP_DIR)/cpu
###########
# Targets #
###########
all: uarch-bench unit-test $(SEQTEST)
-include $(DEPFILES) unit-test.d
clean: libpfc-clean
rm -f *.d *.o uarch-bench
dist-clean: clean $(CLEAN_TARGETS)
# $(filter-out $(OBJECTS), main.o)
# link all object files except main.o into unit-test
UNIT_OBJECTS := $(filter-out main.o, $(OBJECTS)) unit-test.o unit-test-main.o
unit-test: $(UNIT_OBJECTS) $(EXTRA_DEPS)
$(CXX) $(UNIT_OBJECTS) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -std=c++11 -o $@
uarch-bench: $(OBJECTS) $(EXTRA_DEPS)
$(CXX) $(OBJECTS) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -std=c++11 -o $@
# the next two lines are only to print out the size of the binary for diagnostic purposes, feel free to omit them
@wc -c uarch-bench | awk '{print "binary size: " $$1/1000 "KB"}'
@size uarch-bench --format=SysV | egrep '\.text|\.eh_frame|\.rodata|\.debug_info|\.debug_loc|^section'
util/seqtest: util/seqtest.o $(JEVENTS_LIB)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -std=c++11 $^ -o $@
%.o : %.c
$(CC) $(CFLAGS) -c -std=c11 -o $@ $<
define cpp-build
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -std=c++11 -o $@ $<
endef
%.o : %.cpp
$(cpp-build)
%.o : %.cc
$(cpp-build)
%.o: %.asm nasm-utils/nasm-utils-inc.asm
$(ASM) $(ASM_FLAGS) $(NASM_DEFINES) -f elf64 $<
# fake dependency, but prevents make from trying to build libpfc twice in parallel if both the ko and so are missing
libpfc/pfc.ko: libpfc/libpfc.so
libpfc/libpfc.so libpfc/pfc.ko:
@echo "Buiding libpfc targets: $(LIBPFC_TARGET)"
$(MAKE) -C libpfc $(LIBPFC_TARGET)
libpfc-clean:
$(MAKE) -C libpfc clean
ifeq ($(USE_PERF_TIMER),1)
# jevents handling - we just assume jevents depends on all .c or .h files in the root directory
# which doesn't catch stuff in the examples dir (for example), but that's probably fine
$(JEVENTS_LIB): $(JEVENTS_DIR)/*.[ch]
$(MAKE) -C $(JEVENTS_DIR)
# this file just tracks whether you've downloaded the events file for this host
download_events.touch:
ifeq (, $(shell which python2))
@echo "WARNING: No python2 detected, event download skipped - install python2 to use --timer=perf"
else
pmu-tools/event_download.py
echo "This presence of this file is used to indicate to make that the PMU event json files have been downloaded" >> $@
endif
endif
insmod: libpfc
sudo sh -c "echo 2 > /sys/bus/event_source/devices/cpu/rdpmc"
! lsmod | grep -q pfc || sudo rmmod pfc
sudo insmod libpfc/pfc.ko
$(PFM_LIBDIR)/libpfm.so:
$(MAKE) -C $(PFM_DIR) lib
libpfm4-clean:
$(MAKE) -C $(PFM_DIR) clean
LOCAL_MK = $(wildcard local.mk)
# https://stackoverflow.com/a/3892826/149138
dummy.rebuild: Makefile config.mk $(LOCAL_MK)
touch $@
$(MAKE) -s clean