2021-05-29 20:03:22

by Jim Cromie

[permalink] [raw]
Subject: [RFC PATCH v6 05/34] dyndbg: __init iterate over __dyndbg & __dyndbg_site in parallel

In HEAD~1, a new elf section was added, and dynamic_debug_init() got
minimal adjustments; basically s/iter/iter->site/ where needed.

Now we rework the for-loop for clarity:
. iterate over both sections in parallel (iter & site)
. demote iter->site indirection (1st step towards dropping site)
. add __(start|stop)___dyndbg_sites decls (init'd in vmlinux.lds.h)
. add/rename several iterator/mod_start variables for clarity.
. add BUG_ON(iter->site != site)
. var rename n to site_ct

Signed-off-by: Jim Cromie <[email protected]>
---
lib/dynamic_debug.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 691e43d58eef..f7ece35bc722 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -41,6 +41,8 @@

extern struct _ddebug __start___dyndbg[];
extern struct _ddebug __stop___dyndbg[];
+extern struct _ddebug_site __start___dyndbg_sites[];
+extern struct _ddebug_site __stop___dyndbg_sites[];

struct ddebug_table {
struct list_head link;
@@ -118,6 +120,7 @@ do { \

#define vpr_info(fmt, ...) vnpr_info(1, fmt, ##__VA_ARGS__)
#define v2pr_info(fmt, ...) vnpr_info(2, fmt, ##__VA_ARGS__)
+#define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__)

static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
{
@@ -1086,11 +1089,12 @@ static int __init dynamic_debug_init_control(void)

static int __init dynamic_debug_init(void)
{
- struct _ddebug *iter, *iter_start;
+ struct _ddebug *iter, *iter_mod_start;
+ struct _ddebug_site *site, *site_mod_start;
const char *modname = NULL;
char *cmdline;
int ret = 0;
- int n = 0, entries = 0, modct = 0;
+ int site_ct = 0, entries = 0, modct = 0;

if (&__start___dyndbg == &__stop___dyndbg) {
if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
@@ -1101,23 +1105,29 @@ static int __init dynamic_debug_init(void)
ddebug_init_success = 1;
return 0;
}
- iter = __start___dyndbg;
- modname = iter->site->modname;
- iter_start = iter;
- for (; iter < __stop___dyndbg; iter++) {
+
+ iter = iter_mod_start = __start___dyndbg;
+ site = site_mod_start = __start___dyndbg_sites;
+ modname = site->modname;
+
+ for (; iter < __stop___dyndbg; iter++, site++) {
+
+ BUG_ON(site != iter->site);
entries++;
- if (strcmp(modname, iter->site->modname)) {
+
+ if (strcmp(modname, site->modname)) {
modct++;
- ret = ddebug_add_module(iter_start, n, modname);
+ ret = ddebug_add_module(iter_mod_start, site_ct, modname);
if (ret)
goto out_err;
- n = 0;
- modname = iter->site->modname;
- iter_start = iter;
+ site_ct = 0;
+ modname = site->modname;
+ iter_mod_start = iter;
+ site_mod_start = site;
}
- n++;
+ site_ct++;
}
- ret = ddebug_add_module(iter_start, n, modname);
+ ret = ddebug_add_module(iter_mod_start, site_ct, modname);
if (ret)
goto out_err;

--
2.31.1