aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-03-26 12:02:08 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-03-26 12:02:08 +0100
commit1195782d79d282639f54ef9620a9211c96c572f1 (patch)
tree3a910c762453bfa92864c12f4da6ac2dd644a0c0
parentc2bd0b680667c7ec4956552f75d9ff7d040ac941 (diff)
downloadbusybox-w32-1195782d79d282639f54ef9620a9211c96c572f1.tar.gz
busybox-w32-1195782d79d282639f54ef9620a9211c96c572f1.tar.bz2
busybox-w32-1195782d79d282639f54ef9620a9211c96c572f1.zip
ntpd: code shrink (force not-inlining, stop returning structs)
function old new delta d_to_sfp - 133 +133 lfp_to_d - 84 +84 sfp_to_d - 78 +78 d_to_lfp 141 137 -4 .rodata 103182 103174 -8 recv_and_process_peer_pkt 2380 2173 -207 recv_and_process_client_pkt 706 493 -213 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 0/4 up/down: 295/-432) Total: -137 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 0f350fa6f..8cf8830c2 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -552,13 +552,13 @@ gettime1900d(void)
552} 552}
553 553
554static void 554static void
555d_to_tv(double d, struct timeval *tv) 555d_to_tv(struct timeval *tv, double d)
556{ 556{
557 tv->tv_sec = (long)d; 557 tv->tv_sec = (long)d;
558 tv->tv_usec = (d - tv->tv_sec) * 1000000; 558 tv->tv_usec = (d - tv->tv_sec) * 1000000;
559} 559}
560 560
561static double 561static NOINLINE double
562lfp_to_d(l_fixedpt_t lfp) 562lfp_to_d(l_fixedpt_t lfp)
563{ 563{
564 double ret; 564 double ret;
@@ -567,7 +567,7 @@ lfp_to_d(l_fixedpt_t lfp)
567 ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX); 567 ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX);
568 return ret; 568 return ret;
569} 569}
570static double 570static NOINLINE double
571sfp_to_d(s_fixedpt_t sfp) 571sfp_to_d(s_fixedpt_t sfp)
572{ 572{
573 double ret; 573 double ret;
@@ -577,25 +577,25 @@ sfp_to_d(s_fixedpt_t sfp)
577 return ret; 577 return ret;
578} 578}
579#if ENABLE_FEATURE_NTPD_SERVER 579#if ENABLE_FEATURE_NTPD_SERVER
580static l_fixedpt_t 580static void
581d_to_lfp(double d) 581d_to_lfp(l_fixedpt_t *lfp, double d)
582{ 582{
583 l_fixedpt_t lfp; 583 uint32_t intl;
584 lfp.int_partl = (uint32_t)d; 584 uint32_t frac;
585 lfp.fractionl = (uint32_t)((d - lfp.int_partl) * UINT_MAX); 585 intl = (uint32_t)d;
586 lfp.int_partl = htonl(lfp.int_partl); 586 frac = (uint32_t)((d - intl) * UINT_MAX);
587 lfp.fractionl = htonl(lfp.fractionl); 587 lfp->int_partl = htonl(intl);
588 return lfp; 588 lfp->fractionl = htonl(frac);
589} 589}
590static s_fixedpt_t 590static NOINLINE void
591d_to_sfp(double d) 591d_to_sfp(s_fixedpt_t *sfp, double d)
592{ 592{
593 s_fixedpt_t sfp; 593 uint16_t ints;
594 sfp.int_parts = (uint16_t)d; 594 uint16_t frac;
595 sfp.fractions = (uint16_t)((d - sfp.int_parts) * USHRT_MAX); 595 ints = (uint16_t)d;
596 sfp.int_parts = htons(sfp.int_parts); 596 frac = (uint16_t)((d - ints) * USHRT_MAX);
597 sfp.fractions = htons(sfp.fractions); 597 sfp->int_parts = htons(ints);
598 return sfp; 598 sfp->fractions = htons(frac);
599} 599}
600#endif 600#endif
601 601
@@ -1037,7 +1037,7 @@ step_time(double offset)
1037 1037
1038 xgettimeofday(&tvc); 1038 xgettimeofday(&tvc);
1039 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; 1039 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
1040 d_to_tv(dtime, &tvn); 1040 d_to_tv(&tvn, dtime);
1041 xsettimeofday(&tvn); 1041 xsettimeofday(&tvn);
1042 1042
1043 VERB2 { 1043 VERB2 {
@@ -2117,17 +2117,17 @@ recv_and_process_client_pkt(void /*int fd*/)
2117 msg.m_ppoll = G.poll_exp; 2117 msg.m_ppoll = G.poll_exp;
2118 msg.m_precision_exp = G_precision_exp; 2118 msg.m_precision_exp = G_precision_exp;
2119 /* this time was obtained between poll() and recv() */ 2119 /* this time was obtained between poll() and recv() */
2120 msg.m_rectime = d_to_lfp(G.cur_time); 2120 d_to_lfp(&msg.m_rectime, G.cur_time);
2121 msg.m_xmttime = d_to_lfp(gettime1900d()); /* this instant */ 2121 d_to_lfp(&msg.m_xmttime, gettime1900d()); /* this instant */
2122 if (G.peer_cnt == 0) { 2122 if (G.peer_cnt == 0) {
2123 /* we have no peers: "stratum 1 server" mode. reftime = our own time */ 2123 /* we have no peers: "stratum 1 server" mode. reftime = our own time */
2124 G.reftime = G.cur_time; 2124 G.reftime = G.cur_time;
2125 } 2125 }
2126 msg.m_reftime = d_to_lfp(G.reftime); 2126 d_to_lfp(&msg.m_reftime, G.reftime);
2127 msg.m_orgtime = query_xmttime; 2127 msg.m_orgtime = query_xmttime;
2128 msg.m_rootdelay = d_to_sfp(G.rootdelay); 2128 d_to_sfp(&msg.m_rootdelay, G.rootdelay);
2129//simple code does not do this, fix simple code! 2129//simple code does not do this, fix simple code!
2130 msg.m_rootdisp = d_to_sfp(G.rootdisp); 2130 d_to_sfp(&msg.m_rootdisp, G.rootdisp);
2131 //version = (query_status & VERSION_MASK); /* ... >> VERSION_SHIFT - done below instead */ 2131 //version = (query_status & VERSION_MASK); /* ... >> VERSION_SHIFT - done below instead */
2132 msg.m_refid = G.refid; // (version > (3 << VERSION_SHIFT)) ? G.refid : G.refid3; 2132 msg.m_refid = G.refid; // (version > (3 << VERSION_SHIFT)) ? G.refid : G.refid3;
2133 2133