Multiple platofrm support for dpdk/Makefile, fix optimizations
[vpp.git] / dpdk / Makefile
1 # Copyright (c) 2015 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 # Scripts require non-POSIX parts of bash
15 SHELL := /bin/bash
16
17 DPDK_BUILD_DIR        ?= $(CURDIR)/_build
18 DPDK_INSTALL_DIR      ?= $(CURDIR)/_install
19 DPDK_PKTMBUF_HEADROOM ?= 128
20 DPDK_DOWNLOAD_DIR     ?= $(HOME)/Downloads
21 DPDK_DEBUG            ?= n
22 DPDK_CRYPTO_SW_PMD    ?= n
23 DPDK_MLX5_PMD         ?= n
24
25 B := $(DPDK_BUILD_DIR)
26 I := $(DPDK_INSTALL_DIR)
27 DPDK_VERSION ?= 16.11
28 PKG_SUFFIX ?= vpp5
29 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
30 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
31 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
32 DPDK_16.07_TARBALL_MD5_CKSUM := 690a2bb570103e58d12f9806e8bf21be
33 DPDK_16.11_TARBALL_MD5_CKSUM := 06c1c577795360719d0b4fafaeee21e9
34 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
35
36 ifneq (,$(findstring clang,$(CC)))
37 DPDK_CC=clang
38 else ifneq (,$(findstring icc,$(CC)))
39 DPDK_CC=icc
40 else
41 DPDK_CC=gcc
42 endif
43
44 ##############################################################################
45 # Intel x86_64
46 ##############################################################################
47 ifeq ($(shell uname -m),x86_64)
48 DPDK_TARGET           ?= x86_64-native-linuxapp-$(DPDK_CC)
49 DPDK_MACHINE          ?= nhm
50 DPDK_TUNE             ?= core-avx2
51
52 ##############################################################################
53 # Cavium ThunderX
54 ##############################################################################
55 else ifneq (,$(findstring thunder,$(shell cat /sys/bus/pci/devices/0000:00:01.0/uevent | grep cavium)))
56 export CROSS=""
57 DPDK_TARGET           ?= arm64-thunderx-linuxapp-$(DPDK_CC)
58 DPDK_MACHINE          ?= thunderx
59 DPDK_TUNE             ?= generic
60
61 ##############################################################################
62 # Unknown platofrm
63 ##############################################################################
64 else
65 $(error unknown platform)
66 endif
67
68 JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
69
70 # compiler/linker custom arguments
71 DPDK_CPU_CFLAGS := -pie -fPIC
72 DPDK_EXTRA_LDFLAGS := -g
73
74 ifeq ($(DPDK_DEBUG),n)
75 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
76 else
77 DPDK_EXTRA_CFLAGS := -g -O0
78 endif
79
80 # assemble DPDK make arguments
81 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
82         T=$(DPDK_TARGET) \
83         RTE_CONFIG_TEMPLATE=../custom-config \
84         EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
85         EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
86         CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
87         DESTDIR=$(I) \
88         $(DPDK_MAKE_EXTRA_ARGS)
89
90 DPDK_SOURCE_FILES := $(shell  [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
91
92 define set
93 @if grep -q CONFIG_$1 $@ ; \
94         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
95         else echo CONFIG_$1=$2 >> $@ ; \
96 fi
97 endef
98
99 all: build
100
101 $(B)/custom-config: $(B)/.patch.ok Makefile
102         @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
103         @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
104         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
105         @# modify options
106         $(call set,RTE_MAX_LCORE,256)
107         $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
108         $(call set,RTE_LIBEAL_USE_HPET,y)
109         $(call set,RTE_BUILD_COMBINE_LIBS,y)
110         $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
111         $(call set,RTE_PCI_CONFIG,y)
112         $(call set,RTE_PCI_EXTENDED_TAG,"on")
113         $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
114         @# enable debug init for device drivers
115         $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
116         $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
117         $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
118         $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
119         $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
120         $(call set,RTE_LIBRTE_PMD_BOND,y)
121         $(call set,RTE_LIBRTE_IP_FRAG,y)
122         $(call set,RTE_LIBRTE_PMD_QAT,y)
123         $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(DPDK_CRYPTO_SW_PMD))
124         $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(DPDK_CRYPTO_SW_PMD))
125         $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
126         @# not needed
127         $(call set,RTE_LIBRTE_TIMER,n)
128         $(call set,RTE_LIBRTE_CFGFILE,n)
129         $(call set,RTE_LIBRTE_LPM,n)
130         $(call set,RTE_LIBRTE_ACL,n)
131         $(call set,RTE_LIBRTE_POWER,n)
132         $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
133         $(call set,RTE_LIBRTE_REORDER,n)
134         $(call set,RTE_LIBRTE_PORT,n)
135         $(call set,RTE_LIBRTE_TABLE,n)
136         $(call set,RTE_LIBRTE_PIPELINE,n)
137         $(call set,RTE_KNI_KMOD,n)
138         $(call set,RTE_EAL_IGB_UIO,n)
139         @rm -f .config.ok
140
141 $(CURDIR)/$(DPDK_TARBALL):
142         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
143                 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
144                 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
145         fi
146         @rm -f $(B)/.download.ok
147
148 $(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
149         @mkdir -p $(B)
150         @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
151         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
152         ( echo "Bad Checksum! Please remove $< and retry" && \
153                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
154         @touch $@
155
156 .PHONY: download
157 download: $(B)/.download.ok
158
159 $(B)/.extract.ok: $(B)/.download.ok
160         @echo --- extracting $(DPDK_TARBALL) ---
161         @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
162         @touch $@
163
164 .PHONY: extract
165 extract: $(B)/.extract.ok
166
167 $(B)/.patch.ok: $(B)/.extract.ok
168 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
169         @echo --- patching ---
170         @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
171                 echo Applying patch: $$(basename $$f) ; \
172                 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
173         done
174 endif
175         @touch $@
176
177 .PHONY: patch
178 patch: $(B)/.patch.ok
179
180 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
181         @make $(DPDK_MAKE_ARGS) config
182         @touch $@
183
184 .PHONY: config
185 config: $(B)/.config.ok
186
187 $(B)/.build.ok: $(DPDK_SOURCE_FILES)
188         @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
189         @make $(DPDK_MAKE_ARGS) install
190         @touch $@
191
192 .PHONY: build
193 build: $(B)/.build.ok
194
195 .PHONY: install
196 install: $(B)/.build.ok
197
198 .PHONY: clean
199 clean:
200         @rm -rf $(B) $(I)
201
202 ##############################################################################
203 # .deb packaging
204 ##############################################################################
205
206 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
207 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
208 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
209
210 .PHONY: build-deb install-deb check-deb
211
212 deb/debian/changelog: Makefile
213         @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
214         @echo "" >> $@
215         @echo "  * DPDK Release $(DPDK_VERSION)" >> $@
216         @echo "" >> $@
217         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
218
219 $(DEV_DEB): deb/debian/changelog
220         @cd deb && dpkg-buildpackage -b -uc -us
221         git clean -fdx deb
222
223 build-deb: $(DEV_DEB)
224
225 install-deb:
226 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
227         @make $(DEV_DEB)
228         @sudo dpkg -i $(DEV_DEB)
229 else
230         @echo "=========================================================="
231         @echo " Up-to-date DPDK package already installed"
232         @echo "=========================================================="
233 endif
234
235 check-deb:
236 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
237         @echo "=========================================================="
238         @echo " Outdated DPDK package detected:"
239         @echo "  Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
240         @echo "  Current:   vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
241         @echo ""
242         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
243         @echo " from the top level directory."
244         @echo "=========================================================="
245 endif
246
247 ##############################################################################
248 # .rpm packaging
249 ##############################################################################
250
251 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
252 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
253 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
254
255 .PHONY: build-rpm install-rpm check-rpm
256
257 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
258         @rpmbuild -bb \
259           --define "_topdir $(CURDIR)/rpm" \
260           --define "_version $(DPDK_VERSION)" \
261           --define "_release $(PKG_SUFFIX)" \
262           $(CURDIR)/rpm/vpp-dpdk.spec
263         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
264         git clean -fdx rpm
265
266 build-rpm: $(DEV_RPM)
267
268 install-rpm:
269 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
270         @make $(DEV_RPM)
271         sudo rpm -Uih $(DEV_RPM)
272 else
273         @echo "=========================================================="
274         @echo " Up-to-date DPDK package already installed"
275         @echo "=========================================================="
276 endif
277
278 check-rpm:
279 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
280         @echo "=========================================================="
281         @echo " Outdated DPDK package detected:"
282         @echo "  Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
283         @echo "  Current:   vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
284         @echo ""
285         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
286         @echo " from the top level directory."
287         @echo "=========================================================="
288 endif
289
290 ##############################################################################
291 # ebuild support
292 ##############################################################################
293
294 .PHONY: ebuild-build ebuild-install
295
296 ebuild-build:
297 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
298         @echo "=========================================================="
299         @echo "Building DPDK from source. Consider installing development"
300         @echo "package by invoking 'make dpdk-install-dev' from the"
301         @echo "top level directory"
302         @echo "=========================================================="
303         make config
304 else
305 ifneq ($(INSTALLED_DEB_VER),)
306         make check-deb
307 endif
308 ifneq ($(INSTALLED_RPM_VER),)
309         make check-rpm
310 endif
311 endif
312
313 ebuild-install:
314 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
315         make install
316 endif