From patchwork Fri Jan 22 22:24:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 60207 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp139456lbb; Fri, 22 Jan 2016 14:27:57 -0800 (PST) X-Received: by 10.107.164.141 with SMTP id d13mr6456673ioj.88.1453501677864; Fri, 22 Jan 2016 14:27:57 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c187si14763846ioc.20.2016.01.22.14.27.57; Fri, 22 Jan 2016 14:27:57 -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 381E1619D9; Fri, 22 Jan 2016 22:27:57 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=S8QLaFkZ; 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 6A6E6619E7; Fri, 22 Jan 2016 22:26:57 +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 04E26619C1; Fri, 22 Jan 2016 22:26:29 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id 9D16A619EC for ; Fri, 22 Jan 2016 22:25:05 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id oh2so48649059lbb.3 for ; Fri, 22 Jan 2016 14:25:05 -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=dTQvVMLdkEbEBpb6PUiBtc2DvyKy7QHplZ2X+3fZTP4=; b=S8QLaFkZbuzIjI9kMudSo2jr506lYxk2tFdJyyAa8ByzRiZtEYfXzQvQfIrd+oxuql eTgv6Bn2OQtx6R69AZPnSKoeU/i9CBJKoMnptR+SVBW9XgTuWm7yzxhE1q8PvEA96bA5 CMmGwq/3+VFiH1ToFS2Wf4Y6UK/NAio9ShKWI= 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=dTQvVMLdkEbEBpb6PUiBtc2DvyKy7QHplZ2X+3fZTP4=; b=VEGIGLi9V5P53zCxVUqQUK0o8VnWgWaCbYNitFtmNG6IfvJjXOE6NUgsj4c5cHu0zD s0VOgRRBUIvGzFviem9O3Fja162RmSSTUtWJTZTMHMs9ZUJT0/5rYGD154m9Gp+Ip7PD azMTGdV4VdGVHceYqkSlp+0pZn/78Yp6IOikchtXTRo2k+0zyP04in9Bs5zI3klykYxa NNj6KZhH82Cd3NINtWgWTeV/Mur6JbYGlAanRrg4u9ICd7zzZCTbEg2l67xlB7vF0KBw 0Ep4yECw54vgHuplgKlfxDx96Vf6vfawiPRu5abZEmhDu7zbXijColwxJqrHrPK3LVdo PeDw== X-Gm-Message-State: AG10YOSRavqFZ+h2NPFag4ovQ2HbHqhZYZUnu7rpH23il/eVWXizCU74xTDL/5P7aYL53i1EXIA= X-Received: by 10.112.137.129 with SMTP id qi1mr2102048lbb.31.1453501504614; Fri, 22 Jan 2016 14:25:04 -0800 (PST) Received: from khorivan.synapse.com ([212.90.63.58]) by smtp.gmail.com with ESMTPSA id z193sm1138164lfd.0.2016.01.22.14.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jan 2016 14:25:03 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Sat, 23 Jan 2016 00:24:52 +0200 Message-Id: <1453501492-9721-3-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453501492-9721-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1453501492-9721-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/2] linux-generic: init: assign affinity for main thread 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" By default it's supposed CPU0 to be used for control thread. So assign CPU0 as control thread CPU. The CPU0 is still can be used for worker threads, but after this change control thread cannot use CPUs used by "worker" threads. As example, in some cases, can happen, at application initialization, the OS scheduler switches control thread on CPUn (n != 0), and if in this time odp timer is scheduled, it executes notify routine on CPUn, which will consume CPU time off some "worker thread" even after initialization. Also this is good example, how control thread should be used, it always runs on same CPU, allowing to use local time API, which can be legal only on single CPU threads. Signed-off-by: Ivan Khoronzhuk --- platform/linux-generic/odp_init.c | 50 +++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 3a990d2..7637a85 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -4,6 +4,10 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include +#include +#include + #include #include #include @@ -11,6 +15,21 @@ struct odp_global_data_s odp_global_data; +static int init_global_set_affinity(void) +{ + int ret; + cpu_set_t cpuset; + + CPU_ZERO(&cpuset); + CPU_SET(0, &cpuset); + ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); + + if (ret != 0) + return -1; + + return 0; +} + int odp_init_global(const odp_init_t *params, const odp_platform_init_t *platform_params ODP_UNUSED) { @@ -25,12 +44,6 @@ int odp_init_global(const odp_init_t *params, odp_global_data.abort_fn = params->abort_fn; } - if (odp_time_init_global()) { - ODP_ERR("ODP time init failed.\n"); - goto init_failed; - } - stage = TIME_INIT; - if (odp_system_info_init()) { ODP_ERR("ODP system_info init failed.\n"); goto init_failed; @@ -91,6 +104,17 @@ int odp_init_global(const odp_init_t *params, } stage = CLASSIFICATION_INIT; + if (init_global_set_affinity()) { + ODP_ERR("ODP affinity init failed.\n"); + return -1; + } + + if (odp_time_init_global()) { + ODP_ERR("ODP time init failed.\n"); + goto init_failed; + } + stage = TIME_INIT; + return 0; init_failed: @@ -110,6 +134,13 @@ int _odp_term_global(enum init_stage stage) switch (stage) { case ALL_INIT: + case TIME_INIT: + if (odp_time_term_global()) { + ODP_ERR("ODP time term failed.\n"); + rc = -1; + } + /* Fall through */ + case CLASSIFICATION_INIT: if (odp_classification_term_global()) { ODP_ERR("ODP classificatio term failed.\n"); @@ -180,13 +211,6 @@ int _odp_term_global(enum init_stage stage) } /* Fall through */ - case TIME_INIT: - if (odp_time_term_global()) { - ODP_ERR("ODP time term failed.\n"); - rc = -1; - } - /* Fall through */ - case NO_INIT: ; }