All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qinglai Xiao <jigsaw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: dev-VfR2kkLFssw@public.gmane.org
Cc: Qinglai Xiao <jigsaw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH] Add user defined tag calculation callback to librte_distributor.
Date: Wed,  5 Nov 2014 15:30:37 +0200	[thread overview]
Message-ID: <1415194237-1219-1-git-send-email-jigsaw@gmail.com> (raw)

User defined tag calculation has access to mbuf.
Default tag is RSS hash result.

Signed-off-by: Qinglai Xiao <jigsaw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 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

             reply	other threads:[~2014-11-05 13:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05 13:30 Qinglai Xiao [this message]
     [not found] ` <1415194237-1219-1-git-send-email-jigsaw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-11-05 14:27   ` [PATCH] Add user defined tag calculation callback to librte_distributor Bruce Richardson
2014-11-05 15:11     ` jigsaw
     [not found]       ` <CAHVfvh4yAdF-aDnV+sh+PgJpEUW18+aF0=JoZDwJtGHhh=5ZzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-05 16:36         ` Bruce Richardson
2014-11-05 17:24           ` jigsaw
     [not found]             ` <CAHVfvh4X_sUPUzSJTqBdEnkS94t2Jwj_98Vg0xbUS3MPSeo2ZA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-06  9:22               ` Bruce Richardson
2014-11-06 10:14                 ` jigsaw
2014-11-06 10:36                 ` Thomas Monjalon
2014-11-06 12:36                   ` 答复: [PATCH] Add user defined tag calculation callback tolibrte_distributor Qinglai Xiao
     [not found]                     ` <545b6b74.a96db40a.26af.ffffe7fb-ATjtLOhZ0NVl57MIdRCFDg@public.gmane.org>
2014-11-06 13:59                       ` Bruce Richardson
2014-11-06 18:01                         ` jigsaw
     [not found]                           ` <CAHVfvh4U4PZKZSue_kKDQKATC2snb_=10OD08LGmUtieBc_LzA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-06 19:52                             ` jigsaw
     [not found]                               ` <CAHVfvh5SzJ-kpQQ9h=1wmMihiitcJXeR9mcNa1in8x6Gb6tSqQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-07  9:45                                 ` Bruce Richardson
2014-11-07 12:38                                   ` jigsaw
     [not found]                                     ` <CAHVfvh6y4f7+bMhzmwOu5c0Y4wzwNaxj4sQPtq8cabGbdHrzXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-07 13:53                                       ` Bruce Richardson
2014-11-07 14:31                                         ` jigsaw
     [not found]                                           ` <CAHVfvh7ggGB_q1Rs1c3-9PRwDr_GKA+etaMXRSeKCfUKoUx8hQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-07 14:44                                             ` Bruce Richardson
2014-11-07 14:52                                               ` jigsaw
     [not found]                                                 ` <CAHVfvh6HxAVynbvCXFESMfFyHpiaLkgUPwM7eWEjNAF53qJDXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-07 15:04                                                   ` Bruce Richardson
2014-11-07 15:18                                                     ` jigsaw
2014-11-06 13:55                   ` [PATCH] distributor: add comments to make code more readable Bruce Richardson
     [not found]                     ` <1415282132-11056-1-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-11-07 14:08                       ` Thomas Monjalon
2014-11-07 14:31                         ` jigsaw
2014-11-06 13:57                   ` [PATCH] Add user defined tag calculation callback to librte_distributor Bruce Richardson
2014-11-05 15:13     ` Ananyev, Konstantin
     [not found]       ` <2601191342CEEE43887BDE71AB977258213A2938-kPTMFJFq+rEu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-11-05 15:24         ` jigsaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415194237-1219-1-git-send-email-jigsaw@gmail.com \
    --to=jigsaw-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=dev-VfR2kkLFssw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.