Skip to contentSkip to conversation

app/testpmd: support age shared action context

PATCH Superseded Matan Azrad 3 participants 17 messages Nov 1, 2020 – Nov 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: support age shared action context

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
 app/test-pmd/config.c  | 57 ++++++++++++++++++++++++++++++++++++--------------
 app/test-pmd/testpmd.h |  7 +++++++
 2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c +41 -16
index e0203f0..3581f3d 100644
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 		return NULL;
 	}
 	if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-			  error) >= 0)
+			  error) >= 0) {
+		pf->ctype = CONTEXT_TYPE_FLOW;
 		return pf;
+	}
 	free(pf);
 	return NULL;
 }
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	}
 	psa->next = *ppsa;
 	psa->id = id;
+	psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
 	*ppsa = psa;
 	*action = psa;
 	return 0;
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	ret = action_alloc(port_id, id, &psa);
 	if (ret)
 		return ret;
+	if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+		struct rte_flow_action_age *age =
+				(void *)(uintptr_t)(action->conf);
+
+		age->context = psa;
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	psa->action = rte_flow_shared_action_create(port_id, conf, action,
@@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *
 	void **contexts;
 	int nb_context, total = 0, idx;
 	struct rte_flow_error error;
-	struct port_flow *pf;
+	union {
+		struct port_flow *pf;
+		struct port_shared_action *psa;
+	} ctx;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
 	    port_id == (portid_t)RTE_PORT_ALL)
@@ -2397,7 +2409,7 @@ struct rte_flow_shared_action *
 		printf("Cannot allocate contexts for aged flow\n");
 		return;
 	}
-	printf("ID\tGroup\tPrio\tAttr\n");
+	printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
 	nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
 	if (nb_context != total) {
 		printf("Port:%d get aged flows count(%d) != total(%d)\n",
@@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *
 		return;
 	}
 	for (idx = 0; idx < nb_context; idx++) {
-		pf = (struct port_flow *)contexts[idx];
-		if (!pf) {
+		ctx.pf = (struct port_flow *)contexts[idx];
+		if (!ctx.pf) {
 			printf("Error: get Null context in port %u\n", port_id);
 			continue;
 		}
-		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-		       pf->id,
-		       pf->rule.attr->group,
-		       pf->rule.attr->priority,
-		       pf->rule.attr->ingress ? 'i' : '-',
-		       pf->rule.attr->egress ? 'e' : '-',
-		       pf->rule.attr->transfer ? 't' : '-');
+		switch (ctx.pf->ctype) {
+		case CONTEXT_TYPE_FLOW:
+			printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+								 "\t%c%c%c\t\n",
+			       "Flow",
+			       ctx.pf->id,
+			       ctx.pf->rule.attr->group,
+			       ctx.pf->rule.attr->priority,
+			       ctx.pf->rule.attr->ingress ? 'i' : '-',
+			       ctx.pf->rule.attr->egress ? 'e' : '-',
+			       ctx.pf->rule.attr->transfer ? 't' : '-');
+			break;
+		case CONTEXT_TYPE_SHARED_ACTION:
+			printf("%-20s\t%" PRIu32 "\n", "Shared action",
+			       ctx.psa->id);
+			break;
+		default:
+			printf("Error: invalid context type %u\n", port_id);
+			break;
+		}
 	}
 	if (destroy) {
 		int ret;
@@ -2426,15 +2451,15 @@ struct rte_flow_shared_action *
 		total = 0;
 		printf("\n");
 		for (idx = 0; idx < nb_context; idx++) {
-			pf = (struct port_flow *)contexts[idx];
-			if (!pf)
+			ctx.pf = (struct port_flow *)contexts[idx];
+			if (!ctx.pf || ctx.pf->ctype != CONTEXT_TYPE_FLOW)
 				continue;
-			flow_id = pf->id;
+			flow_id = ctx.pf->id;
 			ret = port_flow_destroy(port_id, 1, &flow_id);
 			if (!ret)
 				total++;
 		}
-		printf("%d flows be destroyed\n", total);
+		printf("%d flows destroyed\n", total);
 	}
 	free(contexts);
 }
app/test-pmd/testpmd.h +7 -0
index 519d551..92aaa19 100644
@@ -143,8 +143,14 @@ struct fwd_stream {
 	struct pkt_burst_stats tx_burst_stats;
 };
 
+enum testpmd_context_type {
+	CONTEXT_TYPE_FLOW,
+	CONTEXT_TYPE_SHARED_ACTION,
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
+	enum testpmd_context_type ctype; /**< Context type. */
 	struct port_flow *next; /**< Next flow in list. */
 	struct port_flow *tmp; /**< Temporary linking. */
 	uint32_t id; /**< Flow rule ID. */
@@ -155,6 +161,7 @@ struct port_flow {
 
 /* Descriptor for shared action */
 struct port_shared_action {
+	enum testpmd_context_type ctype; /**< Context type. */
 	struct port_shared_action *next; /**< Next flow in list. */
 	uint32_t id; /**< Shared action ID. */
 	enum rte_flow_action_type type; /**< Action type. */
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 48 lines · Matan Azrad

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
  app/test-pmd/config.c  | 57 ++++++++++++++++++++++++++++++++++++--------------
  app/test-pmd/testpmd.h |  7 +++++++
  2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c +4 -1
index e0203f0..3581f3d 100644
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
  		return NULL;
  	}
  	if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-			  error) >= 0)
+			  error) >= 0) {
+		pf->ctype = CONTEXT_TYPE_FLOW;
  		return pf;
+	}
  	free(pf);
  	return NULL;
  }
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
  	}
  	psa->next = *ppsa;
  	psa->id = id;
+	psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
  	*ppsa = psa;
  	*action = psa;
  	return 0;

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1860

Quoted 9 lines
app/test-pmd/config.c +6 -0
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
  	ret = action_alloc(port_id, id, &psa);
  	if (ret)
  		return ret;
+	if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+		struct rte_flow_action_age *age =
+				(void *)(uintptr_t)(action->conf);
+
+		age->context = psa;
+	}

The port flow is using 'update_age_action_context()' function, can same function be utilized to update age context for shared action too?

btw, not sure why 'update_age_action_context()' is not static, if you will touch it can you please make it static function?

And overall this context setting for the age action is requiring the special conditions in the flow create path, can you please check if it can be moved to 'cmdline_flow.c' for age parsing code somehow?

Quoted 33 lines
app/test-pmd/config.c +7 -4
  	/* Poisoning to make sure PMDs update it in case of error. */
  	memset(&error, 0x22, sizeof(error));
  	psa->action = rte_flow_shared_action_create(port_id, conf, action,
@@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *
  	void **contexts;
  	int nb_context, total = 0, idx;
  	struct rte_flow_error error;
-	struct port_flow *pf;
+	union {
+		struct port_flow *pf;
+		struct port_shared_action *psa;
+	} ctx;
 
  	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
  	    port_id == (portid_t)RTE_PORT_ALL)
@@ -2397,7 +2409,7 @@ struct rte_flow_shared_action *
  		printf("Cannot allocate contexts for aged flow\n");
  		return;
  	}
-	printf("ID\tGroup\tPrio\tAttr\n");
+	printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
  	nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
  	if (nb_context != total) {
  		printf("Port:%d get aged flows count(%d) != total(%d)\n",
@@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *
  		return;
  	}
  	for (idx = 0; idx < nb_context; idx++) {
-		pf = (struct port_flow *)contexts[idx];
-		if (!pf) {
+		ctx.pf = (struct port_flow *)contexts[idx];
+		if (!ctx.pf) {
  			printf("Error: get Null context in port %u\n", port_id);

app/test-pmd/config.c struct rte_flow_shared_action * · line 2426

Quoted 10 lines
app/test-pmd/config.c +1 -7
  			continue;
  		}
-		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-		       pf->id,
-		       pf->rule.attr->group,
-		       pf->rule.attr->priority,
-		       pf->rule.attr->ingress ? 'i' : '-',
-		       pf->rule.attr->egress ? 'e' : '-',
-		       pf->rule.attr->transfer ? 't' : '-');
+		switch (ctx.pf->ctype) {

At this stage you don't know if the context is 'pf' or 'psa', but you rely that both structure first element is "enum testpmd_context_type" and this requirement is completely undocumented.

Why don't create a common context and pass that one the the age action for both 'pf' & 'psa', like

struct port_flow_age_action_context {
    enum testpmd_context_type ctype;
    union {
        struct port_flow *pf;
        struct port_shared_action *psa;
    } ctx;
};

I think this also prevents to corrupt 'pf' and 'psa' just for age action.

Quoted 23 lines
app/test-pmd/config.c +19 -0
+		case CONTEXT_TYPE_FLOW:
+			printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+								 "\t%c%c%c\t\n",
+			       "Flow",
+			       ctx.pf->id,
+			       ctx.pf->rule.attr->group,
+			       ctx.pf->rule.attr->priority,
+			       ctx.pf->rule.attr->ingress ? 'i' : '-',
+			       ctx.pf->rule.attr->egress ? 'e' : '-',
+			       ctx.pf->rule.attr->transfer ? 't' : '-');
+			break;
+		case CONTEXT_TYPE_SHARED_ACTION:
+			printf("%-20s\t%" PRIu32 "\n", "Shared action",
+			       ctx.psa->id);
+			break;
+		default:
+			printf("Error: invalid context type %u\n", port_id);
+			break;
+		}
  	}
  	if (destroy) {
  		int ret;

app/test-pmd/config.c struct rte_flow_shared_action * · line 2456

Quoted 8 lines
app/test-pmd/config.c +2 -2
@@ -2426,15 +2451,15 @@ struct rte_flow_shared_action *
  		total = 0;
  		printf("\n");
  		for (idx = 0; idx < nb_context; idx++) {
-			pf = (struct port_flow *)contexts[idx];
-			if (!pf)
+			ctx.pf = (struct port_flow *)contexts[idx];
+			if (!ctx.pf || ctx.pf->ctype != CONTEXT_TYPE_FLOW)
  				continue;

When the context is 'CONTEXT_TYPE_SHARED_ACTION', who destroys it?

Quoted 16 lines
app/test-pmd/config.c +2 -2
-			flow_id = pf->id;
+			flow_id = ctx.pf->id;
  			ret = port_flow_destroy(port_id, 1, &flow_id);
  			if (!ret)
  				total++;
  		}
-		printf("%d flows be destroyed\n", total);
+		printf("%d flows destroyed\n", total);
  	}
  	free(contexts);
  }
app/test-pmd/testpmd.h +0 -0
index 519d551..92aaa19 100644

app/test-pmd/testpmd.h struct fwd_stream { · line 150

Quoted 8 lines
app/test-pmd/testpmd.h +5 -0
@@ -143,8 +143,14 @@ struct fwd_stream {
  	struct pkt_burst_stats tx_burst_stats;
  };
 
+enum testpmd_context_type {
+	CONTEXT_TYPE_FLOW,
+	CONTEXT_TYPE_SHARED_ACTION,
+};
+

The enum prefix is too generic, 'CONTEXT_TYPE_', what do you think clarifying what context we are talking about?

Quoted 15 lines
app/test-pmd/testpmd.h +2 -0
  /** Descriptor for a single flow. */
  struct port_flow {
+	enum testpmd_context_type ctype; /**< Context type. */
  	struct port_flow *next; /**< Next flow in list. */
  	struct port_flow *tmp; /**< Temporary linking. */
  	uint32_t id; /**< Flow rule ID. */
@@ -155,6 +161,7 @@ struct port_flow {
 
  /* Descriptor for shared action */
  struct port_shared_action {
+	enum testpmd_context_type ctype; /**< Context type. */
  	struct port_shared_action *next; /**< Next flow in list. */
  	uint32_t id; /**< Shared action ID. */
  	enum rte_flow_action_type type; /**< Action type. */
#2 lore raw

Hi Ferruh

Thank you for the fast review.
Please see inline

From: Ferruh Yigit

Quoted 63 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 7 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
  app/test-pmd/config.c  | 57 ++++++++++++++++++++++++++++++++++++-----

---------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
  app/test-pmd/testpmd.h |  7 +++++++
  2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

e0203f0..3581f3d 100644

app/test-pmd/config.c +0 -0
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 12 lines
app/test-pmd/config.c +3 -1
              return NULL;
      }
      if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-                       error) >= 0)
+                       error) >= 0) {
+             pf->ctype = CONTEXT_TYPE_FLOW;
              return pf;
+     }
      free(pf);
      return NULL;
  }
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
app/test-pmd/config.c +1 -0
      }
      psa->next = *ppsa;
      psa->id = id;
+     psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
      *ppsa = psa;
      *action = psa;
      return 0;
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1860

Quoted 9 lines
app/test-pmd/config.c +6 -0
      ret = action_alloc(port_id, id, &psa);
      if (ret)
              return ret;
+     if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+             struct rte_flow_action_age *age =
+                             (void *)(uintptr_t)(action->conf);
+
+             age->context = psa;
+     }
Quoted 2 lines

The port flow is using 'update_age_action_context()' function, can same function be utilized to update age context for shared action too?

For updating flow context, the code iterates all actions to find the age action - so it worth to call dedicate function. For updating shared action context - it a direct access.
So, they have different search method.

Quoted 53 lines

btw, not sure why 'update_age_action_context()' is not static, if you will touch it can you please make it static function?

And overall this context setting for the age action is requiring the special conditions in the flow create path, can you please check if it can be moved to 'cmdline_flow.c' for age parsing code somehow?

Quoted 33 lines
app/test-pmd/config.c +0 -0
      /* Poisoning to make sure PMDs update it in case of error. */
      memset(&error, 0x22, sizeof(error));
      psa->action = rte_flow_shared_action_create(port_id, conf,

action, @@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *

      void **contexts;
      int nb_context, total = 0, idx;
      struct rte_flow_error error;
app/test-pmd/config.c +4 -1
-     struct port_flow *pf;
+     union {
+             struct port_flow *pf;
+             struct port_shared_action *psa;
+     } ctx;
 
      if (port_id_is_invalid(port_id, ENABLED_WARN) ||
          port_id == (portid_t)RTE_PORT_ALL) @@ -2397,7 +2409,7 @@

struct rte_flow_shared_action *

              printf("Cannot allocate contexts for aged flow\n");
              return;
      }
app/test-pmd/config.c +1 -1
-     printf("ID\tGroup\tPrio\tAttr\n");
+     printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
      nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
      if (nb_context != total) {
              printf("Port:%d get aged flows count(%d) !=

total(%d)\n", @@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *

              return;
      }
      for (idx = 0; idx < nb_context; idx++) {
app/test-pmd/config.c +2 -2
-             pf = (struct port_flow *)contexts[idx];
-             if (!pf) {
+             ctx.pf = (struct port_flow *)contexts[idx];
+             if (!ctx.pf) {
                      printf("Error: get Null context in port %u\n", port_id);

app/test-pmd/config.c struct rte_flow_shared_action * · line 2426

Quoted 10 lines
app/test-pmd/config.c +1 -7
                      continue;
              }
-             printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-                    pf->id,
-                    pf->rule.attr->group,
-                    pf->rule.attr->priority,
-                    pf->rule.attr->ingress ? 'i' : '-',
-                    pf->rule.attr->egress ? 'e' : '-',
-                    pf->rule.attr->transfer ? 't' : '-');
+             switch (ctx.pf->ctype) {
Quoted 3 lines

At this stage you don't know if the context is 'pf' or 'psa', but you rely that both structure first element is "enum testpmd_context_type" and this requirement is completely undocumented.

Yes, will add a comment.

Quoted 11 lines

Why don't create a common context and pass that one the the age action for both 'pf' & 'psa', like

struct port_flow_age_action_context {
     enum testpmd_context_type ctype;
     union {
         struct port_flow *pf;
         struct port_shared_action *psa;
     } ctx;
};

We considered this option too,
It looked us more optimized to not utilize more memory and alloc\free time for each age context.

One more option we considered:

Use age action context pointer as uint32_t\uintptr_t - use 2 bits for type and others for pf->id psa->id. What do you think about this?

Quoted 30 lines

I think this also prevents to corrupt 'pf' and 'psa' just for age action.

Quoted 26 lines
app/test-pmd/config.c +19 -0
+             case CONTEXT_TYPE_FLOW:
+                     printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+                                                              "\t%c%c%c\t\n",
+                            "Flow",
+                            ctx.pf->id,
+                            ctx.pf->rule.attr->group,
+                            ctx.pf->rule.attr->priority,
+                            ctx.pf->rule.attr->ingress ? 'i' : '-',
+                            ctx.pf->rule.attr->egress ? 'e' : '-',
+                            ctx.pf->rule.attr->transfer ? 't' : '-');
+                     break;
+             case CONTEXT_TYPE_SHARED_ACTION:
+                     printf("%-20s\t%" PRIu32 "\n", "Shared action",
+                            ctx.psa->id);
+                     break;
+             default:
+                     printf("Error: invalid context type %u\n", port_id);
+                     break;
+             }
      }
      if (destroy) {
              int ret;
@@ -2426,15 +2451,15 @@ struct rte_flow_shared_action *
              total = 0;
              printf("\n");
              for (idx = 0; idx < nb_context; idx++) {
Quoted 8 lines

app/test-pmd/config.c struct rte_flow_shared_action * · line 2456

Quoted 6 lines
app/test-pmd/config.c +3 -2
-                     pf = (struct port_flow *)contexts[idx];
-                     if (!pf)
+                     ctx.pf = (struct port_flow *)contexts[idx];
+                     if (!ctx.pf || ctx.pf->ctype !=
+ CONTEXT_TYPE_FLOW)
                              continue;

When the context is 'CONTEXT_TYPE_SHARED_ACTION', who destroys it?

Destroy request is optional, I didn't add a support to destroy something here:
1 options here is to save all the flows assigned to the age shared action inside the shared action context and destroy all of them + the shared aged action. It can be step 2 later.

Quoted 20 lines
Quoted 20 lines
app/test-pmd/config.c +2 -2
-                     flow_id = pf->id;
+                     flow_id = ctx.pf->id;
                      ret = port_flow_destroy(port_id, 1, &flow_id);
                      if (!ret)
                              total++;
              }
-             printf("%d flows be destroyed\n", total);
+             printf("%d flows destroyed\n", total);
      }
      free(contexts);
  }
app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0 -0

519d551..92aaa19 100644

app/test-pmd/testpmd.h +0 -0
@@ -143,8 +143,14 @@ struct fwd_stream {
      struct pkt_burst_stats tx_burst_stats;
  };
 
Quoted 8 lines

app/test-pmd/testpmd.h struct fwd_stream { · line 150

Quoted 5 lines
app/test-pmd/testpmd.h +5 -0
+enum testpmd_context_type {
+     CONTEXT_TYPE_FLOW,
+     CONTEXT_TYPE_SHARED_ACTION,
+};
+

The enum prefix is too generic, 'CONTEXT_TYPE_', what do you think clarifying what context we are talking about?

enum flow_age_action_context_type {
FLOW_AGE_ACTION_CTX_FLOW,
FLOW_AGE_ACTION_CTX_SHARED_ACTION,
}

?

Quoted 9 lines
Quoted 9 lines
app/test-pmd/testpmd.h +1 -0
  /** Descriptor for a single flow. */
  struct port_flow {
+     enum testpmd_context_type ctype; /**< Context type. */
      struct port_flow *next; /**< Next flow in list. */
      struct port_flow *tmp; /**< Temporary linking. */
      uint32_t id; /**< Flow rule ID. */ @@ -155,6 +161,7 @@ struct

port_flow {

Quoted 7 lines
Quoted 7 lines

/* Descriptor for shared action */
struct port_shared_action {
+ enum testpmd_context_type ctype; /**< Context type. */
struct port_shared_action *next; /**< Next flow in list. */ uint32_t id; /**< Shared action ID. */
enum rte_flow_action_type type; /**< Action type. */

What do you think about changing the rte_flow_get_aged_flows API name to rte_flow_get_aged_contexts ?

Matan

#3 lore raw
Quoted 69 lines · Matan Azrad

Hi Ferruh

Thank you for the fast review.
Please see inline

From: Ferruh Yigit

Quoted 63 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 7 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
   app/test-pmd/config.c  | 57 ++++++++++++++++++++++++++++++++++++-----

---------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
   app/test-pmd/testpmd.h |  7 +++++++
   2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

e0203f0..3581f3d 100644

app/test-pmd/config.c +0 -0
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 12 lines
app/test-pmd/config.c +3 -1
               return NULL;
       }
       if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-                       error) >= 0)
+                       error) >= 0) {
+             pf->ctype = CONTEXT_TYPE_FLOW;
               return pf;
+     }
       free(pf);
       return NULL;
   }
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
app/test-pmd/config.c +1 -0
       }
       psa->next = *ppsa;
       psa->id = id;
+     psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
       *ppsa = psa;
       *action = psa;
       return 0;
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

Quoted 9 lines
app/test-pmd/config.c +6 -0
       ret = action_alloc(port_id, id, &psa);
       if (ret)
               return ret;
+     if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+             struct rte_flow_action_age *age =
+                             (void *)(uintptr_t)(action->conf);
+
+             age->context = psa;
+     }
Quoted 7 lines
Quoted 2 lines

The port flow is using 'update_age_action_context()' function, can same function be utilized to update age context for shared action too?

For updating flow context, the code iterates all actions to find the age action - so it worth to call dedicate function. For updating shared action context - it a direct access.
So, they have different search method.

Just to reduce the age action related churn in the code, if it can be abstracted in to a single function I prefer it, if that doesn't make sense it is OK.

Quoted 72 lines
Quoted 54 lines

btw, not sure why 'update_age_action_context()' is not static, if you will touch it can you please make it static function?

And overall this context setting for the age action is requiring the special conditions in the flow create path, can you please check if it can be moved to 'cmdline_flow.c' for age parsing code somehow?

Quoted 33 lines
app/test-pmd/config.c +0 -0
       /* Poisoning to make sure PMDs update it in case of error. */
       memset(&error, 0x22, sizeof(error));
       psa->action = rte_flow_shared_action_create(port_id, conf,

action, @@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *

       void **contexts;
       int nb_context, total = 0, idx;
       struct rte_flow_error error;
app/test-pmd/config.c +4 -1
-     struct port_flow *pf;
+     union {
+             struct port_flow *pf;
+             struct port_shared_action *psa;
+     } ctx;
 
       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
           port_id == (portid_t)RTE_PORT_ALL) @@ -2397,7 +2409,7 @@

struct rte_flow_shared_action *

               printf("Cannot allocate contexts for aged flow\n");
               return;
       }
app/test-pmd/config.c +1 -1
-     printf("ID\tGroup\tPrio\tAttr\n");
+     printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
       nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
       if (nb_context != total) {
               printf("Port:%d get aged flows count(%d) !=

total(%d)\n", @@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *

               return;
       }
       for (idx = 0; idx < nb_context; idx++) {
app/test-pmd/config.c +2 -2
-             pf = (struct port_flow *)contexts[idx];
-             if (!pf) {
+             ctx.pf = (struct port_flow *)contexts[idx];
+             if (!ctx.pf) {
                       printf("Error: get Null context in port %u\n", port_id);

app/test-pmd/config.c struct rte_flow_shared_action * · line 2426

Quoted 10 lines
app/test-pmd/config.c +1 -7
                       continue;
               }
-             printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-                    pf->id,
-                    pf->rule.attr->group,
-                    pf->rule.attr->priority,
-                    pf->rule.attr->ingress ? 'i' : '-',
-                    pf->rule.attr->egress ? 'e' : '-',
-                    pf->rule.attr->transfer ? 't' : '-');
+             switch (ctx.pf->ctype) {
Quoted 3 lines

At this stage you don't know if the context is 'pf' or 'psa', but you rely that both structure first element is "enum testpmd_context_type" and this requirement is completely undocumented.

Yes, will add a comment.

Quoted 11 lines

Why don't create a common context and pass that one the the age action for both 'pf' & 'psa', like

struct port_flow_age_action_context {
      enum testpmd_context_type ctype;
      union {
          struct port_flow *pf;
          struct port_shared_action *psa;
      } ctx;
};
Quoted 8 lines

We considered this option too,
It looked us more optimized to not utilize more memory and alloc\free time for each age context.

One more option we considered:

Use age action context pointer as uint32_t\uintptr_t - use 2 bits for type and others for pf->id psa->id. What do you think about this?

Will 'id' be enough? I see other information is used, though not sure if it is only for print.

I will be unexpected to use the pointer for id but it works, can you please add enough comment to clarify the usage?

Quoted 40 lines
Quoted 31 lines

I think this also prevents to corrupt 'pf' and 'psa' just for age action.

Quoted 26 lines
app/test-pmd/config.c +19 -0
+             case CONTEXT_TYPE_FLOW:
+                     printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+                                                              "\t%c%c%c\t\n",
+                            "Flow",
+                            ctx.pf->id,
+                            ctx.pf->rule.attr->group,
+                            ctx.pf->rule.attr->priority,
+                            ctx.pf->rule.attr->ingress ? 'i' : '-',
+                            ctx.pf->rule.attr->egress ? 'e' : '-',
+                            ctx.pf->rule.attr->transfer ? 't' : '-');
+                     break;
+             case CONTEXT_TYPE_SHARED_ACTION:
+                     printf("%-20s\t%" PRIu32 "\n", "Shared action",
+                            ctx.psa->id);
+                     break;
+             default:
+                     printf("Error: invalid context type %u\n", port_id);
+                     break;
+             }
       }
       if (destroy) {
               int ret;
@@ -2426,15 +2451,15 @@ struct rte_flow_shared_action *
               total = 0;
               printf("\n");
               for (idx = 0; idx < nb_context; idx++) {
Quoted 8 lines

app/test-pmd/config.c struct rte_flow_shared_action * · line 2456

Quoted 6 lines
app/test-pmd/config.c +3 -2
-                     pf = (struct port_flow *)contexts[idx];
-                     if (!pf)
+                     ctx.pf = (struct port_flow *)contexts[idx];
+                     if (!ctx.pf || ctx.pf->ctype !=
+ CONTEXT_TYPE_FLOW)
                               continue;

When the context is 'CONTEXT_TYPE_SHARED_ACTION', who destroys it?

Quoted 4 lines

Destroy request is optional, I didn't add a support to destroy something here:
1 options here is to save all the flows assigned to the age shared action inside the shared action context and destroy all of them + the shared aged action. It can be step 2 later.

OK

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
app/test-pmd/config.c +2 -2
-                     flow_id = pf->id;
+                     flow_id = ctx.pf->id;
                       ret = port_flow_destroy(port_id, 1, &flow_id);
                       if (!ret)
                               total++;
               }
-             printf("%d flows be destroyed\n", total);
+             printf("%d flows destroyed\n", total);
       }
       free(contexts);
   }
app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0 -0

519d551..92aaa19 100644

app/test-pmd/testpmd.h +0 -0
@@ -143,8 +143,14 @@ struct fwd_stream {
       struct pkt_burst_stats tx_burst_stats;
   };
 
Quoted 8 lines

app/test-pmd/testpmd.h struct fwd_stream { · line 150

Quoted 5 lines
app/test-pmd/testpmd.h +5 -0
+enum testpmd_context_type {
+     CONTEXT_TYPE_FLOW,
+     CONTEXT_TYPE_SHARED_ACTION,
+};
+

The enum prefix is too generic, 'CONTEXT_TYPE_', what do you think clarifying what context we are talking about?

Quoted 6 lines

enum flow_age_action_context_type {
FLOW_AGE_ACTION_CTX_FLOW,
FLOW_AGE_ACTION_CTX_SHARED_ACTION,
}

?

I think better, thanks.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
app/test-pmd/testpmd.h +1 -0
   /** Descriptor for a single flow. */
   struct port_flow {
+     enum testpmd_context_type ctype; /**< Context type. */
       struct port_flow *next; /**< Next flow in list. */
       struct port_flow *tmp; /**< Temporary linking. */
       uint32_t id; /**< Flow rule ID. */ @@ -155,6 +161,7 @@ struct

port_flow {

Quoted 7 lines
Quoted 7 lines
   /* Descriptor for shared action */
   struct port_shared_action {

+ enum testpmd_context_type ctype; /**< Context type. */
struct port_shared_action *next; /**< Next flow in list. */ uint32_t id; /**< Shared action ID. */
enum rte_flow_action_type type; /**< Action type. */

Quoted 2 lines

What do you think about changing the rte_flow_get_aged_flows API name to rte_flow_get_aged_contexts ?

Here context has some data do identify the aged flows, right? If so 'rte_flow_get_aged_flows' also reasonable I think.

No strong opinion but the API name as it is looks good to me.

#4 lore raw

From: Ferruh Yigit

Quoted 164 lines · Matan Azrad
Quoted 72 lines

Hi Ferruh

Thank you for the fast review.
Please see inline

From: Ferruh Yigit

Quoted 66 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
   app/test-pmd/config.c  | 57

++++++++++++++++++++++++++++++++++++-----

---------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1665

Quoted 9 lines
   app/test-pmd/testpmd.h |  7 +++++++
   2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

e0203f0..3581f3d 100644

app/test-pmd/config.c +0 -0
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 12 lines
app/test-pmd/config.c +3 -1
               return NULL;
       }
       if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-                       error) >= 0)
+                       error) >= 0) {
+             pf->ctype = CONTEXT_TYPE_FLOW;
               return pf;
+     }
       free(pf);
       return NULL;
   }
app/test-pmd/config.c +0 -0
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1852

Quoted 9 lines
app/test-pmd/config.c +1 -0
       }
       psa->next = *ppsa;
       psa->id = id;
+     psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
       *ppsa = psa;
       *action = psa;
       return 0;
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 9 lines
app/test-pmd/config.c +6 -0
       ret = action_alloc(port_id, id, &psa);
       if (ret)
               return ret;
+     if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+             struct rte_flow_action_age *age =
+                             (void *)(uintptr_t)(action->conf);
+
+             age->context = psa;
+     }
Quoted 4 lines
Quoted 2 lines

The port flow is using 'update_age_action_context()' function, can same function be utilized to update age context for shared action too?

For updating flow context, the code iterates all actions to find the age action -

so it worth to call dedicate function.

Quoted 3 lines

For updating shared action context - it a direct access. So, they have different search method.

Just to reduce the age action related churn in the code, if it can be abstracted in to a single function I prefer it, if that doesn't make sense it is OK.

Quoted 22 lines
Quoted 22 lines

btw, not sure why 'update_age_action_context()' is not static, if you will touch it can you please make it static function?

And overall this context setting for the age action is requiring the special conditions in the flow create path, can you please check if it can be moved to 'cmdline_flow.c' for age parsing code somehow?

Quoted 13 lines
app/test-pmd/config.c +0 -0
       /* Poisoning to make sure PMDs update it in case of error. */
       memset(&error, 0x22, sizeof(error));
       psa->action = rte_flow_shared_action_create(port_id, conf,
action, @@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *
       void **contexts;
       int nb_context, total = 0, idx;
       struct rte_flow_error error;
app/test-pmd/config.c +4 -1
-     struct port_flow *pf;
+     union {
+             struct port_flow *pf;
+             struct port_shared_action *psa;
+     } ctx;
Quoted 9 lines
Quoted 9 lines

app/test-pmd/config.c struct rte_flow_shared_action *

Quoted 9 lines
       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
           port_id == (portid_t)RTE_PORT_ALL) @@ -2397,7 +2409,7 @@
struct rte_flow_shared_action *
               printf("Cannot allocate contexts for aged flow\n");
               return;
       }
app/test-pmd/config.c +1 -1
-     printf("ID\tGroup\tPrio\tAttr\n");
+     printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
       nb_context = rte_flow_get_aged_flows(port_id, contexts, total,

&error);

Quoted 41 lines
Quoted 23 lines
Quoted 11 lines
       if (nb_context != total) {
               printf("Port:%d get aged flows count(%d) !=
total(%d)\n", @@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *
               return;
       }
       for (idx = 0; idx < nb_context; idx++) {
app/test-pmd/config.c +2 -2
-             pf = (struct port_flow *)contexts[idx];
-             if (!pf) {
+             ctx.pf = (struct port_flow *)contexts[idx];
+             if (!ctx.pf) {
                       printf("Error: get Null context in port %u\n", port_id);

app/test-pmd/config.c struct rte_flow_shared_action * · line 2426

Quoted 10 lines
app/test-pmd/config.c +1 -7
                       continue;
               }
-             printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-                    pf->id,
-                    pf->rule.attr->group,
-                    pf->rule.attr->priority,
-                    pf->rule.attr->ingress ? 'i' : '-',
-                    pf->rule.attr->egress ? 'e' : '-',
-                    pf->rule.attr->transfer ? 't' : '-');
+             switch (ctx.pf->ctype) {
Quoted 3 lines

At this stage you don't know if the context is 'pf' or 'psa', but you rely that both structure first element is "enum testpmd_context_type" and this requirement is completely undocumented.

Yes, will add a comment.

Quoted 11 lines

Why don't create a common context and pass that one the the age action for both 'pf' & 'psa', like

struct port_flow_age_action_context {
      enum testpmd_context_type ctype;
      union {
          struct port_flow *pf;
          struct port_shared_action *psa;
      } ctx;
};
Quoted 2 lines

We considered this option too,
It looked us more optimized to not utilize more memory and alloc\free time

for each age context.

Quoted 3 lines

One more option we considered:

Quoted 8 lines
Quoted 1 line

Use age action context pointer as uint32_t\uintptr_t - use 2 bits for type and

others for pf->id psa->id.

Quoted 2 lines

What do you think about this?

Will 'id' be enough? I see other information is used, though not sure if it is only for print.

From the id we can get the pointer(and other information) - this is the same ID as supplied by the command line user to query\destroy an existed flows.

Quoted 2 lines

I will be unexpected to use the pointer for id but it works, can you please add enough comment to clarify the usage?

If you mean code comment, yes I will add.

Quoted 104 lines
Quoted 40 lines
Quoted 31 lines

I think this also prevents to corrupt 'pf' and 'psa' just for age action.

Quoted 26 lines
app/test-pmd/config.c +19 -0
+             case CONTEXT_TYPE_FLOW:
+                     printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+                                                              "\t%c%c%c\t\n",
+                            "Flow",
+                            ctx.pf->id,
+                            ctx.pf->rule.attr->group,
+                            ctx.pf->rule.attr->priority,
+                            ctx.pf->rule.attr->ingress ? 'i' : '-',
+                            ctx.pf->rule.attr->egress ? 'e' : '-',
+                            ctx.pf->rule.attr->transfer ? 't' : '-');
+                     break;
+             case CONTEXT_TYPE_SHARED_ACTION:
+                     printf("%-20s\t%" PRIu32 "\n", "Shared action",
+                            ctx.psa->id);
+                     break;
+             default:
+                     printf("Error: invalid context type %u\n", port_id);
+                     break;
+             }
       }
       if (destroy) {
               int ret;
@@ -2426,15 +2451,15 @@ struct rte_flow_shared_action *
               total = 0;
               printf("\n");
               for (idx = 0; idx < nb_context; idx++) {
Quoted 8 lines

app/test-pmd/config.c struct rte_flow_shared_action * · line 2456

Quoted 6 lines
app/test-pmd/config.c +3 -2
-                     pf = (struct port_flow *)contexts[idx];
-                     if (!pf)
+                     ctx.pf = (struct port_flow *)contexts[idx];
+                     if (!ctx.pf || ctx.pf->ctype !=
+ CONTEXT_TYPE_FLOW)
                               continue;

When the context is 'CONTEXT_TYPE_SHARED_ACTION', who destroys it?

Quoted 2 lines

Destroy request is optional, I didn't add a support to destroy something here:
1 options here is to save all the flows assigned to the age shared action inside

the shared action context and destroy all of them + the shared aged action.

Quoted 2 lines

It can be step 2 later.

OK

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
app/test-pmd/config.c +2 -2
-                     flow_id = pf->id;
+                     flow_id = ctx.pf->id;
                       ret = port_flow_destroy(port_id, 1, &flow_id);
                       if (!ret)
                               total++;
               }
-             printf("%d flows be destroyed\n", total);
+             printf("%d flows destroyed\n", total);
       }
       free(contexts);
   }
app/test-pmd/testpmd.h index renamed from app/test-pmd/testpmd.h +0 -0

519d551..92aaa19 100644

app/test-pmd/testpmd.h +0 -0
@@ -143,8 +143,14 @@ struct fwd_stream {
       struct pkt_burst_stats tx_burst_stats;
   };
 
Quoted 8 lines

app/test-pmd/testpmd.h struct fwd_stream { · line 150

Quoted 5 lines
app/test-pmd/testpmd.h +5 -0
+enum testpmd_context_type {
+     CONTEXT_TYPE_FLOW,
+     CONTEXT_TYPE_SHARED_ACTION,
+};
+

The enum prefix is too generic, 'CONTEXT_TYPE_', what do you think clarifying what context we are talking about?

Quoted 6 lines

enum flow_age_action_context_type {
FLOW_AGE_ACTION_CTX_FLOW,
FLOW_AGE_ACTION_CTX_SHARED_ACTION,
}

?

I think better, thanks.

Quoted 18 lines
Quoted 16 lines
Quoted 16 lines
app/test-pmd/testpmd.h +1 -0
   /** Descriptor for a single flow. */
   struct port_flow {
+     enum testpmd_context_type ctype; /**< Context type. */
       struct port_flow *next; /**< Next flow in list. */
       struct port_flow *tmp; /**< Temporary linking. */
       uint32_t id; /**< Flow rule ID. */ @@ -155,6 +161,7 @@ struct

port_flow {

   /* Descriptor for shared action */
   struct port_shared_action {

+ enum testpmd_context_type ctype; /**< Context type. */
struct port_shared_action *next; /**< Next flow in list. */ uint32_t id; /**< Shared action ID. */
enum rte_flow_action_type type; /**< Action type. */

Quoted 8 lines
Quoted 1 line

What do you think about changing the rte_flow_get_aged_flows API name to

rte_flow_get_aged_contexts ?

Quoted 1 line

Here context has some data do identify the aged flows, right? If so 'rte_flow_get_aged_flows' also reasonable I think.

No strong opinion but the API name as it is looks good to me.

OK, thanks.

#5 lore raw
Quoted 176 lines · Matan Azrad

From: Ferruh Yigit

Quoted 164 lines · Matan Azrad
Quoted 72 lines

Hi Ferruh

Thank you for the fast review.
Please see inline

From: Ferruh Yigit

Quoted 66 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
    app/test-pmd/config.c  | 57

++++++++++++++++++++++++++++++++++++-----

---------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1665

Quoted 9 lines
    app/test-pmd/testpmd.h |  7 +++++++
    2 files changed, 48 insertions(+), 16 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

e0203f0..3581f3d 100644

app/test-pmd/config.c +0 -0
@@ -1665,8 +1665,10 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 12 lines
app/test-pmd/config.c +3 -1
                return NULL;
        }
        if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
-                       error) >= 0)
+                       error) >= 0) {
+             pf->ctype = CONTEXT_TYPE_FLOW;
                return pf;
+     }
        free(pf);
        return NULL;
    }
app/test-pmd/config.c +0 -0
@@ -1831,6 +1833,7 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1852

Quoted 9 lines
app/test-pmd/config.c +1 -0
        }
        psa->next = *ppsa;
        psa->id = id;
+     psa->ctype = CONTEXT_TYPE_SHARED_ACTION;
        *ppsa = psa;
        *action = psa;
        return 0;
@@ -1849,6 +1852,12 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 9 lines
app/test-pmd/config.c +6 -0
        ret = action_alloc(port_id, id, &psa);
        if (ret)
                return ret;
+     if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+             struct rte_flow_action_age *age =
+                             (void *)(uintptr_t)(action->conf);
+
+             age->context = psa;
+     }
Quoted 4 lines
Quoted 2 lines

The port flow is using 'update_age_action_context()' function, can same function be utilized to update age context for shared action too?

For updating flow context, the code iterates all actions to find the age action -

so it worth to call dedicate function.

Quoted 3 lines

For updating shared action context - it a direct access. So, they have different search method.

Just to reduce the age action related churn in the code, if it can be abstracted in to a single function I prefer it, if that doesn't make sense it is OK.

Quoted 22 lines
Quoted 22 lines

btw, not sure why 'update_age_action_context()' is not static, if you will touch it can you please make it static function?

And overall this context setting for the age action is requiring the special conditions in the flow create path, can you please check if it can be moved to 'cmdline_flow.c' for age parsing code somehow?

Quoted 13 lines
app/test-pmd/config.c +0 -0
        /* Poisoning to make sure PMDs update it in case of error. */
        memset(&error, 0x22, sizeof(error));
        psa->action = rte_flow_shared_action_create(port_id, conf,
action, @@ -2379,7 +2388,10 @@ struct rte_flow_shared_action *
        void **contexts;
        int nb_context, total = 0, idx;
        struct rte_flow_error error;
app/test-pmd/config.c +4 -1
-     struct port_flow *pf;
+     union {
+             struct port_flow *pf;
+             struct port_shared_action *psa;
+     } ctx;
Quoted 9 lines
Quoted 9 lines

app/test-pmd/config.c struct rte_flow_shared_action *

Quoted 9 lines
        if (port_id_is_invalid(port_id, ENABLED_WARN) ||
            port_id == (portid_t)RTE_PORT_ALL) @@ -2397,7 +2409,7 @@
struct rte_flow_shared_action *
                printf("Cannot allocate contexts for aged flow\n");
                return;
        }
app/test-pmd/config.c +1 -1
-     printf("ID\tGroup\tPrio\tAttr\n");
+     printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
        nb_context = rte_flow_get_aged_flows(port_id, contexts, total,

&error);

Quoted 41 lines
Quoted 23 lines
Quoted 11 lines
        if (nb_context != total) {
                printf("Port:%d get aged flows count(%d) !=
total(%d)\n", @@ -2406,18 +2418,31 @@ struct rte_flow_shared_action *
                return;
        }
        for (idx = 0; idx < nb_context; idx++) {
app/test-pmd/config.c +2 -2
-             pf = (struct port_flow *)contexts[idx];
-             if (!pf) {
+             ctx.pf = (struct port_flow *)contexts[idx];
+             if (!ctx.pf) {
                        printf("Error: get Null context in port %u\n", port_id);

app/test-pmd/config.c struct rte_flow_shared_action * · line 2426

Quoted 10 lines
app/test-pmd/config.c +1 -7
                        continue;
                }
-             printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-                    pf->id,
-                    pf->rule.attr->group,
-                    pf->rule.attr->priority,
-                    pf->rule.attr->ingress ? 'i' : '-',
-                    pf->rule.attr->egress ? 'e' : '-',
-                    pf->rule.attr->transfer ? 't' : '-');
+             switch (ctx.pf->ctype) {
Quoted 3 lines

At this stage you don't know if the context is 'pf' or 'psa', but you rely that both structure first element is "enum testpmd_context_type" and this requirement is completely undocumented.

Yes, will add a comment.

Quoted 11 lines

Why don't create a common context and pass that one the the age action for both 'pf' & 'psa', like

struct port_flow_age_action_context {
       enum testpmd_context_type ctype;
       union {
           struct port_flow *pf;
           struct port_shared_action *psa;
       } ctx;
};
Quoted 2 lines

We considered this option too,
It looked us more optimized to not utilize more memory and alloc\free time

for each age context.

Quoted 3 lines

One more option we considered:

Quoted 8 lines
Quoted 1 line

Use age action context pointer as uint32_t\uintptr_t - use 2 bits for type and

others for pf->id psa->id.

Quoted 2 lines

What do you think about this?

Will 'id' be enough? I see other information is used, though not sure if it is only for print.

Quoted 7 lines

From the id we can get the pointer(and other information) - this is the same ID as supplied by the command line user to query\destroy an existed flows.

Quoted 2 lines

I will be unexpected to use the pointer for id but it works, can you please add enough comment to clarify the usage?

If you mean code comment, yes I will add.

Yes, thanks.

#6 lore raw

PATCH v2 1/1 app/testpmd: support age shared action context

In reply to Matan Azrad

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
 app/test-pmd/config.c  | 119 ++++++++++++++++++++++++++++++++++---------------
 app/test-pmd/testpmd.h |   5 +++
 2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c +82 -37
index 755d1df..00a7dd1 100644
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	}
 }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type type, void *obj)
+{
+	uintptr_t value = (uintptr_t)obj;
+
+	/*
+	 * obj is allocated by malloc\calloc which must return an address
+	 * aligned to 8.
+	 * Use the last 2 bits for the age context type.
+	 */
+	value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+	*ctx = (void *)value;
+}
+
+static void *
+parse_age_action_context(void *ctx, enum action_age_context_type *type)
+
+{
+	uintptr_t value = (uintptr_t)ctx;
+
+	*type = (enum action_age_context_type)(value & AGE_ACTION_TYPE_MASK);
+	value &= ~(uintptr_t)AGE_ACTION_TYPE_MASK;
+	return (void *)value;
+}
+
 static struct port_shared_action *
 action_get_by_id(portid_t port_id, uint32_t id)
 {
@@ -1849,6 +1876,14 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	ret = action_alloc(port_id, id, &psa);
 	if (ret)
 		return ret;
+	if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+		struct rte_flow_action_age *age =
+			(struct rte_flow_action_age *)(uintptr_t)(action->conf);
+
+		set_age_action_context(&age->context,
+				       ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION,
+				       psa);
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	psa->action = rte_flow_shared_action_create(port_id, conf, action,
@@ -2113,24 +2148,20 @@ struct rte_flow_shared_action *
 	return 0;
 }
 
-/** Update age action context by port_flow pointer. */
-void
-update_age_action_context(const struct rte_flow_action *actions,
-			struct port_flow *pf)
+/** Return age action structure if exists, otherwise NULL. */
+static struct rte_flow_action_age *
+age_action_get(const struct rte_flow_action *actions)
 {
-	struct rte_flow_action_age *age = NULL;
-
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
 		switch (actions->type) {
 		case RTE_FLOW_ACTION_TYPE_AGE:
-			age = (struct rte_flow_action_age *)
+			return (struct rte_flow_action_age *)
 				(uintptr_t)actions->conf;
-			age->context = pf;
-			return;
 		default:
 			break;
 		}
 	}
+	return NULL;
 }
 
 /** Create flow rule. */
@@ -2147,6 +2178,7 @@ struct rte_flow_shared_action *
 	uint32_t id = 0;
 	struct rte_flow_error error;
 	struct port_flow_tunnel *pft = NULL;
+	struct rte_flow_action_age *age = age_action_get(actions);
 
 	port = &ports[port_id];
 	if (port->flow_list) {
@@ -2170,7 +2202,9 @@ struct rte_flow_shared_action *
 	pf = port_flow_new(attr, pattern, actions, &error);
 	if (!pf)
 		return port_flow_complain(&error);
-	update_age_action_context(actions, pf);
+	if (age)
+		set_age_action_context(&age->context,
+				       ACTION_AGE_CONTEXT_TYPE_FLOW, pf);
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	flow = rte_flow_create(port_id, attr, pattern, actions, &error);
@@ -2379,7 +2413,12 @@ struct rte_flow_shared_action *
 	void **contexts;
 	int nb_context, total = 0, idx;
 	struct rte_flow_error error;
-	struct port_flow *pf;
+	enum action_age_context_type type;
+	union {
+		struct port_flow *pf;
+		struct port_shared_action *psa;
+		void *obj;
+	} ctx;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
 	    port_id == (portid_t)RTE_PORT_ALL)
@@ -2397,7 +2436,7 @@ struct rte_flow_shared_action *
 		printf("Cannot allocate contexts for aged flow\n");
 		return;
 	}
-	printf("ID\tGroup\tPrio\tAttr\n");
+	printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
 	nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
 	if (nb_context != total) {
 		printf("Port:%d get aged flows count(%d) != total(%d)\n",
@@ -2405,37 +2444,43 @@ struct rte_flow_shared_action *
 		free(contexts);
 		return;
 	}
+	total = 0;
 	for (idx = 0; idx < nb_context; idx++) {
-		pf = (struct port_flow *)contexts[idx];
-		if (!pf) {
+		if (!contexts[idx]) {
 			printf("Error: get Null context in port %u\n", port_id);
 			continue;
 		}
-		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-		       pf->id,
-		       pf->rule.attr->group,
-		       pf->rule.attr->priority,
-		       pf->rule.attr->ingress ? 'i' : '-',
-		       pf->rule.attr->egress ? 'e' : '-',
-		       pf->rule.attr->transfer ? 't' : '-');
-	}
-	if (destroy) {
-		int ret;
-		uint32_t flow_id;
-
-		total = 0;
-		printf("\n");
-		for (idx = 0; idx < nb_context; idx++) {
-			pf = (struct port_flow *)contexts[idx];
-			if (!pf)
-				continue;
-			flow_id = pf->id;
-			ret = port_flow_destroy(port_id, 1, &flow_id);
-			if (!ret)
-				total++;
+		ctx.obj = parse_age_action_context(contexts[idx], &type);
+		if (!ctx.obj) {
+			printf("Error: get Null age context in port %u\n",
+			       port_id);
+			continue;
+		}
+		switch (type) {
+		case ACTION_AGE_CONTEXT_TYPE_FLOW:
+			printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+								 "\t%c%c%c\t\n",
+			       "Flow",
+			       ctx.pf->id,
+			       ctx.pf->rule.attr->group,
+			       ctx.pf->rule.attr->priority,
+			       ctx.pf->rule.attr->ingress ? 'i' : '-',
+			       ctx.pf->rule.attr->egress ? 'e' : '-',
+			       ctx.pf->rule.attr->transfer ? 't' : '-');
+			if (destroy && !port_flow_destroy(port_id, 1,
+							  &ctx.pf->id))
+					total++;
+			break;
+		case ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION:
+			printf("%-20s\t%" PRIu32 "\n", "Shared action",
+			       ctx.psa->id);
+			break;
+		default:
+			printf("Error: invalid context type %u\n", port_id);
+			break;
 		}
-		printf("%d flows be destroyed\n", total);
 	}
+	printf("\n%d flows destroyed\n", total);
 	free(contexts);
 }
 
app/test-pmd/testpmd.h +5 -0
index 519d551..52a6bca 100644
@@ -143,6 +143,11 @@ struct fwd_stream {
 	struct pkt_burst_stats tx_burst_stats;
 };
 
+enum action_age_context_type {
+	ACTION_AGE_CONTEXT_TYPE_FLOW,
+	ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION,
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
Signature · 1 line
1.8.3.1
#7 lore raw
Quoted 35 lines · Matan Azrad

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
  app/test-pmd/config.c  | 119 ++++++++++++++++++++++++++++++++++---------------
  app/test-pmd/testpmd.h |   5 +++
  2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c +4 -0
index 755d1df..00a7dd1 100644
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
  	}
  }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type type, void *obj)

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 10 lines
app/test-pmd/config.c +10 -0
+{
+	uintptr_t value = (uintptr_t)obj;
+
+	/*
+	 * obj is allocated by malloc\calloc which must return an address
+	 * aligned to 8.
+	 * Use the last 2 bits for the age context type.
+	 */
+	value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+	*ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)" OR the address pointer and type seems error prone, although you comment you rely on the alignment.
The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

#8 lore raw

Hi Ferruh

From: Ferruh Yigit

Quoted 45 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 7 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
  app/test-pmd/config.c  | 119 ++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
  app/test-pmd/testpmd.h |   5 +++
  2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
      }
  }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type type,
+void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)"
OR the address pointer and type seems error prone, although you comment you rely on the alignment.

I understand your concern, that's why the context value management is wrapped well by dedicated functions for set and parse. Also it's very optimized way for memory and time especially when we are talking about big scale(see below).

Quoted 6 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it.
Since both the flows and the shared actions are saved in a list we need to traverse all the list in order to get the pointer and the needed information.

#9 lore raw
Quoted 64 lines · Matan Azrad

Hi Ferruh

From: Ferruh Yigit

Quoted 45 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 7 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
   app/test-pmd/config.c  | 119 ++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id,

Quoted 8 lines
   app/test-pmd/testpmd.h |   5 +++
   2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
       }
   }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type type,
+void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)"
OR the address pointer and type seems error prone, although you comment you rely on the alignment.

I understand your concern, that's why the context value management is wrapped well by dedicated functions for set and parse. Also it's very optimized way for memory and time especially when we are talking about big scale(see below).

Quoted 2 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Quoted 8 lines
Quoted 2 lines

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it.
Since both the flows and the shared actions are saved in a list we need to traverse all the list in order to get the pointer and the needed information.

Using 'id' was your idea.

OK, what about back to previous suggestion, adding a new data struct for both pointers and type? Your concern there was the memory consumption, yes although it will require more memory the amount is not unreasonable.

#10 lore raw

From: Ferruh Yigit

Quoted 73 lines · Matan Azrad
Quoted 59 lines

Hi Ferruh

From: Ferruh Yigit

Quoted 47 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
   app/test-pmd/config.c  | 119

++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1763

Quoted 9 lines
   app/test-pmd/testpmd.h |   5 +++
   2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
       }
   }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type
+type, void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)" OR the address pointer and type seems error prone, although you comment you rely on the alignment.

Quoted 1 line

I understand your concern, that's why the context value management is

wrapped well by dedicated functions for set and parse.

Quoted 1 line

Also it's very optimized way for memory and time especially when we are

talking about big scale(see below).

Quoted 9 lines
Quoted 7 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Quoted 7 lines
Quoted 3 lines

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it. Since both the flows and the shared actions are saved in a list we need to

traverse all the list in order to get the pointer and the needed information.

Quoted 1 line

Using 'id' was your idea.

Yes, Now I suggest even better one 😊

Quoted 5 lines

OK, what about back to previous suggestion, adding a new data struct for both pointers and type?
Your concern there was the memory consumption, yes although it will require more memory the amount is not unreasonable.

Think about big scale.
It is not only memory (malloc overhead + ~16B) but also time consuming(malloc).

If we have solution that no need malloc and can do things faster, why not to take it?
I don't see here a bug - malloc alignment is a known topic - it should be at least the size of the biggest primitive type.

Matan

#11 lore raw
Quoted 92 lines · Matan Azrad

From: Ferruh Yigit

Quoted 73 lines · Matan Azrad
Quoted 59 lines

Hi Ferruh

From: Ferruh Yigit

Quoted 47 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
    app/test-pmd/config.c  | 119

++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1763

Quoted 9 lines
    app/test-pmd/testpmd.h |   5 +++
    2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
        }
    }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type
+type, void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)" OR the address pointer and type seems error prone, although you comment you rely on the alignment.

Quoted 1 line

I understand your concern, that's why the context value management is

wrapped well by dedicated functions for set and parse.

Quoted 1 line

Also it's very optimized way for memory and time especially when we are

talking about big scale(see below).

Quoted 9 lines
Quoted 7 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Quoted 7 lines
Quoted 3 lines

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it. Since both the flows and the shared actions are saved in a list we need to

traverse all the list in order to get the pointer and the needed information.

Quoted 1 line

Using 'id' was your idea.

Yes, Now I suggest even better one 😊

Quoted 5 lines

OK, what about back to previous suggestion, adding a new data struct for both pointers and type?
Your concern there was the memory consumption, yes although it will require more memory the amount is not unreasonable.

Quoted 6 lines

Think about big scale.
It is not only memory (malloc overhead + ~16B) but also time consuming(malloc).

If we have solution that no need malloc and can do things faster, why not to take it?
I don't see here a bug - malloc alignment is a known topic - it should be at least the size of the biggest primitive type.

I can see there is a cost, either with malloc/free, or traverse the list to find 'id', but updating memory pointer that you will use later to carry more metadata looks hack and error prone to me.

One can do these kind of tricks on their application, but for testpmd which is for testing and reference I didn't like the idea.

#12 lore raw

Hi,
Ferruh and Matan,

Quoted 114 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, November 9, 2020 1:13 PM
To: Matan Azrad <[email protected]>; Wenzhuo Lu <[email protected]>; Beilei Xing <[email protected]>; Bernard Iremonger <[email protected]>; Ori Kam <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] app/testpmd: support age shared action context

Quoted 79 lines · Matan Azrad

From: Ferruh Yigit

Quoted 76 lines · Matan Azrad
Quoted 59 lines

Hi Ferruh

From: Ferruh Yigit

Quoted 47 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
    app/test-pmd/config.c  | 119

++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1763

Quoted 9 lines
    app/test-pmd/testpmd.h |   5 +++
    2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
        }
    }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type
+type, void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops) · line 1779

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)" OR the address pointer and type seems error prone, although you comment you rely on the alignment.

Quoted 1 line

I understand your concern, that's why the context value management is

wrapped well by dedicated functions for set and parse.

Quoted 1 line

Also it's very optimized way for memory and time especially when we are

talking about big scale(see below).

Quoted 12 lines
Quoted 7 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it. Since both the flows and the shared actions are saved in a list we need to

Quoted 9 lines
Quoted 4 lines

traverse all the list in order to get the pointer and the needed information.

Quoted 1 line

Using 'id' was your idea.

Yes, Now I suggest even better one 😊

Quoted 2 lines

OK, what about back to previous suggestion, adding a new data struct for

both

Quoted 2 lines
Quoted 2 lines

pointers and type?
Your concern there was the memory consumption, yes although it will

require

Quoted 4 lines
Quoted 1 line

more memory the amount is not unreasonable.

Think about big scale.
It is not only memory (malloc overhead + ~16B) but also time

consuming(malloc).

Quoted 2 lines

If we have solution that no need malloc and can do things faster, why not to

take it?

Quoted 1 line

I don't see here a bug - malloc alignment is a known topic - it should be at

least the size of the biggest primitive type.

Quoted 1 line
Quoted 7 lines

I can see there is a cost, either with malloc/free, or traverse the list to find 'id', but updating memory pointer that you will use later to carry more metadata
looks hack and error prone to me.

One can do these kind of tricks on their application, but for testpmd which is for testing and reference I didn't like the idea.

I know I'm jumping a bit late, I have a different suggestion. What about creating new struct
Struct context_type {
uint8_t type; /**< holds the type of the context can be enum. */
}
This struct should be added to both shared context and flow. When adding context to the aging action we add the pointer to this struct.

Then when getting the context pointer we cast it to struct context_type, get the value, and based on the type we use parentof function to get to the pointer of the original structure.

The advantages:
1. Just adding one uint8_t to each struct. (not wasting space).
2. Very fast lookup since we just add if on the type and then use parentof.
3. No major changes in structs.
4. Not an hack.
5. save extra allocation.
6. can be expended to support future types.

What do you think?

Best,
Ori

#13 lore raw
Quoted 146 lines · Ori Kam

Hi,
Ferruh and Matan,

Quoted 114 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, November 9, 2020 1:13 PM
To: Matan Azrad <[email protected]>; Wenzhuo Lu <[email protected]>; Beilei Xing <[email protected]>; Bernard Iremonger <[email protected]>; Ori Kam <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] app/testpmd: support age shared action context

Quoted 79 lines · Matan Azrad

From: Ferruh Yigit

Quoted 76 lines · Matan Azrad
Quoted 59 lines

Hi Ferruh

From: Ferruh Yigit

Quoted 47 lines · Matan Azrad
Quoted 13 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration structure.

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
     app/test-pmd/config.c  | 119

++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1763

Quoted 9 lines
     app/test-pmd/testpmd.h |   5 +++
     2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 14 lines
app/test-pmd/config.c +11 -0
         }
     }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type
+type, void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1780

Quoted 3 lines
app/test-pmd/config.c +3 -0
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type * MASK)" OR the address pointer and type seems error prone, although you comment you rely on the alignment.

Quoted 1 line

I understand your concern, that's why the context value management is

wrapped well by dedicated functions for set and parse.

Quoted 1 line

Also it's very optimized way for memory and time especially when we are

talking about big scale(see below).

Quoted 12 lines
Quoted 7 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it. Since both the flows and the shared actions are saved in a list we need to

Quoted 9 lines
Quoted 4 lines

traverse all the list in order to get the pointer and the needed information.

Quoted 1 line

Using 'id' was your idea.

Yes, Now I suggest even better one 😊

Quoted 2 lines

OK, what about back to previous suggestion, adding a new data struct for

both

Quoted 2 lines
Quoted 2 lines

pointers and type?
Your concern there was the memory consumption, yes although it will

require

Quoted 4 lines
Quoted 1 line

more memory the amount is not unreasonable.

Think about big scale.
It is not only memory (malloc overhead + ~16B) but also time

consuming(malloc).

Quoted 2 lines

If we have solution that no need malloc and can do things faster, why not to

take it?

Quoted 1 line

I don't see here a bug - malloc alignment is a known topic - it should be at

least the size of the biggest primitive type.

Quoted 1 line
Quoted 7 lines

I can see there is a cost, either with malloc/free, or traverse the list to find 'id', but updating memory pointer that you will use later to carry more metadata
looks hack and error prone to me.

One can do these kind of tricks on their application, but for testpmd which is for testing and reference I didn't like the idea.

I know I'm jumping a bit late, I have a different suggestion. What about creating new struct
Struct context_type {
uint8_t type; /**< holds the type of the context can be enum. */
}
This struct should be added to both shared context and flow. When adding context to the aging action we add the pointer to this struct.

Then when getting the context pointer we cast it to struct context_type, get the value, and based on the type we use parentof function to get to the pointer of the original structure.

The advantages:
1. Just adding one uint8_t to each struct. (not wasting space).
2. Very fast lookup since we just add if on the type and then use parentof.
3. No major changes in structs.
4. Not an hack.
5. save extra allocation.
6. can be expended to support future types.

Quoted 2 lines

What do you think?

Hi Ori, Matan,

Looks good to me, this is more like first version of the patch but with 'parentof' usage it is safer I think.

#14 lore raw

From: Ferruh Yigit

Quoted 155 lines · Ori Kam
Quoted 24 lines

Hi,
Ferruh and Matan,

Quoted 21 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, November 9, 2020 1:13 PM
To: Matan Azrad <[email protected]>; Wenzhuo Lu <[email protected]>; Beilei Xing <[email protected]>; Bernard Iremonger <[email protected]>; Ori Kam <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] app/testpmd: support age shared action context

Quoted 10 lines · Matan Azrad

From: Ferruh Yigit

Quoted 7 lines · Matan Azrad
Quoted 6 lines

Hi Ferruh

From: Ferruh Yigit

Quoted 3 lines · Matan Azrad
Quoted 2 lines

When an age action becomes aged-out the rte_flow_get_aged_flows should return the action context supplied by the configuration

structure.

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 11 lines

In case the age action created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

Quoted 8 lines

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---
     app/test-pmd/config.c  | 119

++++++++++++++++++++++++++++++++++-------

--------

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1763

Quoted 9 lines
     app/test-pmd/testpmd.h |   5 +++
     2 files changed, 87 insertions(+), 37 deletions(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

755d1df..00a7dd1 100644

app/test-pmd/config.c +0 -0
@@ -1763,6 +1763,33 @@ void port_flow_tunnel_create(portid_t
 port_id,

const struct tunnel_ops *ops)

Quoted 12 lines
app/test-pmd/config.c +9 -0
         }
     }
 
+#define AGE_ACTION_TYPE_MASK 0x3u
+
+static void
+set_age_action_context(void **ctx, enum action_age_context_type
+type, void *obj) {
+     uintptr_t value = (uintptr_t)obj;
+
+     /*
+      * obj is allocated by malloc\calloc which must return an address
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

app/test-pmd/config.c void port_flow_tunnel_create(portid_t · line 1780

Quoted 5 lines
app/test-pmd/config.c +5 -0
+      * aligned to 8.
+      * Use the last 2 bits for the age context type.
+      */
+     value |= (uintptr_t)type & AGE_ACTION_TYPE_MASK;
+     *ctx = (void *)value;

Thanks Matan, I think this is much clear. But I though the 'id' will be used, not the pointer itself, like "uintptr_t value = id | (type *

MASK)"

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
Quoted 2 lines

OR the address pointer and type seems error prone, although you comment you rely on the alignment.

I understand your concern, that's why the context value management is

wrapped well by dedicated functions for set and parse.

Quoted 2 lines

Also it's very optimized way for memory and time especially when we are

talking about big scale(see below).

Quoted 9 lines
Quoted 7 lines

The testpmd usage also kind of sample usage for the applications, I am for not suggesting this for the user applications.

Reserving the two bit of the 'id' reduces the usable 'id' to 30 bits, but it looks still big enough, what do you think?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Yes, it is big enough.
The problem with the id is the latency to get the pointer from it. Since both the flows and the shared actions are saved in a list we need to

traverse all the list in order to get the pointer and the needed

information.

Quoted 54 lines
Quoted 27 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Using 'id' was your idea.

Yes, Now I suggest even better one 😊

Quoted 3 lines

OK, what about back to previous suggestion, adding a new data struct for

both

Quoted 2 lines
Quoted 2 lines

pointers and type?
Your concern there was the memory consumption, yes although it will

require

Quoted 4 lines
Quoted 1 line

more memory the amount is not unreasonable.

Think about big scale.
It is not only memory (malloc overhead + ~16B) but also time

consuming(malloc).

Quoted 3 lines

If we have solution that no need malloc and can do things faster, why not to

take it?

Quoted 2 lines

I don't see here a bug - malloc alignment is a known topic - it should be at

least the size of the biggest primitive type.

Quoted 1 line
Quoted 6 lines

I can see there is a cost, either with malloc/free, or traverse the list to find 'id', but updating memory pointer that you will use later to carry more metadata looks hack and error prone to me.

One can do these kind of tricks on their application, but for testpmd which is for testing and reference I didn't like the idea.

I know I'm jumping a bit late, I have a different suggestion. What about creating new struct
Struct context_type {
uint8_t type; /**< holds the type of the context can be enum. */
} This struct should be added to both shared context and flow. When adding context to the aging action we add the pointer to this struct.

Then when getting the context pointer we cast it to struct context_type, get the value, and based on the type we use parentof function to get to the pointer of the original structure.

The advantages:
1. Just adding one uint8_t to each struct. (not wasting space).
2. Very fast lookup since we just add if on the type and then use parentof.
3. No major changes in structs.
4. Not an hack.
5. save extra allocation.
6. can be expended to support future types.

Quoted 7 lines
Quoted 2 lines

What do you think?

Hi Ori, Matan,

Looks good to me, this is more like first version of the patch but with 'parentof' usage it is safer I think.

Ok, will send v3 soon.
Thanks Ferruh and Ori

#15 lore raw

PATCH v3 1/1 app/testpmd: support age shared action context

In reply to Matan Azrad

When an age action becomes aged-out the next call for rte_flow_get_aged_flows API should return the action context supplied by the action configuration structure.

In case the age action is created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

---

v3:
update age context to point to the context type field inside the context structures.

 app/test-pmd/config.c  | 89 +++++++++++++++++++++++++++++---------------------
 app/test-pmd/testpmd.h | 13 +++++++-
 2 files changed, 64 insertions(+), 38 deletions(-)
app/test-pmd/config.c +52 -37
index 755d1df..91e7542 100644
@@ -1849,6 +1849,13 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	ret = action_alloc(port_id, id, &psa);
 	if (ret)
 		return ret;
+	if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+		struct rte_flow_action_age *age =
+			(struct rte_flow_action_age *)(uintptr_t)(action->conf);
+
+		psa->age_type = ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION;
+		age->context = &psa->age_type;
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	psa->action = rte_flow_shared_action_create(port_id, conf, action,
@@ -1900,8 +1907,8 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 				continue;
 			}
 			*tmp = psa->next;
-			free(psa);
 			printf("Shared action #%u destroyed\n", psa->id);
+			free(psa);
 			break;
 		}
 		if (i == n)
@@ -2113,24 +2120,20 @@ struct rte_flow_shared_action *
 	return 0;
 }
 
-/** Update age action context by port_flow pointer. */
-void
-update_age_action_context(const struct rte_flow_action *actions,
-			struct port_flow *pf)
+/** Return age action structure if exists, otherwise NULL. */
+static struct rte_flow_action_age *
+age_action_get(const struct rte_flow_action *actions)
 {
-	struct rte_flow_action_age *age = NULL;
-
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
 		switch (actions->type) {
 		case RTE_FLOW_ACTION_TYPE_AGE:
-			age = (struct rte_flow_action_age *)
+			return (struct rte_flow_action_age *)
 				(uintptr_t)actions->conf;
-			age->context = pf;
-			return;
 		default:
 			break;
 		}
 	}
+	return NULL;
 }
 
 /** Create flow rule. */
@@ -2147,6 +2150,7 @@ struct rte_flow_shared_action *
 	uint32_t id = 0;
 	struct rte_flow_error error;
 	struct port_flow_tunnel *pft = NULL;
+	struct rte_flow_action_age *age = age_action_get(actions);
 
 	port = &ports[port_id];
 	if (port->flow_list) {
@@ -2170,7 +2174,10 @@ struct rte_flow_shared_action *
 	pf = port_flow_new(attr, pattern, actions, &error);
 	if (!pf)
 		return port_flow_complain(&error);
-	update_age_action_context(actions, pf);
+	if (age) {
+		pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
+		age->context = &pf->age_type;
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	flow = rte_flow_create(port_id, attr, pattern, actions, &error);
@@ -2379,7 +2386,11 @@ struct rte_flow_shared_action *
 	void **contexts;
 	int nb_context, total = 0, idx;
 	struct rte_flow_error error;
-	struct port_flow *pf;
+	enum age_action_context_type *type;
+	union {
+		struct port_flow *pf;
+		struct port_shared_action *psa;
+	} ctx;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
 	    port_id == (portid_t)RTE_PORT_ALL)
@@ -2397,7 +2408,7 @@ struct rte_flow_shared_action *
 		printf("Cannot allocate contexts for aged flow\n");
 		return;
 	}
-	printf("ID\tGroup\tPrio\tAttr\n");
+	printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
 	nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
 	if (nb_context != total) {
 		printf("Port:%d get aged flows count(%d) != total(%d)\n",
@@ -2405,37 +2416,41 @@ struct rte_flow_shared_action *
 		free(contexts);
 		return;
 	}
+	total = 0;
 	for (idx = 0; idx < nb_context; idx++) {
-		pf = (struct port_flow *)contexts[idx];
-		if (!pf) {
+		if (!contexts[idx]) {
 			printf("Error: get Null context in port %u\n", port_id);
 			continue;
 		}
-		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-		       pf->id,
-		       pf->rule.attr->group,
-		       pf->rule.attr->priority,
-		       pf->rule.attr->ingress ? 'i' : '-',
-		       pf->rule.attr->egress ? 'e' : '-',
-		       pf->rule.attr->transfer ? 't' : '-');
-	}
-	if (destroy) {
-		int ret;
-		uint32_t flow_id;
-
-		total = 0;
-		printf("\n");
-		for (idx = 0; idx < nb_context; idx++) {
-			pf = (struct port_flow *)contexts[idx];
-			if (!pf)
-				continue;
-			flow_id = pf->id;
-			ret = port_flow_destroy(port_id, 1, &flow_id);
-			if (!ret)
+		type = (enum age_action_context_type *)contexts[idx];
+		switch (*type) {
+		case ACTION_AGE_CONTEXT_TYPE_FLOW:
+			ctx.pf = container_of(type, struct port_flow, age_type);
+			printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+								 "\t%c%c%c\t\n",
+			       "Flow",
+			       ctx.pf->id,
+			       ctx.pf->rule.attr->group,
+			       ctx.pf->rule.attr->priority,
+			       ctx.pf->rule.attr->ingress ? 'i' : '-',
+			       ctx.pf->rule.attr->egress ? 'e' : '-',
+			       ctx.pf->rule.attr->transfer ? 't' : '-');
+			if (destroy && !port_flow_destroy(port_id, 1,
+							  &ctx.pf->id))
 				total++;
+			break;
+		case ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION:
+			ctx.psa = container_of(type, struct port_shared_action,
+					       age_type);
+			printf("%-20s\t%" PRIu32 "\n", "Shared action",
+			       ctx.psa->id);
+			break;
+		default:
+			printf("Error: invalid context type %u\n", port_id);
+			break;
 		}
-		printf("%d flows be destroyed\n", total);
 	}
+	printf("\n%d flows destroyed\n", total);
 	free(contexts);
 }
 
app/test-pmd/testpmd.h +12 -1
index 519d551..6b901a8 100644
@@ -143,13 +143,23 @@ struct fwd_stream {
 	struct pkt_burst_stats tx_burst_stats;
 };
 
+/**
+ * Age action context types, must be included inside the age action
+ * context structure.
+ */
+enum age_action_context_type {
+	ACTION_AGE_CONTEXT_TYPE_FLOW,
+	ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION,
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
 	struct port_flow *tmp; /**< Temporary linking. */
 	uint32_t id; /**< Flow rule ID. */
 	struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
-	struct rte_flow_conv_rule rule; /* Saved flow rule description. */
+	struct rte_flow_conv_rule rule; /**< Saved flow rule description. */
+	enum age_action_context_type age_type; /**< Age action context type. */
 	uint8_t data[]; /**< Storage for flow rule description */
 };
 
@@ -159,6 +169,7 @@ struct port_shared_action {
 	uint32_t id; /**< Shared action ID. */
 	enum rte_flow_action_type type; /**< Action type. */
 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
+	enum age_action_context_type age_type; /**< Age action context type. */
 };
 
 struct port_flow_tunnel {
Signature · 1 line
1.8.3.1
Reviewed-by on v3 1/1 Applied
#16 lore raw
Quoted 12 lines · Matan Azrad

When an age action becomes aged-out the next call for rte_flow_get_aged_flows API should return the action context supplied by the action configuration structure.

In case the age action is created by the shared action API, the shared action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the rte_flow_get_aged_flows API didn't consider the fact that the action could be set by the shared action API and considered it as regular flow context.

Quoted 7 lines

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and uses it to parse the aged-out contexts correctly.

Applied to dpdk-next-net/main, thanks.