git: 01cad731921b - main - loader: tslog: Add more log for module loading

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Tue, 11 Jan 2022 08:14:39 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=01cad731921bb60b4f6e04c1cac987eea7af9d08

commit 01cad731921bb60b4f6e04c1cac987eea7af9d08
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-12-30 14:49:24 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-11 08:14:10 +0000

    loader: tslog: Add more log for module loading
    
    This helps mesuring what's happening when we load the kernel/modules/mfsroot.
    
    This also adds TSENTER2 which uses the third argument of TSRAW, same
    as in the kernel.
    
    MFC after:      2 weeks
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D33699
---
 stand/common/module.c | 22 ++++++++++++++++++++++
 stand/libsa/stand.h   |  1 +
 2 files changed, 23 insertions(+)

diff --git a/stand/common/module.c b/stand/common/module.c
index 9cb10d0f9f9d..bf95fbc59ea3 100644
--- a/stand/common/module.c
+++ b/stand/common/module.c
@@ -556,6 +556,7 @@ file_load(char *filename, vm_offset_t dest, struct preloaded_file **result)
 	int error;
 	int i;
 
+	TSENTER2(filename);
 	if (archsw.arch_loadaddr != NULL)
 		dest = archsw.arch_loadaddr(LOAD_RAW, filename, dest);
 
@@ -582,6 +583,7 @@ file_load(char *filename, vm_offset_t dest, struct preloaded_file **result)
 			break;
 		}
 	}
+	TSEXIT();
 	return (error);
 }
 
@@ -743,9 +745,11 @@ file_loadraw(const char *fname, char *type, int insert)
 	int			verror;
 #endif
 
+	TSENTER2(fname);
 	/* We can't load first */
 	if ((file_findfile(NULL, NULL)) == NULL) {
 		command_errmsg = "can't load file before kernel";
+		TSEXIT();
 		return(NULL);
 	}
 
@@ -754,6 +758,7 @@ file_loadraw(const char *fname, char *type, int insert)
 	if (name == NULL) {
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "can't find '%s'", fname);
+		TSEXIT();
 		return(NULL);
 	}
 
@@ -761,6 +766,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "can't open '%s': %s", name, strerror(errno));
 		free(name);
+		TSEXIT();
 		return(NULL);
 	}
 
@@ -772,6 +778,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		free(name);
 		free(vctx);
 		close(fd);
+		TSEXIT();
 		return(NULL);
 	}
 #else
@@ -781,6 +788,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		    name, ve_error_get());
 		free(name);
 		close(fd);
+		TSEXIT();
 		return(NULL);
 	}
 #endif
@@ -805,6 +813,7 @@ file_loadraw(const char *fname, char *type, int insert)
 #ifdef LOADER_VERIEXEC_VECTX
 			free(vctx);
 #endif
+			TSEXIT();
 			return(NULL);
 		}
 		laddr += got;
@@ -817,6 +826,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		free(name);
 		close(fd);
 		free(vctx);
+		TSEXIT();
 		return(NULL);
 	}
 #endif
@@ -828,6 +838,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		    "no memory to load %s", name);
 		free(name);
 		close(fd);
+		TSEXIT();
 		return (NULL);
 	}
 	fp->f_name = name;
@@ -843,6 +854,7 @@ file_loadraw(const char *fname, char *type, int insert)
 		    "no memory to load %s", name);
 		free(name);
 		close(fd);
+		TSEXIT();
 		return (NULL);
 	}
 	/* recognise space consumption */
@@ -852,6 +864,7 @@ file_loadraw(const char *fname, char *type, int insert)
 	if (insert != 0)
 		file_insert_tail(fp);
 	close(fd);
+	TSEXIT();
 	return(fp);
 }
 
@@ -867,8 +880,10 @@ mod_load(char *modname, struct mod_depend *verinfo, int argc, char *argv[])
 	int				err;
 	char			*filename;
 
+	TSENTER2(modname);
 	if (file_havepath(modname)) {
 		printf("Warning: mod_load() called instead of mod_loadkld() for module '%s'\n", modname);
+		TSEXIT();
 		return (mod_loadkld(modname, argc, argv));
 	}
 	/* see if module is already loaded */
@@ -880,6 +895,7 @@ mod_load(char *modname, struct mod_depend *verinfo, int argc, char *argv[])
 #endif
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "warning: module '%s' already loaded", mp->m_name);
+		TSEXIT();
 		return (0);
 	}
 	/* locate file with the module on the search path */
@@ -887,10 +903,12 @@ mod_load(char *modname, struct mod_depend *verinfo, int argc, char *argv[])
 	if (filename == NULL) {
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "can't find '%s'", modname);
+		TSEXIT();
 		return (ENOENT);
 	}
 	err = mod_loadkld(filename, argc, argv);
 	free(filename);
+	TSEXIT();
 	return (err);
 }
 
@@ -906,6 +924,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[])
 	char			*filename;
 	vm_offset_t		loadaddr_saved;
 
+	TSENTER2(kldname);
 	/*
 	 * Get fully qualified KLD name
 	 */
@@ -913,6 +932,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[])
 	if (filename == NULL) {
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "can't find '%s'", kldname);
+		TSEXIT();
 		return (ENOENT);
 	}
 	/*
@@ -923,6 +943,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[])
 		snprintf(command_errbuf, sizeof(command_errbuf),
 		  "warning: KLD '%s' already loaded", filename);
 		free(filename);
+		TSEXIT();
 		return (0);
 	}
 
@@ -949,6 +970,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[])
 	if (err)
 		file_discard(fp);
 	free(filename);
+	TSEXIT();
 	return (err);
 }
 
diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h
index 172b54c33b30..99b55e2282e4 100644
--- a/stand/libsa/stand.h
+++ b/stand/libsa/stand.h
@@ -486,6 +486,7 @@ void	hexdump(caddr_t region, size_t len);
 /* tslog.c */
 #define TSRAW(a, b, c) tslog(a, b, c)
 #define TSENTER() TSRAW("ENTER", __func__, NULL)
+#define TSENTER2(x) TSRAW("ENTER", __func__, x)
 #define TSEXIT() TSRAW("EXIT", __func__, NULL)
 #define TSLINE() TSRAW("EVENT", __FILE__, __XSTRING(__LINE__))
 void tslog(const char *, const char *, const char *);