[dpdk-dev,v3,3/7] service cores: coremask parsing

Message ID 1499031314-7172-4-git-send-email-harry.van.haaren@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Van Haaren, Harry July 2, 2017, 9:35 p.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>

Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

---

v2:
- Remove printf() (Jerin)
- Remove commented code (Jerin)
- simplified core tracking, no requirement on
  #include rte_service in EAL parsing anymore.
---
 lib/librte_eal/common/eal_common_options.c | 77 ++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
  

Comments

Jerin Jacob July 4, 2017, 12:45 p.m. UTC | #1
-----Original Message-----
> Date: Sun, 2 Jul 2017 22:35:10 +0100
> From: Harry van Haaren <harry.van.haaren@intel.com>
> To: dev@dpdk.org
> CC: jerin.jacob@caviumnetworks.com, thomas@monjalon.net,
>  keith.wiles@intel.com, bruce.richardson@intel.com, Harry van Haaren
>  <harry.van.haaren@intel.com>
> Subject: [PATCH v3 3/7] 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>
> 
> diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
> index f470195..cee200c 100644
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -61,6 +61,7 @@ const char
>  eal_short_options[] =
>  	"b:" /* pci-blacklist */
>  	"c:" /* coremask */
> +	"s:" /* service coremask */
>  	"d:" /* driver */
>  	"h"  /* help */
>  	"l:" /* corelist */
> @@ -267,6 +268,73 @@ static int xdigit2val(unsigned char c)
>  }

Missing the --help update for service coremask details.

I think, EAL arguments are documented in another area of doc directory
as well. Update the documents.


>  
>  static int
> +eal_parse_service_coremask(const char *coremask)
> +{
> +	struct rte_config *cfg = rte_eal_get_configuration();
> +	int i, j, idx = 0;
> +	unsigned int 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;
> +
> +	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) {
> +				/* handle master lcore already parsed */
> +				uint32_t lcore = idx;
> +				if (master_lcore_parsed &&
> +						cfg->master_lcore == lcore)
> +					continue;
> +
> +				if (!lcore_config[idx].detected) {
> +					RTE_LOG(ERR, EAL,
> +						"lcore %u unavailable\n", idx);
> +					return -1;
> +				}
> +				lcore_config[idx].core_role = ROLE_SERVICE;

Why not to use rte_service_lcore_add(idx) here. So that in future some
changes we don't need to touch this file.

I added following code in unit testcase and I have 8 cores system. So I
was expecting cores prints from "0 3 4 5 6 7" as lcore 1 and 2 will be
stolen by service core. But it looks like RTE_LCORE_FOREACH not honoring
previous rte_service_lcore_add() functions.

testsuite_setup(void)
{
+       int i;
+       rte_service_lcore_add(1);
+       rte_service_lcore_add(2);
+
+       RTE_LCORE_FOREACH(i)
+               printf("cores %d\n", i);
  
Van Haaren, Harry July 6, 2017, 2:47 p.m. UTC | #2
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> Sent: Tuesday, July 4, 2017 1:46 PM
> To: Van Haaren, Harry <harry.van.haaren@intel.com>
> Cc: dev@dpdk.org; thomas@monjalon.net; Wiles, Keith <keith.wiles@intel.com>; Richardson,
> Bruce <bruce.richardson@intel.com>
> Subject: Re: [PATCH v3 3/7] service cores: coremask parsing
> 
> -----Original Message-----
> > Date: Sun, 2 Jul 2017 22:35:10 +0100
> > From: Harry van Haaren <harry.van.haaren@intel.com>
> > To: dev@dpdk.org
> > CC: jerin.jacob@caviumnetworks.com, thomas@monjalon.net,
> >  keith.wiles@intel.com, bruce.richardson@intel.com, Harry van Haaren
> >  <harry.van.haaren@intel.com>
> > Subject: [PATCH v3 3/7] 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>
> >
> > diff --git a/lib/librte_eal/common/eal_common_options.c
> b/lib/librte_eal/common/eal_common_options.c
> > index f470195..cee200c 100644
> > --- a/lib/librte_eal/common/eal_common_options.c
> > +++ b/lib/librte_eal/common/eal_common_options.c
> > @@ -61,6 +61,7 @@ const char
> >  eal_short_options[] =
> >  	"b:" /* pci-blacklist */
> >  	"c:" /* coremask */
> > +	"s:" /* service coremask */
> >  	"d:" /* driver */
> >  	"h"  /* help */
> >  	"l:" /* corelist */
> > @@ -267,6 +268,73 @@ static int xdigit2val(unsigned char c)
> >  }
> 
> Missing the --help update for service coremask details.
> 
> I think, EAL arguments are documented in another area of doc directory
> as well. Update the documents.

Will double check / fix this. Replying here now to advance discussion below; 

> >  static int
> > +eal_parse_service_coremask(const char *coremask)
> > +{
> > +	struct rte_config *cfg = rte_eal_get_configuration();
> > +	int i, j, idx = 0;
> > +	unsigned int 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;
> > +
> > +	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) {
> > +				/* handle master lcore already parsed */
> > +				uint32_t lcore = idx;
> > +				if (master_lcore_parsed &&
> > +						cfg->master_lcore == lcore)
> > +					continue;
> > +
> > +				if (!lcore_config[idx].detected) {
> > +					RTE_LOG(ERR, EAL,
> > +						"lcore %u unavailable\n", idx);
> > +					return -1;
> > +				}
> > +				lcore_config[idx].core_role = ROLE_SERVICE;
> 
> Why not to use rte_service_lcore_add(idx) here. So that in future some
> changes we don't need to touch this file.

The issue here is that the hugepages memory that service-cores requires is not available at this point. Keep in mind, the EAL parse-opts runs before almost anything else (makes sense, given we can specify e.g. --no-huge).

Given that there is not rte_malloc() available at this point, we have a few options:
1) Use existing allocated mem, e.g. the lcore_config[] array as above.
2) Delay the parsing of service-core mask until later. Breaks "parse -> validate-> config -> run" workflow.
3) Allocate temp memory to store the service-core indexes, and later free that back (feels hacky to me?)

Current scheme of (1) makes the most sense to me.


> I added following code in unit testcase and I have 8 cores system. So I
> was expecting cores prints from "0 3 4 5 6 7" as lcore 1 and 2 will be
> stolen by service core. But it looks like RTE_LCORE_FOREACH not honoring
> previous rte_service_lcore_add() functions.
> 
> testsuite_setup(void)
> {
> +       int i;
> +       rte_service_lcore_add(1);
> +       rte_service_lcore_add(2);
> +
> +       RTE_LCORE_FOREACH(i)
> +               printf("cores %d\n", i);


Root cause found - and fixed. If you don't strongly object to lcore_config[] method above, then I can prioritize this and try get a patchset up ASAP.
  
Jerin Jacob July 7, 2017, 10:45 a.m. UTC | #3
-----Original Message-----
> Date: Thu, 6 Jul 2017 14:47:20 +0000
> From: "Van Haaren, Harry" <harry.van.haaren@intel.com>
> To: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> CC: "dev@dpdk.org" <dev@dpdk.org>, "thomas@monjalon.net"
>  <thomas@monjalon.net>, "Wiles, Keith" <keith.wiles@intel.com>,
>  "Richardson, Bruce" <bruce.richardson@intel.com>
> Subject: RE: [PATCH v3 3/7] service cores: coremask parsing
> 
> > From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> > Sent: Tuesday, July 4, 2017 1:46 PM
> > To: Van Haaren, Harry <harry.van.haaren@intel.com>
> > Cc: dev@dpdk.org; thomas@monjalon.net; Wiles, Keith <keith.wiles@intel.com>; Richardson,
> > Bruce <bruce.richardson@intel.com>
> > Subject: Re: [PATCH v3 3/7] service cores: coremask parsing
> > 
> > -----Original Message-----
> > > Date: Sun, 2 Jul 2017 22:35:10 +0100
> > > From: Harry van Haaren <harry.van.haaren@intel.com>
> > > To: dev@dpdk.org
> > > CC: jerin.jacob@caviumnetworks.com, thomas@monjalon.net,
> > >  keith.wiles@intel.com, bruce.richardson@intel.com, Harry van Haaren
> > >  <harry.van.haaren@intel.com>
> > > Subject: [PATCH v3 3/7] 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>
> > >
> > > diff --git a/lib/librte_eal/common/eal_common_options.c
> > b/lib/librte_eal/common/eal_common_options.c
> > > index f470195..cee200c 100644
> > > --- a/lib/librte_eal/common/eal_common_options.c
> > > +++ b/lib/librte_eal/common/eal_common_options.c
> > > @@ -61,6 +61,7 @@ const char
> > >  eal_short_options[] =
> > >  	"b:" /* pci-blacklist */
> > >  	"c:" /* coremask */
> > > +	"s:" /* service coremask */
> > >  	"d:" /* driver */
> > >  	"h"  /* help */
> > >  	"l:" /* corelist */
> > > @@ -267,6 +268,73 @@ static int xdigit2val(unsigned char c)
> > >  }
> > 
> > Missing the --help update for service coremask details.
> > 
> > I think, EAL arguments are documented in another area of doc directory
> > as well. Update the documents.
> 
> Will double check / fix this. Replying here now to advance discussion below; 
> 
> > >  static int
> > > +eal_parse_service_coremask(const char *coremask)
> > > +{
> > > +	struct rte_config *cfg = rte_eal_get_configuration();
> > > +	int i, j, idx = 0;
> > > +	unsigned int 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;
> > > +
> > > +	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) {
> > > +				/* handle master lcore already parsed */
> > > +				uint32_t lcore = idx;
> > > +				if (master_lcore_parsed &&
> > > +						cfg->master_lcore == lcore)
> > > +					continue;
> > > +
> > > +				if (!lcore_config[idx].detected) {
> > > +					RTE_LOG(ERR, EAL,
> > > +						"lcore %u unavailable\n", idx);
> > > +					return -1;
> > > +				}
> > > +				lcore_config[idx].core_role = ROLE_SERVICE;
> > 
> > Why not to use rte_service_lcore_add(idx) here. So that in future some
> > changes we don't need to touch this file.
> 
> The issue here is that the hugepages memory that service-cores requires is not available at this point. Keep in mind, the EAL parse-opts runs before almost anything else (makes sense, given we can specify e.g. --no-huge).
> 
> Given that there is not rte_malloc() available at this point, we have a few options:
> 1) Use existing allocated mem, e.g. the lcore_config[] array as above.
> 2) Delay the parsing of service-core mask until later. Breaks "parse -> validate-> config -> run" workflow.
> 3) Allocate temp memory to store the service-core indexes, and later free that back (feels hacky to me?)
> 
> Current scheme of (1) makes the most sense to me.

Yes. Make sense to keep option 1.

One suggestion:
There is a lot duplicate code between new eal_parse_service_coremask() and
eal_parse_coremask() on the same file. I think, we can add a common parsing logic
and on match, the actions can be invoked through function pointer which
is passed in the parsing function.

> 
> 
> > I added following code in unit testcase and I have 8 cores system. So I
> > was expecting cores prints from "0 3 4 5 6 7" as lcore 1 and 2 will be
> > stolen by service core. But it looks like RTE_LCORE_FOREACH not honoring
> > previous rte_service_lcore_add() functions.
> > 
> > testsuite_setup(void)
> > {
> > +       int i;
> > +       rte_service_lcore_add(1);
> > +       rte_service_lcore_add(2);
> > +
> > +       RTE_LCORE_FOREACH(i)
> > +               printf("cores %d\n", i);
> 
> 
> Root cause found - and fixed. If you don't strongly object to lcore_config[] method above, then I can prioritize this and try get a patchset up ASAP.

Great!!

>
  
Van Haaren, Harry July 7, 2017, 10:57 a.m. UTC | #4
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> Sent: Friday, July 7, 2017 11:46 AM
> To: Van Haaren, Harry <harry.van.haaren@intel.com>
> Cc: dev@dpdk.org; thomas@monjalon.net; Wiles, Keith <keith.wiles@intel.com>; Richardson,
> Bruce <bruce.richardson@intel.com>
> Subject: Re: [PATCH v3 3/7] service cores: coremask parsing
> 
> -----Original Message-----
> > Date: Thu, 6 Jul 2017 14:47:20 +0000
> > From: "Van Haaren, Harry" <harry.van.haaren@intel.com>
> > To: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> > CC: "dev@dpdk.org" <dev@dpdk.org>, "thomas@monjalon.net"
> >  <thomas@monjalon.net>, "Wiles, Keith" <keith.wiles@intel.com>,
> >  "Richardson, Bruce" <bruce.richardson@intel.com>
> > Subject: RE: [PATCH v3 3/7] service cores: coremask parsing
> >
> > > From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> > > Sent: Tuesday, July 4, 2017 1:46 PM
> > > To: Van Haaren, Harry <harry.van.haaren@intel.com>
> > > Cc: dev@dpdk.org; thomas@monjalon.net; Wiles, Keith <keith.wiles@intel.com>;
> Richardson,
> > > Bruce <bruce.richardson@intel.com>
> > > Subject: Re: [PATCH v3 3/7] service cores: coremask parsing
> > >
> > > -----Original Message-----
> > > > Date: Sun, 2 Jul 2017 22:35:10 +0100
> > > > From: Harry van Haaren <harry.van.haaren@intel.com>
> > > > To: dev@dpdk.org
> > > > CC: jerin.jacob@caviumnetworks.com, thomas@monjalon.net,
> > > >  keith.wiles@intel.com, bruce.richardson@intel.com, Harry van Haaren
> > > >  <harry.van.haaren@intel.com>
> > > > Subject: [PATCH v3 3/7] 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>
> > > >
> > > > diff --git a/lib/librte_eal/common/eal_common_options.c
> > > b/lib/librte_eal/common/eal_common_options.c
> > > > index f470195..cee200c 100644
> > > > --- a/lib/librte_eal/common/eal_common_options.c
> > > > +++ b/lib/librte_eal/common/eal_common_options.c
> > > > @@ -61,6 +61,7 @@ const char
> > > >  eal_short_options[] =
> > > >  	"b:" /* pci-blacklist */
> > > >  	"c:" /* coremask */
> > > > +	"s:" /* service coremask */
> > > >  	"d:" /* driver */
> > > >  	"h"  /* help */
> > > >  	"l:" /* corelist */
> > > > @@ -267,6 +268,73 @@ static int xdigit2val(unsigned char c)
> > > >  }
> > >
> > > Missing the --help update for service coremask details.
> > >
> > > I think, EAL arguments are documented in another area of doc directory
> > > as well. Update the documents.
> >
> > Will double check / fix this. Replying here now to advance discussion below;
> >
> > > >  static int
> > > > +eal_parse_service_coremask(const char *coremask)
> > > > +{
> > > > +	struct rte_config *cfg = rte_eal_get_configuration();
> > > > +	int i, j, idx = 0;
> > > > +	unsigned int 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;
> > > > +
> > > > +	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) {
> > > > +				/* handle master lcore already parsed */
> > > > +				uint32_t lcore = idx;
> > > > +				if (master_lcore_parsed &&
> > > > +						cfg->master_lcore == lcore)
> > > > +					continue;
> > > > +
> > > > +				if (!lcore_config[idx].detected) {
> > > > +					RTE_LOG(ERR, EAL,
> > > > +						"lcore %u unavailable\n", idx);
> > > > +					return -1;
> > > > +				}
> > > > +				lcore_config[idx].core_role = ROLE_SERVICE;
> > >
> > > Why not to use rte_service_lcore_add(idx) here. So that in future some
> > > changes we don't need to touch this file.
> >
> > The issue here is that the hugepages memory that service-cores requires is not available
> at this point. Keep in mind, the EAL parse-opts runs before almost anything else (makes
> sense, given we can specify e.g. --no-huge).
> >
> > Given that there is not rte_malloc() available at this point, we have a few options:
> > 1) Use existing allocated mem, e.g. the lcore_config[] array as above.
> > 2) Delay the parsing of service-core mask until later. Breaks "parse -> validate->
> config -> run" workflow.
> > 3) Allocate temp memory to store the service-core indexes, and later free that back
> (feels hacky to me?)
> >
> > Current scheme of (1) makes the most sense to me.
> 
> Yes. Make sense to keep option 1.

Great,

> One suggestion:
> There is a lot duplicate code between new eal_parse_service_coremask() and
> eal_parse_coremask() on the same file. I think, we can add a common parsing logic
> and on match, the actions can be invoked through function pointer which
> is passed in the parsing function.

Agreed - lets leave this cleanup of EAL to another patchset. That patchset can consolidate the various coremask functions in EAL and other parts of DPDK (I recall a similar comment for eventdev_pipeline sample-app).


> > > I added following code in unit testcase and I have 8 cores system. So I
> > > was expecting cores prints from "0 3 4 5 6 7" as lcore 1 and 2 will be
> > > stolen by service core. But it looks like RTE_LCORE_FOREACH not honoring
> > > previous rte_service_lcore_add() functions.
> > >
> > > testsuite_setup(void)
> > > {
> > > +       int i;
> > > +       rte_service_lcore_add(1);
> > > +       rte_service_lcore_add(2);
> > > +
> > > +       RTE_LCORE_FOREACH(i)
> > > +               printf("cores %d\n", i);
> >
> >
> > Root cause found - and fixed. If you don't strongly object to lcore_config[] method
> above, then I can prioritize this and try get a patchset up ASAP.
> 
> Great!!

I'm working on improving one of the unit tests to launch app functions to verify ROLE_RTE, and will post then.

Thanks for the input, -Harry
  

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index f470195..cee200c 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -61,6 +61,7 @@  const char
 eal_short_options[] =
 	"b:" /* pci-blacklist */
 	"c:" /* coremask */
+	"s:" /* service coremask */
 	"d:" /* driver */
 	"h"  /* help */
 	"l:" /* corelist */
@@ -267,6 +268,73 @@  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 int 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;
+
+	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) {
+				/* handle master lcore already parsed */
+				uint32_t lcore = idx;
+				if (master_lcore_parsed &&
+						cfg->master_lcore == lcore)
+					continue;
+
+				if (!lcore_config[idx].detected) {
+					RTE_LOG(ERR, EAL,
+						"lcore %u unavailable\n", idx);
+					return -1;
+				}
+				lcore_config[idx].core_role = ROLE_SERVICE;
+				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->service_lcore_count = count;
+	return 0;
+}
+
+static int
 eal_parse_coremask(const char *coremask)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
@@ -409,6 +477,8 @@  eal_parse_master_lcore(const char *arg)
 	if (cfg->master_lcore >= RTE_MAX_LCORE)
 		return -1;
 	master_lcore_parsed = 1;
+	/* ensure master core is not used as service core */
+	lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
 	return 0;
 }
 
@@ -826,6 +896,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);