From patchwork Tue Jan 17 16:28:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimov X-Patchwork-Id: 91693 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp522986obz; Tue, 17 Jan 2017 08:31:20 -0800 (PST) X-Received: by 10.55.99.81 with SMTP id x78mr40927204qkb.62.1484670680079; Tue, 17 Jan 2017 08:31:20 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h30si16946617qta.318.2017.01.17.08.31.19; Tue, 17 Jan 2017 08:31:20 -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 Received: by lists.linaro.org (Postfix, from userid 109) id B78DC60954; Tue, 17 Jan 2017 16:31:19 +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=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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 2094A60ECA; Tue, 17 Jan 2017 16:29:11 +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 A560160653; Tue, 17 Jan 2017 16:28:57 +0000 (UTC) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0069.outbound.protection.outlook.com [104.47.0.69]) by lists.linaro.org (Postfix) with ESMTPS id 42D2D6094F for ; Tue, 17 Jan 2017 16:28:53 +0000 (UTC) Received: from e109786-lin.cambridge.arm.com (217.140.96.140) by AM5PR0801MB1746.eurprd08.prod.outlook.com (10.169.247.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Tue, 17 Jan 2017 16:28:51 +0000 From: Sergei Trofimov To: Date: Tue, 17 Jan 2017 16:28:39 +0000 Message-ID: <1484670521-28503-4-git-send-email-sergei.trofimov@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484670521-28503-1-git-send-email-sergei.trofimov@arm.com> References: <1484670521-28503-1-git-send-email-sergei.trofimov@arm.com> MIME-Version: 1.0 X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: DB6PR0301CA0004.eurprd03.prod.outlook.com (10.168.49.14) To AM5PR0801MB1746.eurprd08.prod.outlook.com (10.169.247.12) X-MS-Office365-Filtering-Correlation-Id: 6c4e8a38-3314-44e9-565c-08d43ef5ec2f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:AM5PR0801MB1746; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 3:bfMrH3ND1NZp7kVUgS4APOUyl0TwOymMAsrlfJRpSct7UjE7fCA0cqm1UjZTDk2I7mOJbGTR2iO9KTZbeYKi3PCEmz77y0ucZ7EBThNslCWEtpwv89e1XCsZRkoMSCcV9JxYceHaL3t6cp5+B2Zm4JzlCJVZUhV7mKQX6tQv8FxKO3JUbs0c6T9lnc72w1G0M3MKfLv+F+AF85oKrnrm5y/44yMyc8Pdt1wprkdN6yK1M5v3P9jkZWzgHDsOQfdGn8UgAGEpHtUG/G0pFsA7/g==; 25:DDQLJT5hgKMuc0DzqYuOhhJpzvhDwu9afNggyOkwz7qASHWBvJ6FhbN5uoVbrNIKK6n1Y6a2yPtBvcQrVTWCVtZZ9PqBLB1seIKMHFnUinFyHJKXn3zPYP1FzTIN62wmJNAmtjG7pztUxL/sw96WoArShKnQpHK9IWcX90h4C0G8B1zuF4vLJ284ae5rXyQgRMQBFPhV+r6TIFogmCS8YUu9afFBXZYwW5bj64OrCmZlrsWMjaeiWUXQ3knAQZkZWU1fhyUnnQqR5KBEk1YYT6hO+Di+1xybeLqvBz1Lb7WQPdb7fWSpB/BeNs7aAH+GFDmINlYBj7Rwl+OFjXmPmzmSBCLhDcKry7die6f32AHYCIFuQ6dzgUzanfJPvD1I0n5j1BCnjrkjAuMfLr9zVIIRF3kJEreD7QYDZ9K1ntVvs/y0yY/Q/sMF5BL+4S22HXDJ8ygYb6mxvgsd1kSfbw== X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 31:7CpEdNmKHBH7i2Qs1wgHtQpxNKPm76NlZY364msCiQEBvc0nVngDMxg6EThLlbbZRVTxuzi+X3B1+WpGsuNXu4LOj8/4vHlr/5h4jjfRnTG+VZLiEVjB/59D1nmFgXKkjuLuJy4GhfEiiWUt6mqnUPysc41qz3yqlqtN1NhMMeZ9033fgERlESZRwxTE302vdvQdlNE+4+8tebSusc2FjxHBPgUW4/2sFFeBhORS6TA6YLiq8nO5Wy8+ctHG+s5v; 20:+k8WCFKSsxBVmGzDz82arR6X7ToarRd+TzT4N9oYV21hcBEzPr0aaVxoaYMb6NJjF5vh6Q9SBfl0URc6NkK4GaAlwwDcQyRBljsUgSe2prhe2OTP/nsPCqYP43xJ4cJrF8TM9oKpJ4y0wZOeiibrNGTKgNqXZSrECvdBHysyauI= NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(6072148); SRVR:AM5PR0801MB1746; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1746; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 4:6kQ3oQBYCAdR0AZb8uPIuQVwwXe6SF+46pIH5BqE0C2J0NlEzsiGrGdMIux2wa5EuJuhcZogrLGVqgXMPt4rvAh+fubQQb4Yz5zj0k3E6/aQdmRI+KlVatYd6b1avyK1db5nxrDCZTPpSXam2ecgmAhTc7LBXz7tHuMpKTTJv/g0Tu68I2Ed/6S1kT7aDeBsyIgLjJMJbFg9ki0m/gJbVw7P0eNil+Scv81vDXvww1HoEmuTjUpVcaSQx7eMkxPoqRjrf1m5yopReFvIdy5XYhRmyNZoe/3nmB1bHsRvPk5ajfJpuqsx3SBJNWebb5QvZvwz781D9witrZDPcl9WsXxTDmje9sxlCc78xH2ER2ilNJ73VvUIxgtUOCtC7/WKKVsNbaKeb6lWl2fw/NEuV/raioSIJLpLA9i/mmtiy2H1hsSzcgdvxnSXOoxbHhw7OpTJ0kbl8CjMmG/ab0ddq2CDybs3K1lhu3d8kzNJ3m/0lr5K5ur3F7hALO6e8HNcXRcenQuxWVALF3RQWzWps+dQRvHtftE8K5rok55F+AXVFDgvjqw3yuwQUdslJp06EbIUJ+0Uz4Ha+bNyV8IFDlGISN34Hxv16RQtTvcHPgNKVIf+LV1jsdQ0mAJX6mpQpTXad29FMFKv+AuanaTGHw== X-Forefront-PRVS: 01901B3451 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39450400003)(39840400002)(39410400002)(39860400002)(39850400002)(199003)(189002)(6666003)(81166006)(8676002)(50226002)(81156014)(305945005)(450100001)(7736002)(38730400001)(2950100002)(6116002)(97736004)(92566002)(6916009)(47776003)(2906002)(3846002)(54906002)(33646002)(66066001)(48376002)(50466002)(50986999)(189998001)(4326007)(76176999)(25786008)(36756003)(6486002)(110136003)(106356001)(105586002)(5660300001)(101416001)(68736007)(15650500001)(42186005)(2351001)(86362001)(5003940100001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0801MB1746; H:e109786-lin.cambridge.arm.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1746; 23:m6FL8fxLfqClZgN6PhMuj6tBVvLC/C14ebLxpz6?= Zyfb7A0WslJA45PdI5Qh3ZFHUMlNBTNQJiNsHWrItcRnT96Z28laeR1jEjZxGhST2C8nTlUbScuA6e/BLVxy1KOA59uDZGWXbHyRZLMwze0gLa1+I8Hgl9AjFe3ZUAq7fulTJBlXdyyLTtqDbmV1YNVAyiAPrfL+nyoVPXJl8k239AyOacRyzYuiWv/LoVpJS9Nu+yQiNHW9WvxM8oALXdZOIkzRbJbuivh5mdmlyrzaez2ZIExjjwP/Q2pNvlEBTTRk/A+/ds2l+1mLVEU76ZD4vKntkhJSC54aFN3mXRkDb5dozF+JxZQ6aBh2yBFaYRzejas36QPBLOJs+6KZwRmMOrb60wxq9wGjhOq4/15KAqAjaILSrWz7fX1GxlQ46U9D/1rcaeZzX24OqQ3KYqWcDI0pElxa1uvI3zqTusqZYFmKF52OVS3LZaNWgdjCHweLQHViW215CSwcGdd6aWDwoImSj23fRMdhqa02y2Ele6HhoKetpn5bAu6xUP18HGCpSUSru7GtFhRGxwXy7b5OKgkYPpkVKU02Zny2VinwFfn7FiLArpD5Hhr5/VGqB09s5byb+Xd8IjQQQsQuxk+Ipy2Nn2jWyJTl1Vnnmv+mfRuatUa4yH1yrKrdClPqliofPVfZ5OfTdgiGLNiw41KHNvrOJ1EQrA5klUHzGMzkoJSvvTxjdsVx1iQJfPAd44cC3nodDjZxth8X8uANMqlim4h4AZwNktYYmcUBq7A39l2whHVIY9k/qF8KXd/Fj4ZEyJnPbpHhUI1/QPzPxG0vIkscIOPr58iX26OLKfdNCYcZfcxZ9kacZpEVAfr7FXn6z/zNnZtlMsJLzdqEHjkz0dMrCN5iRvAcJD4fPlVfBc501mtYyDlN1WGtVjVIUF92IYrinxCRfNJYxxB8QhnXu+DQOKmiJ+QId+DNKw/bIbTdp6kKR/ookY/ox4nKP5uC4cI32nVr0u3FR8f7bHcAhuxWA2r0vDh0Dqe7htA7zd+Yx3B8bLo4+5wDMYMBCTuIgoWl5J1OzMZgvlMK3wytwEg5THt+KK0ICQuj9JegRveAMEpCRVky9dAmVzixl94vP08LS51JpzuZAu8qy8d/ZoSOIZQjAxeB7imv9zDm0e8oIde29sogWkMkuT1VwaSPZ4DREUL4FWH5qZZuIHzQgbtqDibFyaNDP26z1PBhwGu+xmglUELESmYP6J/Ul/F8= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 6:AemMuuYPyfrr0J+Za+SlvWT79Dfpav2S+diC80Ii7XEd/GwX5nfY5Gd4KzfvlcrDLfegc8lpe+HTEevAnnhMiryEkjl3IXl77t0+y3zNMglbFunCxK2vndmm5+MJoQdaBh+JFlXpwJ7DO6sc+0BvdMfnOil1LSMgXw6AyIYi1Y3RDvTFNRZAg3oYLzH1OG2yfrXr90r38t2w0w86a1Bn4XnQxrfbmNOHwaQTNut6gXbsGRhGsiaQeoakrI5IdRX+bVJpFo9PYqLtgwRxoq/lcC6+72r8vOwZeEvXlwHv0kPCfmsRmGOMno8NJ6+wUVOLEukirGStK2o4hCRo3X/2/y/MCaYLoLklK/WLHwnKhFbkEKoTm0ez5778i5UE/e55ODiiGX5UTTjqx9puZaUzyn/cVV9tbjJs1KcSnEjlU1ke/eI4vtKJ3dq18ZiA2/xAeBtV4CANFTpk1ijFcPWZIQ==; 5:ONH90XTEkePD8X9TBZ7ogkgkHo4mrT7IFmHAiDEtcfqVKtKbkI3Lz7D9t5ub+i5wo5hCLUViFro89G/uvwPBrTf22CzN4bZeSaZsxcxQG2YJ7LBnG/VKiy/EZ5gt4EIMyKg+9FDqJYU7DUY2TD7z7Q==; 24:d4v90dOwSCGJqmJIxHhmFV60Vx4SkR26DT3ogLGS8aeUmo7P1dARM2DIxaGu/tB2QvlIBQVaLtLaEK5Amu+xoc7rr/+z24mNkFocWoF8kHY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 7:dG3q4AFjtXuAEhxnqGnzUGKZ6Y4ByqKrpusNEct26aq2Vt+1fM6iQKYbdMvSK0VzJVgVsEssaFTgzUVMhkD/KRwXPZiXo1hogJe5xR6vACT6hfp9KcZFFURJ48/+XA9+pCjxLOmn7iVzLzRa5BWY7wvWmAXbB16vZ3w7GqoBCiAUnjp+tBr86er1kyjuGX78k5SwlVzl0XfJ7RZB3Sg5Y2PFzDQdcX8OqpSAE8N1jvs+JUXEh6m2mIE6GNE1jV0KhDLSwrXoaqpf9e7l2u8sJF7YImY6tKlyJtK1HNTRSTJ5/5m9roZs6Edst65lEXJToGEKLfp3zuoiT1ngnZ86vaiqoLsE9DEY36Js1sTxpH9t7/rauuRnS/IC6okq6Iz5rjj1JifnVm+7YtNjyu/dvVx/bQ14P75D7zfyt6FOEWdD+dD2cow9CTvhsGjh7LDNcDsdy4H2yr5oia5lTrsbzg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2017 16:28:51.4475 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1746 Cc: nd@arm.com Subject: [lng-odp] [API-NEXT PATCH 3/5] queue: adding a notification queue type 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" This adds ODP_QUEUE_TYPE_NOTIF along side the existing plain and sched queues. Notification queues are similar to plain queues, in that they are dequeued manually. However it is also possible to wait on dequeue (via the new odp_queue_deq_wait) method, which will block on an empty queue in such a way that (if supported by the platform) the execution will yield allowing the CPU to either run another thread or idle. Signed-off-by: Sergei Trofimov --- include/odp/api/spec/queue.h | 23 +++++++++- .../linux-generic/include/odp_packet_io_queue.h | 4 +- .../linux-generic/include/odp_queue_internal.h | 8 +++- platform/linux-generic/odp_packet_io.c | 6 +-- platform/linux-generic/odp_queue.c | 49 ++++++++++++++++++++-- 5 files changed, 79 insertions(+), 11 deletions(-) -- 1.9.1 diff --git a/include/odp/api/spec/queue.h b/include/odp/api/spec/queue.h index ed9284f..5af676b 100644 --- a/include/odp/api/spec/queue.h +++ b/include/odp/api/spec/queue.h @@ -62,7 +62,15 @@ typedef enum odp_queue_type_t { * Scheduled queues are connected to the scheduler. Application must * not dequeue events directly from these queues but use the scheduler * instead. */ - ODP_QUEUE_TYPE_SCHED + ODP_QUEUE_TYPE_SCHED, + + /** Notification queue + * + * Behave similar to plain queues, however, threads can execute a waiting + * dequeue, causing them to block if the queue is empty. + * + */ + ODP_QUEUE_TYPE_NOTIF } odp_queue_type_t; /** @@ -309,6 +317,19 @@ odp_event_t odp_queue_deq(odp_queue_t queue); int odp_queue_deq_multi(odp_queue_t queue, odp_event_t events[], int num); /** + * Queue dequeue + * + * Dequeues next event from head of the queue, blocking if the queue + * is empty. Must be used only with ODP_QUEUE_TYPE_NOTIF type queues. + * + * @param queue Queue handle + * + * @return Event handle + * @retval ODP_EVENT_INVALID on failure (e.g. not a notification queue) + */ +odp_event_t odp_queue_deq_wait(odp_queue_t handle); + +/** * Queue type * * @param queue Queue handle diff --git a/platform/linux-generic/include/odp_packet_io_queue.h b/platform/linux-generic/include/odp_packet_io_queue.h index d1d4b22..a24adfc 100644 --- a/platform/linux-generic/include/odp_packet_io_queue.h +++ b/platform/linux-generic/include/odp_packet_io_queue.h @@ -29,14 +29,14 @@ ODP_STATIC_ASSERT(ODP_PKTIN_QUEUE_MAX_BURST >= QUEUE_MULTI_MAX, "ODP_PKTIN_DEQ_MULTI_MAX_ERROR"); int pktin_enqueue(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr); -odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *queue); +odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *queue, int wait); int pktin_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); int pktin_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); int pktout_enqueue(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr); -odp_buffer_hdr_t *pktout_dequeue(queue_entry_t *queue); +odp_buffer_hdr_t *pktout_dequeue(queue_entry_t *queue, int wait); int pktout_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index a10628e..fb78124 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -26,9 +26,12 @@ extern "C" { #include #include #include + #include #include +#include + #define QUEUE_MULTI_MAX CONFIG_BURST_SIZE #define QUEUE_STATUS_FREE 0 @@ -42,7 +45,7 @@ extern "C" { union queue_entry_u; typedef int (*enq_func_t)(union queue_entry_u *, odp_buffer_hdr_t *); -typedef odp_buffer_hdr_t *(*deq_func_t)(union queue_entry_u *); +typedef odp_buffer_hdr_t *(*deq_func_t)(union queue_entry_u *, int); typedef int (*enq_multi_func_t)(union queue_entry_u *, odp_buffer_hdr_t **, int); @@ -77,6 +80,7 @@ struct queue_entry_s { char name[ODP_QUEUE_NAME_LEN]; int depth; + sem_t notif_sem; }; union queue_entry_u { @@ -88,7 +92,7 @@ union queue_entry_u { queue_entry_t *get_qentry(uint32_t queue_id); int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr); -odp_buffer_hdr_t *queue_deq(queue_entry_t *queue); +odp_buffer_hdr_t *queue_deq(queue_entry_t *queue, int wait); int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num); diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 98460a5..8063806 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -590,7 +590,7 @@ int pktout_enqueue(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr) return (nbr == len ? 0 : -1); } -odp_buffer_hdr_t *pktout_dequeue(queue_entry_t *qentry ODP_UNUSED) +odp_buffer_hdr_t *pktout_dequeue(queue_entry_t *qentry ODP_UNUSED, int wait ODP_UNUSED) { ODP_ABORT("attempted dequeue from a pktout queue"); return NULL; @@ -625,13 +625,13 @@ int pktin_enqueue(queue_entry_t *qentry ODP_UNUSED, return -1; } -odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry) +odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry, int wait ODP_UNUSED) { odp_buffer_hdr_t *buf_hdr; odp_buffer_hdr_t *hdr_tbl[QUEUE_MULTI_MAX]; int pkts; - buf_hdr = queue_deq(qentry); + buf_hdr = queue_deq(qentry, 0); if (buf_hdr != NULL) return buf_hdr; diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index d364801..82fe794 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -34,6 +34,7 @@ #include #include #include +#include typedef struct queue_table_t { queue_entry_t queue[ODP_CONFIG_QUEUES]; @@ -88,6 +89,10 @@ static int queue_init(queue_entry_t *queue, const char *name, 0); } } + + if (param->type == ODP_QUEUE_TYPE_NOTIF) + sem_init(&queue->s.notif_sem, 0, 0); + queue->s.type = queue->s.param.type; queue->s.enqueue = queue_enq; @@ -452,8 +457,14 @@ static inline int enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], queue->s.status = QUEUE_STATUS_SCHED; sched = 1; /* retval: schedule queue */ } + UNLOCK(&queue->s.lock); + if (queue->s.type == ODP_QUEUE_TYPE_NOTIF) { + for (i = 0; i < num; i++) + sem_post(&queue->s.notif_sem); + } + /* Add queue to scheduling */ if (sched && sched_fn->sched_queue(queue->s.index)) ODP_ABORT("schedule_queue failed\n"); @@ -571,6 +582,12 @@ static inline int deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], queue->s.depth -= i; } + if (queue->s.type == ODP_QUEUE_TYPE_NOTIF) { + for (j = 0; j < i; j++) { + sem_trywait(&queue->s.notif_sem); + } + } + /* Queue is empty */ if (hdr == NULL) queue->s.tail = NULL; @@ -588,11 +605,20 @@ int queue_deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) return deq_multi(queue, buf_hdr, num); } -odp_buffer_hdr_t *queue_deq(queue_entry_t *queue) +odp_buffer_hdr_t *queue_deq(queue_entry_t *queue, int wait) { odp_buffer_hdr_t *buf_hdr = NULL; int ret; + if (queue->s.type == ODP_QUEUE_TYPE_NOTIF) { + if (wait) { + sem_wait(&queue->s.notif_sem); + } else { + if (sem_trywait(&queue->s.notif_sem)) + return NULL; + } + } + ret = deq_multi(queue, &buf_hdr, 1); if (ret == 1) @@ -620,14 +646,31 @@ int odp_queue_deq_multi(odp_queue_t handle, odp_event_t events[], int num) return ret; } - odp_event_t odp_queue_deq(odp_queue_t handle) { queue_entry_t *queue; odp_buffer_hdr_t *buf_hdr; queue = queue_to_qentry(handle); - buf_hdr = queue->s.dequeue(queue); + buf_hdr = queue->s.dequeue(queue, 0); + + if (buf_hdr) + return odp_buffer_to_event(buf_hdr->handle.handle); + + return ODP_EVENT_INVALID; +} + +odp_event_t odp_queue_deq_wait(odp_queue_t handle) +{ + queue_entry_t *queue; + odp_buffer_hdr_t *buf_hdr; + + queue = queue_to_qentry(handle); + + if (queue->s.type != ODP_QUEUE_TYPE_NOTIF) + return ODP_EVENT_INVALID; + + buf_hdr = queue->s.dequeue(queue, 1); if (buf_hdr) return odp_buffer_to_event(buf_hdr->handle.handle);