lib/vdso: Force inlining of __cvdso_clock_getres_common()
PATCH 1/1 lib/vdso: Force inlining of __cvdso_clock_getres_common()
With CONFIG_CC_OPTIMIZE_FOR_SIZE=y, gcc may decide not to inline __cvdso_clock_getres_common(). This introduces spurious internl function calls in the vDSO fastpath.
Furthermore, with automatic stack variable initialization (CONFIG_INIT_STACK_ALL_ZERO or CONFIG_INIT_STACK_ALL_PATTERN) gcc can emit a call to memset() which is not valid in the vDSO.
Mark the __cvdso_clock_getres_common() as __always_inline to avoid both issues.
Paradoxically the inlining even reduces the size of the code:
$ ./scripts/bloat-o-meter arch/powerpc/kernel/vdso/vgettimeofday-32.o.before arch/powerpc/kernel/vdso/vgettimeofday-32.o.after add/remove: 0/1 grow/shrink: 1/1 up/down: 52/-148 (-96) Function old new delta __c_kernel_clock_getres_time64 92 144 +52 __c_kernel_clock_getres 136 132 -4 __cvdso_clock_getres_common 144 - -144 Total: Before=2788, After=2692, chg -3.44%
With CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y the functions are always inlined and therefore the behaviour stays the same.
See also the equivalent change for clock_gettime() in commit b91c8c42ffdd ("lib/vdso: Force inlining of __cvdso_clock_gettime_common()").
--- lib/vdso/gettimeofday.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vdso/gettimeofday.c +1 -1
@@ -421,7 +421,7 @@ static __maybe_unused __kernel_old_time_t __cvdso_time(__kernel_old_time_t *time#endif /* VDSO_HAS_TIME */ #ifdef VDSO_HAS_CLOCK_GETRES -static __maybe_unused +static __always_inline bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t clock,struct __kernel_timespec *res) {
---
base-commit: bbef8e2c29c32f048fac8e07f884f827d028f1da
change-id: 20260122-vdso-clock_getres-inline-eec620d6025e
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
[tip: timers/vdso] vdso/gettimeofday: Force inlining of __cvdso_clock_getres_common()
The following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 546e9289c74f606423ef72075b34cc38eda3bb49 Gitweb: https://git.kernel.org/tip/546e9289c74f606423ef72075b34cc38eda3bb49 Author: Thomas Weißschuh <[email protected]> AuthorDate: Fri, 23 Jan 2026 08:35:41 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 26 Jan 2026 22:27:07 +01:00
vdso/gettimeofday: Force inlining of __cvdso_clock_getres_common()
With CONFIG_CC_OPTIMIZE_FOR_SIZE=y, GCC may decide not to inline __cvdso_clock_getres_common(). This introduces spurious internal function calls in the vDSO fastpath.
Furthermore, with automatic stack variable initialization (CONFIG_INIT_STACK_ALL_ZERO or CONFIG_INIT_STACK_ALL_PATTERN) GCC can emit a call to memset() which is not valid in the vDSO.
Mark __cvdso_clock_getres_common() as __always_inline to avoid both issues.
Paradoxically the inlining even reduces the size of the code:
$ ./scripts/bloat-o-meter arch/powerpc/kernel/vdso/vgettimeofday-32.o.before arch/powerpc/kernel/vdso/vgettimeofday-32.o.after add/remove: 0/1 grow/shrink: 1/1 up/down: 52/-148 (-96) Function old new delta __c_kernel_clock_getres_time64 92 144 +52 __c_kernel_clock_getres 136 132 -4 __cvdso_clock_getres_common 144 - -144 Total: Before=2788, After=2692, chg -3.44%
With CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y the functions are always inlined and therefore the behaviour stays the same.
See also the equivalent change for clock_gettime() in commit b91c8c42ffdd ("lib/vdso: Force inlining of __cvdso_clock_gettime_common()").
--- lib/vdso/gettimeofday.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vdso/gettimeofday.c +1 -1
@@ -421,7 +421,7 @@ static __maybe_unused __kernel_old_time_t __cvdso_time(__kernel_old_time_t *time#endif /* VDSO_HAS_TIME */ #ifdef VDSO_HAS_CLOCK_GETRES -static __maybe_unused +static __always_inline bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t clock,struct __kernel_timespec *res) {