From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-la0-f42.google.com (mail-la0-f42.google.com [209.85.215.42]) by dpdk.org (Postfix) with ESMTP id B3F813989 for ; Wed, 5 Nov 2014 14:21:18 +0100 (CET) Received: by mail-la0-f42.google.com with SMTP id gq15so680461lab.1 for ; Wed, 05 Nov 2014 05:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lUd127NxDx66zu+nTt46RFhFm5O/klyZ4hcaXHEt5qc=; b=N+brjgO/LWWr4Dnsny5grfhc0gBjkG1x9XixQLAaZIKoy+3Osum+wdkhfelBpe7eM+ BH19EA13eSWRPNcoJnsWQ4Joweu8F4dhed3bGZCnGQwcf8IpU1mWs2S21MEoR+Toa8Sc na2eLShr51gMuXQD0Mik34XKEjwTrsCOXoW/sbv//IWItq+9valXwvawp8JVaXDYcKSC cqre5ItV194Kh43cxiB/VWmheh5I1I5RuPeqxirU/cfJnXd1U53nHH7F+0HCH2I7vKSB ARdqxeAhZpebvQxWd5xEoSPmQck2M2TEnDvSFFKJY+ghS4Xgm714Gc9Uy5FuV8T39aye gZYg== X-Received: by 10.152.5.100 with SMTP id r4mr68012364lar.26.1415194241515; Wed, 05 Nov 2014 05:30:41 -0800 (PST) Received: from localhost.localdomain ([194.251.119.201]) by mx.google.com with ESMTPSA id q7sm1308329laq.32.2014.11.05.05.30.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Nov 2014 05:30:40 -0800 (PST) From: Qinglai Xiao To: dev@dpdk.org Date: Wed, 5 Nov 2014 15:30:37 +0200 Message-Id: <1415194237-1219-1-git-send-email-jigsaw@gmail.com> X-Mailer: git-send-email 1.7.1 Cc: Qinglai Xiao Subject: [dpdk-dev] [PATCH] Add user defined tag calculation callback to librte_distributor. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Nov 2014 13:21:19 -0000 User defined tag calculation has access to mbuf. Default tag is RSS hash result. Signed-off-by: Qinglai Xiao --- app/test/test_distributor.c | 6 +++--- app/test/test_distributor_perf.c | 2 +- lib/librte_distributor/rte_distributor.c | 12 ++++++++++-- lib/librte_distributor/rte_distributor.h | 7 ++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c index ce06436..6ea4943 100644 --- a/app/test/test_distributor.c +++ b/app/test/test_distributor.c @@ -452,7 +452,7 @@ int test_error_distributor_create_name(void) char *name = NULL; d = rte_distributor_create(name, rte_socket_id(), - rte_lcore_count() - 1); + rte_lcore_count() - 1, NULL); if (d != NULL || rte_errno != EINVAL) { printf("ERROR: No error on create() with NULL name param\n"); return -1; @@ -467,7 +467,7 @@ int test_error_distributor_create_numworkers(void) { struct rte_distributor *d = NULL; d = rte_distributor_create("test_numworkers", rte_socket_id(), - RTE_MAX_LCORE + 10); + RTE_MAX_LCORE + 10, NULL); if (d != NULL || rte_errno != EINVAL) { printf("ERROR: No error on create() with num_workers > MAX\n"); return -1; @@ -515,7 +515,7 @@ test_distributor(void) if (d == NULL) { d = rte_distributor_create("Test_distributor", rte_socket_id(), - rte_lcore_count() - 1); + rte_lcore_count() - 1, NULL); if (d == NULL) { printf("Error creating distributor\n"); return -1; diff --git a/app/test/test_distributor_perf.c b/app/test/test_distributor_perf.c index b04864c..507e446 100644 --- a/app/test/test_distributor_perf.c +++ b/app/test/test_distributor_perf.c @@ -227,7 +227,7 @@ test_distributor_perf(void) if (d == NULL) { d = rte_distributor_create("Test_perf", rte_socket_id(), - rte_lcore_count() - 1); + rte_lcore_count() - 1, NULL); if (d == NULL) { printf("Error creating distributor\n"); return -1; diff --git a/lib/librte_distributor/rte_distributor.c b/lib/librte_distributor/rte_distributor.c index 585ff88..78c92bd 100644 --- a/lib/librte_distributor/rte_distributor.c +++ b/lib/librte_distributor/rte_distributor.c @@ -97,6 +97,7 @@ struct rte_distributor { union rte_distributor_buffer bufs[RTE_MAX_LCORE]; struct rte_distributor_returned_pkts returns; + rte_distributor_tag_fn tag_cb; }; TAILQ_HEAD(rte_distributor_list, rte_distributor); @@ -267,6 +268,7 @@ rte_distributor_process(struct rte_distributor *d, struct rte_mbuf *next_mb = NULL; int64_t next_value = 0; uint32_t new_tag = 0; + rte_distributor_tag_fn tag_cb = d->tag_cb; unsigned ret_start = d->returns.start, ret_count = d->returns.count; @@ -282,7 +284,11 @@ rte_distributor_process(struct rte_distributor *d, next_mb = mbufs[next_idx++]; next_value = (((int64_t)(uintptr_t)next_mb) << RTE_DISTRIB_FLAG_BITS); - new_tag = (next_mb->hash.rss | 1); + if (tag_cb) { + new_tag = tag_cb(next_mb); + } else { + new_tag = (next_mb->hash.rss | 1); + } uint32_t match = 0; unsigned i; @@ -401,7 +407,8 @@ rte_distributor_clear_returns(struct rte_distributor *d) struct rte_distributor * rte_distributor_create(const char *name, unsigned socket_id, - unsigned num_workers) + unsigned num_workers, + rte_distributor_tag_fn tag_cb) { struct rte_distributor *d; struct rte_distributor_list *distributor_list; @@ -435,6 +442,7 @@ rte_distributor_create(const char *name, d = mz->addr; snprintf(d->name, sizeof(d->name), "%s", name); d->num_workers = num_workers; + d->tag_cb = tag_cb; rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); TAILQ_INSERT_TAIL(distributor_list, d, next); diff --git a/lib/librte_distributor/rte_distributor.h b/lib/librte_distributor/rte_distributor.h index ec0d74a..844d325 100644 --- a/lib/librte_distributor/rte_distributor.h +++ b/lib/librte_distributor/rte_distributor.h @@ -52,6 +52,9 @@ extern "C" { struct rte_distributor; +typedef uint32_t (*rte_distributor_tag_fn)(struct rte_mbuf *); +/**< User defined tag calculation function */ + /** * Function to create a new distributor instance * @@ -65,12 +68,14 @@ struct rte_distributor; * @param num_workers * The maximum number of workers that will request packets from this * distributor + * @param tag_cb + * The callback function for calculation of user defined tag. * @return * The newly created distributor instance */ struct rte_distributor * rte_distributor_create(const char *name, unsigned socket_id, - unsigned num_workers); + unsigned num_workers, rte_distributor_tag_fn tag_cb); /* *** APIS to be called on the distributor lcore *** */ /* -- 1.7.1