Testers for lang/ruby19 with Profile-Guided Optimization
Mario Sergio Fujikawa Ferreira
lioux at FreeBSD.org
Sun Mar 1 02:11:52 PST 2009
Hi,
After the work on lang/ruby18, I did some work on lang/ruby19
to enable Profile-Guided Optimization (PGO) build support.
What I did? (Steps 1-4 handled by pgo port target).
------- RECIPE
1) Compile everything with CFLAGS/LDFLAGS containing
'-fprofile-generate';
2) Run lots of test cases to generate profiling information
(make test);
3) Remove all binaries leaving only the profiling information behind;
4) Replace all instances of '-fprofile-generate' with
'-fprofile-use';
5) Re-compile everything using the profiling information.
-------
If I did it correctly, you should not notice any differences
on port usage aside from PGO option and a huge build compilation
time. Please, verify if you can that I did all steps of the "RECIPE"
correctly.
What is different from the previous lang/ruby19 patch? Well,
the test cases have some timing problems when ran profiling
instrumentation so we do not generate as much profiling information
with this one; i.e., it is not as optimized as it could be because
some tests fail during profiling. However, we are safe since the
tests work after we re-build without the instrumentation.
I am not a ruby expert so I would like input on this one:
1) Does it perform better than ruby19 compiled without PGO?
Hard number benchmarks welcome. Check
http://github.com/acangiano/ruby-benchmark-suite/tree/master
2) Also, could others run specification conformance
verification checks on the resulting ruby interpreter?
So that we have multiple cross verification. Perhaps,
with rubyspec?
I hope you find this useful and that it performs as expected.
I want to go after lang/ruby19. Perhaps, even python and perl5.
The modified port file can be found at
http://people.freebsd.org/~lioux/ruby19-pgo-2009030100.tbz
but the patch is so small that I have it as an attachment.
Regards,
--
Mario S F Ferreira - DF - Brazil - "I guess this is a signature."
feature, n: a documented bug | bug, n: an undocumented feature
-------------- next part --------------
--- Makefile.orig 2009-03-01 07:05:01.000000000 -0300
+++ Makefile 2009-03-01 07:05:18.000000000 -0300
@@ -42,7 +42,8 @@
NO_LATEST_LINK= yes
-OPTIONS= RDOC "Build and install Rdoc indexes" off \
+OPTIONS= PGO "Enable Profile-Guided Optimization" off \
+ RDOC "Build and install Rdoc indexes" off \
DEBUG "Compile-in debug info" off
.include <bsd.port.pre.mk>
@@ -75,8 +76,14 @@
CONFIGURE_ARGS+= --disable-install-doc
.endif
+.if defined(WITH_PGO)
+CONFIGURE_ENV= CFLAGS="${CFLAGS} -fprofile-generate" \
+ LDFLAGS="-fprofile-generate" \
+ LIBS="${LDFLAGS}"
+.else
CONFIGURE_ENV= CFLAGS="${CFLAGS}" \
LIBS="${LDFLAGS}"
+.endif
.if ${RUBY_VER} == ${RUBY_DEFAULT_VER}
MLINKS= ${RUBY_NAME}.1 ruby.1
@@ -133,6 +140,13 @@
${MV} ${BUILD_WRKSRC}/ext/${d} ${WRKDIR}/
.endfor
+.if defined(WITH_PGO)
+.if target(pre-build)
+.error Makefile error since pre-build target has already been defined
+.endif
+pre-build: pgo
+.endif
+
post-build:
#
# Hack to allow modules to be installed into separate PREFIX and/or under user
@@ -288,4 +302,54 @@
test:
@(cd ${WRKSRC}; ${MAKE} test)
+validate::
+ @(cd ${WRKSRC}; ${MAKE} update-rubyspec)
+ @(cd ${WRKSRC}; ${MAKE} test-rubyspec)
+
+.if defined(WITH_PGO)
+pgo: pgo-pre-build pgo-build pgo-run pgo-post-run pgo-clean
+
+pgo-pre-build:
+ @${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+ ${REINPLACE_CMD} -E \
+ -e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+ -e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+ -e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)$$,\1 -fprofile-generate,' \
+ {} \;
+
+# XXX
+# Can I use do-build directly instead of copying its contents?
+# I mean, if I do
+#
+# pgo-build: do-build
+#
+# Will do-build still be called when bsd.port.mk gets to the build target?
+# Or, will it have "already" been executed by the pgo-build target?
+#
+pgo-build:
+ @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} ${MAKE_ARGS} ${ALL_TARGET})
+
+pgo-run:
+# Check everything to generate profiling information.
+# Everything run so slowly that thread tests break on timing issues
+# so we will have to "trust" it just works during the build phase.
+# Manually test after build to make sure.
+ @-(cd ${BUILD_WRKSRC}; ${MAKE} test)
+# @-(cd ${BUILD_WRKSRC}; ${MAKE} test-all)
+
+pgo-post-run:
+ @${FIND} ${BUILD_WRKSRC} -type f -name Makefile -exec \
+ ${REINPLACE_CMD} -E \
+ -e 's,^(((C|LD)FLAGS|LDSHARED|ldflags)[[:space:]]*=.*)-fprofile-generate,\1,' \
+ -e 's,^(CFLAGS[[:space:]]*=.*)-fprofile-use,\1,' \
+ -e 's,^(CFLAGS[[:space:]]*=.*)$$,\1 -fprofile-use,' \
+ {} \;
+ @${REINPLACE_CMD} -E \
+ -e 's,-fprofile-generate,-fprofile-use,g' \
+ ${CONFIGURE_WRKSRC}/config.status
+
+pgo-clean:
+ @(cd ${BUILD_WRKSRC}; ${MAKE} clean)
+.endif # if defined(WITH_PGO)
+
.include <bsd.port.post.mk>
More information about the freebsd-ports
mailing list