[gnome-photos/wip/max-threads] gegl: Don't exceed arbitrary maximum number of threads
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/max-threads] gegl: Don't exceed arbitrary maximum number of threads
- Date: Wed, 9 Dec 2020 12:55:37 +0000 (UTC)
commit 4b1d7f31446683a0dfd98895cc81800d5b99d219
Author: Simon McVittie <smcv debian org>
Date: Wed Dec 9 12:46:04 2020 +0000
gegl: Don't exceed arbitrary maximum number of threads
gegl has an arbitrary maximum value for GeglConfig:threads, currently 64,
and exceeding it causes critical warnings. This can make the build-time
tests fail on massively parallel hardware. For example, on a dual
POWER8 system used to build Debian ppc64el packages (2 CPUs, 10 cores
per CPU and 8 threads per core, for a total of 160 threads), we ask
gegl to use 80 threads, which is more than 64.
The simple approach to this would be to clamp to the range
[1, GEGL_MAX_THREADS], but this would not be robust against possible
future changes to the value of GEGL_MAX_THREADS, so this commit
introspects the property to find out the true maximum at runtime.
Bug-Debian: https://bugs.debian.org/976932
Signed-off-by: Simon McVittie <smcv debian org>
src/photos-gegl.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index c2e12af3..a2424400 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -680,23 +680,39 @@ void
photos_gegl_init (void)
{
GeglConfig *config;
- gint threads;
+ GParamSpec *threads_property;
+ GParamSpecInt *threads_property_int;
+ guint threads;
+ guint max_threads;
guint n_processors;
n_processors = g_get_num_processors ();
- g_return_if_fail (n_processors > 0);
+ config = gegl_config ();
+
+ /* gegl has an arbitrary maximum for the number of threads. The maximum
+ * for the version of gegl we were compiled against is given by the
+ * GEGL_MAX_THREADS macro, but there's no guarantee that the version we
+ * are eventually run against will be the same, so introspect the property
+ * to get the current maximum. */
+ threads_property = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
+ "threads");
+ g_return_if_fail (threads_property != NULL);
+ g_return_if_fail (G_IS_PARAM_SPEC_INT (threads_property));
+ threads_property_int = G_PARAM_SPEC_INT (threads_property);
+ g_return_if_fail (threads_property_int->maximum >= 1);
+ max_threads = threads_property_int->maximum;
/* The number of threads should match the number of physical CPU
* cores, not the number of virtual hyper-threading cores. In the
* absence of an API to get the number of physical CPU cores, we
* assume that a number higher than one is indicative of
* hyper-threading, and hence divide by two.
+ * Make sure it's in the allowed range for the threads property.
*/
- threads = (gint) (n_processors > 1 ? n_processors / 2 : n_processors);
+ threads = CLAMP (n_processors / 2, 1U, max_threads);
- config = gegl_config ();
g_object_set (config, "application-license", "GPL3", NULL);
- g_object_set (config, "threads", threads, NULL);
+ g_object_set (config, "threads", (gint) threads, NULL);
g_object_set (config, "use-opencl", FALSE, NULL);
gegl_init (NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]