diff --git a/CONFIG b/CONFIG index f8a488126..60092b23d 100644 --- a/CONFIG +++ b/CONFIG @@ -46,6 +46,12 @@ CONFIG_WERROR=n # Build with link-time optimization. CONFIG_LTO=n +# Generate profile guided optimization data. +CONFIG_PGO_CAPTURE=n + +# Use profile guided optimization data. +CONFIG_PGO_USE=n + # Build with code coverage instrumentation. CONFIG_COVERAGE=n diff --git a/configure b/configure index a2a8bbb4e..e06b0daf6 100755 --- a/configure +++ b/configure @@ -24,6 +24,8 @@ function usage() echo " --enable-ubsan Enable undefined behavior sanitizer" echo " --enable-coverage Enable code coverage tracking" echo " --enable-lto Enable link-time optimization" + echo " --enable-pgo-capture Enable generation of profile guided optimization data" + echo " --enable-pgo-use Use previously captured profile guided optimization data" echo " --disable-tests Disable building of tests" echo " --with-env=path Use an alternate environment implementation" echo "" @@ -146,6 +148,18 @@ for i in "$@"; do --disable-lto) CONFIG[LTO]=n ;; + --enable-pgo-capture) + CONFIG[PGO_CAPTURE]=y + ;; + --disable-pgo-capture) + CONFIG[PGO_CAPTURE]=n + ;; + --enable-pgo-use) + CONFIG[PGO_USE]=y + ;; + --disable-pgo-use) + CONFIG[PGO_USE]=n + ;; --enable-tests) CONFIG[TESTS]=y ;; @@ -466,6 +480,12 @@ if [[ "${CONFIG[OCF]}" = "y" ]]; then fi fi +if [[ "${CONFIG[PGO_CAPTURE]}" = "y" && "${CONFIG[PGO_USE]}" = "y" ]]; then + echo "ERROR: --enable-pgo-capture and --enable-pgo-use are mutually exclusive." + exit 1 +fi + + # We are now ready to generate final configuration. But first do sanity # check to see if all keys in CONFIG array have its reflection in CONFIG file. if [ $(egrep -c "^\s*CONFIG_[[:alnum:]_]+=" CONFIG) -ne ${#CONFIG[@]} ]; then diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index 52e28a46f..9f2a175a5 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -94,6 +94,16 @@ COMMON_CFLAGS += -flto LDFLAGS += -flto endif +ifeq ($(CONFIG_PGO_CAPTURE),y) +COMMON_CFLAGS += -fprofile-generate=$(SPDK_ROOT_DIR)/build/pgo +LDFLAGS += -fprofile-generate=$(SPDK_ROOT_DIR)/build/pgo +endif + +ifeq ($(CONFIG_PGO_USE),y) +COMMON_CFLAGS += -fprofile-use=$(SPDK_ROOT_DIR)/build/pgo +LDFLAGS += -fprofile-use=$(SPDK_ROOT_DIR)/build/pgo +endif + COMMON_CFLAGS += -Wformat -Wformat-security COMMON_CFLAGS += -D_GNU_SOURCE