All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 00/10] python: support profile-optimized build
@ 2017-01-25 12:40 Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 01/10] python-native: support profile optimized build Markus Lehtonen
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

This patchset makes it possible to enable profile-guided-optimization (PGO) for
Python 2.7 - both native and target recipes.

Enabling PGO for python-native is simple, one patch, basically just changing
the make target if PGO is enabled in build conf.

However, the target version requires a lot more convoluted approach because of
the cross-build environment.  Normally, (python-native in our case) PGO is done
in one go by just running "make profile-opt". It first builds python binaries
with profile instrumentation enabled. Then, a specific profile task, using that
python, is run to get the profile data. Last, a complete re-build of python is
done, feeding the compiler with the profile data obtained earlier.
Unfortunately, in our cross-build environment this is not possible as the
binaries are (cross-)built on the host machine but profiling needs to be done
on the target architecture.

The approach used in this patchset splits the PGO build of target python into
three steps:
1. build a target python binary with profile instrumentation enabled
2. build a special target image and run the profile task there,
   copying the profile data back to the build host
3. build an optimized target python binary, guided by the profile data

The first step is done by adding a new "python-profile-opt" recipe. It builds a
special version of python that has the profile instrumentation enabled. The
idea behind this is to keep "normal" python clean and isolated - not do any
intermediate builds or contaminate python with pgo instrumentation.

The second step is implemented by adding a new image recipe. This is a minimal
image that basically only contains the functionality for running the special
profile-instrumented python and obtaining the profile data. It re-uses
facilities from oeqa to communicate with the target instance over ssh. Also
here, the idea behind a separate "profiling image" is to keep it isolated and
not contaminate the main target build.

The third step is relatively straightforward, enabling the usage of profile
data in do_compile in the python recipe.

Instructions for doing a PGO build for target python are:
1. enable profile-optimized build by specifying
   PYTHON_PROFILE_OPT = "1" in local.conf
2. get profile data by running
   bitbake python-pgo-image -c profile
3. (re-)build your distro image


Benchmark results from my i7-3770K desktop machine show 8% to 20% improvement
for python-native and 3.6% to 15% improvement for python (qemux86 target).

python-native:
  pystone:          141883 -> 168168 pystones/s     (+18%)
  pybench avg:      3367   -> 2795 ms               (-20%)
  regrtest time:    270    -> 250 s                 (-8%)

python (target):
  pystone:          2045   -> 2355 pystones/s       (+15%)
  pybench avg:      181901 -> 175600 ms             (-3.6%)
  regrtest time:    4210   -> 4050 s                (-3.8%)

I've not done extensive testing to get statistically reliable results, but, the
numbers above should give a useful enough ballpark figure.


New configuration variables, related to this patchset  are:
PYTHON_PROFILE_OPT          - set to "1" to enable PGO build of python
PYTHON_PROFILE_TASK         - profile task to run for python
PYTHON_NATIVE_PROFILE_OPT   - set to "1" to enable PGO build of python-native
PYTHON_NATIVE_PROFILE_TASK  - profile task to run for python-native


I have a corresponding patchset for Python3, too, and I will send that shortly.


The following changes since commit fc97963bc61bf16112859fe1d7e460a13d34baca:

  oeqa/selftest/devtool: rewrite modify testcase (2017-01-19 22:45:46 +0000)

are available in the git repository at:

  git://git.openembedded.org/openembedded-core-contrib marquiz/fixes-9338-py2
  http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/fixes-9338-py2


Markus Lehtonen (10):
  python-native: support profile optimized build
  python: add python-profile-opt recipe
  python: remove path hack from setup.py
  python-profile-opt: rename libpython
  devtools/images: add python-pgo-image
  python: make profile-optimized build possible
  python-pgo-image: exclude tests from the default profile target
  python: add python-tools subpackage
  python-pgo-image: switch python default profile task to pybench
  python-pgo-image: enable sstate for do_profile

 meta/recipes-devtools/images/python-pgo-image.bb   | 75 +++++++++++++++++
 .../python/python-2.7-manifest.inc                 |  8 +-
 ...x-.so-loading-when-when-running-profile-t.patch | 26 ++++++
 .../python/python-native_2.7.12.bb                 | 10 +++
 .../python/python-profile-opt_2.7.12.bb            | 13 +++
 .../01-use-proper-tools-for-cross-build.patch      | 10 ---
 ...rename-libpython-to-libpython-profile-opt.patch | 94 ++++++++++++++++++++++
 meta/recipes-devtools/python/python_2.7.12.bb      | 54 +++++++++++--
 8 files changed, 269 insertions(+), 21 deletions(-)
 create mode 100644 meta/recipes-devtools/images/python-pgo-image.bb
 create mode 100644 meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch
 create mode 100644 meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
 create mode 100644 meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch

-- 
2.10.2



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH RFC 01/10] python-native: support profile optimized build
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 02/10] python: add python-profile-opt recipe Markus Lehtonen
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

Make it possible to build python-native with profile directed
optimization enabled.  The feature is enabled by setting
PYTHON_NATIVE_PROFILE_OPT = "1" in local.conf.

The profile task to run may be specified with PYTHON_NATIVE_PROFILE_TASK
variable in local.conf, e.g.
PYTHON_NATIVE_PROFILE_TASK = "${S}/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck"

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 ...x-.so-loading-when-when-running-profile-t.patch | 26 ++++++++++++++++++++++
 .../python/python-native_2.7.12.bb                 | 10 +++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch

diff --git a/meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch b/meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch
new file mode 100644
index 0000000..e4c89db
--- /dev/null
+++ b/meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch
@@ -0,0 +1,26 @@
+Makefile: fix .so loading when when running profile task
+
+Use correct search path when doing profiling for profile-optimized
+build. This way we load the correct Python libraries, i.e. the ones from
+our build directory, and not the ones from the host os.
+
+Upstream-Status: Pending
+
+Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
+
+diff --git a/Makefile.pre.in b/Makefile.pre.in
+index 2affc41..4355e7f 100644
+--- a/Makefile.pre.in
++++ b/Makefile.pre.in
+@@ -458,7 +458,7 @@ build_all_generate_profile:
+ 
+ run_profile_task:
+ 	: # FIXME: can't run for a cross build
+-	$(LLVM_PROF_FILE) ./$(BUILDPYTHON) $(PROFILE_TASK) || true
++	$(LLVM_PROF_FILE) $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) || true
+ 
+ build_all_merge_profile:
+ 	$(LLVM_PROF_MERGER)
+-- 
+2.6.6
+
diff --git a/meta/recipes-devtools/python/python-native_2.7.12.bb b/meta/recipes-devtools/python/python-native_2.7.12.bb
index de83cbd..2359b47 100644
--- a/meta/recipes-devtools/python/python-native_2.7.12.bb
+++ b/meta/recipes-devtools/python/python-native_2.7.12.bb
@@ -17,6 +17,7 @@ SRC_URI += "\
             file://builddir.patch \
             file://parallel-makeinst-create-bindir.patch \
             file://revert_use_of_sysconfigdata.patch \
+            file://Makefile-fix-.so-loading-when-when-running-profile-t.patch \
            "
 
 S = "${WORKDIR}/Python-${PV}"
@@ -35,10 +36,19 @@ EXTRA_OEMAKE = '\
   STAGING_INCDIR=${STAGING_INCDIR_NATIVE} \
 '
 
+PYTHON_NATIVE_MAKE_TARGET ?= "${@'profile-opt' if d.getVar('PYTHON_NATIVE_PROFILE_OPT', True) == '1' else ''}"
+
 do_configure_append() {
 	autoreconf --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
 }
 
+do_compile() {
+    if [ -n "${PYTHON_NATIVE_PROFILE_TASK}" ]; then
+        sed -i -e 's,^PROFILE_TASK=.*,PROFILE_TASK=${PYTHON_NATIVE_PROFILE_TASK},g' Makefile
+    fi
+    oe_runmake ${PYTHON_NATIVE_MAKE_TARGET}
+}
+
 do_install() {
 	oe_runmake 'DESTDIR=${D}' install
 	install -d ${D}${bindir}/${PN}
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 02/10] python: add python-profile-opt recipe
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 01/10] python-native: support profile optimized build Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 03/10] python: remove path hack from setup.py Markus Lehtonen
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

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.12.bb            | 17 ++++++++++++++
 meta/recipes-devtools/python/python_2.7.12.bb      | 26 +++++++++++++++-------
 2 files changed, 35 insertions(+), 8 deletions(-)
 create mode 100644 meta/recipes-devtools/python/python-profile-opt_2.7.12.bb

diff --git a/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb b/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
new file mode 100644
index 0000000..058cc63
--- /dev/null
+++ b/meta/recipes-devtools/python/python-profile-opt_2.7.12.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.12.bb b/meta/recipes-devtools/python/python_2.7.12.bb
index 9fe35db..b4d6efb 100644
--- a/meta/recipes-devtools/python/python_2.7.12.bb
+++ b/meta/recipes-devtools/python/python_2.7.12.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.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 03/10] python: remove path hack from setup.py
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 01/10] python-native: support profile optimized build Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 02/10] python: add python-profile-opt recipe Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 04/10] python-profile-opt: rename libpython Markus Lehtonen
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

There should be no need to hack the library and include dirs in
setup.py. The script detects them from compiler output. We need to
remove this is because python-profile-opt recipe is built with a
non-standard prefix setting (i.e. /opt) and the hack breaks the
discovery of system libraries and headers.

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 .../python/python/01-use-proper-tools-for-cross-build.patch    | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/meta/recipes-devtools/python/python/01-use-proper-tools-for-cross-build.patch b/meta/recipes-devtools/python/python/01-use-proper-tools-for-cross-build.patch
index b2a8c3b..6449738 100644
--- a/meta/recipes-devtools/python/python/01-use-proper-tools-for-cross-build.patch
+++ b/meta/recipes-devtools/python/python/01-use-proper-tools-for-cross-build.patch
@@ -85,13 +85,3 @@ Index: Python-2.7.12/setup.py
              assert not self.inplace
              basename, tail = os.path.splitext(ext_filename)
              newname = basename + "_failed" + tail
-@@ -574,6 +575,9 @@ class PyBuildExt(build_ext):
- 
-         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
- 
-+        lib_dirs = [ os.getenv("STAGING_LIBDIR"),  os.getenv("STAGING_BASELIBDIR") ]
-+        inc_dirs = [ os.getenv("STAGING_INCDIR") ]
-+
-         #
-         # The following modules are all pretty straightforward, and compile
-         # on pretty much any POSIXish platform.
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 04/10] python-profile-opt: rename libpython
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (2 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 03/10] python: remove path hack from setup.py Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 05/10] devtools/images: add python-pgo-image Markus Lehtonen
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

The python library needs to be renamed so that the automatic dependency
generation/checking mechanism in bitbake does not get confused.
Otherwise python-profile-opt will depend on libpython from the "normal"
python package.

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 .../python/python-profile-opt_2.7.12.bb            |  6 +-
 ...rename-libpython-to-libpython-profile-opt.patch | 94 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 5 deletions(-)
 create mode 100644 meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch

diff --git a/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb b/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
index 058cc63..df5eee8 100644
--- a/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
+++ b/meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
@@ -1,7 +1,6 @@
 require python_${PV}.bb
 
-PROVIDES += "libpython2"
-RPROVIDES_${PN}-core += "libpython2"
+SRC_URI += "file://rename-libpython-to-libpython-profile-opt.patch"
 
 # Use special prefix in order to prevent clash with normal python
 STAGING_INCDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/include"
@@ -12,6 +11,3 @@ 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/rename-libpython-to-libpython-profile-opt.patch b/meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch
new file mode 100644
index 0000000..06bb4c0
--- /dev/null
+++ b/meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch
@@ -0,0 +1,94 @@
+From bc4690886248d87c019cf3c955d5349327f6fdfc Mon Sep 17 00:00:00 2001
+From: Markus Lehtonen <markus.lehtonen@linux.intel.com>
+Date: Mon, 17 Oct 2016 15:58:21 +0300
+Subject: [PATCH] rename libpython to libpython-profile-opt
+
+Upstream-Status: Inappropriate [oe-specific]
+
+Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
+---
+ Lib/distutils/command/build_ext.py | 2 +-
+ Makefile.pre.in                    | 2 +-
+ Misc/python-config.in              | 2 +-
+ Misc/python.pc.in                  | 2 +-
+ configure.ac                       | 6 +++---
+ 5 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
+index 3a49454..56cabce 100644
+--- a/Lib/distutils/command/build_ext.py
++++ b/Lib/distutils/command/build_ext.py
+@@ -758,7 +758,7 @@ class build_ext (Command):
+         else:
+             from distutils import sysconfig
+             if sysconfig.get_config_var('Py_ENABLE_SHARED'):
+-                template = "python%d.%d"
++                template = "python-profile-opt%d.%d"
+                 pythonlib = (template %
+                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+                 return ext.libraries + [pythonlib]
+diff --git a/Makefile.pre.in b/Makefile.pre.in
+index d4b81dc..43fe5fe 100644
+--- a/Makefile.pre.in
++++ b/Makefile.pre.in
+@@ -562,7 +562,7 @@ $(LIBRARY): $(LIBRARY_OBJS)
+ 	$(AR) $(ARFLAGS) $@ $(MODOBJS)
+ 	$(RANLIB) $@
+ 
+-libpython$(VERSION).so: $(LIBRARY_OBJS)
++libpython-profile-opt$(VERSION).so: $(LIBRARY_OBJS)
+ 	if test $(INSTSONAME) != $(LDLIBRARY); then \
+ 		$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+ 		$(LN) -f $(INSTSONAME) $@; \
+diff --git a/Misc/python-config.in b/Misc/python-config.in
+index 9ee0fdf..9fb149d 100644
+--- a/Misc/python-config.in
++++ b/Misc/python-config.in
+@@ -44,7 +44,7 @@ for opt in opt_flags:
+         print ' '.join(flags)
+ 
+     elif opt in ('--libs', '--ldflags'):
+-        libs = ['-lpython' + pyver]
++        libs = ['-lpython-profile-opt' + pyver]
+         libs += getvar('LIBS').split()
+         libs += getvar('SYSLIBS').split()
+         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
+diff --git a/Misc/python.pc.in b/Misc/python.pc.in
+index 08481a9..0822e54 100644
+--- a/Misc/python.pc.in
++++ b/Misc/python.pc.in
+@@ -8,6 +8,6 @@ Description: Python library
+ Requires: 
+ Version: @VERSION@
+ Libs.private: @LIBS@
+-Libs: -L${libdir} -lpython@VERSION@
++Libs: -L${libdir} -lpython-profile-opt@VERSION@
+ Cflags: -I${includedir}/python@VERSION@ 
+ 
+diff --git a/configure.ac b/configure.ac
+index 353b533..0b8e399 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -765,7 +765,7 @@ AC_SUBST(LIBRARY)
+ AC_MSG_CHECKING(LIBRARY)
+ if test -z "$LIBRARY"
+ then
+-	LIBRARY='libpython$(VERSION).a'
++	LIBRARY='libpython-profile-opt$(VERSION).a'
+ fi
+ AC_MSG_RESULT($LIBRARY)
+ 
+@@ -911,8 +911,8 @@ if test $enable_shared = "yes"; then
+ 	  INSTSONAME="$LDLIBRARY".$SOVERSION
+           ;;
+     Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*)
+-	  LDLIBRARY='libpython$(VERSION).so'
+-	  BLDLIBRARY='-L. -lpython$(VERSION)'
++	  LDLIBRARY='libpython-profile-opt$(VERSION).so'
++	  BLDLIBRARY='-L. -lpython-profile-opt$(VERSION)'
+ 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
+ 	  case $ac_sys_system in
+ 	      FreeBSD*)
+-- 
+2.6.6
+
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 05/10] devtools/images: add python-pgo-image
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (3 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 04/10] python-profile-opt: rename libpython Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 06/10] python: make profile-optimized build possible Markus Lehtonen
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

This is a special image for profiling Python in order to utilize
profile-guided-optimization. Profile data can be obtained by by running
bitbake python-pgo-image -c profile. It will be located in the directory
pointed by ${PYTHON_PROFILE_DIR}. The profile task that is run can be
altered by specifying ${PYTHON_PROFILE_TASK}.

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/recipes-devtools/images/python-pgo-image.bb | 55 ++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 meta/recipes-devtools/images/python-pgo-image.bb

diff --git a/meta/recipes-devtools/images/python-pgo-image.bb b/meta/recipes-devtools/images/python-pgo-image.bb
new file mode 100644
index 0000000..1aabd56
--- /dev/null
+++ b/meta/recipes-devtools/images/python-pgo-image.bb
@@ -0,0 +1,55 @@
+SUMMARY = "Minimal image for doing Python profiling (for PGO)"
+
+IMAGE_FEATURES += "ssh-server-dropbear"
+IMAGE_INSTALL = "packagegroup-core-boot python-profile-opt python-profile-opt-tests"
+
+LICENSE = "MIT"
+
+inherit core-image
+
+PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data"
+PYTHON_PROFILE_TASK ?= "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess"
+
+# We need these because we're utilizing the runtime test helpers from oeqa
+TEST_TARGET ?= "qemu"
+TEST_QEMUBOOT_TIMEOUT ?= "1000"
+TEST_LOG_DIR ?= "${WORKDIR}/qemulogs"
+
+python do_profile() {
+    from oeqa.targetcontrol import get_target_controller
+    from oe.utils import getstatusoutput
+
+    target = get_target_controller(d)
+    target.deploy()
+    try:
+        # Boot target
+        bootparams = None
+        if d.getVar('VIRTUAL-RUNTIME_init_manager', True) == 'systemd':
+            bootparams = 'systemd.log_level=debug systemd.log_target=console'
+        target.start(extra_bootparams=bootparams)
+
+        # Run profile task
+        profile_cmd = 'LD_LIBRARY_PATH=/opt/lib /opt/bin/python %s' % d.getVar("PYTHON_PROFILE_TASK", True)
+        ret, output = target.run(profile_cmd, timeout=7200)
+        if ret:
+            bb.fatal("Failed to run profile task on target: %s" % output)
+        ret, output = target.run('tar czf pgo-data.tgz -C /home/root/python-pgo-profiles/ .')
+        if ret:
+            bb.fatal("Failed to archive profile data on target: %s" % output)
+
+        # Retrieve and unpack profile data
+        profile_dir = d.getVar("PYTHON_PROFILE_DIR", True)
+        target.copy_from('/home/root/pgo-data.tgz', profile_dir)
+
+        profile_tarball = os.path.join(profile_dir, 'pgo-data.tgz')
+        ret, output = getstatusoutput('tar xf %s -C %s' % (profile_tarball, profile_dir))
+        os.unlink(profile_tarball)
+        if ret:
+            bb.fatal("Failed to unpack python profile data: %s" % output)
+    finally:
+        target.stop()
+}
+
+addtask profile after do_build
+do_profile[depends] += "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
+do_profile[cleandirs] = "${PYTHON_PROFILE_DIR}"
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 06/10] python: make profile-optimized build possible
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (4 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 05/10] devtools/images: add python-pgo-image Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 07/10] python-pgo-image: exclude tests from the default profile target Markus Lehtonen
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

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 <markus.lehtonen@linux.intel.com>
---
 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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 07/10] python-pgo-image: exclude tests from the default profile target
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (5 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 06/10] python: make profile-optimized build possible Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:40 ` [PATCH RFC 08/10] python: add python-tools subpackage Markus Lehtonen
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

Exclue tests that are segfaulting or otherwise failing (on qemux86
target), and thus, causing the profile task to fail.

Also, disable tests that are taking very long to execute. In qemux86
target on my i7-3770K:
  test_lib2to3: 1908.8s
  test_io: 1278.4s
  test_itertools: 436.4s

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/recipes-devtools/images/python-pgo-image.bb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-devtools/images/python-pgo-image.bb b/meta/recipes-devtools/images/python-pgo-image.bb
index 1aabd56..222d7a8 100644
--- a/meta/recipes-devtools/images/python-pgo-image.bb
+++ b/meta/recipes-devtools/images/python-pgo-image.bb
@@ -8,7 +8,14 @@ LICENSE = "MIT"
 inherit core-image
 
 PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data"
-PYTHON_PROFILE_TASK ?= "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess"
+PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess"
+# Exclude tests that are segfaulting on qemux86 target
+PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc"
+# Exclude tests that are failing on qemux86
+PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings"
+# Exclude tests that are taking very long on qemux86
+PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools"
+PYTHON_PROFILE_TASK ?= "${PYTHON_PROFILE_TASK_DEFAULT}"
 
 # We need these because we're utilizing the runtime test helpers from oeqa
 TEST_TARGET ?= "qemu"
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 08/10] python: add python-tools subpackage
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (6 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 07/10] python-pgo-image: exclude tests from the default profile target Markus Lehtonen
@ 2017-01-25 12:40 ` Markus Lehtonen
  2017-01-25 12:41 ` [PATCH RFC 09/10] python-pgo-image: switch python default profile task to pybench Markus Lehtonen
  2017-01-25 12:41 ` [PATCH RFC 10/10] python-pgo-image: enable sstate for do_profile Markus Lehtonen
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:40 UTC (permalink / raw)
  To: openembedded-core

Useful in developing Python, e.g. in benchmarking.

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/recipes-devtools/python/python-2.7-manifest.inc | 8 +++++---
 meta/recipes-devtools/python/python_2.7.12.bb        | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/meta/recipes-devtools/python/python-2.7-manifest.inc b/meta/recipes-devtools/python/python-2.7-manifest.inc
index 621024f..fdd6a16 100644
--- a/meta/recipes-devtools/python/python-2.7-manifest.inc
+++ b/meta/recipes-devtools/python/python-2.7-manifest.inc
@@ -5,9 +5,9 @@
 
  
 
-PROVIDES+="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils ${PN}-distutils-staticdev ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib "
+PROVIDES+="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils ${PN}-distutils-staticdev ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-tools"
 
-PACKAGES="${PN}-dbg ${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils-staticdev ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-modules"
+PACKAGES="${PN}-dbg ${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils-staticdev ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-modules ${PN}-tools"
 
 SUMMARY_${PN}-2to3="Python automated Python 2 to 3 code translator"
 RDEPENDS_${PN}-2to3="${PN}-core"
@@ -285,4 +285,6 @@ SUMMARY_${PN}-modules="All Python modules"
 RDEPENDS_${PN}-modules="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-difflib ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib  "
 ALLOW_EMPTY_${PN}-modules = "1"
 
-
+SUMMARY_${PN}-tools="Useful scripts from Python"
+RDEPENDS_${PN}-tools="${PN}-modules"
+FILES_${PN}-tools="${docdir}/${PN}/Tools"
diff --git a/meta/recipes-devtools/python/python_2.7.12.bb b/meta/recipes-devtools/python/python_2.7.12.bb
index 492bd24..e81ce51 100644
--- a/meta/recipes-devtools/python/python_2.7.12.bb
+++ b/meta/recipes-devtools/python/python_2.7.12.bb
@@ -148,6 +148,11 @@ do_install() {
 	fi
 
 	oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
+
+    # Install tools
+    install -d -m 755 ${D}/${docdir}/${PN}
+    cp -r ${S}/Tools ${D}/${docdir}/${PN}/
+    find ${D}/${docdir}/${PN}/ -name Makefile -delete
 }
 
 do_install_append_class-nativesdk () {
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 09/10] python-pgo-image: switch python default profile task to pybench
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (7 preceding siblings ...)
  2017-01-25 12:40 ` [PATCH RFC 08/10] python: add python-tools subpackage Markus Lehtonen
@ 2017-01-25 12:41 ` Markus Lehtonen
  2017-01-25 12:41 ` [PATCH RFC 10/10] python-pgo-image: enable sstate for do_profile Markus Lehtonen
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:41 UTC (permalink / raw)
  To: openembedded-core

Switch to pybench in order to reduce the time taken by profiling.

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/recipes-devtools/images/python-pgo-image.bb | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/meta/recipes-devtools/images/python-pgo-image.bb b/meta/recipes-devtools/images/python-pgo-image.bb
index 222d7a8..82cb001 100644
--- a/meta/recipes-devtools/images/python-pgo-image.bb
+++ b/meta/recipes-devtools/images/python-pgo-image.bb
@@ -1,7 +1,8 @@
 SUMMARY = "Minimal image for doing Python profiling (for PGO)"
 
 IMAGE_FEATURES += "ssh-server-dropbear"
-IMAGE_INSTALL = "packagegroup-core-boot python-profile-opt python-profile-opt-tests"
+IMAGE_INSTALL = "packagegroup-core-boot"
+IMAGE_INSTALL += "python-profile-opt python-profile-opt-tests python-profile-opt-tools"
 
 LICENSE = "MIT"
 
@@ -9,12 +10,13 @@ inherit core-image
 
 PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data"
 PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess"
-# Exclude tests that are segfaulting on qemux86 target
-PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc"
-# Exclude tests that are failing on qemux86
-PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings"
-# Exclude tests that are taking very long on qemux86
-PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools"
+## Exclude tests that are segfaulting on qemux86 target
+#PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc"
+## Exclude tests that are failing on qemux86
+#PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings"
+## Exclude tests that are taking very long on qemux86
+#PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools"
+PYTHON_PROFILE_TASK_DEFAULT = "/opt/share/doc/python-profile-opt/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck"
 PYTHON_PROFILE_TASK ?= "${PYTHON_PROFILE_TASK_DEFAULT}"
 
 # We need these because we're utilizing the runtime test helpers from oeqa
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH RFC 10/10] python-pgo-image: enable sstate for do_profile
  2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
                   ` (8 preceding siblings ...)
  2017-01-25 12:41 ` [PATCH RFC 09/10] python-pgo-image: switch python default profile task to pybench Markus Lehtonen
@ 2017-01-25 12:41 ` Markus Lehtonen
  9 siblings, 0 replies; 11+ messages in thread
From: Markus Lehtonen @ 2017-01-25 12:41 UTC (permalink / raw)
  To: openembedded-core

There are caveats however, basically because of the circular dependency
between python-pgo-image and python (python is a build dep of
python-pgo-image, and at the same time, depends on the profile data
generated by python-pgo-image). In practice the sstate data is only used
when no profile data is yet present. Existing profile data (i.e.
non-empty PYTHON_PROFILE_DIR) changes signature hash of python which, in
turn, changes signature of python-pgo-image and causes a sstate
signature mismatch and rebuild of python-pgo-image. Thus, in order to
utilize sstate data the user should run "bitbake python-pgo-image -c clean"
(or otherwise wipe pre-existing profile data) before running
"bitbake python-pgo-image -c profile".

[YOCTO #9338]

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/recipes-devtools/images/python-pgo-image.bb | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/meta/recipes-devtools/images/python-pgo-image.bb b/meta/recipes-devtools/images/python-pgo-image.bb
index 82cb001..bab95f8 100644
--- a/meta/recipes-devtools/images/python-pgo-image.bb
+++ b/meta/recipes-devtools/images/python-pgo-image.bb
@@ -9,6 +9,7 @@ LICENSE = "MIT"
 inherit core-image
 
 PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data"
+PROFILE_DATA_WORKDIR = "${WORKDIR}/profile-data"
 PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess"
 ## Exclude tests that are segfaulting on qemux86 target
 #PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc"
@@ -47,7 +48,7 @@ python do_profile() {
             bb.fatal("Failed to archive profile data on target: %s" % output)
 
         # Retrieve and unpack profile data
-        profile_dir = d.getVar("PYTHON_PROFILE_DIR", True)
+        profile_dir = d.getVar("PROFILE_DATA_WORKDIR", True)
         target.copy_from('/home/root/pgo-data.tgz', profile_dir)
 
         profile_tarball = os.path.join(profile_dir, 'pgo-data.tgz')
@@ -61,4 +62,14 @@ python do_profile() {
 
 addtask profile after do_build
 do_profile[depends] += "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
-do_profile[cleandirs] = "${PYTHON_PROFILE_DIR}"
+do_profile[cleandirs] = "${PROFILE_DATA_WORKDIR}"
+
+
+python do_profile_setscene () {
+    sstate_setscene(d)
+}
+
+SSTATETASKS += "do_profile"
+do_profile[sstate-inputdirs] = "${PROFILE_DATA_WORKDIR}"
+do_profile[sstate-outputdirs] = "${PYTHON_PROFILE_DIR}"
+addtask do_profile_setscene
-- 
2.10.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-01-25 12:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-25 12:40 [PATCH RFC 00/10] python: support profile-optimized build Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 01/10] python-native: support profile optimized build Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 02/10] python: add python-profile-opt recipe Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 03/10] python: remove path hack from setup.py Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 04/10] python-profile-opt: rename libpython Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 05/10] devtools/images: add python-pgo-image Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 06/10] python: make profile-optimized build possible Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 07/10] python-pgo-image: exclude tests from the default profile target Markus Lehtonen
2017-01-25 12:40 ` [PATCH RFC 08/10] python: add python-tools subpackage Markus Lehtonen
2017-01-25 12:41 ` [PATCH RFC 09/10] python-pgo-image: switch python default profile task to pybench Markus Lehtonen
2017-01-25 12:41 ` [PATCH RFC 10/10] python-pgo-image: enable sstate for do_profile Markus Lehtonen

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.