From nobody Sun Feb 8 16:32:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2396151CD9; Fri, 2 Feb 2024 15:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889540; cv=none; b=XgQ4U62xvrd3wKecJZnrIuB7Wt9++dXe0hXEn4TGoOTCWW6mNr2HHgszQfL7eX7I7Q+fdZP1VznWJOpchIZo5K4HbG/85WoaQcMQXlm+XkJIgXFlVZYCiXRbtY2sg8bAkZiU/adbWMZzU2rk8MUAy3tTadwMLHc74dlPselRz/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889540; c=relaxed/simple; bh=k9Sfj6G74FhB17Co2/07H2mwmXKZRLmR93bIQOS6wrw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CAQnELQbF86QnuQG0s9SyB2pWiTA2JlfWR9IrqHjc99+LSWTAxAHyPeEm7cNElFdrnf3hU24Kr2WBOydN3oTsF/NnmevwN1a4+lsREzl88bGqwK8Dd0GF97YFexzM7b1qXhqHDa2tW8KZlyo9lInahLMgSLLiqcWj3Hs6qcKeyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eYqeowhx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eYqeowhx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B327FC43394; Fri, 2 Feb 2024 15:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889539; bh=k9Sfj6G74FhB17Co2/07H2mwmXKZRLmR93bIQOS6wrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eYqeowhxfk0mGaeCDX4LInidLVKrblDFemMbSzO9p90R8KzMZhtZ6rt+KbL88mLHM 3c+y/y18m5psSDUS14JLyVs9MThe5pmyuE9BceKtpThf/4tEb7YuFIk66EEbcBsDT/ o73nmSoQbPvZvNqTgOA0hz0Bmi9J6sI48BTq4FGGNbcmP6B98vH/eYVTvDhV5/pu1z uC81v28M8BEAOZmUxIDpFPFnEKhylLXapPijRiAdZOxswFZ3rtgpLo4xsZFYm8j/Zv S6SpAzWPWpfXGND3Ndp2kkKZOlcfmNDoyPpIITXUMTzD7sYniQSS6+tDa5ae+6BKPl jG+h2ti3vNWiA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 26/27] kconfig: use generic macros to implement symbol hashtable Date: Sat, 3 Feb 2024 00:58:24 +0900 Message-Id: <20240202155825.314567-27-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use helper macros in hashtable.h for generic hashtable implementation. We can git rid of the hash head index of for_all_symbols(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 12 ++++++------ scripts/kconfig/confdata.c | 25 ++++++++++++------------- scripts/kconfig/expr.h | 9 ++++----- scripts/kconfig/internal.h | 9 +++++++++ scripts/kconfig/lkc_proto.h | 2 -- scripts/kconfig/parser.y | 5 +---- scripts/kconfig/symbol.c | 22 +++++++++++----------- 7 files changed, 43 insertions(+), 41 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 662a5e7c37c2..b5730061872b 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -14,6 +14,7 @@ #include #include =20 +#include "internal.h" #include "lkc.h" =20 static void conf(struct menu *menu); @@ -171,7 +172,7 @@ enum conf_def_mode { static bool conf_set_all_new_symbols(enum conf_def_mode mode) { struct symbol *sym, *csym; - int i, cnt; + int cnt; /* * can't go as the default in switch-case below, otherwise gcc whines * about -Wmaybe-uninitialized @@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode= mode) } } =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) continue; switch (sym_get_type(sym)) { @@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mo= de mode) * and the rest to no. */ if (mode !=3D def_random) { - for_all_symbols(i, csym) { + for_all_symbols(csym) { if ((sym_is_choice(csym) && !sym_has_value(csym)) || sym_is_choice_value(csym)) csym->flags |=3D SYMBOL_NEED_SET_CHOICE_VALUES; } } =20 - for_all_symbols(i, csym) { + for_all_symbols(csym) { if (sym_has_value(csym) || !sym_is_choice(csym)) continue; =20 @@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode= mode) static void conf_rewrite_tristates(tristate old_val, tristate new_val) { struct symbol *sym; - int i; =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_get_type(sym) =3D=3D S_TRISTATE && sym->def[S_DEF_USER].tri =3D=3D old_val) sym->def[S_DEF_USER].tri =3D new_val; diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index dafc572e7b7e..c5b6487d68ac 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -18,6 +18,7 @@ #include #include =20 +#include "internal.h" #include "lkc.h" =20 struct gstr autoconf_cmd; @@ -322,7 +323,7 @@ int conf_read_simple(const char *name, int def) size_t line_asize =3D 0; char *p, *val; struct symbol *sym; - int i, def_flags; + int def_flags; const char *warn_unknown, *sym_name; =20 warn_unknown =3D getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS"); @@ -380,7 +381,7 @@ int conf_read_simple(const char *name, int def) conf_warnings =3D 0; =20 def_flags =3D SYMBOL_DEF << def; - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym->flags |=3D SYMBOL_CHANGED; sym->flags &=3D ~(def_flags|SYMBOL_VALID); if (sym_is_choice(sym)) @@ -489,7 +490,6 @@ int conf_read(const char *name) { struct symbol *sym; int conf_unsaved =3D 0; - int i; =20 conf_set_changed(false); =20 @@ -500,7 +500,7 @@ int conf_read(const char *name) =20 sym_calc_value(modules_sym); =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE)) continue; @@ -524,7 +524,7 @@ int conf_read(const char *name) /* maybe print value in verbose mode... */ } =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) && !sym_is_choice_value(sym)) { /* Reset values of generates values, so they'll appear * as new, if they should become visible, but that @@ -862,7 +862,6 @@ int conf_write(const char *name) const char *str; char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; char *env; - int i; bool need_newline =3D false; =20 if (!name) @@ -946,7 +945,7 @@ int conf_write(const char *name) } fclose(out); =20 - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &=3D ~SYMBOL_WRITTEN; =20 if (*tmpname) { @@ -1016,7 +1015,7 @@ static int conf_touch_deps(void) { const char *name, *tmp; struct symbol *sym; - int res, i; + int res; =20 name =3D conf_get_autoconfig_name(); tmp =3D strrchr(name, '/'); @@ -1030,7 +1029,7 @@ static int conf_touch_deps(void) conf_read_simple(name, S_DEF_AUTO); sym_calc_value(modules_sym); =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) continue; @@ -1096,7 +1095,7 @@ static int __conf_write_autoconf(const char *filename, char tmp[PATH_MAX]; FILE *file; struct symbol *sym; - int ret, i; + int ret; =20 if (make_parent_dir(filename)) return -1; @@ -1113,7 +1112,7 @@ static int __conf_write_autoconf(const char *filename, =20 conf_write_heading(file, comment_style); =20 - for_all_symbols(i, sym) + for_all_symbols(sym) if ((sym->flags & SYMBOL_WRITE) && sym->name) print_symbol(file, sym); =20 @@ -1136,7 +1135,7 @@ int conf_write_autoconf(int overwrite) { struct symbol *sym; const char *autoconf_name =3D conf_get_autoconfig_name(); - int ret, i; + int ret; =20 if (!overwrite && is_present(autoconf_name)) return 0; @@ -1148,7 +1147,7 @@ int conf_write_autoconf(int overwrite) if (conf_touch_deps()) return 1; =20 - for_all_symbols(i, sym) + for_all_symbols(sym) sym_calc_value(sym); =20 ret =3D __conf_write_autoconf(conf_get_autoheader_name(), diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index dd3350aed302..3bc375f1a1cd 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -17,6 +17,8 @@ extern "C" { #include #endif =20 +#include "list_types.h" + typedef enum tristate { no, mod, yes } tristate; @@ -74,8 +76,8 @@ enum { * SYMBOL_CHOICE bit set in 'flags'. */ struct symbol { - /* The next symbol in the same bucket in the symbol hash table */ - struct symbol *next; + /* link node for the hash table */ + struct hlist_node node; =20 /* The name of the symbol, e.g. "FOO" for 'config FOO' */ char *name; @@ -124,8 +126,6 @@ struct symbol { struct expr_value implied; }; =20 -#define for_all_symbols(i, sym) for (i =3D 0; i < SYMBOL_HASHSIZE; i++) fo= r (sym =3D symbol_hash[i]; sym; sym =3D sym->next) - #define SYMBOL_CONST 0x0001 /* symbol is const */ #define SYMBOL_CHECK 0x0008 /* used during dependency checking */ #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */ @@ -150,7 +150,6 @@ struct symbol { #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 =20 #define SYMBOL_MAXLENGTH 256 -#define SYMBOL_HASHSIZE 9973 =20 /* A property represent the config options that can be associated * with a config "symbol". diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h index 788401cd5d6f..6c721c4cfd72 100644 --- a/scripts/kconfig/internal.h +++ b/scripts/kconfig/internal.h @@ -2,6 +2,15 @@ #ifndef INTERNAL_H #define INTERNAL_H =20 +#include "hashtable.h" + +#define SYMBOL_HASHSIZE (1U << 14) + +extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE); + +#define for_all_symbols(sym) \ + hash_for_each(sym_hashtable, sym, node) + struct menu; =20 extern struct menu *current_menu, *current_entry; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 94299e42402f..2807fa584c2b 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s)); bool conf_errors(void); =20 /* symbol.c */ -extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; - struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); void print_symbol_for_listconfig(struct symbol *sym); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index e58c24d2e5ab..112831da4f44 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -28,8 +28,6 @@ static void zconf_error(const char *err, ...); static bool zconf_endtoken(const char *tokenname, const char *expected_tokenname); =20 -struct symbol *symbol_hash[SYMBOL_HASHSIZE]; - struct menu *current_menu, *current_entry; =20 %} @@ -474,7 +472,6 @@ assign_val: void conf_parse(const char *name) { struct symbol *sym; - int i; =20 autoconf_cmd =3D str_new(); =20 @@ -517,7 +514,7 @@ void conf_parse(const char *name) } =20 menu_finalize(&rootmenu); - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_check_deps(sym)) yynerrs++; } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 518977c525de..1290c6d2f8c2 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -9,6 +9,7 @@ #include #include =20 +#include "internal.h" #include "lkc.h" #include "util.h" =20 @@ -161,9 +162,8 @@ static void sym_set_changed(struct symbol *sym) static void sym_set_all_changed(void) { struct symbol *sym; - int i; =20 - for_all_symbols(i, sym) + for_all_symbols(sym) sym_set_changed(sym); } =20 @@ -476,9 +476,8 @@ void sym_calc_value(struct symbol *sym) void sym_clear_all_valid(void) { struct symbol *sym; - int i; =20 - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &=3D ~SYMBOL_VALID; conf_set_changed(true); sym_calc_value(modules_sym); @@ -804,6 +803,8 @@ bool sym_is_changeable(struct symbol *sym) return sym->visible > sym->rev_dep.tri; } =20 +HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE); + struct symbol *sym_lookup(const char *name, int flags) { struct symbol *symbol; @@ -818,9 +819,9 @@ struct symbol *sym_lookup(const char *name, int flags) case 'n': return &symbol_no; } } - hash =3D strhash(name) % SYMBOL_HASHSIZE; + hash =3D strhash(name); =20 - for (symbol =3D symbol_hash[hash]; symbol; symbol =3D symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && (flags ? symbol->flags & flags @@ -839,8 +840,7 @@ struct symbol *sym_lookup(const char *name, int flags) symbol->type =3D S_UNKNOWN; symbol->flags =3D flags; =20 - symbol->next =3D symbol_hash[hash]; - symbol_hash[hash] =3D symbol; + hash_add(sym_hashtable, &symbol->node, hash); =20 return symbol; } @@ -860,9 +860,9 @@ struct symbol *sym_find(const char *name) case 'n': return &symbol_no; } } - hash =3D strhash(name) % SYMBOL_HASHSIZE; + hash =3D strhash(name); =20 - for (symbol =3D symbol_hash[hash]; symbol; symbol =3D symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && !(symbol->flags & SYMBOL_CONST)) @@ -922,7 +922,7 @@ struct symbol **sym_re_search(const char *pattern) if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) return NULL; =20 - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym->flags & SYMBOL_CONST || !sym->name) continue; if (regexec(&re, sym->name, 1, match, 0)) --=20 2.40.1