From patchwork Sat Jan 31 20:50:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44099 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 845D62359E for ; Sat, 31 Jan 2015 20:51:33 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf8629825wiv.0 for ; Sat, 31 Jan 2015 12:51:32 -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=kIz9Vwx83E5tJXKHp/ibu0EnhfpPX9TFVfyn+WbR5mvN/HALKY385EouxEETKFlNK5 oi02/zOHGIPszOvVvwWLHPNwrYf6eOP5Dj9Z312NkmNM8y6gJ4CKE99BIujosvoL9Gy+ daLoVtGWinOBT3TTE4B3WgaupC0sf1UKE2TLYsfXaYuyHWPH5V7KUH1DDYZgQ6ZkKn6N TNysFIGn9QE+NhW08uHtj+tfbRoKiceXDIfMhn/F/mreule6J6LZX0HzluyKs0AI98Ae pJY6IFB4vSjWN/ToWiiljHKdwTEvTIq0fJeysgyl+49WVK5wWNdXf8DGM19piCGlqM9Z oEeA== X-Gm-Message-State: ALoCoQkTzCQWFpLl9igMJtGcn19CuDNqtSj+06swjemSNj07sb/Z+U7MfekuDV+toxJ81k9K2PgD X-Received: by 10.194.161.194 with SMTP id xu2mr1537881wjb.1.1422737492832; Sat, 31 Jan 2015 12:51:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.37 with SMTP id ll5ls588692lac.53.gmail; Sat, 31 Jan 2015 12:51:32 -0800 (PST) X-Received: by 10.152.203.230 with SMTP id kt6mr12117295lac.38.1422737492645; Sat, 31 Jan 2015 12:51:32 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id lf12si13124653lac.48.2015.01.31.12.51.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gd6so30514376lab.4 for ; Sat, 31 Jan 2015 12:51:32 -0800 (PST) X-Received: by 10.112.164.101 with SMTP id yp5mr12208738lbb.82.1422737492546; Sat, 31 Jan 2015 12:51:32 -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 h5csp450320lbj; Sat, 31 Jan 2015 12:51:31 -0800 (PST) X-Received: by 10.224.98.196 with SMTP id r4mr25734959qan.27.1422737490596; Sat, 31 Jan 2015 12:51:30 -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 b5si19163789qat.123.2015.01.31.12.51.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51:30 -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 1YHf0p-0000wL-EC; Sat, 31 Jan 2015 20:51:27 +0000 Received: from mail-oi0-f46.google.com ([209.85.218.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHf0V-0000u5-Fp for lng-odp@lists.linaro.org; Sat, 31 Jan 2015 20:51:07 +0000 Received: by mail-oi0-f46.google.com with SMTP id a141so39534018oig.5 for ; Sat, 31 Jan 2015 12:51:02 -0800 (PST) X-Received: by 10.202.77.13 with SMTP id a13mr7093619oib.49.1422737462253; Sat, 31 Jan 2015 12:51:02 -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 uv10sm7202439obc.27.2015.01.31.12.51.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 12:51:01 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 14:50:45 -0600 Message-Id: <1422737449-11540-6-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> References: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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.45 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,