All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Lehtonen <markus.lehtonen@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 02/20] python: add python-profile-opt recipe
Date: Tue, 16 May 2017 16:18:32 +0300	[thread overview]
Message-ID: <8b7d2e2fa9c1a678989c31246ec439148271690d.1494939394.git.markus.lehtonen@linux.intel.com> (raw)
In-Reply-To: <cover.1494939394.git.markus.lehtonen@linux.intel.com>
In-Reply-To: <cover.1494939394.git.markus.lehtonen@linux.intel.com>

This patch adds a new recipe that builds a special version of python
that produces profile data for profile guided optimization. It will
install under /opt in order to prevent clash with the "normal" python.
The new recipe directly includes the base python recipe so that they are
build in as similar way as possible and this hopefully decreases the
recipe maintenance burden, too.

Normally, python profile-guided-optimization is done simply by doing
"make profile-opt" which first builds python with profile
instrumentation enabled, then runs a profile task to get the profile
data, and last, re-builds python with profile data guiding the
optimization. However, in our cross-build environment this gets a lot
trickier. We need to split out the steps as building is done on the
build host but we need to run the second step (i.e. run the profile
task) on the target hardware. This patch enables the first step, i.e.
building python with profile instrumentation enabled

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 .../python/python-profile-opt_2.7.13.bb            | 17 ++++++++++++++
 meta/recipes-devtools/python/python_2.7.13.bb      | 26 +++++++++++++++-------
 2 files changed, 35 insertions(+), 8 deletions(-)
 create mode 100644 meta/recipes-devtools/python/python-profile-opt_2.7.13.bb

diff --git a/meta/recipes-devtools/python/python-profile-opt_2.7.13.bb b/meta/recipes-devtools/python/python-profile-opt_2.7.13.bb
new file mode 100644
index 0000000000..058cc63bc9
--- /dev/null
+++ b/meta/recipes-devtools/python/python-profile-opt_2.7.13.bb
@@ -0,0 +1,17 @@
+require python_${PV}.bb
+
+PROVIDES += "libpython2"
+RPROVIDES_${PN}-core += "libpython2"
+
+# Use special prefix in order to prevent clash with normal python
+STAGING_INCDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/include"
+STAGING_LIBDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/${baselib}"
+TARGET_CFLAGS += "-I${STAGING_INCDIR_DEFAULT}"
+TARGET_CPPFLAGS += "-I${STAGING_INCDIR_DEFAULT}"
+prefix = "/opt"
+exec_prefix = "/opt"
+
+PYTHON_MAKE_TARGET = "build_all_generate_profile"
+
+# Force pkgdata not to clash with python recipe
+PKG_libpython-profile-opt2 = "libpython-profile-opt2.7-1.0"
diff --git a/meta/recipes-devtools/python/python_2.7.13.bb b/meta/recipes-devtools/python/python_2.7.13.bb
index 4ef99523e0..efe02aa8a3 100644
--- a/meta/recipes-devtools/python/python_2.7.13.bb
+++ b/meta/recipes-devtools/python/python_2.7.13.bb
@@ -37,6 +37,11 @@ CONFIGUREOPTS += " --with-system-ffi "
 
 EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no"
 
+# These are needed in order to build with modified prefix (python-prorile-opt
+# recipe)
+STAGING_INCDIR_DEFAULT ?= "${STAGING_INCDIR}"
+STAGING_LIBDIR_DEFAULT ?= "${STAGING_LIBDIR}"
+
 do_configure_append() {
 	rm -f ${S}/Makefile.orig
         autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
@@ -45,12 +50,12 @@ do_configure_append() {
 do_compile() {
         # regenerate platform specific files, because they depend on system headers
         cd ${S}/Lib/plat-linux2
-        include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \
+        include=${STAGING_INCDIR_DEFAULT} ${STAGING_BINDIR_NATIVE}/python-native/python \
                 ${S}/Tools/scripts/h2py.py -i '(u_long)' \
-                ${STAGING_INCDIR}/dlfcn.h \
-                ${STAGING_INCDIR}/linux/cdrom.h \
-                ${STAGING_INCDIR}/netinet/in.h \
-                ${STAGING_INCDIR}/sys/types.h
+                ${STAGING_INCDIR_DEFAULT}/dlfcn.h \
+                ${STAGING_INCDIR_DEFAULT}/linux/cdrom.h \
+                ${STAGING_INCDIR_DEFAULT}/netinet/in.h \
+                ${STAGING_INCDIR_DEFAULT}/sys/types.h
         sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
         cd -
 
@@ -60,7 +65,7 @@ do_compile() {
 	if [ ! -f Makefile.orig ]; then
 		install -m 0644 Makefile Makefile.orig
 	fi
-	sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \
+	sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR_DEFAULT}#g' \
 		-e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
 		-e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
 		-e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
@@ -74,13 +79,17 @@ 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
+        export EXTRA_CFLAGS="-fprofile-dir=./python-pgo-profiles/"
+    fi
 
 	oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
 		HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
 		STAGING_LIBDIR=${STAGING_LIBDIR} \
 		STAGING_INCDIR=${STAGING_INCDIR} \
 		STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
-		OPT="${CFLAGS}"
+		OPT="${CFLAGS}" ${PYTHON_MAKE_TARGET}
 }
 
 do_install() {
@@ -99,7 +108,8 @@ do_install() {
 		STAGING_LIBDIR=${STAGING_LIBDIR} \
 		STAGING_INCDIR=${STAGING_INCDIR} \
 		STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
-		DESTDIR=${D} LIBDIR=${libdir}
+		DESTDIR=${D} LIBDIR=${libdir} ${PYTHON_MAKE_TARGET}
+
 	
 	oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
 		HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
-- 
2.12.0



  parent reply	other threads:[~2017-05-16 13:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16 13:18 [PATCH v2 00/20] support profile-optimized build for Python Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 01/20] python-native: support profile optimized build Markus Lehtonen
2017-05-16 13:18 ` Markus Lehtonen [this message]
2017-05-16 13:18 ` [PATCH v2 03/20] python: remove path hack from setup.py Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 04/20] python-profile-opt: rename libpython Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 05/20] devtools/images: add python-pgo-image Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 06/20] python: make profile-optimized build possible Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 07/20] python-pgo-image: exclude tests from the default profile target Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 08/20] python: add python-tools subpackage Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 09/20] python-pgo-image: switch python default profile task to pybench Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 10/20] python-pgo-image: enable sstate for do_profile Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 11/20] python3-native: support profile optimized build Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 12/20] python3: fix depends of python-tests Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 13/20] python3: add python-profile-opt3 recipe Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 14/20] python-pgo-image: profiling for python3 Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 15/20] python3: remove two setup.py cross-compile hacks Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 16/20] python3: support profile optimized build Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 17/20] python3: fix profile-optimized build of modules Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 18/20] python-pgo-image: exclude tests from the python3 profile target Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 19/20] python3: add python3-tools subpackage Markus Lehtonen
2017-05-16 13:18 ` [PATCH v2 20/20] python-pgo-image: change python3 profile target to pybench Markus Lehtonen
2017-05-16 13:23 ` [PATCH v2 00/20] support profile-optimized build for Python Alexander Kanavin
2017-05-16 14:07   ` Markus Lehtonen
2017-05-16 14:08     ` Alexander Kanavin
2017-05-16 13:45 ` Richard Purdie
2017-05-16 14:16   ` Markus Lehtonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b7d2e2fa9c1a678989c31246ec439148271690d.1494939394.git.markus.lehtonen@linux.intel.com \
    --to=markus.lehtonen@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.