From patchwork Wed Jan 11 07:50:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi He X-Patchwork-Id: 90821 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1003108qgi; Tue, 10 Jan 2017 23:51:53 -0800 (PST) X-Received: by 10.55.43.74 with SMTP id r71mr6535865qkh.306.1484121113612; Tue, 10 Jan 2017 23:51:53 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o67si3232036qka.120.2017.01.10.23.51.53; Tue, 10 Jan 2017 23:51:53 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4C9B760A0F; Wed, 11 Jan 2017 07:51:53 +0000 (UTC) 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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 26E8760A21; Wed, 11 Jan 2017 07:51:19 +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 24D1E60987; Wed, 11 Jan 2017 07:50:55 +0000 (UTC) Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by lists.linaro.org (Postfix) with ESMTPS id 7231A60508 for ; Wed, 11 Jan 2017 07:50:53 +0000 (UTC) Received: by mail-pf0-f173.google.com with SMTP id 127so60328272pfg.1 for ; Tue, 10 Jan 2017 23:50:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1+9pnqMpr5Wm47BT5iUkyByEcnvzR/kNdWEuTOzYx6M=; b=NGbvK9q2N9gXP0TU2kcUXJwdXoZUaVrebztHuythxkWOpyikJj1nbCG0a3GYqESy9b tSdKaPJFSMIBxPYeXAh+bIEoms6tMzmYP7CaelFs2eeruIyU7V2eR22/lIpjgZLkCQFg 07z2gZ7oVgaj1mw9c/9z7/KatkBISHNmYSSSVAfQhvxnfqlbnmMJnT3BXRSAR91cFtaq zH8Dmdsy/+XG8SdB/O/wRiSeoUGPyr3vM8/DlQPsdBIHriHOVooSdF2pbSRZcInDoZlQ cL2lkRAKLKXZWESNIlQVzJEFdZo2fswAox/sgpW6ZWDcY4at17w57CJiRgRDAnt40JuE g/Hg== X-Gm-Message-State: AIkVDXKsj6yHINiNwOGRo6mOaPDABqw2PZbpN5MwiWXp8u240nTyTpGtFMyDYNOyOei8NIXIXv0= X-Received: by 10.84.141.164 with SMTP id 33mr11275832plv.86.1484121052607; Tue, 10 Jan 2017 23:50:52 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id l12sm3543001pfj.37.2017.01.10.23.50.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Jan 2017 23:50:51 -0800 (PST) From: Yi He To: bill.fischofer@linaro.org, maxim.uvarov@linaro.org, lng-odp@lists.linaro.org Date: Wed, 11 Jan 2017 07:50:30 +0000 Message-Id: <1484121033-15354-2-git-send-email-yi.he@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484121033-15354-1-git-send-email-yi.he@linaro.org> References: <1484121033-15354-1-git-send-email-yi.he@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv3 1/4] linux-gen: sched: solve ordered context inversion 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" For ordered queue, a thread consumes events (dequeue) and acquires its unique sequential context in two steps, non atomic and preemptable. This leads to potential ordered context inversion in case the thread consumes prior events acquired subsequent context, while the thread consumes subsequent events but acquired prior context. This patch insert the ordered context acquisition into event dequeue operation to make these two steps atomic. Signed-off-by: Yi He --- platform/linux-generic/include/odp_schedule_if.h | 3 +++ platform/linux-generic/odp_queue.c | 3 +++ platform/linux-generic/odp_schedule.c | 7 ++++++- platform/linux-generic/odp_schedule_sp.c | 7 ++++++- 4 files changed, 18 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/include/odp_schedule_if.h b/platform/linux-generic/include/odp_schedule_if.h index 6c2b050..c0aee42 100644 --- a/platform/linux-generic/include/odp_schedule_if.h +++ b/platform/linux-generic/include/odp_schedule_if.h @@ -12,6 +12,7 @@ extern "C" { #endif #include +#include #include typedef void (*schedule_pktio_start_fn_t)(int pktio_index, int num_in_queue, @@ -33,6 +34,7 @@ typedef int (*schedule_term_local_fn_t)(void); typedef void (*schedule_order_lock_fn_t)(void); typedef void (*schedule_order_unlock_fn_t)(void); typedef unsigned (*schedule_max_ordered_locks_fn_t)(void); +typedef void (*schedule_save_context_fn_t)(queue_entry_t *queue); typedef struct schedule_fn_t { schedule_pktio_start_fn_t pktio_start; @@ -50,6 +52,7 @@ typedef struct schedule_fn_t { schedule_order_lock_fn_t order_lock; schedule_order_unlock_fn_t order_unlock; schedule_max_ordered_locks_fn_t max_ordered_locks; + schedule_save_context_fn_t save_context; } schedule_fn_t; /* Interface towards the scheduler */ diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index d9cb9f3..3b6a68b 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -568,6 +568,9 @@ static inline int deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], if (hdr == NULL) queue->s.tail = NULL; + if (queue->s.type == ODP_QUEUE_TYPE_SCHED) + sched_fn->save_context(queue); + UNLOCK(&queue->s.lock); return i; diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 645630a..264c58f 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -1205,6 +1205,10 @@ static int schedule_num_grps(void) return NUM_SCHED_GRPS; } +static void schedule_save_context(queue_entry_t *queue ODP_UNUSED) +{ +} + /* Fill in scheduler interface */ const schedule_fn_t schedule_default_fn = { .pktio_start = schedule_pktio_start, @@ -1221,7 +1225,8 @@ const schedule_fn_t schedule_default_fn = { .term_local = schedule_term_local, .order_lock = order_lock, .order_unlock = order_unlock, - .max_ordered_locks = schedule_max_ordered_locks + .max_ordered_locks = schedule_max_ordered_locks, + .save_context = schedule_save_context }; /* Fill in scheduler API calls */ diff --git a/platform/linux-generic/odp_schedule_sp.c b/platform/linux-generic/odp_schedule_sp.c index 5150d28..1406312 100644 --- a/platform/linux-generic/odp_schedule_sp.c +++ b/platform/linux-generic/odp_schedule_sp.c @@ -803,6 +803,10 @@ static void order_unlock(void) { } +static void save_context(queue_entry_t *queue ODP_UNUSED) +{ +} + /* Fill in scheduler interface */ const schedule_fn_t schedule_sp_fn = { .pktio_start = pktio_start, @@ -819,7 +823,8 @@ const schedule_fn_t schedule_sp_fn = { .term_local = term_local, .order_lock = order_lock, .order_unlock = order_unlock, - .max_ordered_locks = max_ordered_locks + .max_ordered_locks = max_ordered_locks, + .save_context = save_context }; /* Fill in scheduler API calls */