From patchwork Tue Jan 17 16:28:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimov X-Patchwork-Id: 91692 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp522734obz; Tue, 17 Jan 2017 08:30:40 -0800 (PST) X-Received: by 10.107.21.196 with SMTP id 187mr1400994iov.105.1484670640420; Tue, 17 Jan 2017 08:30:40 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j25si12760381iti.119.2017.01.17.08.30.40; Tue, 17 Jan 2017 08:30:40 -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 D447860954; Tue, 17 Jan 2017 16:30:39 +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 AC9FD60ECF; Tue, 17 Jan 2017 16:29:04 +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 5F6AA60954; Tue, 17 Jan 2017 16:28:56 +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 AE5DF60653 for ; Tue, 17 Jan 2017 16:28:52 +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:50 +0000 From: Sergei Trofimov To: Date: Tue, 17 Jan 2017 16:28:38 +0000 Message-ID: <1484670521-28503-3-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: f3e7ec40-6865-4b80-7a93-08d43ef5ebdd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:AM5PR0801MB1746; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 3:eHm1o9HyQNBw90nwNtEZSY2AKshWHOsM7hiekuWVe5+I3YCftCDNm54yd7qlxrcaaAgHoy2nVeXBfEEYjZrPsUAF2sXm8N2phmHclRL2eWFdBaxcno2Xx0c0oOSVzrGmg5Kuv05ifmg+yROfb9vK8001J7lba16xnN5OoZmam5uEbAiC3C8XhWQwA4uZAbR7JKnVYA0hyatZuHHUugvnTyjHrvOI/WFs8w7gWPAi1XSgV4jCrRDktpI7j00Tctxd8caQ6hRWKcY1/LeNp+7X3Q==; 25:BKjzJlCpz75WfyojrA97knfqI0CmdYViB681gRz2dS+nz2CxDOxh/1c9+8i65+rdzo0L7MRjQ/ChgkiX79mio9GIT3/7mM5hPc3Bs8QwSFWPbd0MK3HfIMqKOKWSAy1EnBp/UYfN//s8lXI23zIwm4sYxYNRH3ti92PPO2zI8udcM3qboIj2/Z5JBg8ko+grl6cdpW1la6Sk1zIh1HZnk1gAKWwpEFcvMa778iii5U/x9RpGOU1HejAeot7M7aIdYvmi/Yf2unnflO80dHxpugJZTZlkQhGpQVr+t17IEdZFKq/jvO+lKSRjvD2vNuocES44z9cO4aQcq3Oog0oMSuZZqMQ+oEc6UJrHoRS1+gjmIedXLvv4m1p1Tfcm8c5ybAlvQ9NowCiPkM79XBiTqXMAIx36kHZ7MxwvOCK/T+cAqJXs6eE2IfmNo6vL6aB/dxqrtskAer/U7oTI5jgCxA== X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 31:hnfxLmf6hMQcHtB0N/eaAc3Iud7EHSVxG7gCwtivf6zcnsdOA2t8l5N5QOMW3xh+LxqM0HNkwStZpytd/z1lzjLvjsnSLmUeGdW4NdBb+FdmYsk6DWeEhsmSV9BqZMMWR+5kV/vH5AxL5LonctqxcsnpRDoBUY2M08KVHdJVIIHyOm381wxDpYBfhp7eXOyiEiP50ARh4oifGoWsMtJQvDMztQlDEWB7ATMqG/hCx2XRFuo1PYQ0AjgG/RmyKc39u69/nsr/PsFm100DY8YKiQ==; 20:RQRIU5ZECqsP95rjfDqodm9UizjIeCeTdg54dkHf40rf+ssHNqRNvLdXgMMYR1bePBnHI06gIfmxK0IDszHQ2HsjUk0YoPxywDqx5wom0LWJroeg/qEGfMg/N1o4SwX+dtVMr/h37oYB8s0leMys9o5XDjkU+a9yKFE6rnXMCJE= 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:Kw3st2ctlBWW1lymgSI2igK/t0w2Jqv8DVdgMVjjIOoQolI2lvyWZ6O5WRnuljfhp6TDYPg1hdK9qUlB4aPY1GrjTnTE1W36m0rKm7nWoUnaL8VD4G/fdd6m5sRRh9Ur21SKBJNo5HvlAERfDdLEWX+1DFRpaBiusg0UQjjCrtac4+Ch+1tHFuABAuJwOlbJtUQ2eqtczzS5aCCdEOmtIT5vB7G9xCiMEj8Zad1OAsIwqFvw8IZL8IIxqTWEd7lDHRhGKcebaoNZrRJvG1wGqqs6jHven0mZkb80mDEBgbLlhFQIsSK27OoK4RmIawcZSPC8Ob0nncEucX0MsqzyjNZwMvipUQDskiAHdvVoqGswQCl7b7Iq3X43azHxPHzTMq1Fm+mXz+zhdYoswmSm2eo1KtZ9mh7P88+uakqsEd09jEBttC176Vjapwjdy8lBPuAN6P4+CdEJoyfLTVu/TMvhHYIaTB9pTgWwoz3+fEriC4g8jGwYDNQDV5qYTOY5enqbWWDRBvLZVk9ipfycxUN0nLoJbA+Wi6Oceugq+OJxFlZ3+OqFGrac11kZTPNPgTNCdA0368PGf0VUFLWtdrrmJVvgldyEElhwaaU2om/JDgknjZja7929bviuzw+43GgxMguMsnBTstmKkGh/jw== 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)(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:V2WBg1qvBTNaV/6cUAbgv95AX41b+hjQDIX8Btz?= IS+vDyrTgeOfe50fOCaxHKeIxCTWfPglFN/6VC2a+AUqG6ZR8E997AYd32rNwZJ0eIVX4hEhDTMwK34kh3vnv9xMR1EMLyNCXVfG+Ci2dDZNUrQEMyzHtLpKs0/AuGCf8plWLevBKyfErEBka7+C97IChKoT4Hk0GRhPM3A8ef9wc7yappjcL2NX+hrkovJJOTbbNL3WrWSIbqzbla+LAITexRFJXB/uswjh6kEnQmeMFW9mLgpyJYt6AlGI2E86ugnBHVmkC/7tuVxDQ8wMbwZZ+ZHbiKq+kr0LejO36I3NzMBZB0OAcDrh9aXvCDXtaIKyu/Zb89J1i3rFCz+Ktx9Iy0NUApTJY0XXOr4cr5EDtNq4BzV33PALNdh5T4qgQ/YpAKM9MUc51nrpYhSLsuxM7V8hDYPn4lLjlKgc4z4N1PDNzKnvv1IRpJBbZuZ5TANfF6Ua1IPoKJxzhMOF3Z2lT+y/DBwBvf7Q04gc7qYBgYbNBDqf3wCGCQnzB62KdqUEMBpNgprsLvVbsMfQHMIktbjXSNFOc5tvied6mgjRDdChL96OVoh8bSfofgJy6s0FJsus8tcfZ2GM/nsZLjd+1EeN3LCtSDUIgkO4q7832KgPzHRDMn4OnWZQQATZNoFnq3AB6eOjNxe2yBjoQWomY2HNvtlL4EnXAuZRCIRmvCp2DcWMrQ7bOjibfrW603PBcBamzrWdqpFhEeUlNHzW5ALhm35AllA+QGPCp5ofYRY/yVqEeZC0ssAU8ZuL02MyLHD3P9GtaXfgSLL0O4ZHhZMV0Z1AkKVBl+ErP4vMMDwcxAawxDbJqsQnCYRSEpvlETgXhAgDeRj5wuBVsY/crpUg/Ya522X+8jl2WH/co5yW1tfVs1xF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CPhUhL6A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1746; 7:l65t44e5YEZSlZye/eoZeKm21W7vS66IRz4Jt6v9XtA0Iz0ozAQIyCBUAFohq7r1VU3Dtg5tDtF+LIokv+n960gY68Id23CJJQJwKBCKPzRWQhSaq95Vr0+59NuvUyTWc3Ig7rsGc791MVIWwzKBxOei9UECwR8r9dIMRDQ+X4GfTxupgBj9CATAkkHB51dGqW/ytsMC1JDUGKbZSQ6rTHHoGtoEyOIkykA90Wp2GKFyt3GBr2CWyb5F+5Qc1IkdkTPSDX2mGnTS23PDhowCTJnpi2aNXJYPW6G5gj+LwHlxNngPr3KaN5bdmsZg2AcR9DGgbd2vSIYMYZFcM4am7cIhCg2yh/EbtPwvsTYf2wK2F11RCGpBhqd1UBAWLRx6Bs8s4HtgKeh+CGgdTuLj5hiMoJ+OzmjF9Q7IXBTp702xtSh7K+IgF2ml/lJd2koFTpvYKuMrKrqLhxa9Hi8/XQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2017 16:28:50.9121 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1746 Cc: nd@arm.com Subject: [lng-odp] [API-NEXT PATCH 2/5] odp_queue: added support for queue depth tracking 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" - Added a counter to queue_entry_t to keep track of the current queue depth (number of enqueued events). - Added odp_queue_depth function to the API to query the above counter. Signed-off-by: Sergei Trofimov --- include/odp/api/spec/queue.h | 15 +++++++++++ .../linux-generic/include/odp_queue_internal.h | 2 ++ platform/linux-generic/odp_queue.c | 30 +++++++++++++++++++++- test/common_plat/validation/api/queue/queue.c | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/include/odp/api/spec/queue.h b/include/odp/api/spec/queue.h index 7972fea..ed9284f 100644 --- a/include/odp/api/spec/queue.h +++ b/include/odp/api/spec/queue.h @@ -409,6 +409,21 @@ typedef struct odp_queue_info_t { int odp_queue_info(odp_queue_t queue, odp_queue_info_t *info); /** + * Retrieve current approximate depth of a queue + * + * The returned value is not guaranteed to be exact, but can be used as a + * general indicator of how "busy" the queue is. + * + * Invalid queue handles or handles to free/destroyed queues leads to + * undefined behaviour. + * + * @param queue Queue handle + * + * @retval Number of events currently in the queue. + */ +int odp_queue_depth(odp_queue_t queue); + +/** * @} */ diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 8b55de1..a10628e 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -75,6 +75,8 @@ struct queue_entry_s { odp_pktin_queue_t pktin; odp_pktout_queue_t pktout; char name[ODP_QUEUE_NAME_LEN]; + + int depth; }; union queue_entry_u { diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 6608695..d364801 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -33,6 +33,7 @@ #include #include +#include typedef struct queue_table_t { queue_entry_t queue[ODP_CONFIG_QUEUES]; @@ -99,6 +100,8 @@ static int queue_init(queue_entry_t *queue, const char *name, queue->s.head = NULL; queue->s.tail = NULL; + queue->s.depth = 0; + return 0; } @@ -443,6 +446,7 @@ static inline int enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], queue->s.tail->next = hdr; queue->s.tail = tail; + queue->s.depth += num; if (queue->s.status == QUEUE_STATUS_NOTSCHED) { queue->s.status = QUEUE_STATUS_SCHED; @@ -498,6 +502,7 @@ int odp_queue_enq(odp_queue_t handle, odp_event_t ev) queue_entry_t *queue; queue = queue_to_qentry(handle); + buf_hdr = buf_hdl_to_hdr(odp_buffer_from_event(ev)); return queue->s.enqueue(queue, buf_hdr); @@ -560,8 +565,11 @@ static inline int deq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], } /* Write head only if updated */ - if (updated) + if (updated) { queue->s.head = hdr; + ODP_ASSERT(queue->s.depth >= (uint64_t)i); + queue->s.depth -= i; + } /* Queue is empty */ if (hdr == NULL) @@ -761,3 +769,23 @@ int sched_cb_queue_empty(uint32_t queue_index) return ret; } + +int odp_queue_depth(odp_queue_t handle) +{ + uint32_t queue_id; + queue_entry_t *queue; + int depth; + + queue_id = queue_to_id(handle); + + if (odp_unlikely(queue_id >= ODP_CONFIG_QUEUES)) { + ODP_ERR("Invalid queue handle:%" PRIu64 "\n", + odp_queue_to_u64(handle)); + return 0; + } + + queue = get_qentry(queue_id); + depth = queue->s.depth; + + return depth; +} diff --git a/test/common_plat/validation/api/queue/queue.c b/test/common_plat/validation/api/queue/queue.c index 1f7913a..6d603a4 100644 --- a/test/common_plat/validation/api/queue/queue.c +++ b/test/common_plat/validation/api/queue/queue.c @@ -216,6 +216,8 @@ void queue_test_param(void) * But here we assume that we succeed in enqueuing all buffers. */ ret = odp_queue_enq_multi(queue, enev, MAX_BUFFER_QUEUE); + int depth = odp_queue_depth(queue); + CU_ASSERT_EQUAL(depth, MAX_BUFFER_QUEUE); CU_ASSERT(MAX_BUFFER_QUEUE == ret); i = ret < 0 ? 0 : ret; for ( ; i < MAX_BUFFER_QUEUE; i++)