[RFC/PATCH] posix-timers: make them configurable

From: Nicolas Pitre
Date: Thu Sep 08 2016 - 17:20:52 EST



Small embedded systems typically don't need them. This removes about
16KB from the kernel binary size on ARM when configured out.
Corresponding syscalls are routed to a stub logging the attempt to
use those syscalls which should be enough of a clue if they were
disabled without proper consideration.

Signed-off-by: Nicolas Pitre <nico@xxxxxxxxxx>

diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
index ee3de3421f..00e6098e9a 100644
--- a/drivers/ptp/Kconfig
+++ b/drivers/ptp/Kconfig
@@ -6,7 +6,7 @@ menu "PTP clock support"

config PTP_1588_CLOCK
tristate "PTP clock support"
- depends on NET
+ depends on NET && POSIX_TIMERS
select PPS
select NET_PTP_CLASSIFY
help
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig
index 62824f2fe4..b055aa1b6b 100644
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -195,3 +195,13 @@ config HIGH_RES_TIMERS

endmenu
endif
+
+config POSIX_TIMERS
+ bool "Posix Clocks & timers" if EMBEDDED
+ default y
+ help
+ This includes native support for POSIX timers into the kernel.
+ Small embedded systems may have no use for them and therefore they
+ can be configured out to reduce the size of the kernel image.
+ If unsure say y.
+
diff --git a/kernel/time/Makefile b/kernel/time/Makefile
index 49eca0beed..fc26c308f5 100644
--- a/kernel/time/Makefile
+++ b/kernel/time/Makefile
@@ -1,6 +1,12 @@
-obj-y += time.o timer.o hrtimer.o itimer.o posix-timers.o posix-cpu-timers.o
+obj-y += time.o timer.o hrtimer.o itimer.o
obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
-obj-y += timeconv.o timecounter.o posix-clock.o alarmtimer.o
+obj-y += timeconv.o timecounter.o alarmtimer.o
+
+ifeq ($(CONFIG_POSIX_TIMERS),y)
+ obj-y += posix-timers.o posix-cpu-timers.o posix-clock.o
+else
+ obj-y += posix-stubs.o
+endif

obj-$(CONFIG_GENERIC_CLOCKEVENTS) += clockevents.o tick-common.o
ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
new file mode 100644
index 0000000000..879f37f6f3
--- /dev/null
+++ b/kernel/time/posix-stubs.c
@@ -0,0 +1,82 @@
+/*
+ * Dummy stubs used when CONFIG_POSIX_TIMERS=n
+ *
+ * Created by: Nicolas Pitre, July 2016
+ * Copyright: (C) 2016 Linaro Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+#include <linux/kernel.h>
+#include <linux/random.h>
+#include <linux/errno.h>
+#include <linux/posix-timers.h>
+
+asmlinkage long sys_ni_posix_timers(void)
+{
+ pr_err_once("process %d (%s) attempted a POSIX timer syscall "
+ "while CONFIG_POSIX_TIMERS is not set\n",
+ current->pid, current->comm);
+ return -ENOSYS;
+}
+
+#define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
+
+SYS_NI(timer_create);
+SYS_NI(timer_gettime);
+SYS_NI(timer_getoverrun);
+SYS_NI(timer_settime);
+SYS_NI(timer_delete);
+SYS_NI(clock_settime);
+SYS_NI(clock_gettime);
+SYS_NI(clock_adjtime);
+SYS_NI(clock_getres);
+SYS_NI(clock_nanosleep);
+
+void do_schedule_next_timer(struct siginfo *info)
+{
+}
+
+void exit_itimers(struct signal_struct *sig)
+{
+}
+
+void posix_timers_register_clock(const clockid_t clock_id,
+ struct k_clock *new_clock)
+{
+}
+
+int posix_timer_event(struct k_itimer *timr, int si_private)
+{
+ return 0;
+}
+
+void run_posix_cpu_timers(struct task_struct *tsk)
+{
+}
+
+void posix_cpu_timers_exit(struct task_struct *tsk)
+{
+ add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
+ sizeof(unsigned long long));
+}
+
+void posix_cpu_timers_exit_group(struct task_struct *tsk)
+{
+}
+
+void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
+ cputime_t *newval, cputime_t *oldval)
+{
+}
+
+void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new)
+{
+}
+
+void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times)
+{
+}