[PATCH 2/2] Use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytes
Bartosz Golaszewski
bartekgola at gmail.com
Thu Jun 19 20:42:07 UTC 2014
function old new delta
bb_sc_clk_tck - 10 +10
timescmd 118 113 -5
print_route 1763 1758 -5
mpstat_main 1288 1283 -5
iostat_main 1947 1942 -5
INET_setroute 879 871 -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/5 up/down: 10/-28) Total: -18 bytes
Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
---
include/libbb.h | 2 +-
libbb/sysconf.c | 6 ++++++
networking/libiproute/iproute.c | 2 +-
networking/route.c | 2 +-
procps/iostat.c | 7 +------
procps/mpstat.c | 8 +-------
shell/ash.c | 2 +-
7 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index 4ea0777..a261925 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -732,7 +732,7 @@ extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST
extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
/* sysconf() wrappers */
-
+long bb_sc_clk_tck(void) FAST_FUNC;
/* Define the maximum command-line length limit.
*
* In case neither _SC_ARG_MAX nor ARG_MAX macros are defined
diff --git a/libbb/sysconf.c b/libbb/sysconf.c
index dd79a6d..261631f 100644
--- a/libbb/sysconf.c
+++ b/libbb/sysconf.c
@@ -21,3 +21,9 @@ long FAST_FUNC bb_sc_arg_max(void)
return sysconf(_SC_ARG_MAX) - 2048;
}
#endif
+
+/* Return the number of clock ticks per second. */
+long FAST_FUNC bb_sc_clk_tck(void)
+{
+ return sysconf(_SC_CLK_TCK);
+}
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index f8a67d9..99bf930 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -73,7 +73,7 @@ static unsigned get_hz(void)
fclose(fp);
}
if (!hz_internal)
- hz_internal = sysconf(_SC_CLK_TCK);
+ hz_internal = bb_sc_clk_tck();
return hz_internal;
}
diff --git a/networking/route.c b/networking/route.c
index 4235ea7..eca4177 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -283,7 +283,7 @@ static NOINLINE void INET_setroute(int action, char **args)
if (k == KW_IPVx_IRTT) {
rt->rt_flags |= RTF_IRTT;
rt->rt_irtt = xatoul(args_m1);
- rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */
+ rt->rt_irtt *= (bb_sc_clk_tck() / 100); /* FIXME */
#if 0 /* FIXME: do we need to check anything of this? */
if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
bb_error_msg_and_die("bad irtt");
diff --git a/procps/iostat.c b/procps/iostat.c
index 978d234..924f4c0 100644
--- a/procps/iostat.c
+++ b/procps/iostat.c
@@ -109,11 +109,6 @@ enum {
OPT_m = 1 << 5,
};
-static ALWAYS_INLINE unsigned get_user_hz(void)
-{
- return sysconf(_SC_CLK_TCK);
-}
-
static ALWAYS_INLINE int this_is_smp(void)
{
return (G.total_cpus > 1);
@@ -414,7 +409,7 @@ int iostat_main(int argc UNUSED_PARAM, char **argv)
memset(&stats_data, 0, sizeof(stats_data));
/* Get number of clock ticks per sec */
- G.clk_tck = get_user_hz();
+ G.clk_tck = bb_sc_clk_tck();
/* Determine number of CPUs */
G.total_cpus = get_cpu_count();
diff --git a/procps/mpstat.c b/procps/mpstat.c
index aa5a5c7..b1fe963 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -775,12 +775,6 @@ static void main_loop(void)
/* Initialization */
-/* Get number of clock ticks per sec */
-static ALWAYS_INLINE unsigned get_hz(void)
-{
- return sysconf(_SC_CLK_TCK);
-}
-
static void alloc_struct(int cpus)
{
int i;
@@ -873,7 +867,7 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv)
G.cpu_nr = get_cpu_count();
/* Get number of clock ticks per sec */
- G.hz = get_hz();
+ G.hz = bb_sc_clk_tck();
/* Calculate number of interrupts per processor */
G.irqcpu_nr = get_irqcpu_nr(PROCFS_INTERRUPTS, NR_IRQS) + NR_IRQCPU_PREALLOC;
diff --git a/shell/ash.c b/shell/ash.c
index cabeb40..dc770a3 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12759,7 +12759,7 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
const unsigned char *p;
struct tms buf;
- clk_tck = sysconf(_SC_CLK_TCK);
+ clk_tck = bb_sc_clk_tck();
times(&buf);
p = timescmd_str;
--
1.9.1
More information about the busybox
mailing list