diff mbox

[API-NEXT,4/4] linux-generic: add support for initial cpumasks

Message ID 1456354201-31304-5-git-send-email-gary.robertson@linaro.org
State New
Headers show

Commit Message

gary.robertson@linaro.org Feb. 24, 2016, 10:50 p.m. UTC
These code changes depend on the addition of control and worker
    cpumask pointers to the ODP initialization parameter data structure,
    and implement the change in behavior suggested with that patch.
    They serve as the 'glue' between the input of the new ODP API
    initial cpuset masks and the use of those new cpumasks by the
    ODP application or instance.

    Specifically: if both of the cpumask pointers are NULL or
    if neither of the new cpumasks are populated prior to
    calling odp_init_global(), then the behavior for allocation of
    control and worker cpumasks is unchanged from its current
    (pre-patch) state.

    However, if the cpumasks are populated and their pointers initialized
    prior to calling odp_init_global() then that routine saves
    their contents into global variables for later reference.
    Then when odp_cpumask_default_control() or odp_cpumask_default_worker()
    are called they build the caller's cpumasks based on the
    saved contents of the pre-populated cpumask input.

    These changes allow multiple concurrent ODP applications
    or instances to be given CPU resources which do not conflict
    with one another, so multiple ODP instances can coexist harmoniously
    with any isolation support on the underlying platform
    as well as with one another.

Signed-off-by: Gary S. Robertson <gary.robertson@linaro.org>
---
 platform/linux-generic/odp_init.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 5433eec..371b76c 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -98,16 +98,43 @@  int odp_init_global(const odp_init_t *params,
 	odp_global_data.log_fn = odp_override_log;
 	odp_global_data.abort_fn = odp_override_abort;
 
+	/*
+	 * Default to allowing all installed CPUs for both
+	 * control and worker cpumasks.
+	 * If externally specified cpumasks are provided,
+	 * we will use the installed CPU masks to confine
+	 * the specified cpumasks to CPUs actually installed.
+	 */
+	if (get_installed_cpus()) {
+		ODP_ERR("ODP cpumask init failed.\n");
+		goto init_failed;
+	}
+
 	if (params != NULL) {
 		if (params->log_fn != NULL)
 			odp_global_data.log_fn = params->log_fn;
 		if (params->abort_fn != NULL)
 			odp_global_data.abort_fn = params->abort_fn;
-	}
 
-	if (get_installed_cpus()) {
-		ODP_ERR("ODP cpumask init failed.\n");
-		goto init_failed;
+		/*
+		 * If either control or worker cpumasks were specified,
+		 * 'AND' the specified cpumasks with the masks of
+		 * installed CPUs to ensure only installed CPUs are
+		 * specified as available.
+		 * Save the control and / or worker cpumask contents
+		 * in globally accessible data structures
+		 * so odp_cpumask_default_control(),
+		 * odp_cpumask_default_worker(), and any
+		 * isolation support logic may reference them later.
+		 */
+		if (params->control_cpus)
+			odp_cpumask_and(&odp_global_data.control_cpus,
+					&odp_global_data.control_cpus,
+					params->control_cpus);
+		if (params->worker_cpus)
+			odp_cpumask_and(&odp_global_data.worker_cpus,
+					&odp_global_data.worker_cpus,
+					params->worker_cpus);
 	}
 
 	if (odp_time_init_global()) {