[dpdk-dev,2/6] service cores: coremask parsing

Message ID 1498208779-166205-2-git-send-email-harry.van.haaren@intel.com (mailing list archive)
State Changes Requested, archived
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Van Haaren, Harry June 23, 2017, 9:06 a.m. UTC
  Add logic for parsing a coremask from EAL, which allows
the application to be unaware of the cores being taken from
its coremask.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/librte_eal/common/eal_common_options.c | 78 ++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
  

Comments

Jerin Jacob June 26, 2017, 12:49 p.m. UTC | #1
-----Original Message-----
> Date: Fri, 23 Jun 2017 10:06:15 +0100
> From: Harry van Haaren <harry.van.haaren@intel.com>
> To: dev@dpdk.org
> CC: thomas@monjalon.net, jerin.jacob@caviumnetworks.com,
>  keith.wiles@intel.com, bruce.richardson@intel.com, Harry van Haaren
>  <harry.van.haaren@intel.com>
> Subject: [PATCH 2/6] service cores: coremask parsing
> X-Mailer: git-send-email 2.7.4
> 
> Add logic for parsing a coremask from EAL, which allows
> the application to be unaware of the cores being taken from
> its coremask.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>  lib/librte_eal/common/eal_common_options.c | 78 ++++++++++++++++++++++++++++++
>  1 file changed, 78 insertions(+)
> 
> diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
> index f470195..3599784 100644
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -50,6 +50,7 @@
>  #include <rte_version.h>
>  #include <rte_devargs.h>
>  #include <rte_memcpy.h>
> +#include <rte_service.h>
>  
>  #include "eal_internal_cfg.h"
>  #include "eal_options.h"
> @@ -61,6 +62,7 @@ const char
>  eal_short_options[] =
>  	"b:" /* pci-blacklist */
>  	"c:" /* coremask */
> +	"s:" /* service coremask */
>  	"d:" /* driver */
>  	"h"  /* help */
>  	"l:" /* corelist */

Good to have a corelist variant for service lcore list. May be for future.

> @@ -267,6 +269,75 @@ static int xdigit2val(unsigned char c)
>  }
>  
>  static int
> +eal_parse_service_coremask(const char *coremask)
> +{
> +	struct rte_config *cfg = rte_eal_get_configuration();
> +	int i, j, idx = 0;
> +	unsigned count = 0;
> +	char c;
> +	int val;
> +
> +	if (coremask == NULL)
> +		return -1;
> +	/* Remove all blank characters ahead and after .
> +	 * Remove 0x/0X if exists.
> +	 */
> +	while (isblank(*coremask))
> +		coremask++;
> +	if (coremask[0] == '0' && ((coremask[1] == 'x')
> +		|| (coremask[1] == 'X')))
> +		coremask += 2;
> +	i = strlen(coremask);
> +	while ((i > 0) && isblank(coremask[i - 1]))
> +		i--;
> +
> +	if (i == 0)
> +		return -1;
> +
> +	printf("\n\nRemoving Service Cores from lcore roles now\n\n");

s/printf/RTE_LOG


> +
> +	/* TODO: only scan active cores in coremask */
> +	for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
> +		c = coremask[i];
> +		if (isxdigit(c) == 0) {
> +			/* invalid characters */
> +			return -1;
> +		}
> +		val = xdigit2val(c);
> +		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
> +				j++, idx++) {
> +			if ((1 << j) & val) {
> +				/* TODO: enable flexible master core */
> +				if (idx == 0)
> +					continue;
> +
> +				if (!lcore_config[idx].detected) {
> +					RTE_LOG(ERR, EAL,
> +						"lcore %u unavailable\n", idx);
> +					return -1;
> +				}
> +				//cfg->lcore_role[idx] = ROLE_SERVICE;

remove commented code.

> +				rte_service_core_add(idx);
> +				count++;
> +			}
> +		}
> +	}
> +
> +	for (; i >= 0; i--)
> +		if (coremask[i] != '0')
> +			return -1;
> +
> +	for (; idx < RTE_MAX_LCORE; idx++)
> +		lcore_config[idx].core_index = -1;
> +
> +	if (count == 0)
> +		return -1;
> +
> +	cfg->score_count = count;
> +	return 0;
> +}
> +
> +static int
>  eal_parse_coremask(const char *coremask)
>  {
>  	struct rte_config *cfg = rte_eal_get_configuration();
> @@ -826,6 +897,13 @@ eal_parse_common_option(int opt, const char *optarg,
>  		}
>  		core_parsed = 1;
>  		break;
> +	/* service coremask */
> +	case 's':
> +		if (eal_parse_service_coremask(optarg) < 0) {
> +			RTE_LOG(ERR, EAL, "invalid service coremask\n");
> +			return -1;
> +		}
> +		break;
>  	/* size of memory */
>  	case 'm':
>  		conf->memory = atoi(optarg);
> --

With above change:

Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
  
Van Haaren, Harry June 29, 2017, 11:13 a.m. UTC | #2
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]

<snip>

> >  #include "eal_internal_cfg.h"
> >  #include "eal_options.h"
> > @@ -61,6 +62,7 @@ const char
> >  eal_short_options[] =
> >  	"b:" /* pci-blacklist */
> >  	"c:" /* coremask */
> > +	"s:" /* service coremask */
> >  	"d:" /* driver */
> >  	"h"  /* help */
> >  	"l:" /* corelist */
> 
> Good to have a corelist variant for service lcore list. May be for future.

Yep agreed.


> > @@ -267,6 +269,75 @@ static int xdigit2val(unsigned char c)
> >  }
> >
> >  static int
> > +eal_parse_service_coremask(const char *coremask)
> > +{
> > +	struct rte_config *cfg = rte_eal_get_configuration();
> > +	int i, j, idx = 0;
> > +	unsigned count = 0;
> > +	char c;
> > +	int val;
> > +
> > +	if (coremask == NULL)
> > +		return -1;
> > +	/* Remove all blank characters ahead and after .
> > +	 * Remove 0x/0X if exists.
> > +	 */
> > +	while (isblank(*coremask))
> > +		coremask++;
> > +	if (coremask[0] == '0' && ((coremask[1] == 'x')
> > +		|| (coremask[1] == 'X')))
> > +		coremask += 2;
> > +	i = strlen(coremask);
> > +	while ((i > 0) && isblank(coremask[i - 1]))
> > +		i--;
> > +
> > +	if (i == 0)
> > +		return -1;
> > +
> > +	printf("\n\nRemoving Service Cores from lcore roles now\n\n");
> 
> s/printf/RTE_LOG

Removed.


> > +	/* TODO: only scan active cores in coremask */
> > +	for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
> > +		c = coremask[i];
> > +		if (isxdigit(c) == 0) {
> > +			/* invalid characters */
> > +			return -1;
> > +		}
> > +		val = xdigit2val(c);
> > +		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
> > +				j++, idx++) {
> > +			if ((1 << j) & val) {
> > +				/* TODO: enable flexible master core */
> > +				if (idx == 0)
> > +					continue;
> > +
> > +				if (!lcore_config[idx].detected) {
> > +					RTE_LOG(ERR, EAL,
> > +						"lcore %u unavailable\n", idx);
> > +					return -1;
> > +				}
> > +				//cfg->lcore_role[idx] = ROLE_SERVICE;
> 
> remove commented code.

Doh - thanks.

<snip>
  

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index f470195..3599784 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -50,6 +50,7 @@ 
 #include <rte_version.h>
 #include <rte_devargs.h>
 #include <rte_memcpy.h>
+#include <rte_service.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_options.h"
@@ -61,6 +62,7 @@  const char
 eal_short_options[] =
 	"b:" /* pci-blacklist */
 	"c:" /* coremask */
+	"s:" /* service coremask */
 	"d:" /* driver */
 	"h"  /* help */
 	"l:" /* corelist */
@@ -267,6 +269,75 @@  static int xdigit2val(unsigned char c)
 }
 
 static int
+eal_parse_service_coremask(const char *coremask)
+{
+	struct rte_config *cfg = rte_eal_get_configuration();
+	int i, j, idx = 0;
+	unsigned count = 0;
+	char c;
+	int val;
+
+	if (coremask == NULL)
+		return -1;
+	/* Remove all blank characters ahead and after .
+	 * Remove 0x/0X if exists.
+	 */
+	while (isblank(*coremask))
+		coremask++;
+	if (coremask[0] == '0' && ((coremask[1] == 'x')
+		|| (coremask[1] == 'X')))
+		coremask += 2;
+	i = strlen(coremask);
+	while ((i > 0) && isblank(coremask[i - 1]))
+		i--;
+
+	if (i == 0)
+		return -1;
+
+	printf("\n\nRemoving Service Cores from lcore roles now\n\n");
+
+	/* TODO: only scan active cores in coremask */
+	for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
+		c = coremask[i];
+		if (isxdigit(c) == 0) {
+			/* invalid characters */
+			return -1;
+		}
+		val = xdigit2val(c);
+		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
+				j++, idx++) {
+			if ((1 << j) & val) {
+				/* TODO: enable flexible master core */
+				if (idx == 0)
+					continue;
+
+				if (!lcore_config[idx].detected) {
+					RTE_LOG(ERR, EAL,
+						"lcore %u unavailable\n", idx);
+					return -1;
+				}
+				//cfg->lcore_role[idx] = ROLE_SERVICE;
+				rte_service_core_add(idx);
+				count++;
+			}
+		}
+	}
+
+	for (; i >= 0; i--)
+		if (coremask[i] != '0')
+			return -1;
+
+	for (; idx < RTE_MAX_LCORE; idx++)
+		lcore_config[idx].core_index = -1;
+
+	if (count == 0)
+		return -1;
+
+	cfg->score_count = count;
+	return 0;
+}
+
+static int
 eal_parse_coremask(const char *coremask)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
@@ -826,6 +897,13 @@  eal_parse_common_option(int opt, const char *optarg,
 		}
 		core_parsed = 1;
 		break;
+	/* service coremask */
+	case 's':
+		if (eal_parse_service_coremask(optarg) < 0) {
+			RTE_LOG(ERR, EAL, "invalid service coremask\n");
+			return -1;
+		}
+		break;
 	/* size of memory */
 	case 'm':
 		conf->memory = atoi(optarg);