From patchwork Fri Nov 21 08:53:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 41288 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 071DC244B0 for ; Fri, 21 Nov 2014 08:54:31 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id mc6sf2759504lab.11 for ; Fri, 21 Nov 2014 00:54:29 -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=AbNrPc96H84lxDeBXLvTjuX1xjbJl5A/HvA8u4+K2QI=; b=DpCUtKK/sVJv7vUSp7PvX7L+iIAJCvYJIxGf2OdYGPjUc59jhM/lqfyMCFL4CCO9Ty m7iEtqmQ3Tbj/L4KFDNQu1PFwqKJVtJZvEOb2XOukRo8Yf91FyuBAPEAEHTjOsVOXEFZ Y6vOPf+7ViT8W1HfE/yha1P9Mhzj5GSgsremi2CRVVaXZYpBiYYzczc0npXqqu7I7rrg fSWuVrFmsWEff5fhAB+7EbNvK8iyDFvpfBZEmY393ocFVA20cVTX+R37CvEzlYIaS+hy 9D6pFxxG5/wP1XQWkwYxVhNL/rQOxcwl0knOnVokPtrk/16JNyv/cpQ6S5W+8i1DGYG6 /Mbw== X-Gm-Message-State: ALoCoQm9qTFjRT0J2YXr21akflr4YTvi2MLQKaCceNtttUmw4Y5LfXQrcfrcildEGNWHnNYAbDKg X-Received: by 10.112.17.65 with SMTP id m1mr414603lbd.16.1416560069889; Fri, 21 Nov 2014 00:54:29 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.67 with SMTP id o3ls155393laj.86.gmail; Fri, 21 Nov 2014 00:54:29 -0800 (PST) X-Received: by 10.152.43.229 with SMTP id z5mr1764631lal.86.1416560069677; Fri, 21 Nov 2014 00:54:29 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id rd1si4385418lac.70.2014.11.21.00.54.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 00:54:29 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id s18so3801548lam.21 for ; Fri, 21 Nov 2014 00:54:29 -0800 (PST) X-Received: by 10.112.45.102 with SMTP id l6mr2930091lbm.46.1416560069217; Fri, 21 Nov 2014 00:54:29 -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.184.201 with SMTP id ew9csp47022lbc; Fri, 21 Nov 2014 00:54:28 -0800 (PST) X-Received: by 10.140.22.71 with SMTP id 65mr4626495qgm.19.1416560067886; Fri, 21 Nov 2014 00:54:27 -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 x109si5921426qge.89.2014.11.21.00.54.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 21 Nov 2014 00:54:27 -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 1Xrjyz-0002Hp-5k; Fri, 21 Nov 2014 08:54:25 +0000 Received: from mail-yk0-f172.google.com ([209.85.160.172]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xrjym-0002H0-E2 for lng-odp@lists.linaro.org; Fri, 21 Nov 2014 08:54:12 +0000 Received: by mail-yk0-f172.google.com with SMTP id 131so2088757ykp.17 for ; Fri, 21 Nov 2014 00:54:07 -0800 (PST) X-Received: by 10.236.223.198 with SMTP id v66mr1507114yhp.38.1416560047250; Fri, 21 Nov 2014 00:54:07 -0800 (PST) Received: from bala-PowerEdge-T110-II.caveonetworks.com ([111.93.218.67]) by mx.google.com with ESMTPSA id y67sm2345495yhc.11.2014.11.21.00.54.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 00:54:06 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Fri, 21 Nov 2014 14:23:42 +0530 Message-Id: <1416560024-20661-3-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1416560024-20661-1-git-send-email-bala.manoharan@linaro.org> References: <1416560024-20661-1-git-send-email-bala.manoharan@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [PATCH v1 3/5] Linux-generic: Pktio changes for Classification 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: bala.manoharan@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.48 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 This patch links classification with pktio module. The classification variables are stored as a separate struct with pktio entry and the same is initialized as part of pktio initialization. This patch also moves the inline function get_pktio_entry() to header file as the same is called from classification module. Signed-off-by: Balasubramanian Manoharan --- .../linux-generic/include/odp_packet_io_internal.h | 17 +++++ platform/linux-generic/odp_packet_io.c | 81 +++++++++++++--------- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 23633ed..0599573 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -20,6 +20,7 @@ extern "C" { #include #include +#include /** * Packet IO types @@ -38,6 +39,7 @@ struct pktio_entry { odp_pktio_type_t type; /**< pktio type */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap API for IO */ + classifier_t cls; }; typedef union { @@ -45,6 +47,21 @@ typedef union { uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(struct pktio_entry))]; } pktio_entry_t; +typedef struct { + pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; +} pktio_table_t; + +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)) + return NULL; + + return pktio_entry_ptr[id - 1]; +} #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f78b7fd..4226db4 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -11,31 +11,22 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include -typedef struct { - pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; -} pktio_table_t; - static pktio_table_t *pktio_tbl; - -static pktio_entry_t *get_entry(odp_pktio_t id) -{ - if (odp_unlikely(id == ODP_PKTIO_INVALID || - id > ODP_CONFIG_PKTIO_ENTRIES)) - return NULL; - - return &pktio_tbl->entries[id - 1]; -} +/* pktio pointer entries ( for inlines) */ +void *pktio_entry_ptr[ODP_CONFIG_PKTIO_ENTRIES]; int odp_pktio_init_global(void) { @@ -57,10 +48,12 @@ int odp_pktio_init_global(void) memset(pktio_tbl, 0, sizeof(pktio_table_t)); for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) { - pktio_entry = get_entry(id); + pktio_entry = &pktio_tbl->entries[id - 1]; odp_spinlock_init(&pktio_entry->s.lock); + odp_rwlock_init(&pktio_entry->s.cls.lock); + pktio_entry_ptr[id - 1] = pktio_entry; /* Create a default output queue for each pktio resource */ snprintf(name, sizeof(name), "%i-pktio_outq_default", (int)id); name[ODP_QUEUE_NAME_LEN-1] = '\0'; @@ -107,12 +100,25 @@ static void unlock_entry(pktio_entry_t *entry) odp_spinlock_unlock(&entry->s.lock); } +static void lock_entry_classifier(pktio_entry_t *entry) +{ + odp_spinlock_lock(&entry->s.lock); + odp_rwlock_write_lock(&entry->s.cls.lock); +} + +static void unlock_entry_classifier(pktio_entry_t *entry) +{ + odp_rwlock_write_unlock(&entry->s.cls.lock); + odp_spinlock_unlock(&entry->s.lock); +} + static void init_pktio_entry(pktio_entry_t *entry) { set_taken(entry); entry->s.inq_default = ODP_QUEUE_INVALID; memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock)); memset(&entry->s.pkt_sock_mmap, 0, sizeof(entry->s.pkt_sock_mmap)); + pktio_classifier_init(entry); } static odp_pktio_t alloc_lock_pktio_entry(void) @@ -124,13 +130,13 @@ static odp_pktio_t alloc_lock_pktio_entry(void) for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = &pktio_tbl->entries[i]; if (is_free(entry)) { - lock_entry(entry); + lock_entry_classifier(entry); if (is_free(entry)) { init_pktio_entry(entry); id = i + 1; return id; /* return with entry locked! */ } - unlock_entry(entry); + unlock_entry_classifier(entry); } } @@ -139,7 +145,7 @@ static odp_pktio_t alloc_lock_pktio_entry(void) static int free_pktio_entry(odp_pktio_t id) { - pktio_entry_t *entry = get_entry(id); + pktio_entry_t *entry = get_pktio_entry(id); if (entry == NULL) return -1; @@ -163,7 +169,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) } /* if successful, alloc_pktio_entry() returns with the entry locked */ - pktio_entry = get_entry(id); + pktio_entry = get_pktio_entry(id); ODP_DBG("ODP_PKTIO_USE_FANOUT: %d\n", fanout); if (getenv("ODP_PKTIO_DISABLE_SOCKET_MMAP") == NULL) { @@ -197,13 +203,13 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) close_pkt_sock(&pktio_entry->s.pkt_sock); } - unlock_entry(pktio_entry); + unlock_entry_classifier(pktio_entry); free_pktio_entry(id); ODP_ERR("Unable to init any I/O type.\n"); return ODP_PKTIO_INVALID; done: - unlock_entry(pktio_entry); + unlock_entry_classifier(pktio_entry); return id; } @@ -212,7 +218,7 @@ int odp_pktio_close(odp_pktio_t id) pktio_entry_t *entry; int res = -1; - entry = get_entry(id); + entry = get_pktio_entry(id); if (entry == NULL) return -1; @@ -251,7 +257,7 @@ odp_pktio_t odp_pktio_get_input(odp_packet_t pkt) int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) { - pktio_entry_t *pktio_entry = get_entry(id); + pktio_entry_t *pktio_entry = get_pktio_entry(id); int pkts; int i; @@ -289,7 +295,7 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) { - pktio_entry_t *pktio_entry = get_entry(id); + pktio_entry_t *pktio_entry = get_pktio_entry(id); int pkts; if (pktio_entry == NULL) @@ -319,7 +325,7 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) int odp_pktio_inq_setdef(odp_pktio_t id, odp_queue_t queue) { - pktio_entry_t *pktio_entry = get_entry(id); + pktio_entry_t *pktio_entry = get_pktio_entry(id); queue_entry_t *qentry = queue_to_qentry(queue); if (pktio_entry == NULL || qentry == NULL) @@ -349,7 +355,7 @@ int odp_pktio_inq_remdef(odp_pktio_t id) odp_queue_t odp_pktio_inq_getdef(odp_pktio_t id) { - pktio_entry_t *pktio_entry = get_entry(id); + pktio_entry_t *pktio_entry = get_pktio_entry(id); if (pktio_entry == NULL) return ODP_QUEUE_INVALID; @@ -359,7 +365,7 @@ odp_queue_t odp_pktio_inq_getdef(odp_pktio_t id) odp_queue_t odp_pktio_outq_getdef(odp_pktio_t id) { - pktio_entry_t *pktio_entry = get_entry(id); + pktio_entry_t *pktio_entry = get_pktio_entry(id); if (pktio_entry == NULL) return ODP_QUEUE_INVALID; @@ -419,7 +425,7 @@ odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry) odp_buffer_t buf; odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; - int pkts, i; + int pkts, i, j; buf_hdr = queue_deq(qentry); if (buf_hdr != NULL) @@ -429,12 +435,15 @@ odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry) if (pkts <= 0) return NULL; - for (i = 0; i < pkts; ++i) { + for (i = 0, j = 0; i < pkts; ++i) { buf = odp_packet_to_buffer(pkt_tbl[i]); - tmp_hdr_tbl[i] = odp_buf_to_hdr(buf); + buf_hdr = odp_buf_to_hdr(buf); + if (0 > packet_classifier(qentry->s.pktin, pkt_tbl[i])) + tmp_hdr_tbl[j++] = buf_hdr; } - queue_enq_multi(qentry, tmp_hdr_tbl, pkts); + if (j) + queue_enq_multi(qentry, tmp_hdr_tbl, j); buf_hdr = tmp_hdr_tbl[0]; return buf_hdr; } @@ -450,8 +459,9 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) int nbr; odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; + odp_buffer_hdr_t *tmp_hdr; odp_buffer_t buf; - int pkts, i; + int pkts, i, j; nbr = queue_deq_multi(qentry, buf_hdr, num); if (odp_unlikely(nbr > num)) @@ -468,11 +478,14 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) if (pkts <= 0) return nbr; - for (i = 0; i < pkts; ++i) { + for (i = 0, j = 0; i < pkts; ++i) { buf = odp_packet_to_buffer(pkt_tbl[i]); - tmp_hdr_tbl[i] = odp_buf_to_hdr(buf); + tmp_hdr = odp_buf_to_hdr(buf); + if (0 > packet_classifier(qentry->s.pktin, pkt_tbl[i])) + tmp_hdr_tbl[j++] = tmp_hdr; } - queue_enq_multi(qentry, tmp_hdr_tbl, pkts); + if (j) + queue_enq_multi(qentry, tmp_hdr_tbl, j); return nbr; }