From patchwork Thu Oct 9 14:08:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 38510 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4C7542032C for ; Thu, 9 Oct 2014 14:09:44 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf897775lab.11 for ; Thu, 09 Oct 2014 07:09:38 -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: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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=O7Xlf9xjygIMClIqRugKGmLGUdQtLqNsu0JbU+mwrT0=; b=RppzQpfFygpKQYWpCIO31wag/S1ekKn2IBUjZtUkYQH5jiajNmjmpg/q2XITv1VwgH Hq4JAimFtgtGLRkLml+dsoMWjbWmUfKwZZh32IezfLJNfkq5HaB0IKFNHvVKbT506t4J 6sMhflzvcGs5MTC/njwiDyyfGWWFCpC78lBeU+Sb7UZ0NKbC89JjUsGexTWV0uqxlSwE 0Uc0I6RHg8eDylW8uweCrNWWuS1J8eQduXms28jCTURaA8S8qs+8XuGAGFPubRJDFUpW mW7K2RLLOxew6mVYmKQ5ImKchBQJkyRUNSEQr8L9ZIl5Ez8AvYG47TCtc1oJgQ8AgeOI YIyA== X-Gm-Message-State: ALoCoQlLUIfNIvSvgqFEgtAVchMohBfNRZPK7sgu4uq7QR7/bAIdcyP5oqmBX0HVRieXdMeCT9rF X-Received: by 10.112.198.226 with SMTP id jf2mr2745948lbc.1.1412863778210; Thu, 09 Oct 2014 07:09:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.97 with SMTP id s1ls52721lag.81.gmail; Thu, 09 Oct 2014 07:09:37 -0700 (PDT) X-Received: by 10.153.6.36 with SMTP id cr4mr19048040lad.40.1412863777853; Thu, 09 Oct 2014 07:09:37 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com [209.85.217.171]) by mx.google.com with ESMTPS id xu5si4504111lab.64.2014.10.09.07.09.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Oct 2014 07:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id z12so1225400lbi.2 for ; Thu, 09 Oct 2014 07:09:37 -0700 (PDT) X-Received: by 10.152.28.167 with SMTP id c7mr18724638lah.27.1412863777754; Thu, 09 Oct 2014 07:09:37 -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.84.229 with SMTP id c5csp254768lbz; Thu, 9 Oct 2014 07:09:36 -0700 (PDT) X-Received: by 10.68.96.4 with SMTP id do4mr132148pbb.44.1412863775943; Thu, 09 Oct 2014 07:09:35 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id 4si5715787qav.89.2014.10.09.07.09.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Oct 2014 07:09:35 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XcEPO-0006xs-Gn; Thu, 09 Oct 2014 14:09:34 +0000 Received: from mail-lb0-f178.google.com ([209.85.217.178]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XcEP7-0006wL-7e for lng-odp@lists.linaro.org; Thu, 09 Oct 2014 14:09:17 +0000 Received: by mail-lb0-f178.google.com with SMTP id w7so1229894lbi.37 for ; Thu, 09 Oct 2014 07:09:11 -0700 (PDT) X-Received: by 10.112.170.165 with SMTP id an5mr5553991lbc.6.1412863749716; Thu, 09 Oct 2014 07:09:09 -0700 (PDT) Received: from localhost (c-853670d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.54.133]) by mx.google.com with ESMTPSA id k3sm995502lam.33.2014.10.09.07.09.08 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 09 Oct 2014 07:09:09 -0700 (PDT) From: Anders Roxell To: lng-odp@lists.linaro.org Date: Thu, 9 Oct 2014 16:08:47 +0200 Message-Id: <1412863729-28176-6-git-send-email-anders.roxell@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1412863729-28176-1-git-send-email-anders.roxell@linaro.org> References: <1412863729-28176-1-git-send-email-anders.roxell@linaro.org> Subject: [lng-odp] [DO NOT REVIEW 5/7] packet_io: add Usage examples X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: anders.roxell@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.217.171 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 Signed-off-by: Anders Roxell --- packet_io.dox | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/packet_io.dox b/packet_io.dox index 6204159..25de47f 100644 --- a/packet_io.dox +++ b/packet_io.dox @@ -475,4 +475,67 @@ This routine returns the output queue for a packet. This is a shorthand equivalent of calling odp_packet_get_input() followed by odp_pktio_outq_getdef() to determine the output queue based on the interface the packet was received on. +@section examples Usage Examples + +This section contains some example code sequences demonstrating expected usage +of the APIs defined here. This is pseudo-ish code rather than something that +will actually compile, for real usable examples check the examples in the ODP +source repository. + +Each example has two sections of code, an "Initialisation" section that is +expected to be run once from a single thread (e.g. the "main" thread) and a +"Worker" section that would be run from each worker thread. + +@subsection exsched Single Interface via Scheduler + +@subsubsection Initialisation + +@code +odp_cos_t default_cos = odp_cos_create(..); +odp_buffer_pool_t pkt_pool = odp_buffer_pool_create(..); +odp_queue_t inq = odp_queue_create(..); +odp_cos_set_pool(default_cos, pkt_pool); +odp_cos_set_queue(default_cos, inq); + +odp_pktio_t pktio = odp_pktio_open("eth0", default_cos); +/* additional pktios could be opened here, passing the same default_cos */ +@endcode + +@subsubsection Worker + +@code +while (1) { + pkt = odp_schedule(); + outq = odp_packet_outq(pkt); + buf = odp_buffer_from_packet(pkt); + + /* do stuff.. */ + + odp_queue_enq(outq, buf); +} +@endcode + +@subsection exdirect Direct Send/Receive + +@subsubsection Initialisation + +@code +odp_pktio_t pktio = odp_pktio_open("eth0", ODP_COS_INVALID); +@endcode + +No buffer pool is associated with the pktio interface as it will only be +accessed by direct polling, in which case pools and buffers are managed +within the application. + +@subsubsection Worker + +@code +odp_pktio_worker_t io = odp_pktio_open_worker("eth0"); + +while (1) { + num_pkts = odp_pktio_worker_recv(io, pkt_tbl, ARRAY_SIZE(pkt_tbl)); + odp_pktio_worker_send(io, pkt_tbl, num_pkts); +} +@endcode + */