Received: by 10.223.164.221 with SMTP id h29csp2474815wrb; Thu, 2 Nov 2017 11:31:10 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Q62H1uKNKyky+PBkeOW0lrfiUoy0CSpnKueHwITqwpeah5TFxzb4KgefO649sMJtfRHbrF X-Received: by 10.159.245.142 with SMTP id a14mr4153362pls.394.1509647470793; Thu, 02 Nov 2017 11:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509647470; cv=none; d=google.com; s=arc-20160816; b=vmIrvJSZZP8+NHQW/1nTVjls6hqWamAK+GDRFbEDkgBbyrtV9fPdNHxiJiUL9hVtHH QFtepCXB+Sni9Le84ofIabPj30Wn7t5YKLBgsvFz7d0CJGVnzaQJaJO8aUcDXe/AK6hz jMKJqbGQAgeAiZai7HyxPxY6cQbeVWP3iKFJNVNG8kBZ4NdMK6/Ty6xDO3LYlsJRKkHK jd2Rob+eX8YLdh3Oj37UhTgcsczjl1+AsYgRNq5Hlmcv82M+XM8LNQe8cX3aW3+AuA+b ombzc/QsqOdrvRdmN1oL0dSNYfoeoGY3Vf7sqgyry+pPfBW+m9D9ROGY22TOkqvyC6G0 uRIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=94eqedt+Fu+sQz2yjlBFEaFqyGNczb3X2AbIKG+Hu/I=; b=WIXRBv0Kk+bfClhfjurdJTgOHnXqHbavPEoeZWBkPWR/HBHRUAGgPQ3qVHJ7eQ5kQa 76rOklqw/rCSCJcJzQTBcj4h5NJj70ZN82wljIVsGsaAmshh2DiLtS4TGkmqkDUpfehV SaBz1GjbawBb4qhfe+bFGkdXMQHPmluXAiMt+qR6fWwPSwxCwK69LT2AfZQWC9Oz/C3a BTxFKiDw229g13FjkKNA8oEEBxKwm4olWFYAAOGY8uDOwCr2p+69ux3q5YeiefIJrz5k z1xeFRwpeHqQjOnseEYoPKJ2vXC4YQ7uSw6ZuzVPIaMhUjhtQL3kbgtnoss/tePGtkeG J/GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pkjOzlaQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si2824953plb.681.2017.11.02.11.30.56; Thu, 02 Nov 2017 11:31:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pkjOzlaQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933666AbdKBSaO (ORCPT + 97 others); Thu, 2 Nov 2017 14:30:14 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:53311 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752105AbdKBSaM (ORCPT ); Thu, 2 Nov 2017 14:30:12 -0400 Received: by mail-wm0-f67.google.com with SMTP id r196so789268wmf.2; Thu, 02 Nov 2017 11:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=94eqedt+Fu+sQz2yjlBFEaFqyGNczb3X2AbIKG+Hu/I=; b=pkjOzlaQULNFWesYfCElZC7In6gwqLSaganAKwWCjPGBmaRJxpcNaOUH7AbaGMu8Rg D+B2CydkJLKSUwHQ+Tv9wmpqfQJq1MAYKVRk/9HtaBKhYs69NAAF9ypMhfXPZAjm8Bl+ pl5vIPnPepvLr+2ucX1PCJfBxdAwmOVomxQdmN27hedQKSqwj6L3055Z/4JZGYTy23Cp szMA+UNmxien+g0aK5TlpOhpLGc/oydVOFSpwxRwk8Vfqxrj4x85P9yvTODyJiu5vYsA miMRqNq8kyoY1zKvprNbXPVOhCzEGn+l9sH9SNf34v7aqElLfTyiFB+zdBil4FnE3o/9 KBfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=94eqedt+Fu+sQz2yjlBFEaFqyGNczb3X2AbIKG+Hu/I=; b=CgJcqNJXkF2GNOVbk2GwlZWRsRn4h7HcsNeeCVpX5Qh4/jAi1WWxAdlFUDQVP3d63E +ES849SmWayDLCc7H0YJ311EiXgzl2KPNEGYMhTFLvhYJuV6ezItqba7vR56gVdEcIBi g3J/k2e/24zwIAGwIxAXhanArcn97vcSfFp3kTRGmJIhFyb3OgXkpWUE+l2Fyd3Dyq4x oU2GqtKsNYJjKXF2UxlGKpEhHZH2Qr0da89QrLad+lfkNT+kvtleZ6XiVkjEfWbGho/m qLl2am2W/fBxYdHuYfotQHzmDyukQDqV5PswrLb/oOrCLuqnkqhkyLHRYwPgsOH40tUv vfUg== X-Gm-Message-State: AMCzsaUTF4eU05KBW8E+HONlymztZqoKwEgUEz0DTNRoYxYVVWM/VFRi oGK9vjM7URfd/ZwTd560iwY= X-Received: by 10.28.29.205 with SMTP id d196mr2248893wmd.106.1509647410539; Thu, 02 Nov 2017 11:30:10 -0700 (PDT) Received: from rperier-xps-l502x (AToulouse-651-1-14-246.w92-149.abo.wanadoo.fr. [92.149.189.246]) by smtp.gmail.com with ESMTPSA id t135sm276025wmt.24.2017.11.02.11.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 11:30:09 -0700 (PDT) From: Romain Perier To: John Stultz , Thomas Gleixner , Stephen Boyd Cc: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Romain Perier Subject: [PATCH] time: Make NTP optionnal Date: Thu, 2 Nov 2017 19:29:50 +0100 Message-Id: <20171102182950.6129-1-romain.perier@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On embedded systems with limited space, synchronizing system clock via NTP might be not needed. This commit introduces a new Kconfig entry. When disabled, it compiles out the adjtimex and clock_adjtimes system calls. The corresponding NTP accessors are also disabled from timekeeping.c and their declaration are replaced by no_op static inline functions in time.h The bloat-o-meter output is the following: add/remove: 1/35 grow/shrink: 2/9 up/down: 170/-3760 (-3590) function old new delta tk_set_wall_to_mono.constprop - 164 +164 tk_xtime_add.constprop 200 204 +4 timespec_trunc 60 62 +2 ntp_notify_cmos_timer 2 - -2 k_itimer_rcu_free 18 16 -2 timekeeping_forward_now.constprop 256 252 -4 time_status 4 - -4 time_state 4 - -4 time_maxerror 4 - -4 time_esterror 4 - -4 time_constant 4 - -4 time_adjust 4 - -4 tick_usec 4 - -4 tick_nsec 4 - -4 ntp_init 4 - -4 posix_clock_realtime_adj 6 - -6 time_reftime 8 - -8 time_offset 8 - -8 time_freq 8 - -8 tick_length_base 8 - -8 tick_length 8 - -8 ntp_tick_adj 8 - -8 ntp_next_leap_sec 8 - -8 mask_to_bit_num 8 - -8 mask_to_allowed_status 8 - -8 ntp_tick_length 12 - -12 __setup_ntp_tick_adj_setup 12 - -12 __setup_str_ntp_tick_adj_setup 14 - -14 timekeeping_resume 614 598 -16 timekeeping_inject_offset 352 336 -16 timekeeping_init 400 384 -16 do_settimeofday64 342 326 -16 ntp_tick_adj_setup 28 - -28 timekeeping_update 236 206 -30 branch_table 32 - -32 sys_adjtimex 42 - -42 sys_clock_adjtime 64 - -64 ntp_clear 72 - -72 ntp_get_next_leap 76 - -76 ntp_validate_timex 78 - -78 tk_set_wall_to_mono 166 - -166 ntp_update_frequency 180 - -180 update_wall_time 1846 1590 -256 do_adjtimex 272 - -272 second_overflow 476 - -476 bcj_apply 1100 224 -876 __do_adjtimex 888 - -888 Signed-off-by: Romain Perier --- include/linux/timex.h | 14 +++++++++++--- init/Kconfig | 9 +++++++++ kernel/compat.c | 2 ++ kernel/sys_ni.c | 6 ++++++ kernel/time/Makefile | 6 +++++- kernel/time/ntp_internal.h | 29 +++++++++++++++++++++++++++++ kernel/time/posix-timers.c | 13 ++++++++----- kernel/time/time.c | 4 ++-- kernel/time/timekeeping.c | 2 ++ 9 files changed, 74 insertions(+), 11 deletions(-) diff --git a/include/linux/timex.h b/include/linux/timex.h index 39c25dbebfe8..5906b654821a 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -151,12 +151,20 @@ extern unsigned long tick_nsec; /* SHIFTED_HZ period (nsec) */ #define NTP_INTERVAL_FREQ (HZ) #define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ) +#ifdef CONFIG_NTP extern int do_adjtimex(struct timex *); extern void hardpps(const struct timespec64 *, const struct timespec64 *); - -int read_current_timer(unsigned long *timer_val); void ntp_notify_cmos_timer(void); - +#else +static inline int do_adjtimex(struct timex *txc) +{ + return TIME_OK; +} +static inline void hardpps(const struct timespec64 *phase_ts, + const struct timespec64 *raw_ts) +{} +#endif +int read_current_timer(unsigned long *timer_val); /* The clock frequency of the i8253/i8254 PIT */ #define PIT_TICK_RATE 1193182ul diff --git a/init/Kconfig b/init/Kconfig index 3c1faaa2af4a..d4b0b33f7e91 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1332,6 +1332,15 @@ config EVENTFD If unsure, say Y. +config NTP + bool "Enable NTP support" if EXPERT + default y + help + This enables support for synchronizing system clock with NTP + and its corresponding syscalls adjtimex and clock_adjtimex. + + If unsure, say Y. + # syscall, maps, verifier config BPF_SYSCALL bool "Enable bpf() system call" diff --git a/kernel/compat.c b/kernel/compat.c index 772e038d04d9..12945ae5ae94 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -30,6 +30,7 @@ #include +#ifdef CONFIG_NTP int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp) { struct compat_timex tx32; @@ -91,6 +92,7 @@ int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc) return -EFAULT; return 0; } +#endif static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv) { diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 8acef8576ce9..f854d24b813c 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -258,3 +258,9 @@ cond_syscall(sys_membarrier); cond_syscall(sys_pkey_mprotect); cond_syscall(sys_pkey_alloc); cond_syscall(sys_pkey_free); +#ifndef CONFIG_NTP +cond_syscall(sys_adjtimex); +cond_syscall(sys_clock_adjtime); +cond_syscall(compat_sys_adjtimex); +cond_syscall(compat_sys_clock_adjtime); +#endif diff --git a/kernel/time/Makefile b/kernel/time/Makefile index 938dbf33ef49..44bd321e4560 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -1,7 +1,11 @@ obj-y += time.o timer.o hrtimer.o -obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o +obj-y += timekeeping.o clocksource.o jiffies.o timer_list.o obj-y += timeconv.o timecounter.o alarmtimer.o +ifeq ($(CONFIG_NTP),y) + obj-y += ntp.o +endif + ifeq ($(CONFIG_POSIX_TIMERS),y) obj-y += posix-timers.o posix-cpu-timers.o posix-clock.o itimer.o else diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h index d8a7c11fa71a..9d1ebc042968 100644 --- a/kernel/time/ntp_internal.h +++ b/kernel/time/ntp_internal.h @@ -1,6 +1,7 @@ #ifndef _LINUX_NTP_INTERNAL_H #define _LINUX_NTP_INTERNAL_H +#ifdef CONFIG_NTP extern void ntp_init(void); extern void ntp_clear(void); /* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ @@ -10,4 +11,32 @@ extern int second_overflow(time64_t secs); extern int ntp_validate_timex(struct timex *); extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); extern void __hardpps(const struct timespec64 *, const struct timespec64 *); +#else +static inline void ntp_init(void) +{} +static inline void ntp_clear(void) +{} +static inline u64 ntp_tick_length(void) +{ + return 0; +} +static inline ktime_t ntp_get_next_leap(void) +{ + return KTIME_MAX; +} +static inline int second_overflow(time64_t secs) +{ + return 0; +} +static inline int ntp_validate_timex(struct timex *txc) +{ + return 0; +} +static inline int __do_adjtimex(struct timex *txc, struct timespec64 *ts, + s32 *time_tai) +{ + return TIME_OK; +} +#endif + #endif /* _LINUX_NTP_INTERNAL_H */ diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 13d6881f908b..dd31eaddc196 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -207,12 +207,13 @@ static int posix_clock_realtime_set(const clockid_t which_clock, return do_sys_settimeofday64(tp, NULL); } +#ifdef CONFIG_NTP static int posix_clock_realtime_adj(const clockid_t which_clock, struct timex *t) { return do_adjtimex(t); } - +#endif /* * Get monotonic time for posix timers */ @@ -1065,7 +1066,7 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, return error; } - +#ifdef CONFIG_NTP SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, struct timex __user *, utx) { @@ -1088,7 +1089,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, return err; } - +#endif SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) { @@ -1141,7 +1142,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, return err; } - +#ifdef CONFIG_NTP COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, struct compat_timex __user *, utp) { @@ -1165,7 +1166,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, return err; } - +#endif COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, struct compat_timespec __user *, tp) { @@ -1252,7 +1253,9 @@ static const struct k_clock clock_realtime = { .clock_getres = posix_get_hrtimer_res, .clock_get = posix_clock_realtime_get, .clock_set = posix_clock_realtime_set, +#ifdef CONFIG_NTP .clock_adj = posix_clock_realtime_adj, +#endif .nsleep = common_nsleep, .timer_create = common_timer_create, .timer_set = common_timer_set, diff --git a/kernel/time/time.c b/kernel/time/time.c index 44a8c1402133..413eca43a09c 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -297,7 +297,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv, return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); } #endif - +#ifdef CONFIG_NTP SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p) { struct timex txc; /* Local copy of parameter */ @@ -333,7 +333,7 @@ COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp) return ret; } #endif - +#endif /* * Convert jiffies to milliseconds and back. * diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 2cafb49aa65e..223fe15daa75 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2247,6 +2247,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, return base; } +#ifdef CONFIG_NTP /** * do_adjtimex() - Accessor function to NTP __do_adjtimex function */ @@ -2317,6 +2318,7 @@ void hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts) } EXPORT_SYMBOL(hardpps); #endif /* CONFIG_NTP_PPS */ +#endif /* CONFIG_NTP */ /** * xtime_update() - advances the timekeeping infrastructure -- 2.14.1 From 1584761799470432993@xxx Wed Nov 22 10:30:25 +0000 2017 X-GM-THRID: 1584761584885981126 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread