Skip to contentSkip to conversation

kmod: Paper cuts - dead code removal, don't SED manually

PATCH Applied Emil Velikov 2 participants 7 messages Feb 21, 2023 – Feb 22, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

cover kmod: Paper cuts - dead code removal, don't SED manually

Greetings everyone,

Here's another, final, round of paper cuts while browsing through the project.

Note that despite the enabled linker garbage collector, the first few cleanup patches result in detectable improvement in the final binaries.

The last patch, removes the open-coded replacement and by doing so fixes a genuine bug - albeit one that is uncommon to hit.

As always, feel free to pick any bits that seem suitable.

Thanks
Emil

Emil Velikov (4):
libkmod: remove unused kmod_module_get_builtin
libkmod: annotate kmod_builtin_iter API as static
shared: annotate local API as static
configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES

 Makefile.am                | 25 ----------------------
 configure.ac               |  2 ++
 libkmod/libkmod-builtin.c  |  8 +++----
 libkmod/libkmod-internal.h |  6 ------
 libkmod/libkmod-module.c   | 43 --------------------------------------
 shared/util.c              |  6 +++---
 shared/util.h              |  3 ---
 7 files changed, 9 insertions(+), 84 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/4 libkmod: remove unused kmod_module_get_builtin

From: Emil Velikov <[email protected]>

The last and only user was removed with commit 0246e06 ("depmod: Stop opening modules.modinfo once per module")

---
 libkmod/libkmod-internal.h |  1 -
 libkmod/libkmod-module.c   | 43 --------------------------------------
 2 files changed, 44 deletions(-)
libkmod/libkmod-internal.h +0 -1
index c22644a..95c0377 100644
@@ -148,7 +148,6 @@ void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute_
 void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1))));
 void kmod_module_set_required(struct kmod_module *mod, bool required) __attribute__((nonnull(1)));
 bool kmod_module_is_builtin(struct kmod_module *mod) __attribute__((nonnull(1)));
-int kmod_module_get_builtin(struct kmod_ctx *ctx, struct kmod_list **list) __attribute__((nonnull(1, 2)));
 
 /* libkmod-file.c */
 struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
libkmod/libkmod-module.c +0 -43

46 lines not on this page · raw message

Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/4 libkmod: annotate kmod_builtin_iter API as static

In reply to Emil Velikov

From: Emil Velikov <[email protected]>

It's no longer used outside the compilation unit, as of last commit.

---
 libkmod/libkmod-builtin.c  | 8 ++++----
 libkmod/libkmod-internal.h | 5 -----
 2 files changed, 4 insertions(+), 9 deletions(-)
libkmod/libkmod-builtin.c +4 -4
index a002cb5..65334a8 100644
@@ -54,7 +54,7 @@ struct kmod_builtin_iter {
 	char *buf;
 };
 
-struct kmod_builtin_iter *kmod_builtin_iter_new(struct kmod_ctx *ctx)
+static struct kmod_builtin_iter *kmod_builtin_iter_new(struct kmod_ctx *ctx)
 {
 	char path[PATH_MAX];
 	int file, sv_errno;
@@ -108,7 +108,7 @@ fail:
 	return iter;
 }
 
-void kmod_builtin_iter_free(struct kmod_builtin_iter *iter)
+static void kmod_builtin_iter_free(struct kmod_builtin_iter *iter)
 {
 	close(iter->file);
 	free(iter->buf);
@@ -165,7 +165,7 @@ fail:
 	return -1;
 }
 
-bool kmod_builtin_iter_next(struct kmod_builtin_iter *iter)
+static bool kmod_builtin_iter_next(struct kmod_builtin_iter *iter)
 {
 	char *line,  *modname;
 	size_t linesz;
@@ -216,7 +216,7 @@ bool kmod_builtin_iter_next(struct kmod_builtin_iter *iter)
 	return (iter->pos < iter->size);
 }
 
-bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter,
+static bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter,
 				char modname[static PATH_MAX])
 {
 	int sv_errno;
libkmod/libkmod-internal.h +0 -5
index 95c0377..4a4af58 100644
@@ -198,9 +198,4 @@ bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signat
 void kmod_module_signature_info_free(struct kmod_signature_info *sig_info) __attribute__((nonnull));
 
 /* libkmod-builtin.c */
-struct kmod_builtin_iter;
-struct kmod_builtin_iter *kmod_builtin_iter_new(struct kmod_ctx *ctx) __attribute__((nonnull(1)));
-void kmod_builtin_iter_free(struct kmod_builtin_iter *iter) __attribute__((nonnull(1)));
-bool kmod_builtin_iter_next(struct kmod_builtin_iter *iter) __attribute__((nonnull(1)));
-bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, char modname[static PATH_MAX]) __attribute__((nonnull(1, 2)));
 ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, char ***modinfo) __attribute__((nonnull(1, 2, 3)));
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/4 shared: annotate local API as static

In reply to Emil Velikov

From: Emil Velikov <[email protected]>

None of the API is used outside of the compilation unit.

---
 shared/util.c | 6 +++---
 shared/util.h | 3 ---
 2 files changed, 3 insertions(+), 6 deletions(-)
shared/util.c +3 -3
index 4b547ff..e2bab83 100644
@@ -354,7 +354,7 @@ char *freadline_wrapped(FILE *fp, unsigned int *linenum)
 /* path handling functions                                                  */
 /* ************************************************************************ */
 
-bool path_is_absolute(const char *p)
+static bool path_is_absolute(const char *p)
 {
 	assert(p != NULL);
 
@@ -460,13 +460,13 @@ int mkdir_parents(const char *path, mode_t mode)
 	return mkdir_p(path, end - path, mode);
 }
 
-unsigned long long ts_usec(const struct timespec *ts)
+static unsigned long long ts_usec(const struct timespec *ts)
 {
 	return (unsigned long long) ts->tv_sec * USEC_PER_SEC +
 	       (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
 }
 
-unsigned long long ts_msec(const struct timespec *ts)
+static unsigned long long ts_msec(const struct timespec *ts)
 {
 	return (unsigned long long) ts->tv_sec * MSEC_PER_SEC +
 	       (unsigned long long) ts->tv_nsec / NSEC_PER_MSEC;
shared/util.h +0 -3
index 7030653..c4a3916 100644
@@ -38,7 +38,6 @@ char *freadline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(
 
 /* path handling functions                                                  */
 /* ************************************************************************ */
-bool path_is_absolute(const char *p) _must_check_ __attribute__((nonnull(1)));
 char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(1)));
 int mkdir_p(const char *path, int len, mode_t mode);
 int mkdir_parents(const char *path, mode_t mode);
@@ -51,8 +50,6 @@ unsigned long long stat_mstamp(const struct stat *st);
 #define MSEC_PER_SEC	1000ULL
 #define NSEC_PER_MSEC	1000000ULL
 
-unsigned long long ts_usec(const struct timespec *ts);
-unsigned long long ts_msec(const struct timespec *ts);
 unsigned long long now_usec(void);
 unsigned long long now_msec(void);
 int sleep_until_msec(unsigned long long msec);
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/4 configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES

In reply to Emil Velikov

From: Emil Velikov <[email protected]>

Replace the manual sed command, build rules and dist/clean for using AC_CONFIG_FILES. It does the exact same thing, with an added bonus...

Currently we're missing version.py.in in the EXTRA_DIST. Thus a simple "touch Makefile" should retrigger the regeneration of version.py. Which would presumably fail, since the input file isn't in the distribution tarball.

---
Feel free to compare the diff between the old/new "make distcheck". Cannot realistically add that here as it seemingly confuses the hell out of git am.

---
 Makefile.am  | 25 -------------------------
 configure.ac |  2 ++
 2 files changed, 2 insertions(+), 25 deletions(-)
Makefile.am +0 -25
index 61dbdf0..8ba85c9 100644
@@ -24,26 +24,6 @@ AM_CPPFLAGS = \
 AM_CFLAGS = $(OUR_CFLAGS)
 AM_LDFLAGS = $(OUR_LDFLAGS)
 
-SED_PROCESS = \
-	$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \
-	-e 's,@VERSION\@,$(VERSION),g' \
-	-e 's,@prefix\@,$(prefix),g' \
-	-e 's,@exec_prefix\@,$(exec_prefix),g' \
-	-e 's,@libdir\@,$(libdir),g' \
-	-e 's,@includedir\@,$(includedir),g' \
-	-e 's,@libzstd_CFLAGS\@,${libzstd_CFLAGS},g' \
-	-e 's,@libzstd_LIBS\@,${libzstd_LIBS},g' \
-	-e 's,@liblzma_CFLAGS\@,${liblzma_CFLAGS},g' \
-	-e 's,@liblzma_LIBS\@,${liblzma_LIBS},g' \
-	-e 's,@zlib_CFLAGS\@,${zlib_CFLAGS},g' \
-	-e 's,@zlib_LIBS\@,${zlib_LIBS},g' \
-	-e 's,@libcrypto_CFLAGS\@,${libcrypto_CFLAGS},g' \
-	-e 's,@libcrypto_LIBS\@,${libcrypto_LIBS},g' \
-	< $< > $@ || rm $@
-
-%.pc: %.pc.in Makefile
-	$(SED_PROCESS)
-
 # Rules for libtool versioning (from https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html)
 # 1. Start with version information of ‘0:0:0’ for each libtool library.
 # 2. Update the version information only immediately before a public release of
@@ -116,8 +96,6 @@ libkmod_libkmod_internal_la_LIBADD = $(libkmod_libkmod_la_LIBADD)
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libkmod/libkmod.pc
-EXTRA_DIST += libkmod/libkmod.pc.in
-CLEANFILES += libkmod/libkmod.pc
 
 bashcompletiondir=@bashcompletiondir@
 dist_bashcompletion_DATA = \
@@ -179,9 +157,6 @@ am__v_CYTHON_0 = @echo "  CYTHON " $@;
 .pyx.c:
 	$(AM_V_CYTHON)$(CYTHON) -o $@ $<
 
-%.py: %.py.in Makefile
-	$(SED_PROCESS)
-
 # Remove some warnings for generated code
 PYTHON_NOWARN = -Wno-redundant-decls -Wno-shadow -Wno-strict-aliasing
 
configure.ac +2 -0
index 892f5d9..65902d1 100644
@@ -292,6 +292,8 @@ AC_CONFIG_FILES([
 	man/Makefile
 	libkmod/docs/Makefile
 	libkmod/docs/version.xml
+	libkmod/libkmod.pc
+	libkmod/python/kmod/version.py
 ])
 
 
Signature · 1 line
2.39.2
#5 lore raw
In reply to Emil Velikov
Quoted 9 lines · Emil Velikov

Here's another, final, round of paper cuts while browsing through the project.

Note that despite the enabled linker garbage collector, the first few cleanup patches result in detectable improvement in the final binaries.

The last patch, removes the open-coded replacement and by doing so fixes a genuine bug - albeit one that is uncommon to hit.

[...]

Applied all the patches, thanks!

[1/4] libkmod: remove unused kmod_module_get_builtin

      commit: 0237665beff4fa5e45b1d1ac5857627f949721b5
[2/4] libkmod: annotate kmod_builtin_iter API as static
      commit: df9d07a1492d7185413985add42ab38650ec2378
[3/4] shared: annotate local API as static
      commit: 06e6f167c211106212290aa7980880f972d71ba2
[4/4] configure: manage libkmod.pc.in and version.py.in via AC_CONFIG_FILES
      commit: e4c1a5b2998bc2c9dbcff8d62f121d1f8f5f4fe5

My intention is to release kmod 31 soon. Let me know if you have
anything pending that you'd like in the next release. If nothing is pending I may just do a release in the next days/week.

Best regards,

Signature · 1 line
Lucas De Marchi <[email protected]>
#6 lore raw

Greetings Lucas,

Quoted 4 lines · Lucas De Marchi

My intention is to release kmod 31 soon. Let me know if you have
anything pending that you'd like in the next release. If nothing is pending I may just do a release in the next days/week.

There are no other patches on my end - rolling a release would be great.

Thanks o/
Emil