libbb: use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytes

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@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Bartosz Golaszewski 2014-06-22 14:01:13 +02:00 committed by Denys Vlasenko
parent f92f1d0181
commit 5d2e409ef8
7 changed files with 12 additions and 16 deletions

View File

@ -738,6 +738,7 @@ unsigned bb_arg_max(void) FAST_FUNC;
#else #else
# define bb_arg_max() ((unsigned)(32 * 1024)) # define bb_arg_max() ((unsigned)(32 * 1024))
#endif #endif
unsigned bb_clk_tck(void) FAST_FUNC;
#define SEAMLESS_COMPRESSION (0 \ #define SEAMLESS_COMPRESSION (0 \
|| ENABLE_FEATURE_SEAMLESS_XZ \ || ENABLE_FEATURE_SEAMLESS_XZ \

View File

@ -14,3 +14,9 @@ unsigned FAST_FUNC bb_arg_max(void)
return sysconf(_SC_ARG_MAX); return sysconf(_SC_ARG_MAX);
} }
#endif #endif
/* Return the number of clock ticks per second. */
unsigned FAST_FUNC bb_clk_tck(void)
{
return sysconf(_SC_CLK_TCK);
}

View File

@ -73,7 +73,7 @@ static unsigned get_hz(void)
fclose(fp); fclose(fp);
} }
if (!hz_internal) if (!hz_internal)
hz_internal = sysconf(_SC_CLK_TCK); hz_internal = bb_clk_tck();
return hz_internal; return hz_internal;
} }

View File

@ -283,7 +283,7 @@ static NOINLINE void INET_setroute(int action, char **args)
if (k == KW_IPVx_IRTT) { if (k == KW_IPVx_IRTT) {
rt->rt_flags |= RTF_IRTT; rt->rt_flags |= RTF_IRTT;
rt->rt_irtt = xatoul(args_m1); rt->rt_irtt = xatoul(args_m1);
rt->rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ rt->rt_irtt *= (bb_clk_tck() / 100); /* FIXME */
#if 0 /* FIXME: do we need to check anything of this? */ #if 0 /* FIXME: do we need to check anything of this? */
if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) { if (rt->rt_irtt < 1 || rt->rt_irtt > (120 * HZ)) {
bb_error_msg_and_die("bad irtt"); bb_error_msg_and_die("bad irtt");

View File

@ -109,11 +109,6 @@ enum {
OPT_m = 1 << 5, 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) static ALWAYS_INLINE int this_is_smp(void)
{ {
return (G.total_cpus > 1); 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)); memset(&stats_data, 0, sizeof(stats_data));
/* Get number of clock ticks per sec */ /* Get number of clock ticks per sec */
G.clk_tck = get_user_hz(); G.clk_tck = bb_clk_tck();
/* Determine number of CPUs */ /* Determine number of CPUs */
G.total_cpus = get_cpu_count(); G.total_cpus = get_cpu_count();

View File

@ -775,12 +775,6 @@ static void main_loop(void)
/* Initialization */ /* 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) static void alloc_struct(int cpus)
{ {
int i; int i;
@ -873,7 +867,7 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv)
G.cpu_nr = get_cpu_count(); G.cpu_nr = get_cpu_count();
/* Get number of clock ticks per sec */ /* Get number of clock ticks per sec */
G.hz = get_hz(); G.hz = bb_clk_tck();
/* Calculate number of interrupts per processor */ /* Calculate number of interrupts per processor */
G.irqcpu_nr = get_irqcpu_nr(PROCFS_INTERRUPTS, NR_IRQS) + NR_IRQCPU_PREALLOC; G.irqcpu_nr = get_irqcpu_nr(PROCFS_INTERRUPTS, NR_IRQS) + NR_IRQCPU_PREALLOC;

View File

@ -12759,7 +12759,7 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
const unsigned char *p; const unsigned char *p;
struct tms buf; struct tms buf;
clk_tck = sysconf(_SC_CLK_TCK); clk_tck = bb_clk_tck();
times(&buf); times(&buf);
p = timescmd_str; p = timescmd_str;