From b20b3790b428aab75449995d0866bad15879bc00 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 13 Jul 2024 11:46:15 +0200 Subject: powertop: code shrink function old new delta print_intel_cstates 477 475 -2 Signed-off-by: Denys Vlasenko --- procps/powertop.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/procps/powertop.c b/procps/powertop.c index 147b7a3ef..6fe892540 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -498,24 +498,11 @@ static NOINLINE int process_timer_stats(void) } #ifdef __i386__ -/* - * Get information about CPU using CPUID opcode. - */ -static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, - unsigned int *edx) +static void cpuid_eax_ecx_edx(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) { - /* EAX value specifies what information to return */ - asm ( - " cpuid\n" - : "=a"(*eax), /* Output */ - "=b"(*ebx), - "=c"(*ecx), - "=d"(*edx) - : "0"(*eax), /* Input */ - "1"(*ebx), - "2"(*ecx), - "3"(*edx) - /* No clobbered registers */ + asm ("cpuid" + : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) + : "0" (*eax), "2" (*ecx), "3" (*edx) ); } #endif @@ -592,8 +579,8 @@ static NOINLINE void print_intel_cstates(void) return; eax = 5; - ebx = ecx = edx = 0; - cpuid(&eax, &ebx, &ecx, &edx); + ecx = edx = 0; /* paranoia, should not be needed */ + cpuid_eax_ecx_edx(&eax, /*unused:*/&ebx, &ecx, &edx); if (!edx || !(ecx & 1)) return; -- cgit v1.2.3-55-g6feb From e4b5ccd13bb59eaaec6aa7f22655cc469f8900a2 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 8 Apr 2024 13:12:25 +0100 Subject: timeout: allow fractional seconds in timeout values The 'timeout' applet uses parse_duration_str() to obtain its timeout values. The default configuration enables float durations. However, the applet silently ignores fractional seconds. This results in unexpected behaviour: $ timeout 5.99 sleep 5.1; echo $? Terminated 143 When float durations are enabled ensure that any fractional seconds are taken into account. function old new delta timeout_wait 44 92 +48 timeout_main 383 365 -18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18) Total: 30 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- coreutils/timeout.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 18aa9ebeb..84299a0a5 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c @@ -47,11 +47,16 @@ #include "libbb.h" -static NOINLINE int timeout_wait(int timeout, pid_t pid) +static NOINLINE int timeout_wait(duration_t timeout, pid_t pid) { /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ while (1) { - sleep1(); +#if ENABLE_FLOAT_DURATION + if (timeout < 1) + sleep_for_duration(timeout); + else +#endif + sleep1(); if (--timeout <= 0) break; if (kill(pid, 0)) { @@ -68,8 +73,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) int signo; int status; int parent = 0; - int timeout; - int kill_timeout; + duration_t timeout; + duration_t kill_timeout; pid_t pid; #if !BB_MMU char *sv1, *sv2; -- cgit v1.2.3-55-g6feb From 371fe9f71d445d18be28c82a2a6d82115c8af19d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 6 Apr 2024 09:50:42 +0100 Subject: ash: move hashvar() calls into findvar() dash has accepted a patch to remove the first argument of findvar(). It's commit e85e972 (var: move hashvar() calls into findvar()). Apply the same change to BusyBox ash. function old new delta findvar 35 40 +5 mklocal 268 261 -7 exportcmd 164 157 -7 setvareq 319 310 -9 lookupvar 150 141 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32) Total: -27 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- shell/ash.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 9da3e956a..bbd730770 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2327,9 +2327,11 @@ initvar(void) } static struct var ** -findvar(struct var **vpp, const char *name) +findvar(const char *name) { - for (; *vpp; vpp = &(*vpp)->next) { + struct var **vpp; + + for (vpp = hashvar(name); *vpp; vpp = &(*vpp)->next) { if (varcmp((*vpp)->var_text, name) == 0) { break; } @@ -2345,7 +2347,7 @@ lookupvar(const char *name) { struct var *v; - v = *findvar(hashvar(name), name); + v = *findvar(name); if (v) { #if ENABLE_ASH_RANDOM_SUPPORT || BASH_EPOCH_VARS /* @@ -2412,9 +2414,8 @@ setvareq(char *s, int flags) { struct var *vp, **vpp; - vpp = hashvar(s); flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1)); - vpp = findvar(vpp, s); + vpp = findvar(s); vp = *vpp; if (vp) { if ((vp->flags & (VREADONLY|VDYNAMIC)) == VREADONLY) { @@ -9978,7 +9979,6 @@ static void mklocal(char *name, int flags) { struct localvar *lvp; - struct var **vpp; struct var *vp; char *eq = strchr(name, '='); @@ -10007,8 +10007,7 @@ mklocal(char *name, int flags) lvp->text = memcpy(p, optlist, sizeof(optlist)); vp = NULL; } else { - vpp = hashvar(name); - vp = *findvar(vpp, name); + vp = *findvar(name); if (vp == NULL) { /* variable did not exist yet */ if (eq) @@ -14156,7 +14155,7 @@ exportcmd(int argc UNUSED_PARAM, char **argv) if (p != NULL) { p++; } else { - vp = *findvar(hashvar(name), name); + vp = *findvar(name); if (vp) { vp->flags = ((vp->flags | flag) & flag_off); continue; -- cgit v1.2.3-55-g6feb