summaryrefslogtreecommitdiff
path: root/networking/ntpd.c
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /networking/ntpd.c
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r--networking/ntpd.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index d55b070c5..2700cf515 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -905,7 +905,7 @@ do_sendto(int fd,
905 ret = send_to_from(fd, msg, len, MSG_DONTWAIT, to, from, addrlen); 905 ret = send_to_from(fd, msg, len, MSG_DONTWAIT, to, from, addrlen);
906 } 906 }
907 if (ret != len) { 907 if (ret != len) {
908 bb_perror_msg("send failed"); 908 bb_simple_perror_msg("send failed");
909 return -1; 909 return -1;
910 } 910 }
911 return 0; 911 return 0;
@@ -1121,7 +1121,7 @@ step_time(double offset)
1121 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; 1121 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
1122 d_to_tv(dtime, &tvn); 1122 d_to_tv(dtime, &tvn);
1123 if (settimeofday(&tvn, NULL) == -1) 1123 if (settimeofday(&tvn, NULL) == -1)
1124 bb_perror_msg_and_die("settimeofday"); 1124 bb_simple_perror_msg_and_die("settimeofday");
1125 1125
1126 VERB2 { 1126 VERB2 {
1127 tval = tvc.tv_sec; 1127 tval = tvc.tv_sec;
@@ -1494,7 +1494,7 @@ select_and_cluster(void)
1494 /* Starting from 1 is ok here */ 1494 /* Starting from 1 is ok here */
1495 for (i = 1; i < num_survivors; i++) { 1495 for (i = 1; i < num_survivors; i++) {
1496 if (G.last_update_peer == survivor[i].p) { 1496 if (G.last_update_peer == survivor[i].p) {
1497 VERB5 bb_error_msg("keeping old synced peer"); 1497 VERB5 bb_simple_error_msg("keeping old synced peer");
1498 p = G.last_update_peer; 1498 p = G.last_update_peer;
1499 goto keep_old; 1499 goto keep_old;
1500 } 1500 }
@@ -1702,7 +1702,7 @@ update_local_clock(peer_t *p)
1702#else 1702#else
1703 set_new_values(STATE_SYNC, offset, recv_time); 1703 set_new_values(STATE_SYNC, offset, recv_time);
1704#endif 1704#endif
1705 VERB4 bb_error_msg("transitioning to FREQ, datapoint ignored"); 1705 VERB4 bb_simple_error_msg("transitioning to FREQ, datapoint ignored");
1706 return 0; /* "leave poll interval as is" */ 1706 return 0; /* "leave poll interval as is" */
1707 1707
1708#if 0 /* this is dead code for now */ 1708#if 0 /* this is dead code for now */
@@ -1796,7 +1796,7 @@ update_local_clock(peer_t *p)
1796 VERB4 { 1796 VERB4 {
1797 memset(&tmx, 0, sizeof(tmx)); 1797 memset(&tmx, 0, sizeof(tmx));
1798 if (adjtimex(&tmx) < 0) 1798 if (adjtimex(&tmx) < 0)
1799 bb_perror_msg_and_die("adjtimex"); 1799 bb_simple_perror_msg_and_die("adjtimex");
1800 bb_error_msg("p adjtimex freq:%ld offset:%+ld status:0x%x tc:%ld", 1800 bb_error_msg("p adjtimex freq:%ld offset:%+ld status:0x%x tc:%ld",
1801 tmx.freq, tmx.offset, tmx.status, tmx.constant); 1801 tmx.freq, tmx.offset, tmx.status, tmx.constant);
1802 } 1802 }
@@ -1906,7 +1906,7 @@ update_local_clock(peer_t *p)
1906 //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); 1906 //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6);
1907 rc = adjtimex(&tmx); 1907 rc = adjtimex(&tmx);
1908 if (rc < 0) 1908 if (rc < 0)
1909 bb_perror_msg_and_die("adjtimex"); 1909 bb_simple_perror_msg_and_die("adjtimex");
1910 /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4. 1910 /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4.
1911 * Not sure why. Perhaps it is normal. 1911 * Not sure why. Perhaps it is normal.
1912 */ 1912 */
@@ -2248,7 +2248,7 @@ recv_and_process_client_pkt(void /*int fd*/)
2248 if (size < 0) { 2248 if (size < 0) {
2249 if (errno == EAGAIN) 2249 if (errno == EAGAIN)
2250 goto bail; 2250 goto bail;
2251 bb_perror_msg_and_die("recv"); 2251 bb_simple_perror_msg_and_die("recv");
2252 } 2252 }
2253 addr = xmalloc_sockaddr2dotted_noport(from); 2253 addr = xmalloc_sockaddr2dotted_noport(from);
2254 bb_error_msg("malformed packet received from %s: size %u", addr, (int)size); 2254 bb_error_msg("malformed packet received from %s: size %u", addr, (int)size);
@@ -2415,7 +2415,7 @@ static NOINLINE void ntp_init(char **argv)
2415 srand(getpid()); 2415 srand(getpid());
2416 2416
2417 if (getuid()) 2417 if (getuid())
2418 bb_error_msg_and_die(bb_msg_you_must_be_root); 2418 bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
2419 2419
2420 /* Set some globals */ 2420 /* Set some globals */
2421 G.discipline_jitter = G_precision_sec; 2421 G.discipline_jitter = G_precision_sec;
@@ -2491,7 +2491,7 @@ static NOINLINE void ntp_init(char **argv)
2491 /* supports 'sha' and 'sha1' formats */ 2491 /* supports 'sha' and 'sha1' formats */
2492 hash_type = HASH_SHA1; 2492 hash_type = HASH_SHA1;
2493 else 2493 else
2494 bb_error_msg_and_die("only MD5 and SHA1 keys supported"); 2494 bb_simple_error_msg_and_die("only MD5 and SHA1 keys supported");
2495/* man ntp.keys: 2495/* man ntp.keys:
2496 * MD5 The key is 1 to 16 printable characters terminated by an EOL, 2496 * MD5 The key is 1 to 16 printable characters terminated by an EOL,
2497 * whitespace, or a # (which is the "start of comment" character). 2497 * whitespace, or a # (which is the "start of comment" character).
@@ -2674,7 +2674,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
2674 if (p->p_fd == -1) { 2674 if (p->p_fd == -1) {
2675 /* Time to send new req */ 2675 /* Time to send new req */
2676 if (--cnt == 0) { 2676 if (--cnt == 0) {
2677 VERB4 bb_error_msg("disabling burst mode"); 2677 VERB4 bb_simple_error_msg("disabling burst mode");
2678 G.polladj_count = 0; 2678 G.polladj_count = 0;
2679 G.poll_exp = MINPOLL; 2679 G.poll_exp = MINPOLL;
2680 } 2680 }