From patchwork Sat Jan 31 16:14:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44086 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 984502359E for ; Sat, 31 Jan 2015 16:15:11 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id fb4sf7771077wid.3 for ; Sat, 31 Jan 2015 08:15:10 -0800 (PST) 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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=miC0Dx7DpU+RGyPqZ8M7lsLpdlsA/WZgH0Y7tY9ncbk=; b=amu3E21bXbk2ge6zT99lmhEbLZLy9HyawCbgVeo+c/q614Wnr3ZUN6+6/Ct9GCy4Rc puZSbWednrPACG+dQlMJM8ThPDxFcZy2BXm43we3EGqhFitK+vOqEyS/O31QmT1Yenqr H5gKS4+HI4ISadBDk1P+V2C6h9eNEQYavBvXbKzC58nQViDFnwZWiQqLnkSDfocKDCI5 TtkxOm1lDUfb4KQKsAdhLuPDPKIrUvqWRPu+AFPAwaFkb9PDOTWI2qgBElDpuCQhyFh+ 3QS4jz+bG25olhv99b2skaMEgQndhak0OUFs1NcpIVWwpi3tGCdYAfsqQqatLIN6xVjd BlqA== X-Gm-Message-State: ALoCoQmfQyTAdsukrbWUhh/Ta0XvyK5kTMi8rxMCq8mM2M77gJkbDPgbIZejLlgQfMw8itDyrZ5o X-Received: by 10.194.221.65 with SMTP id qc1mr1446909wjc.7.1422720910872; Sat, 31 Jan 2015 08:15:10 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.162 with SMTP id f2ls549593lam.5.gmail; Sat, 31 Jan 2015 08:15:10 -0800 (PST) X-Received: by 10.152.10.4 with SMTP id e4mr11652384lab.62.1422720910616; Sat, 31 Jan 2015 08:15:10 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id w6si9246666lad.83.2015.01.31.08.15.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 08:15:10 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ge10so29645862lab.10 for ; Sat, 31 Jan 2015 08:15:10 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr11674032laa.80.1422720910516; Sat, 31 Jan 2015 08:15:10 -0800 (PST) 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.35.133 with SMTP id h5csp351960lbj; Sat, 31 Jan 2015 08:15:09 -0800 (PST) X-Received: by 10.224.75.196 with SMTP id z4mr24186487qaj.50.1422720908951; Sat, 31 Jan 2015 08:15:08 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id t5si18307501qar.69.2015.01.31.08.15.07 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 08:15:08 -0800 (PST) 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 1YHahN-00058J-SI; Sat, 31 Jan 2015 16:15:05 +0000 Received: from mail-ob0-f176.google.com ([209.85.214.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHah4-00055p-H8 for lng-odp@lists.linaro.org; Sat, 31 Jan 2015 16:14:46 +0000 Received: by mail-ob0-f176.google.com with SMTP id wo20so2178721obc.7 for ; Sat, 31 Jan 2015 08:14:41 -0800 (PST) X-Received: by 10.202.226.2 with SMTP id z2mr6651609oig.64.1422720881254; Sat, 31 Jan 2015 08:14:41 -0800 (PST) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by mx.google.com with ESMTPSA id ur1sm6921411obc.3.2015.01.31.08.14.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 08:14:40 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 10:14:22 -0600 Message-Id: <1422720866-22194-6-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422720866-22194-1-git-send-email-bill.fischofer@linaro.org> References: <1422720866-22194-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 5/9] linux-generic: pktio: add strong typing support 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: bill.fischofer@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.51 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: Bill Fischofer --- example/generator/odp_generator.c | 11 +++++++---- example/ipsec/odp_ipsec.c | 10 ++++++---- example/l2fwd/odp_l2fwd.c | 11 +++++++---- example/packet/odp_pktio.c | 22 ++++++++++++++-------- include/odp/api/packet_io.h | 12 ++++++++++++ .../include/odp/plat/packet_io_types.h | 15 ++++++++++++--- .../linux-generic/include/odp_packet_io_internal.h | 4 ++-- platform/linux-generic/odp_packet.c | 3 ++- platform/linux-generic/odp_packet_io.c | 11 ++++++----- test/validation/odp_pktio.c | 3 ++- 10 files changed, 70 insertions(+), 32 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 03dab50..b98aba5 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -308,7 +308,8 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "%i-pktio_inq_def", (int)pktio); + snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def", + odp_pktio_t_print(pktio)); inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam); @@ -319,9 +320,11 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) if (ret != 0) EXAMPLE_ABORT("Error: default input-Q setup for %s\n", dev); - printf(" created pktio:%02i, dev:%s, queue mode (ATOMIC queues)\n" - " default pktio%02i-INPUT queue:%u\n", - pktio, dev, pktio, inq_def); + printf(" created pktio:%02" PRIu64 + ", dev:%s, queue mode (ATOMIC queues)\n" + " default pktio%02" PRIu64 "-INPUT queue:%u\n", + odp_pktio_t_print(pktio), dev, + odp_pktio_t_print(pktio), inq_def); return pktio; } diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index 03f2419..2f7106d 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -567,7 +567,8 @@ void initialize_intf(char *intf) qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "%i-pktio_inq_def", (int)pktio); + snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def", + odp_pktio_t_print(pktio)); inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; inq_def = QUEUE_CREATE(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam); @@ -595,10 +596,11 @@ void initialize_intf(char *intf) exit(EXIT_FAILURE); } - printf("Created pktio:%02i, queue mode (ATOMIC queues)\n" - " default pktio%02i-INPUT queue:%u\n" + printf("Created pktio:%02" PRIu64 ", queue mode (ATOMIC queues)\n" + " default pktio%02" PRIu64 "-INPUT queue:%u\n" " source mac address %s\n", - pktio, pktio, inq_def, mac_addr_str(src_mac_str, src_mac)); + odp_pktio_t_print(pktio), odp_pktio_t_print(pktio), inq_def, + mac_addr_str(src_mac_str, src_mac)); /* Resolve any routes using this interface for output */ resolve_fwd_db(intf, outq_def, src_mac); diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index 7a520fb..7d3234a 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -197,11 +197,12 @@ static void *pktio_ifburst_thread(void *arg) pktio_src = gbl_args->pktios[src_idx]; pktio_dst = gbl_args->pktios[dst_idx]; - printf("[%02i] srcif:%s dstif:%s spktio:%02i dpktio:%02i BURST mode\n", + printf("[%02i] srcif:%s dstif:%s spktio:%02" PRIu64 + " dpktio:%02" PRIu64 " BURST mode\n", thr, gbl_args->appl.if_names[src_idx], gbl_args->appl.if_names[dst_idx], - pktio_src, pktio_dst); + odp_pktio_t_print(pktio_src), odp_pktio_t_print(pktio_dst)); /* Loop packets */ for (;;) { @@ -255,7 +256,8 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, return ODP_PKTIO_INVALID; } - printf("created pktio %d (%s)\n", pktio, dev); + printf("created pktio %" PRIu64 " (%s)\n", + odp_pktio_t_print(pktio), dev); /* no further setup needed for burst mode */ if (mode == APPL_MODE_PKT_BURST) @@ -264,7 +266,8 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "%i-pktio_inq_def", (int)pktio); + snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def", + odp_pktio_t_print(pktio)); inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam); diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 28ed98c..cd13576 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -120,7 +120,8 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode) qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "%i-pktio_inq_def", (int)pktio); + snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def", + odp_pktio_t_print(pktio)); inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam); @@ -131,9 +132,11 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode) if (ret != 0) EXAMPLE_ABORT("Error: default input-Q setup for %s\n", dev); - printf(" created pktio:%02i, dev:%s, queue mode (ATOMIC queues)\n" - " \tdefault pktio%02i-INPUT queue:%u\n", - pktio, dev, pktio, inq_def); + printf(" created pktio:%02" PRIu64 + ", dev:%s, queue mode (ATOMIC queues)\n" + " \tdefault pktio%02" PRIu64 "-INPUT queue:%u\n", + odp_pktio_t_print(pktio), dev, + odp_pktio_t_print(pktio), inq_def); return pktio; } @@ -164,9 +167,11 @@ static void *pktio_queue_thread(void *arg) return NULL; } - printf(" [%02i] looked up pktio:%02i, queue mode (ATOMIC queues)\n" - " default pktio%02i-INPUT queue:%u\n", - thr, pktio, pktio, odp_pktio_inq_getdef(pktio)); + printf(" [%02i] looked up pktio:%02" PRIu64 + ", queue mode (ATOMIC queues)\n" + " default pktio%02" PRIu64 "-INPUT queue:%u\n", + thr, odp_pktio_t_print(pktio), odp_pktio_t_print(pktio), + odp_pktio_inq_getdef(pktio)); /* Loop packets */ for (;;) { @@ -242,7 +247,8 @@ static void *pktio_ifburst_thread(void *arg) return NULL; } - printf(" [%02i] looked up pktio:%02i, burst mode\n", thr, pktio); + printf(" [%02i] looked up pktio:%02" PRIu64 ", burst mode\n", + thr, odp_pktio_t_print(pktio)); /* Loop packets */ for (;;) { diff --git a/include/odp/api/packet_io.h b/include/odp/api/packet_io.h index da7bc3f..31b3a36 100644 --- a/include/odp/api/packet_io.h +++ b/include/odp/api/packet_io.h @@ -232,6 +232,18 @@ int odp_pktio_skip_set(odp_pktio_t pktio_in, uint32_t offset); */ int odp_pktio_headroom_set(odp_pktio_t pktio_in, uint32_t headroom); +/** + * Get printable value for an odp_pktio_t + * + * @param hdl odp_pktio_t handle to be printed + * @return uint64_t value that can be used to print/display this + * handle + * + * @note This routine is intended to be used for diagnostic purposes + * to enable applications to generate a printable value that represents + * an odp_pktio_t handle. + */ +uint64_t odp_pktio_t_print(odp_pktio_t hdl); /** * @} diff --git a/platform/linux-generic/include/odp/plat/packet_io_types.h b/platform/linux-generic/include/odp/plat/packet_io_types.h index a6bbacf..cc57cec 100644 --- a/platform/linux-generic/include/odp/plat/packet_io_types.h +++ b/platform/linux-generic/include/odp/plat/packet_io_types.h @@ -18,16 +18,25 @@ extern "C" { #endif +#include +#include + /** @addtogroup odp_packet_io ODP PACKET IO * Operations on a packet. * @{ */ -typedef uint32_t odp_pktio_t; +typedef odp_handle_t odp_pktio_t; + +#define ODP_PKTIO_INVALID _odp_cast_scalar(odp_pktio_t, 0) -#define ODP_PKTIO_INVALID 0 +#define ODP_PKTIO_ANY _odp_cast_scalar(odp_pktio_t, ~0) -#define ODP_PKTIO_ANY ((odp_pktio_t)~0) +/** Get printable format of odp_pktio_t */ +static inline uint64_t odp_pktio_t_print(odp_pktio_t hdl) +{ + return _odp_pri(hdl); +} /** * @} diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 488818c..47b8992 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -68,10 +68,10 @@ extern void *pktio_entry_ptr[]; static inline pktio_entry_t *get_pktio_entry(odp_pktio_t id) { if (odp_unlikely(id == ODP_PKTIO_INVALID || - id > ODP_CONFIG_PKTIO_ENTRIES)) + _odp_typeval(id) > ODP_CONFIG_PKTIO_ENTRIES)) return NULL; - return pktio_entry_ptr[id - 1]; + return pktio_entry_ptr[_odp_typeval(id) - 1]; } #ifdef __cplusplus } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a031f13..04787e8 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -572,7 +572,8 @@ void odp_packet_print(odp_packet_t pkt) len += snprintf(&str[len], n-len, " frame_len %u\n", hdr->frame_len); len += snprintf(&str[len], n-len, - " input %u\n", hdr->input); + " input %" PRIu64 "\n", + odp_pktio_t_print(hdr->input)); str[len] = '\0'; ODP_PRINT("\n%s\n", str); diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index bdb690e..8e2c6b2 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -73,7 +73,7 @@ int odp_pktio_init_global(void) pktio_entry->s.outq_default = qid; queue_entry = queue_to_qentry(qid); - queue_entry->s.pktout = id; + queue_entry->s.pktout = _odp_cast_scalar(odp_pktio_t, id); } return 0; @@ -146,7 +146,7 @@ static odp_pktio_t alloc_lock_pktio_entry(void) lock_entry_classifier(entry); if (is_free(entry)) { init_pktio_entry(entry); - id = i + 1; + id = _odp_cast_scalar(odp_pktio_t, i + 1); return id; /* return with entry locked! */ } unlock_entry_classifier(entry); @@ -205,7 +205,8 @@ static int init_loop(pktio_entry_t *entry, odp_pktio_t id) char loopq_name[ODP_QUEUE_NAME_LEN]; entry->s.type = ODP_PKTIO_TYPE_LOOPBACK; - snprintf(loopq_name, sizeof(loopq_name), "%i-pktio_loopq", (int)id); + snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq", + odp_pktio_t_print(id)); entry->s.loopq = odp_queue_create(loopq_name, ODP_QUEUE_TYPE_POLL, NULL); @@ -319,7 +320,7 @@ odp_pktio_t odp_pktio_lookup(const char *dev) odp_spinlock_lock(&pktio_tbl->lock); for (i = 1; i <= ODP_CONFIG_PKTIO_ENTRIES; ++i) { - entry = get_pktio_entry(i); + entry = get_pktio_entry(_odp_cast_scalar(odp_pktio_t, i)); if (is_free(entry)) continue; @@ -327,7 +328,7 @@ odp_pktio_t odp_pktio_lookup(const char *dev) if (!is_free(entry) && strncmp(entry->s.name, dev, IFNAMSIZ) == 0) - id = i; + id = _odp_cast_scalar(odp_pktio_t, i); unlock_entry(entry); diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index 84121f5..d7274a9 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -234,7 +234,8 @@ static int create_inq(odp_pktio_t pktio) qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "inq-pktio-%d", pktio); + snprintf(inq_name, sizeof(inq_name), "inq-pktio-%" PRIu64, + odp_pktio_t_print(pktio)); inq_def = odp_queue_lookup(inq_name); if (inq_def == ODP_QUEUE_INVALID) inq_def = odp_queue_create(inq_name,