Message ID | 1415137233-6364-1-git-send-email-thomas.monjalon@6wind.com (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
Hi Thomas, Few questions/comments below. Konstantin > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon > Sent: Tuesday, November 04, 2014 9:41 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH v2] eal: add option --master-lcore > > From: Simon Kuenzer <simon.kuenzer@neclab.eu> > > Enable users to specify the lcore id that is used as master lcore. > > Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> > Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com> > --- > > changes in v2: > - rebase on HEAD including common options for BSD and Linux > - use strtol() instead of atoi() to check syntax errors > - unit tests > > app/test/test.c | 1 + > app/test/test_eal_flags.c | 49 +++++++++++++++++++++++++++++ > lib/librte_eal/bsdapp/eal/eal.c | 7 +++++ > lib/librte_eal/common/eal_common_options.c | 31 ++++++++++++++++++ > lib/librte_eal/common/include/eal_options.h | 2 ++ > lib/librte_eal/linuxapp/eal/eal.c | 7 +++++ > 6 files changed, 97 insertions(+) > > diff --git a/app/test/test.c b/app/test/test.c > index 9bee6bb..2fecff5 100644 > --- a/app/test/test.c > +++ b/app/test/test.c > @@ -82,6 +82,7 @@ do_recursive_call(void) > } actions[] = { > { "run_secondary_instances", test_mp_secondary }, > { "test_missing_c_flag", no_action }, > + { "test_master_lcore_flag", no_action }, > { "test_missing_n_flag", no_action }, > { "test_no_hpet_flag", no_action }, > { "test_whitelist_flag", no_action }, > diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c > index 21e6cca..45020b8 100644 > --- a/app/test/test_eal_flags.c > +++ b/app/test/test_eal_flags.c > @@ -520,6 +520,49 @@ test_missing_c_flag(void) > } > > /* > + * Test --master-lcore option with matching coremask > + */ > +static int > +test_master_lcore_flag(void) > +{ > +#ifdef RTE_EXEC_ENV_BSDAPP > + /* BSD target doesn't support prefixes at this point */ > + const char * prefix = ""; > +#else > + char prefix[PATH_MAX], tmp[PATH_MAX]; > + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { > + printf("Error - unable to get current prefix!\n"); > + return -1; > + } > + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); > +#endif > + > + /* --master-lcore flag but no value */ > + const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"}; > + /* --master-lcore flag with invalid value */ > + const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"}; > + /* --master-lcore flag with invalid value */ > + const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"}; > + /* master lcore not in coremask */ > + const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"}; > + /* valid value */ > + const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"}; > + > + if (launch_proc(argv1) == 0 > + || launch_proc(argv2) == 0 > + || launch_proc(argv3) == 0 > + || launch_proc(argv4) == 0) { > + printf("Error - process ran without error with wrong --master-lcore\n"); > + return -1; > + } > + if (launch_proc(argv5) != 0) { > + printf("Error - process did not run ok with valid --master-lcore\n"); > + return -1; > + } > + return 0; > +} > + > +/* > * Test that the app doesn't run without the -n flag. In all cases > * should give an error and fail to run. > * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf > @@ -1214,6 +1257,12 @@ test_eal_flags(void) > return ret; > } > > + ret = test_master_lcore_flag(); > + if (ret < 0) { > + printf("Error in test_master_lcore_flag()\n"); > + return ret; > + } > + > ret = test_missing_n_flag(); > if (ret < 0) { > printf("Error in test_missing_n_flag()\n"); > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > index ca99cb9..c764fec 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -354,6 +354,13 @@ eal_parse_args(int argc, char **argv) > if (opt == '?') > return -1; > > + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n"); > + eal_usage(prgname); > + return -1; > + } > + > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { > diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c > index 7a5d55e..9166ea1 100644 > --- a/lib/librte_eal/common/eal_common_options.c > +++ b/lib/librte_eal/common/eal_common_options.c > @@ -64,6 +64,7 @@ eal_short_options[] = > const struct option > eal_long_options[] = { > {OPT_HUGE_DIR, 1, 0, OPT_HUGE_DIR_NUM}, > + {OPT_MASTER_LCORE, 1, 0, OPT_MASTER_LCORE_NUM}, > {OPT_PROC_TYPE, 1, 0, OPT_PROC_TYPE_NUM}, > {OPT_NO_SHCONF, 0, 0, OPT_NO_SHCONF_NUM}, > {OPT_NO_HPET, 0, 0, OPT_NO_HPET_NUM}, > @@ -163,6 +164,27 @@ eal_parse_coremask(const char *coremask) > return 0; > } > > +/* Changes the lcore id of the master thread */ > +static int > +eal_parse_master_lcore(const char *arg) > +{ > + long master_lcore; > + char *parsing_end; > + struct rte_config *cfg = rte_eal_get_configuration(); > + > + errno = 0; > + master_lcore = strtol(arg, &parsing_end, 0); > + if (errno || parsing_end == arg) > + return -1; Why not: "errno || parsing_end[0] != 0" ? Otherwise something like "1blah" would be considered as valid input. > + > + if (!(master_lcore >= 0 && master_lcore < RTE_MAX_LCORE)) > + return -1; If negative values are not allowed, then why not: unsigned long master_lcore; ... master_lcore = strtoul(...) ... if(master_clore > RTE_MAX_LCORE) return -1; > + if (cfg->lcore_role[master_lcore] != ROLE_RTE) > + return -1; > + cfg->master_lcore = master_lcore; > + return 0; > +} > + > static int > eal_parse_syslog(const char *facility, struct internal_config *conf) > { > @@ -320,6 +342,14 @@ eal_parse_common_option(int opt, const char *optarg, > conf->process_type = eal_parse_proc_type(optarg); > break; > > + case OPT_MASTER_LCORE_NUM: > + if (eal_parse_master_lcore(optarg) < 0) { > + RTE_LOG(ERR, EAL, "invalid parameter for --" > + OPT_MASTER_LCORE "\n"); > + return -1; > + } > + break; > + > case OPT_VDEV_NUM: > if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, > optarg) < 0) { > @@ -364,6 +394,7 @@ eal_common_usage(void) > "[--proc-type primary|secondary|auto]\n\n" > "EAL common options:\n" > " -c COREMASK : A hexadecimal bitmask of cores to run on\n" > + " --"OPT_MASTER_LCORE" ID: Core ID that is used as master\n" > " -n NUM : Number of memory channels\n" > " -v : Display version information on startup\n" > " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n" > diff --git a/lib/librte_eal/common/include/eal_options.h b/lib/librte_eal/common/include/eal_options.h > index 22819ec..deb872d 100644 > --- a/lib/librte_eal/common/include/eal_options.h > +++ b/lib/librte_eal/common/include/eal_options.h > @@ -43,6 +43,8 @@ enum { > OPT_LONG_MIN_NUM = 256, > #define OPT_HUGE_DIR "huge-dir" > OPT_HUGE_DIR_NUM = OPT_LONG_MIN_NUM, > +#define OPT_MASTER_LCORE "master-lcore" > + OPT_MASTER_LCORE_NUM, > #define OPT_PROC_TYPE "proc-type" > OPT_PROC_TYPE_NUM, > #define OPT_NO_SHCONF "no-shconf" > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index 7a1d087..7fcb349 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -550,6 +550,13 @@ eal_parse_args(int argc, char **argv) > if (opt == '?') > return -1; > > + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n"); > + eal_usage(prgname); > + return -1; > + } > + I don't really like an idea of introducing strict order between -c and "--master-lcore.. Can we move check for coremask_ok/ and assignment of cfg->master_lcore out of while (getopt_long(...)) loop? > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { > -- > 2.1.3
Acked-by: Aaron Campbell <aaron@arbor.net <mailto:aaron@arbor.net>> Minor comments inline below, I don’t need to see another patch. Thanks, -Aaron > On Nov 4, 2014, at 5:40 PM, Thomas Monjalon <thomas.monjalon@6wind.com> wrote: > > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n”); Missing a space between “id” and “after”. > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n”); Same here in the Linux version of the code.
2014-11-05 11:54, Ananyev, Konstantin: > From: Thomas Monjalon > > + long master_lcore; > > + char *parsing_end; > > + struct rte_config *cfg = rte_eal_get_configuration(); > > + > > + errno = 0; > > + master_lcore = strtol(arg, &parsing_end, 0); > > + if (errno || parsing_end == arg) > > + return -1; > > Why not: "errno || parsing_end[0] != 0" > ? > Otherwise something like "1blah" would be considered as valid input. Good point. > > + if (!(master_lcore >= 0 && master_lcore < RTE_MAX_LCORE)) > > + return -1; > > If negative values are not allowed, then why not: > > unsigned long master_lcore; > ... > master_lcore = strtoul(...) > ... > if(master_clore > RTE_MAX_LCORE) > return -1; Matter of taste. Your code is less explicit. But it should be if(master_clore >= RTE_MAX_LCORE) Anyone else to vote for 1 solution or the other? > > + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { > > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > > + "after specifying the coremask\n"); > > + eal_usage(prgname); > > + return -1; > > + } > > + > > I don't really like an idea of introducing strict order between -c and "--master-lcore.. Me too. And Aaron too :) > Can we move check for coremask_ok/ and assignment of cfg->master_lcore out of > while (getopt_long(...)) loop? > > > ret = eal_parse_common_option(opt, optarg, &internal_config); > > /* common parser is not happy */ > > if (ret < 0) { Yes we should move the check outside of the loop. First we should migrate all flags check in a common function for BSD and Linux. Simon made the v1. I made the v2. Any volunteer for the v3?
Thanks, that was quick! Quicker than me, actually. ;-) I started to rebase and modify my previous patch as well but I got a bit stuck because I wanted to try to solve the command order issue that Aaron mentioned. In fact, I agree with him in this point. However, I figured out that more preceding patches might be required to get this proberly done. The issue is that I would like to have all code that changes the master lcore placed completely in eal_common_options.c. Something like eal_common_sanity_check() and eal_common_configure() functions would be needed because eal_parse_common_option() is just called within the option parsing loop. Maybe we can improve this later? I am fine with this patch but I have some comments inlined. In general: acknowledged from my side. Thanks a lot, Simon On 04.11.2014 22:40, Thomas Monjalon wrote: > From: Simon Kuenzer <simon.kuenzer@neclab.eu> > > Enable users to specify the lcore id that is used as master lcore. > > Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> > Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com> > --- > > changes in v2: > - rebase on HEAD including common options for BSD and Linux > - use strtol() instead of atoi() to check syntax errors > - unit tests > > app/test/test.c | 1 + > app/test/test_eal_flags.c | 49 +++++++++++++++++++++++++++++ > lib/librte_eal/bsdapp/eal/eal.c | 7 +++++ > lib/librte_eal/common/eal_common_options.c | 31 ++++++++++++++++++ > lib/librte_eal/common/include/eal_options.h | 2 ++ > lib/librte_eal/linuxapp/eal/eal.c | 7 +++++ > 6 files changed, 97 insertions(+) > > diff --git a/app/test/test.c b/app/test/test.c > index 9bee6bb..2fecff5 100644 > --- a/app/test/test.c > +++ b/app/test/test.c > @@ -82,6 +82,7 @@ do_recursive_call(void) > } actions[] = { > { "run_secondary_instances", test_mp_secondary }, > { "test_missing_c_flag", no_action }, > + { "test_master_lcore_flag", no_action }, > { "test_missing_n_flag", no_action }, > { "test_no_hpet_flag", no_action }, > { "test_whitelist_flag", no_action }, > diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c > index 21e6cca..45020b8 100644 > --- a/app/test/test_eal_flags.c > +++ b/app/test/test_eal_flags.c > @@ -520,6 +520,49 @@ test_missing_c_flag(void) > } > > /* > + * Test --master-lcore option with matching coremask > + */ > +static int > +test_master_lcore_flag(void) > +{ > +#ifdef RTE_EXEC_ENV_BSDAPP > + /* BSD target doesn't support prefixes at this point */ > + const char * prefix = ""; > +#else > + char prefix[PATH_MAX], tmp[PATH_MAX]; > + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { > + printf("Error - unable to get current prefix!\n"); > + return -1; > + } > + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); > +#endif > + > + /* --master-lcore flag but no value */ > + const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"}; > + /* --master-lcore flag with invalid value */ > + const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"}; > + /* --master-lcore flag with invalid value */ > + const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"}; > + /* master lcore not in coremask */ > + const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"}; > + /* valid value */ > + const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"}; > + > + if (launch_proc(argv1) == 0 > + || launch_proc(argv2) == 0 > + || launch_proc(argv3) == 0 > + || launch_proc(argv4) == 0) { > + printf("Error - process ran without error with wrong --master-lcore\n"); > + return -1; > + } > + if (launch_proc(argv5) != 0) { > + printf("Error - process did not run ok with valid --master-lcore\n"); > + return -1; > + } > + return 0; > +} > + > +/* > * Test that the app doesn't run without the -n flag. In all cases > * should give an error and fail to run. > * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf > @@ -1214,6 +1257,12 @@ test_eal_flags(void) > return ret; > } > > + ret = test_master_lcore_flag(); > + if (ret < 0) { > + printf("Error in test_master_lcore_flag()\n"); > + return ret; > + } > + > ret = test_missing_n_flag(); > if (ret < 0) { > printf("Error in test_missing_n_flag()\n"); > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > index ca99cb9..c764fec 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -354,6 +354,13 @@ eal_parse_args(int argc, char **argv) > if (opt == '?') > return -1; > > + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n"); A space is missing in this message. > + eal_usage(prgname); > + return -1; > + } > + > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { > diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c > index 7a5d55e..9166ea1 100644 > --- a/lib/librte_eal/common/eal_common_options.c > +++ b/lib/librte_eal/common/eal_common_options.c > @@ -64,6 +64,7 @@ eal_short_options[] = > const struct option > eal_long_options[] = { > {OPT_HUGE_DIR, 1, 0, OPT_HUGE_DIR_NUM}, > + {OPT_MASTER_LCORE, 1, 0, OPT_MASTER_LCORE_NUM}, > {OPT_PROC_TYPE, 1, 0, OPT_PROC_TYPE_NUM}, > {OPT_NO_SHCONF, 0, 0, OPT_NO_SHCONF_NUM}, > {OPT_NO_HPET, 0, 0, OPT_NO_HPET_NUM}, > @@ -163,6 +164,27 @@ eal_parse_coremask(const char *coremask) > return 0; > } > > +/* Changes the lcore id of the master thread */ > +static int > +eal_parse_master_lcore(const char *arg) > +{ > + long master_lcore; > + char *parsing_end; > + struct rte_config *cfg = rte_eal_get_configuration(); > + > + errno = 0; > + master_lcore = strtol(arg, &parsing_end, 0); > + if (errno || parsing_end == arg) > + return -1; > + > + if (!(master_lcore >= 0 && master_lcore < RTE_MAX_LCORE)) > + return -1; > + if (cfg->lcore_role[master_lcore] != ROLE_RTE) > + return -1; It might be helpful to return another error code (e.g., -2) that signals that the specified lcore is not part of the lcore mask. > + cfg->master_lcore = master_lcore; > + return 0; > +} > + > static int > eal_parse_syslog(const char *facility, struct internal_config *conf) > { > @@ -320,6 +342,14 @@ eal_parse_common_option(int opt, const char *optarg, > conf->process_type = eal_parse_proc_type(optarg); > break; > > + case OPT_MASTER_LCORE_NUM: > + if (eal_parse_master_lcore(optarg) < 0) { > + RTE_LOG(ERR, EAL, "invalid parameter for --" > + OPT_MASTER_LCORE "\n"); > + return -1; It might be nice here to get another message displayed whenever the specified lcore is not part of the core mask (see comment ahead). > + } > + break; > + > case OPT_VDEV_NUM: > if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, > optarg) < 0) { > @@ -364,6 +394,7 @@ eal_common_usage(void) > "[--proc-type primary|secondary|auto]\n\n" > "EAL common options:\n" > " -c COREMASK : A hexadecimal bitmask of cores to run on\n" > + " --"OPT_MASTER_LCORE" ID: Core ID that is used as master\n" > " -n NUM : Number of memory channels\n" > " -v : Display version information on startup\n" > " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n" > diff --git a/lib/librte_eal/common/include/eal_options.h b/lib/librte_eal/common/include/eal_options.h > index 22819ec..deb872d 100644 > --- a/lib/librte_eal/common/include/eal_options.h > +++ b/lib/librte_eal/common/include/eal_options.h > @@ -43,6 +43,8 @@ enum { > OPT_LONG_MIN_NUM = 256, > #define OPT_HUGE_DIR "huge-dir" > OPT_HUGE_DIR_NUM = OPT_LONG_MIN_NUM, > +#define OPT_MASTER_LCORE "master-lcore" > + OPT_MASTER_LCORE_NUM, > #define OPT_PROC_TYPE "proc-type" > OPT_PROC_TYPE_NUM, > #define OPT_NO_SHCONF "no-shconf" > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index 7a1d087..7fcb349 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -550,6 +550,13 @@ eal_parse_args(int argc, char **argv) > if (opt == '?') > return -1; > > + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { > + RTE_LOG(ERR, EAL, "please specify the master lcore id" > + "after specifying the coremask\n"); > + eal_usage(prgname); > + return -1; > + } > + > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { >
diff --git a/app/test/test.c b/app/test/test.c index 9bee6bb..2fecff5 100644 --- a/app/test/test.c +++ b/app/test/test.c @@ -82,6 +82,7 @@ do_recursive_call(void) } actions[] = { { "run_secondary_instances", test_mp_secondary }, { "test_missing_c_flag", no_action }, + { "test_master_lcore_flag", no_action }, { "test_missing_n_flag", no_action }, { "test_no_hpet_flag", no_action }, { "test_whitelist_flag", no_action }, diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index 21e6cca..45020b8 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -520,6 +520,49 @@ test_missing_c_flag(void) } /* + * Test --master-lcore option with matching coremask + */ +static int +test_master_lcore_flag(void) +{ +#ifdef RTE_EXEC_ENV_BSDAPP + /* BSD target doesn't support prefixes at this point */ + const char * prefix = ""; +#else + char prefix[PATH_MAX], tmp[PATH_MAX]; + if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { + printf("Error - unable to get current prefix!\n"); + return -1; + } + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); +#endif + + /* --master-lcore flag but no value */ + const char *argv1[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore"}; + /* --master-lcore flag with invalid value */ + const char *argv2[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "-1"}; + /* --master-lcore flag with invalid value */ + const char *argv3[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "X"}; + /* master lcore not in coremask */ + const char *argv4[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "2"}; + /* valid value */ + const char *argv5[] = { prgname, prefix, mp_flag, "-n", "1", "-c", "3", "--master-lcore", "1"}; + + if (launch_proc(argv1) == 0 + || launch_proc(argv2) == 0 + || launch_proc(argv3) == 0 + || launch_proc(argv4) == 0) { + printf("Error - process ran without error with wrong --master-lcore\n"); + return -1; + } + if (launch_proc(argv5) != 0) { + printf("Error - process did not run ok with valid --master-lcore\n"); + return -1; + } + return 0; +} + +/* * Test that the app doesn't run without the -n flag. In all cases * should give an error and fail to run. * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf @@ -1214,6 +1257,12 @@ test_eal_flags(void) return ret; } + ret = test_master_lcore_flag(); + if (ret < 0) { + printf("Error in test_master_lcore_flag()\n"); + return ret; + } + ret = test_missing_n_flag(); if (ret < 0) { printf("Error in test_missing_n_flag()\n"); diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index ca99cb9..c764fec 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -354,6 +354,13 @@ eal_parse_args(int argc, char **argv) if (opt == '?') return -1; + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { + RTE_LOG(ERR, EAL, "please specify the master lcore id" + "after specifying the coremask\n"); + eal_usage(prgname); + return -1; + } + ret = eal_parse_common_option(opt, optarg, &internal_config); /* common parser is not happy */ if (ret < 0) { diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 7a5d55e..9166ea1 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -64,6 +64,7 @@ eal_short_options[] = const struct option eal_long_options[] = { {OPT_HUGE_DIR, 1, 0, OPT_HUGE_DIR_NUM}, + {OPT_MASTER_LCORE, 1, 0, OPT_MASTER_LCORE_NUM}, {OPT_PROC_TYPE, 1, 0, OPT_PROC_TYPE_NUM}, {OPT_NO_SHCONF, 0, 0, OPT_NO_SHCONF_NUM}, {OPT_NO_HPET, 0, 0, OPT_NO_HPET_NUM}, @@ -163,6 +164,27 @@ eal_parse_coremask(const char *coremask) return 0; } +/* Changes the lcore id of the master thread */ +static int +eal_parse_master_lcore(const char *arg) +{ + long master_lcore; + char *parsing_end; + struct rte_config *cfg = rte_eal_get_configuration(); + + errno = 0; + master_lcore = strtol(arg, &parsing_end, 0); + if (errno || parsing_end == arg) + return -1; + + if (!(master_lcore >= 0 && master_lcore < RTE_MAX_LCORE)) + return -1; + if (cfg->lcore_role[master_lcore] != ROLE_RTE) + return -1; + cfg->master_lcore = master_lcore; + return 0; +} + static int eal_parse_syslog(const char *facility, struct internal_config *conf) { @@ -320,6 +342,14 @@ eal_parse_common_option(int opt, const char *optarg, conf->process_type = eal_parse_proc_type(optarg); break; + case OPT_MASTER_LCORE_NUM: + if (eal_parse_master_lcore(optarg) < 0) { + RTE_LOG(ERR, EAL, "invalid parameter for --" + OPT_MASTER_LCORE "\n"); + return -1; + } + break; + case OPT_VDEV_NUM: if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, optarg) < 0) { @@ -364,6 +394,7 @@ eal_common_usage(void) "[--proc-type primary|secondary|auto]\n\n" "EAL common options:\n" " -c COREMASK : A hexadecimal bitmask of cores to run on\n" + " --"OPT_MASTER_LCORE" ID: Core ID that is used as master\n" " -n NUM : Number of memory channels\n" " -v : Display version information on startup\n" " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n" diff --git a/lib/librte_eal/common/include/eal_options.h b/lib/librte_eal/common/include/eal_options.h index 22819ec..deb872d 100644 --- a/lib/librte_eal/common/include/eal_options.h +++ b/lib/librte_eal/common/include/eal_options.h @@ -43,6 +43,8 @@ enum { OPT_LONG_MIN_NUM = 256, #define OPT_HUGE_DIR "huge-dir" OPT_HUGE_DIR_NUM = OPT_LONG_MIN_NUM, +#define OPT_MASTER_LCORE "master-lcore" + OPT_MASTER_LCORE_NUM, #define OPT_PROC_TYPE "proc-type" OPT_PROC_TYPE_NUM, #define OPT_NO_SHCONF "no-shconf" diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 7a1d087..7fcb349 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -550,6 +550,13 @@ eal_parse_args(int argc, char **argv) if (opt == '?') return -1; + if (opt == OPT_MASTER_LCORE_NUM && !coremask_ok) { + RTE_LOG(ERR, EAL, "please specify the master lcore id" + "after specifying the coremask\n"); + eal_usage(prgname); + return -1; + } + ret = eal_parse_common_option(opt, optarg, &internal_config); /* common parser is not happy */ if (ret < 0) {