From patchwork Fri Jan 22 23:37:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary.robertson@linaro.org X-Patchwork-Id: 60210 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp171557lbb; Fri, 22 Jan 2016 15:41:29 -0800 (PST) X-Received: by 10.140.109.33 with SMTP id k30mr7063546qgf.75.1453506088928; Fri, 22 Jan 2016 15:41:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c21si9731951qkj.47.2016.01.22.15.41.27; Fri, 22 Jan 2016 15:41:28 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1C4A0619BC; Fri, 22 Jan 2016 23:41:27 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=hJ9KtSdD; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A6D6461A0A; Fri, 22 Jan 2016 23:39:42 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E754961A0A; Fri, 22 Jan 2016 23:39:34 +0000 (UTC) Received: from mail-oi0-f49.google.com (mail-oi0-f49.google.com [209.85.218.49]) by lists.linaro.org (Postfix) with ESMTPS id 1900861A23 for ; Fri, 22 Jan 2016 23:37:54 +0000 (UTC) Received: by mail-oi0-f49.google.com with SMTP id p187so57200100oia.2 for ; Fri, 22 Jan 2016 15:37:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gzkHaG0DWFFCZL0hP83ku2lI94MCcTmLzbbi0PGY2MI=; b=hJ9KtSdDMUXoHsG6yzykiVW6REofBUfKWC8mNjznQWuksoZg6l5a4K0RBS9+m8+KZG 57lulaW8H1H1k4wMO1NGRyZe5H7kAofjM+fvJXVrQMs5lbw0+9V9xmIiGnnmU2Vn9rPk JjkIDYJzEs8HH8rgqPiiGEKZXcx23Q7lXiTdo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gzkHaG0DWFFCZL0hP83ku2lI94MCcTmLzbbi0PGY2MI=; b=c5On1/VDYQC+DqvH6Mj6/cWLrfJdzUJZivHvlRke2+d3L0/uB2AY7g8HAgknEEo7Dr Ggo2+RM8WKxXTl4pjDTT6ulig2vg1wxHRNJLS3FZUn7NArWULVJdNVvQcNLJnpK8kTXj /fLO2DwboLo5PB4xe+3JuVkN4+8MY5m2V3UeUfgnPHAt9FD1dQUHrQAGzbKRsWsBEyHI 1WlwhiIGQdcbx0cPzV4liss2xzVx4KSJ/8DfKcvF5E/pkh71at+o2DMB7GQxg2Yq73QV 3+JBB0ue9p33PSkt8PaDbLZOJBPGGAC2TKS6ZX2m8BkcxseY0GNTA8+ym0gIYTygsbGq gQhQ== X-Gm-Message-State: AG10YOTsv3KwNGUpblh/Haa61fXvukr2NBsuCSb66MSfrA/HaBaCj8zP+cj+PmKDdvNRDV7XNiw= X-Received: by 10.202.49.9 with SMTP id x9mr4531144oix.75.1453505873663; Fri, 22 Jan 2016 15:37:53 -0800 (PST) Received: from honkintosh.cybertech.lan (65-120-133-114.dia.static.qwest.net. [65.120.133.114]) by smtp.googlemail.com with ESMTPSA id s7sm4372237obk.17.2016.01.22.15.37.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 15:37:52 -0800 (PST) From: "Gary S. Robertson" To: mike.holmes@linaro.org, bill.fischofer@linaro.org, maxim.uvarov@linaro.org, anders.roxell@linaro.org, stuart.haslam@linaro.org, petri.savolainen@linaro.org Date: Fri, 22 Jan 2016 17:37:38 -0600 Message-Id: <1453505859-20419-3-git-send-email-gary.robertson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453505859-20419-1-git-send-email-gary.robertson@linaro.org> References: <1453505859-20419-1-git-send-email-gary.robertson@linaro.org> X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API_NEXT PATCH V3 01/01] linux-generic: add support for initial cpumasks X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" 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 --- platform/linux-generic/include/odp_internal.h | 2 ++ platform/linux-generic/odp_cpumask_task.c | 48 ++++++++++++++++++++++----- platform/linux-generic/odp_init.c | 19 +++++++++++ platform/linux-generic/odp_system_info.c | 13 +++----- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index cdbed7d..7488b3b 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -38,6 +38,8 @@ struct odp_global_data_s { odp_log_func_t log_fn; odp_abort_func_t abort_fn; odp_system_info_t system_info; + odp_cpumask_t control_cpus; + odp_cpumask_t worker_cpus; }; enum init_stage { diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c index c5093e0..a5a9791 100644 --- a/platform/linux-generic/odp_cpumask_task.c +++ b/platform/linux-generic/odp_cpumask_task.c @@ -17,10 +17,27 @@ int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) int ret, cpu, i; cpu_set_t cpuset; - ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpu_set_t), &cpuset); - if (ret != 0) - ODP_ABORT("failed to read CPU affinity value\n"); + CPU_ZERO(&cpuset); + + /* + * If the available worker cpumask was specified prior to global init, + * then allocate worker CPUs from that cpumask. + */ + if (odp_cpumask_count(&odp_global_data.worker_cpus)) { + for (i = 0; i < CPU_SETSIZE; i++) + if (odp_cpumask_isset(&odp_global_data.worker_cpus, i)) + CPU_SET(i, &cpuset); + } else { + /* + * No initial worker cpumask was specified. + * So allocate worker CPUs from the available CPUs defined + * by the default OS environment. + */ + ret = pthread_getaffinity_np(pthread_self(), + sizeof(cpu_set_t), &cpuset); + if (ret != 0) + ODP_ABORT("failed to read CPU affinity value\n"); + } odp_cpumask_zero(mask); @@ -28,7 +45,7 @@ int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) * If no user supplied number or it's too large, then attempt * to use all CPUs */ - if (0 == num || CPU_SETSIZE < num) + if (0 == num || CPU_COUNT(&cpuset) < num) num = CPU_COUNT(&cpuset); /* build the mask, allocating down from highest numbered CPU */ @@ -48,10 +65,25 @@ int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) int odp_cpumask_default_control(odp_cpumask_t *mask, int num ODP_UNUSED) { + int cpu_count = 0; + odp_cpumask_zero(mask); - /* By default all control threads on CPU 0 */ - odp_cpumask_set(mask, 0); - return 1; + + /* + * If the available control cpumask was specified prior to global init, + * then allocate control CPUs from that cpumask. + */ + cpu_count = odp_cpumask_count(&odp_global_data.control_cpus); + if (cpu_count) + odp_cpumask_copy(mask, &odp_global_data.control_cpus); + + /* CPU 0 must always be usable for control threads */ + if (!odp_cpumask_isset(mask, 0)) { + odp_cpumask_set(mask, 0); + cpu_count++; + } + + return cpu_count; } int odp_cpumask_all_available(odp_cpumask_t *mask) diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 6ad3320..38850ce 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -23,6 +23,25 @@ int odp_init_global(const odp_init_t *params, odp_global_data.log_fn = params->log_fn; if (params->abort_fn != NULL) odp_global_data.abort_fn = params->abort_fn; + /* + * Save the control and worker cpumask contents + * in a globally accessible data structure + * so odp_cpumask_default_control(), + * odp_cpumask_default_worker(), and any + * isolation support logic may reference them later. + */ + if (params->control_cpus && + odp_cpumask_count(params->control_cpus)) + odp_cpumask_copy(&odp_global_data.control_cpus, + params->control_cpus); + else + odp_cpumask_zero(&odp_global_data.control_cpus); + if (params->worker_cpus && + odp_cpumask_count(params->worker_cpus)) + odp_cpumask_copy(&odp_global_data.worker_cpus, + params->worker_cpus); + else + odp_cpumask_zero(&odp_global_data.worker_cpus); } if (odp_time_init_global()) { diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index de28fab..70ebf57 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -39,19 +40,13 @@ typedef struct { /* - * Report the number of CPUs in the affinity mask of the main thread + * Report the number of CPUs available to this ODP application / instance */ static int sysconf_cpu_count(void) { - cpu_set_t cpuset; - int ret; - - ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpuset), &cpuset); - if (ret != 0) - return 0; + odp_cpumask_t mask; - return CPU_COUNT(&cpuset); + return odp_cpumask_all_available(&mask); } #if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \