[pypy-commit] pypy default: issue900: Implement processor pinning on win32,
amauryfa
noreply at buildbot.pypy.org
Sun Jan 8 21:17:03 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r51147:a7e8e37cbf30
Date: 2012-01-08 21:16 +0100
http://bitbucket.org/pypy/pypy/changeset/a7e8e37cbf30/
Log: issue900: Implement processor pinning on win32, should fix
inconsistent figures with cProfile.
diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py
--- a/pypy/module/_lsprof/interp_lsprof.py
+++ b/pypy/module/_lsprof/interp_lsprof.py
@@ -19,8 +19,9 @@
# cpu affinity settings
srcdir = py.path.local(pypydir).join('translator', 'c', 'src')
-eci = ExternalCompilationInfo(separate_module_files=
- [srcdir.join('profiling.c')])
+eci = ExternalCompilationInfo(
+ separate_module_files=[srcdir.join('profiling.c')],
+ export_symbols=['pypy_setup_profiling', 'pypy_teardown_profiling'])
c_setup_profiling = rffi.llexternal('pypy_setup_profiling',
[], lltype.Void,
diff --git a/pypy/translator/c/src/profiling.c b/pypy/translator/c/src/profiling.c
--- a/pypy/translator/c/src/profiling.c
+++ b/pypy/translator/c/src/profiling.c
@@ -29,6 +29,35 @@
profiling_setup = 0;
}
}
+
+#elif defined(_WIN32)
+#include <windows.h>
+
+DWORD_PTR base_affinity_mask;
+int profiling_setup = 0;
+
+void pypy_setup_profiling() {
+ if (!profiling_setup) {
+ DWORD_PTR affinity_mask, system_affinity_mask;
+ GetProcessAffinityMask(GetCurrentProcess(),
+ &base_affinity_mask, &system_affinity_mask);
+ affinity_mask = 1;
+ /* Pick one cpu allowed by the system */
+ if (system_affinity_mask)
+ while ((affinity_mask & system_affinity_mask) == 0)
+ affinity_mask <<= 1;
+ SetProcessAffinityMask(GetCurrentProcess(), affinity_mask);
+ profiling_setup = 1;
+ }
+}
+
+void pypy_teardown_profiling() {
+ if (profiling_setup) {
+ SetProcessAffinityMask(GetCurrentProcess(), base_affinity_mask);
+ profiling_setup = 0;
+ }
+}
+
#else
void pypy_setup_profiling() { }
void pypy_teardown_profiling() { }
More information about the pypy-commit
mailing list