From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mail.openembedded.org (Postfix) with ESMTP id DEF9B7320F for ; Wed, 25 Jan 2017 12:41:09 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 25 Jan 2017 04:41:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,283,1477983600"; d="scan'208";a="35260423" Received: from marquiz.fi.intel.com ([10.237.72.155]) by orsmga002.jf.intel.com with ESMTP; 25 Jan 2017 04:41:09 -0800 From: Markus Lehtonen To: openembedded-core@lists.openembedded.org Date: Wed, 25 Jan 2017 14:40:57 +0200 Message-Id: <20170125124101.29425-7-markus.lehtonen@linux.intel.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170125124101.29425-1-markus.lehtonen@linux.intel.com> References: <20170125124101.29425-1-markus.lehtonen@linux.intel.com> Subject: [PATCH RFC 06/10] python: make profile-optimized build possible X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jan 2017 12:41:11 -0000 This patch makes it possible to build python with profile directed optimization. That is, feed python build process with profile data to guide optimization. This is the third (and the last) step in profile directed optimization for Python. In order to do a profile-optimized build you need to set PYTHON_PROFILE_OPT = "1" in your local.conf. Be sure to get the profile data for python, preferably by running "bitbake python-pgo-image -c profile". [YOCTO #9338] Signed-off-by: Markus Lehtonen --- meta/recipes-devtools/python/python_2.7.12.bb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/meta/recipes-devtools/python/python_2.7.12.bb b/meta/recipes-devtools/python/python_2.7.12.bb index b4d6efb..492bd24 100644 --- a/meta/recipes-devtools/python/python_2.7.12.bb +++ b/meta/recipes-devtools/python/python_2.7.12.bb @@ -42,6 +42,17 @@ EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no" STAGING_INCDIR_DEFAULT ?= "${STAGING_INCDIR}" STAGING_LIBDIR_DEFAULT ?= "${STAGING_LIBDIR}" +# Automatic profile guided optimization +PYTHON_MAKE_TARGET ?= "${@'build_all_use_profile' if d.getVar('PYTHON_PROFILE_OPT', True) == '1' else ''}" +PYTHON_PROFILE_DIR ?= "${@'${TMPDIR}/work-shared/${MACHINE}/python/pgo-data' if d.getVar('PYTHON_PROFILE_OPT', True) == '1' else ''}" +python () { + if (d.getVar('PYTHON_PROFILE_OPT', True) == '1' and + d.getVar('PYTHON_MAKE_TARGET', True) == 'build_all_use_profile'): + profile_dir = d.getVar('PYTHON_PROFILE_DIR', True) + bb.utils.mkdirhier(profile_dir) + d.setVarFlag('do_compile', 'file-checksums', '%s:True' % profile_dir) +} + do_configure_append() { rm -f ${S}/Makefile.orig autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi @@ -79,9 +90,15 @@ do_compile() { export CROSS_COMPILE="${TARGET_PREFIX}" export PYTHONBUILDDIR="${B}" - # This is only used in PGO profiling by python-profile-opt package if [ "${PYTHON_MAKE_TARGET}" = "build_all_generate_profile" ]; then + # This is only used in PGO profiling by python-profile-opt package export EXTRA_CFLAGS="-fprofile-dir=./python-pgo-profiles/" + else + if [ -n "${PYTHON_PROFILE_DIR}" ]; then + export EXTRA_CFLAGS="-fprofile-dir=${PYTHON_PROFILE_DIR}" + # Remove non-optimized build artefacts + oe_runmake clean + fi fi oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ @@ -99,6 +116,11 @@ do_install() { export CROSS_COMPILE="${TARGET_PREFIX}" export PYTHONBUILDDIR="${B}" + # This only has effect if we build with -fprofile-use, e.g. when make + # target is build_all_use_profile + if [ -n "${PYTHON_PROFILE_DIR}" ]; then + export EXTRA_CFLAGS="-fprofile-dir=${PYTHON_PROFILE_DIR}" + fi # After swizzling the makefile, we need to run the build again. # install can race with the build so we have to run this first, then install @@ -146,6 +168,7 @@ py_package_preprocess () { python -m py_compile ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py } + require python-${PYTHON_MAJMIN}-manifest.inc # manual dependency additions -- 2.10.2