aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Lichvar <mlichvar@redhat.com>2014-09-18 16:19:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-09-24 15:37:17 +0200
commit590a22cf8d100edc968aa5d691c1ca3000654350 (patch)
treee69adfbbd74930d107d1adeb8b16bf2acf3cc3d5
parentfb143f783da8a3b13ae7a35f6750c2d0c86081e6 (diff)
downloadbusybox-w32-590a22cf8d100edc968aa5d691c1ca3000654350.tar.gz
busybox-w32-590a22cf8d100edc968aa5d691c1ca3000654350.tar.bz2
busybox-w32-590a22cf8d100edc968aa5d691c1ca3000654350.zip
ntpd: split out poll adjusting code
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c76
1 files changed, 39 insertions, 37 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 3c708c1c5..2d1ad69a0 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -1679,6 +1679,41 @@ poll_interval(int exponent)
1679 return interval; 1679 return interval;
1680} 1680}
1681static NOINLINE void 1681static NOINLINE void
1682adjust_poll(int count)
1683{
1684 G.polladj_count += count;
1685 if (G.polladj_count > POLLADJ_LIMIT) {
1686 G.polladj_count = 0;
1687 if (G.poll_exp < MAXPOLL) {
1688 G.poll_exp++;
1689 VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d",
1690 G.discipline_jitter, G.poll_exp);
1691 }
1692 } else if (G.polladj_count < -POLLADJ_LIMIT || (count < 0 && G.poll_exp >= BIGPOLL)) {
1693 G.polladj_count = 0;
1694 if (G.poll_exp > MINPOLL) {
1695 llist_t *item;
1696
1697 G.poll_exp--;
1698 /* Correct p->next_action_time in each peer
1699 * which waits for sending, so that they send earlier.
1700 * Old pp->next_action_time are on the order
1701 * of t + (1 << old_poll_exp) + small_random,
1702 * we simply need to subtract ~half of that.
1703 */
1704 for (item = G.ntp_peers; item != NULL; item = item->link) {
1705 peer_t *pp = (peer_t *) item->data;
1706 if (pp->p_fd < 0)
1707 pp->next_action_time -= (1 << G.poll_exp);
1708 }
1709 VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d",
1710 G.discipline_jitter, G.poll_exp);
1711 }
1712 } else {
1713 VERB4 bb_error_msg("polladj: count:%d", G.polladj_count);
1714 }
1715}
1716static NOINLINE void
1682recv_and_process_peer_pkt(peer_t *p) 1717recv_and_process_peer_pkt(peer_t *p)
1683{ 1718{
1684 int rc; 1719 int rc;
@@ -1837,7 +1872,8 @@ recv_and_process_peer_pkt(peer_t *p)
1837 */ 1872 */
1838 if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) { 1873 if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) {
1839 VERB4 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset); 1874 VERB4 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset);
1840 goto poll_down; 1875 adjust_poll(-POLLADJ_LIMIT * 3);
1876 rc = 0;
1841 } 1877 }
1842 } 1878 }
1843 } 1879 }
@@ -1853,43 +1889,9 @@ recv_and_process_peer_pkt(peer_t *p)
1853 if (rc > 0 && G.offset_to_jitter_ratio <= POLLADJ_GATE) { 1889 if (rc > 0 && G.offset_to_jitter_ratio <= POLLADJ_GATE) {
1854 /* was += G.poll_exp but it is a bit 1890 /* was += G.poll_exp but it is a bit
1855 * too optimistic for my taste at high poll_exp's */ 1891 * too optimistic for my taste at high poll_exp's */
1856 G.polladj_count += MINPOLL; 1892 adjust_poll(MINPOLL);
1857 if (G.polladj_count > POLLADJ_LIMIT) {
1858 G.polladj_count = 0;
1859 if (G.poll_exp < MAXPOLL) {
1860 G.poll_exp++;
1861 VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d",
1862 G.discipline_jitter, G.poll_exp);
1863 }
1864 } else {
1865 VERB4 bb_error_msg("polladj: incr:%d", G.polladj_count);
1866 }
1867 } else { 1893 } else {
1868 G.polladj_count -= G.poll_exp * 2; 1894 adjust_poll(-G.poll_exp * 2);
1869 if (G.polladj_count < -POLLADJ_LIMIT || G.poll_exp >= BIGPOLL) {
1870 poll_down:
1871 G.polladj_count = 0;
1872 if (G.poll_exp > MINPOLL) {
1873 llist_t *item;
1874
1875 G.poll_exp--;
1876 /* Correct p->next_action_time in each peer
1877 * which waits for sending, so that they send earlier.
1878 * Old pp->next_action_time are on the order
1879 * of t + (1 << old_poll_exp) + small_random,
1880 * we simply need to subtract ~half of that.
1881 */
1882 for (item = G.ntp_peers; item != NULL; item = item->link) {
1883 peer_t *pp = (peer_t *) item->data;
1884 if (pp->p_fd < 0)
1885 pp->next_action_time -= (1 << G.poll_exp);
1886 }
1887 VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d",
1888 G.discipline_jitter, G.poll_exp);
1889 }
1890 } else {
1891 VERB4 bb_error_msg("polladj: decr:%d", G.polladj_count);
1892 }
1893 } 1895 }
1894 } 1896 }
1895 1897