From patchwork Fri Jun 5 11:53:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 49568 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E95942154F for ; Fri, 5 Jun 2015 11:58:18 +0000 (UTC) Received: by wgez8 with SMTP id z8sf16784681wge.2 for ; Fri, 05 Jun 2015 04:58:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=KKNjRS1sCsp0JF3FMFxTR8NdlW+7xuSRSVOrmKbul5w=; b=jmxVqe/B1zHqxXojh0YgkVVo8rn/3Tx1dICiPf7ev6PxyVdViFmDV27JNplh7OaTdA 7Wtx0SjSw0f9DzY1XvViyJAHAFlbMYujYtDEeEeL7683ryn35+Kv1Oex/q0n18U8gleC oGkgieCbdIJS2Qu/j8SzMq95sKMVsOIuZdnNHBC8+xPFqGEHcW23vY9tHJT/jD3bfR3S 4CAst2w6Hqoaqxv0wPlAl1pBRB0O5vvdhlHq3QHPZrg2+JWkOVz08Rpz1oIvfKIAUzep JvxbbkCLreFZBK2p0RKK1sK3AoQSCygWjUiaXN8XwqU+1/20F6F1WJD+PiMQqTY4jkWz 1etA== X-Gm-Message-State: ALoCoQlRUCltoN6JBpJNsTro2+bvHHmIHdk5zUFGjoWgjenjBMv4hQxbygFIsnVTBtk7AYxIZHTi X-Received: by 10.194.179.42 with SMTP id dd10mr2899194wjc.7.1433505498272; Fri, 05 Jun 2015 04:58:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.169 with SMTP id l9ls353920lah.52.gmail; Fri, 05 Jun 2015 04:58:18 -0700 (PDT) X-Received: by 10.112.119.139 with SMTP id ku11mr2906613lbb.49.1433505498099; Fri, 05 Jun 2015 04:58:18 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id pd4si4643479lbc.40.2015.06.05.04.58.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 04:58:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labko7 with SMTP id ko7so52543803lab.2 for ; Fri, 05 Jun 2015 04:58:17 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr3098041lbb.56.1433505497638; Fri, 05 Jun 2015 04:58:17 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1370153lbb; Fri, 5 Jun 2015 04:58:16 -0700 (PDT) X-Received: by 10.140.202.130 with SMTP id x124mr3681874qha.9.1433505495638; Fri, 05 Jun 2015 04:58:15 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 19si7258990qkt.64.2015.06.05.04.58.14; Fri, 05 Jun 2015 04:58:15 -0700 (PDT) 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; Received: by lists.linaro.org (Postfix, from userid 109) id 8438F6202D; Fri, 5 Jun 2015 11:58:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9826362051; Fri, 5 Jun 2015 11:55:16 +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 D5DF961D3C; Fri, 5 Jun 2015 11:55:07 +0000 (UTC) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by lists.linaro.org (Postfix) with ESMTPS id C33D362047 for ; Fri, 5 Jun 2015 11:54:21 +0000 (UTC) Received: by wifx6 with SMTP id x6so18021473wif.0 for ; Fri, 05 Jun 2015 04:54:21 -0700 (PDT) X-Received: by 10.180.77.129 with SMTP id s1mr62564260wiw.40.1433505261031; Fri, 05 Jun 2015 04:54:21 -0700 (PDT) Received: from localhost.localdomain ([90.152.119.35]) by mx.google.com with ESMTPSA id b20sm10268741wjb.46.2015.06.05.04.54.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jun 2015 04:54:20 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Fri, 5 Jun 2015 12:53:50 +0100 Message-Id: <1433505231-28843-9-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433505231-28843-1-git-send-email-zoltan.kiss@linaro.org> References: <1433505231-28843-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v2 8/9] queue: handle return value of odp_queue_enq() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zoltan.kiss@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Unsent packet has to be released. If the event type is obvious from the context, use directly the relevant release functions, otherwise odp_event(free). Wider error handling is attempted, but this patch can't fix all the flaws in the many calling functions of odp_queue_enq() Signed-off-by: Zoltan Kiss --- example/classifier/odp_classifier.c | 7 ++++++- example/generator/odp_generator.c | 1 + example/ipsec/odp_ipsec.c | 11 ++++++++--- example/ipsec/odp_ipsec_stream.c | 6 +++++- example/packet/odp_pktio.c | 6 +++++- platform/linux-generic/include/odp_schedule_internal.h | 4 ++-- platform/linux-generic/odp_crypto.c | 5 ++++- platform/linux-generic/odp_queue.c | 8 ++++---- platform/linux-generic/odp_schedule.c | 14 ++++++++++---- platform/linux-generic/odp_timer.c | 4 +++- test/performance/odp_l2fwd.c | 6 +++++- test/performance/odp_pktio_perf.c | 10 ++++++++-- test/performance/odp_scheduling.c | 7 +++++++ test/validation/classification/odp_classification_tests.c | 3 ++- test/validation/odp_pktio.c | 1 + test/validation/odp_queue.c | 9 ++++++--- test/validation/odp_scheduler.c | 12 ++++++++---- 17 files changed, 85 insertions(+), 29 deletions(-) diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 48fc1ab..129b042 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -292,7 +292,12 @@ static void *pktio_receive_thread(void *arg) if (appl->appl_mode == APPL_MODE_DROP) odp_packet_free(pkt); else - odp_queue_enq(outq_def, ev); + if (odp_queue_enq(outq_def, ev)) { + EXAMPLE_ERR(" [%i] Queue enqueue failed.\n", + thr); + odp_packet_free(pkt); + continue; + } } return NULL; diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 8ae5b29..4dcaff5 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -410,6 +410,7 @@ static void *gen_send_thread(void *arg) err = odp_queue_enq(outq_def, odp_packet_to_event(pkt)); if (err != 0) { EXAMPLE_ERR(" [%02i] send pkt err!\n", thr); + odp_packet_free(pkt); return NULL; } diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index cb8f535..1d034dd 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -1078,7 +1078,8 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) ctx->state = PKT_STATE_TRANSMIT; } else { ctx->state = PKT_STATE_IPSEC_OUT_SEQ; - odp_queue_enq(seqnumq, ev); + if (odp_queue_enq(seqnumq, ev)) + rc = PKT_DROP; } break; @@ -1096,8 +1097,12 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) case PKT_STATE_TRANSMIT: - odp_queue_enq(ctx->outq, ev); - rc = PKT_DONE; + if (odp_queue_enq(ctx->outq, ev)) { + odp_event_free(ev); + rc = PKT_DROP; + } else { + rc = PKT_DONE; + } break; default: diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index 35042f5..af143ee 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -494,7 +494,11 @@ int create_stream_db_inputs(void) break; } stream->created++; - odp_queue_enq(queue, odp_packet_to_event(pkt)); + if (odp_queue_enq(queue, odp_packet_to_event(pkt))) { + odp_packet_free(pkt); + printf("Queue enqueue failed\n"); + break; + } /* Count this stream when we create first packet */ if (1 == stream->created) diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 0b4a8f1..8004d69 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -233,7 +233,11 @@ static void *pktio_queue_thread(void *arg) swap_pkt_addrs(&pkt, 1); /* Enqueue the packet for output */ - odp_queue_enq(outq_def, ev); + if (odp_queue_enq(outq_def, ev)) { + EXAMPLE_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_packet_free(pkt); + continue; + } /* Print packet counts every once in a while */ if (odp_unlikely(pkt_cnt++ % 100000 == 0)) { diff --git a/platform/linux-generic/include/odp_schedule_internal.h b/platform/linux-generic/include/odp_schedule_internal.h index 904bfbd..4c6577d 100644 --- a/platform/linux-generic/include/odp_schedule_internal.h +++ b/platform/linux-generic/include/odp_schedule_internal.h @@ -23,9 +23,9 @@ extern "C" { int schedule_queue_init(queue_entry_t *qe); void schedule_queue_destroy(queue_entry_t *qe); -static inline void schedule_queue(const queue_entry_t *qe) +static inline int schedule_queue(const queue_entry_t *qe) { - odp_queue_enq(qe->s.pri_queue, qe->s.cmd_ev); + return odp_queue_enq(qe->s.pri_queue, qe->s.cmd_ev); } diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index b16316c..e799047 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -431,7 +431,10 @@ odp_crypto_operation(odp_crypto_op_params_t *params, op_result = get_op_result_from_event(completion_event); op_result->magic = OP_RESULT_MAGIC; op_result->result = local_result; - odp_queue_enq(session->compl_queue, completion_event); + if (odp_queue_enq(session->compl_queue, completion_event)) { + odp_event_free(completion_event); + return -1; + } /* Indicate to caller operation was async */ *posted = 1; diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 4a0465b..818e28e 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -355,8 +355,8 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr) UNLOCK(&queue->s.lock); /* Add queue to scheduling */ - if (sched) - schedule_queue(queue); + if (sched && schedule_queue(queue)) + return -1; return 0; } @@ -395,8 +395,8 @@ int queue_enq_multi(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr[], int num) UNLOCK(&queue->s.lock); /* Add queue to scheduling */ - if (sched) - schedule_queue(queue); + if (sched && schedule_queue(queue)) + return -1; return num; /* All events enqueued */ } diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 9206d5c..9e20fda 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -355,7 +355,10 @@ int schedule_pktio_start(odp_pktio_t pktio, int prio) pri_queue = pri_set_pktio(pktio, prio); - odp_queue_enq(pri_queue, odp_buffer_to_event(buf)); + if (odp_queue_enq(pri_queue, odp_buffer_to_event(buf))) { + odp_buffer_free(buf); + return -1; + } return 0; } @@ -365,7 +368,8 @@ void odp_schedule_release_atomic(void) if (sched_local.pri_queue != ODP_QUEUE_INVALID && sched_local.num == 0) { /* Release current atomic queue */ - odp_queue_enq(sched_local.pri_queue, sched_local.cmd_ev); + if (odp_queue_enq(sched_local.pri_queue, sched_local.cmd_ev)) + odp_event_free(sched_local.cmd_ev); sched_local.pri_queue = ODP_QUEUE_INVALID; } } @@ -456,7 +460,8 @@ static int schedule(odp_queue_t *out_queue, odp_event_t out_ev[], odp_buffer_free(buf); } else { /* Continue scheduling the pktio */ - odp_queue_enq(pri_q, ev); + if (odp_queue_enq(pri_q, ev)) + odp_event_free(ev); } continue; @@ -487,7 +492,8 @@ static int schedule(odp_queue_t *out_queue, odp_event_t out_ev[], sched_local.cmd_ev = ev; } else { /* Continue scheduling the queue */ - odp_queue_enq(pri_q, ev); + if (odp_queue_enq(pri_q, ev)) + odp_event_free(ev); } /* Output the source queue handle */ diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index e5391dc..2eebb51 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -577,9 +577,11 @@ static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) /* Post the timeout to the destination queue */ int rc = odp_queue_enq(tim->queue, odp_buffer_to_event(tmo_buf)); - if (odp_unlikely(rc != 0)) + if (odp_unlikely(rc != 0)) { + odp_buffer_free(tmo_buf); ODP_ABORT("Failed to enqueue timeout buffer (%d)\n", rc); + } return 1; } else { /* Else false positive, ignore */ diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c index dd0b4b1..9cc201f 100644 --- a/test/performance/odp_l2fwd.c +++ b/test/performance/odp_l2fwd.c @@ -152,7 +152,11 @@ static void *pktio_queue_thread(void *arg) outq_def = lookup_dest_q(pkt); /* Enqueue the packet for output */ - odp_queue_enq(outq_def, ev); + if (odp_queue_enq(outq_def, ev)) { + printf(" [%i] Queue enqueue failed.\n", thr); + odp_packet_free(pkt); + continue; + } stats->packets += 1; } diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c index d362669..f572633 100644 --- a/test/performance/odp_pktio_perf.c +++ b/test/performance/odp_pktio_perf.c @@ -270,8 +270,14 @@ static int send_packets(odp_queue_t outq, { if (num_pkts == 0) return 0; - else if (num_pkts == 1) - return odp_queue_enq(outq, event_tbl[0]) == 0 ? 1 : 0; + else if (num_pkts == 1) { + if (odp_queue_enq(outq, event_tbl[0])) { + odp_event_free(event_tbl[0]); + return 0; + } else { + return 1; + } + } return odp_queue_enq_multi(outq, event_tbl, num_pkts); } diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c index 558fec8..1283986 100644 --- a/test/performance/odp_scheduling.c +++ b/test/performance/odp_scheduling.c @@ -114,6 +114,7 @@ static int create_queue(int thr, odp_pool_t msg_pool, int prio) if (odp_queue_enq(queue, odp_buffer_to_event(buf))) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_buffer_free(buf); return -1; } @@ -161,6 +162,7 @@ static int create_queues(int thr, odp_pool_t msg_pool, int prio) if (odp_queue_enq(queue, odp_buffer_to_event(buf))) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_buffer_free(buf); return -1; } } @@ -294,6 +296,7 @@ static int test_poll_queue(int thr, odp_pool_t msg_pool) if (odp_queue_enq(queue, ev)) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_buffer_free(buf); return -1; } @@ -352,6 +355,7 @@ static int test_schedule_single(const char *str, int thr, if (odp_queue_enq(queue, ev)) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_event_free(ev); return -1; } } @@ -371,6 +375,7 @@ static int test_schedule_single(const char *str, int thr, if (odp_queue_enq(queue, ev)) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_event_free(ev); return -1; } } @@ -431,6 +436,7 @@ static int test_schedule_many(const char *str, int thr, if (odp_queue_enq(queue, ev)) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_event_free(ev); return -1; } } @@ -450,6 +456,7 @@ static int test_schedule_many(const char *str, int thr, if (odp_queue_enq(queue, ev)) { LOG_ERR(" [%i] Queue enqueue failed.\n", thr); + odp_event_free(ev); return -1; } } diff --git a/test/validation/classification/odp_classification_tests.c b/test/validation/classification/odp_classification_tests.c index 441c194..ed4739d 100644 --- a/test/validation/classification/odp_classification_tests.c +++ b/test/validation/classification/odp_classification_tests.c @@ -109,7 +109,8 @@ void enqueue_loop_interface(odp_packet_t pkt) odp_queue_t defqueue = odp_pktio_outq_getdef(pktio_loop); ev = odp_packet_to_event(pkt); - CU_ASSERT(odp_queue_enq(defqueue, ev) == 0); + if (!(CU_ASSERT(odp_queue_enq(defqueue, ev) == 0))) + odp_packet_free(pkt); } static inline diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index 090057b..3027b25 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -380,6 +380,7 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, ret = odp_queue_enq(pktio_a->outq, tx_ev[0]); if (ret != 0) { CU_FAIL("failed to enqueue test packet"); + odp_packet_free(tx_pkt[0]); return; } } else { diff --git a/test/validation/odp_queue.c b/test/validation/odp_queue.c index 5123939..4bd95ff 100644 --- a/test/validation/odp_queue.c +++ b/test/validation/odp_queue.c @@ -77,9 +77,12 @@ static void test_odp_queue_sunnyday(void) CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - odp_queue_enq(queue_id, ev); - CU_ASSERT_EQUAL(ev, odp_queue_deq(queue_id)); - odp_buffer_free(buf); + if (!(CU_ASSERT(odp_queue_enq(queue_id, ev) == 0))) { + odp_buffer_free(buf); + } else { + CU_ASSERT_EQUAL(ev, odp_queue_deq(queue_id)); + odp_buffer_free(buf); + } for (i = 0; i < MAX_BUFFER_QUEUE; i++) { odp_buffer_t buf = odp_buffer_alloc(msg_pool); diff --git a/test/validation/odp_scheduler.c b/test/validation/odp_scheduler.c index e4df4f2..fa03f39 100644 --- a/test/validation/odp_scheduler.c +++ b/test/validation/odp_scheduler.c @@ -138,7 +138,8 @@ static void test_schedule_queue_destroy(void) u32[0] = MAGIC; ev = odp_buffer_to_event(buf); - CU_ASSERT(odp_queue_enq(queue, ev) == 0); + if (!(CU_ASSERT(odp_queue_enq(queue, ev) == 0))) + odp_buffer_free(buf); ev = odp_schedule(&from, ODP_SCHED_WAIT); @@ -288,8 +289,10 @@ static void fill_queues(thread_args_t *args) buf = odp_buffer_alloc(pool); CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - CU_ASSERT(odp_queue_enq(queue, ev) == 0); - buf_count++; + if (!(CU_ASSERT(odp_queue_enq(queue, ev) == 0))) + odp_buffer_free(buf); + else + buf_count++; } } } @@ -560,7 +563,8 @@ static void test_schedule_pause_resume(void) buf = odp_buffer_alloc(pool); CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID); ev = odp_buffer_to_event(buf); - odp_queue_enq(queue, ev); + if (odp_queue_enq(queue, ev)) + odp_buffer_free(buf); } for (i = 0; i < NUM_BUFS_BEFORE_PAUSE; i++) {