From 184832c981fd38b1052f2dfa0262e793fa6c67d3 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Sun, 15 Mar 2009 11:05:12 +0100 Subject: kconfig: fix randconfig for choice blocks Ingo Molnar reported that 'make randconfig' was not covering choice blocks properly, resulting in certain config options being left out of randconfig testing altogether. With the following patch we: - properly randomize choice value for normal choice blocks - properly randomize for multi choice blocks - added several comments to explain what is going on The root cause of the bug was that SYMBOL_VALID was set on the symbol representing the choice block so clearing this did the trick initially. But testign revealed a few more issues that is now fixed. Reported-by: Ingo Molnar Cc: Ingo Molnar Cc: Roman Zippel Signed-off-by: Sam Ravnborg --- scripts/kconfig/confdata.c | 51 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 830d9eae11f9..273d73888f9d 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -843,7 +843,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) default: continue; } - if (!sym_is_choice(sym) || mode != def_random) + if (!(sym_is_choice(sym) && mode == def_random)) sym->flags |= SYMBOL_DEF_USER; break; default: @@ -856,28 +856,49 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) if (mode != def_random) return; - + /* + * We have different type of choice blocks. + * If curr.tri equal to mod then we can select several + * choice symbols in one block. + * In this case we do nothing. + * If curr.tri equal yes then only one symbol can be + * selected in a choice block and we set it to yes, + * and the rest to no. + */ for_all_symbols(i, csym) { if (sym_has_value(csym) || !sym_is_choice(csym)) continue; sym_calc_value(csym); + + if (csym->curr.tri != yes) + continue; + prop = sym_get_choice_prop(csym); - def = -1; - while (1) { - cnt = 0; - expr_list_for_each_sym(prop->expr, e, sym) { - if (sym->visible == no) - continue; - if (def == cnt++) { - csym->def[S_DEF_USER].val = sym; - break; - } + + /* count entries in choice block */ + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) + cnt++; + + /* + * find a random value and set it to yes, + * set the rest to no so we have only one set + */ + def = (rand() % cnt); + + cnt = 0; + expr_list_for_each_sym(prop->expr, e, sym) { + if (def == cnt++) { + sym->def[S_DEF_USER].tri = yes; + csym->def[S_DEF_USER].val = sym; + } + else { + sym->def[S_DEF_USER].tri = no; } - if (def >= 0 || cnt < 2) - break; - def = (rand() % cnt) + 1; } csym->flags |= SYMBOL_DEF_USER; + /* clear VALID to get value calculated */ + csym->flags &= ~(SYMBOL_VALID); } } -- cgit v1.2.3 From b0fe551000179c868d46266278a890eab878baca Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Thu, 12 Mar 2009 15:15:31 +0100 Subject: kconfig: improve seed in randconfig 'make randconfig' uses glibc's rand function, and the seed of that PRNG is set via: srand(time(NULL)); But 'time()' only increases once every second - freezing the randconfig result within a single second. My Nehalem testbox does randconfig much faster than 1 second and i have a few scripts that do 'randconfig until condition X' loops. Those scripts currently waste a lot of CPU time due to randconfig changing its seed only once per second currently. Change the seed to be micrseconds based. (I checked the statistical spread of the seed - the now.tv_sec*now.tv_usec multiplication there further improves it.) Signed-off-by: Ingo Molnar Cc: Roman Zippel [sam: fix for systems where usec is zero - noticed by Geert Uytterhoeven] Signed-off-by: Sam Ravnborg --- scripts/kconfig/conf.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 3e1057f885c6..d190092c3b6e 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -11,6 +11,7 @@ #include #include #include +#include #define LKC_DIRECT_LINK #include "lkc.h" @@ -464,9 +465,22 @@ int main(int ac, char **av) input_mode = set_yes; break; case 'r': + { + struct timeval now; + unsigned int seed; + + /* + * Use microseconds derived seed, + * compensate for systems where it may be zero + */ + gettimeofday(&now, NULL); + + seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); + srand(seed); + input_mode = set_random; - srand(time(NULL)); break; + } case 'h': printf(_("See README for usage info\n")); exit(0); -- cgit v1.2.3