Skip to contentSkip to conversation

constify struct k_clock

PATCH In review Christoph Hellwig 4 participants 12 messages May 26, 2017 – May 27, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

this series constifies all struct k_clock instances as well as the global posix_clocks array. To do so it first removes the SGI mmtimer driver, which only supports very old IA64 hardware, as that drivers has the only non core kernel struct k_clock instance.

#1 lore raw

PATCH 1/2 remove the SGI SN2 mmtimer driver

This driver supports direct system clock access on the ancient SGI SN2 IA64 systems, and implement the only non-builtin k_clock instance. Remove it as any remaining IA64 altix user will be running just as old distros anyway.

Note that this does not affect the never uv_mmtimer driver for x86-based Altix systems.

---
 drivers/char/Kconfig   |   9 -
 drivers/char/Makefile  |   1 -
 drivers/char/mmtimer.c | 858 -------------------------------------------------
 3 files changed, 868 deletions(-)
 delete mode 100644 drivers/char/mmtimer.c
drivers/char/Kconfig +0 -9
index 31adbebf812e..2af70014ee5a 100644
@@ -539,15 +539,6 @@ config HANGCHECK_TIMER
 	  out to lunch past a certain margin.  It can reboot the system
 	  or merely print a warning.
 
-config MMTIMER
-	tristate "MMTIMER Memory mapped RTC for SGI Altix"
-	depends on IA64_GENERIC || IA64_SGI_SN2
-	depends on POSIX_TIMERS
-	default y
-	help
-	  The mmtimer device allows direct userspace access to the
-	  Altix system timer.
-
 config UV_MMTIMER
 	tristate "UV_MMTIMER Memory mapped RTC for SGI UV"
 	depends on X86_UV
drivers/char/Makefile +0 -1
index 6e6c244a66a0..53e33720818c 100644
@@ -10,7 +10,6 @@ obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
 obj-$(CONFIG_RAW_DRIVER)	+= raw.o
 obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
 obj-$(CONFIG_MSPEC)		+= mspec.o
-obj-$(CONFIG_MMTIMER)		+= mmtimer.o
 obj-$(CONFIG_UV_MMTIMER)	+= uv_mmtimer.o
 obj-$(CONFIG_IBM_BSR)		+= bsr.o
 obj-$(CONFIG_SGI_MBCS)		+= mbcs.o
drivers/char/mmtimer.c deleted +0 -858

858 lines not on this page · raw message

Signature · 1 line
2.11.0
#2 lore raw

[tip:timers/core] mmtimer: Remove the SGI SN2 mmtimer driver

mmtimer: Remove the SGI SN2 mmtimer driver
Commit-ID:  07903ada96139ced48f2f893fe57a26a8fbc6043
Gitweb:     http://git.kernel.org/tip/07903ada96139ced48f2f893fe57a26a8fbc6043
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Fri, 26 May 2017 12:03:10 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 26 May 2017 12:52:19 +0200

mmtimer: Remove the SGI SN2 mmtimer driver

This driver supports direct system clock access on the ancient SGI SN2 IA64 systems, and implement the only non-builtin k_clock instance. Remove it as any remaining IA64 altix user will be running just as old distros anyway.

Dimitri Sivanich stated: "Since this is SN2 specific, this can be removed."

Note that this does not affect the never uv_mmtimer driver for x86-based Altix systems.

[ tglx: Added comment to CLOCK_SGI_CYCLE ]

---
 drivers/char/Kconfig      |   9 -
 drivers/char/Makefile     |   1 -
 drivers/char/mmtimer.c    | 858 ----------------------------------------------
 include/uapi/linux/time.h |   6 +-
 4 files changed, 5 insertions(+), 869 deletions(-)
drivers/char/Kconfig +0 -9
index 31adbeb..2af7001 100644
@@ -539,15 +539,6 @@ config HANGCHECK_TIMER
 	  out to lunch past a certain margin.  It can reboot the system
 	  or merely print a warning.
 
-config MMTIMER
-	tristate "MMTIMER Memory mapped RTC for SGI Altix"
-	depends on IA64_GENERIC || IA64_SGI_SN2
-	depends on POSIX_TIMERS
-	default y
-	help
-	  The mmtimer device allows direct userspace access to the
-	  Altix system timer.
-
 config UV_MMTIMER
 	tristate "UV_MMTIMER Memory mapped RTC for SGI UV"
 	depends on X86_UV
drivers/char/Makefile +0 -1
index 6e6c244..53e3372 100644
@@ -10,7 +10,6 @@ obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
 obj-$(CONFIG_RAW_DRIVER)	+= raw.o
 obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
 obj-$(CONFIG_MSPEC)		+= mspec.o
-obj-$(CONFIG_MMTIMER)		+= mmtimer.o
 obj-$(CONFIG_UV_MMTIMER)	+= uv_mmtimer.o
 obj-$(CONFIG_IBM_BSR)		+= bsr.o
 obj-$(CONFIG_SGI_MBCS)		+= mbcs.o
drivers/char/mmtimer.c deleted +0 -858

858 lines not on this page · raw message

include/uapi/linux/time.h +5 -1
index e75e1b6..09299fc 100644
@@ -54,7 +54,11 @@ struct itimerval {
 #define CLOCK_BOOTTIME			7
 #define CLOCK_REALTIME_ALARM		8
 #define CLOCK_BOOTTIME_ALARM		9
-#define CLOCK_SGI_CYCLE			10	/* Hardware specific */
+/*
+ * The driver implementing this got removed. The clock ID is kept as a
+ * place holder. Do not reuse!
+ */
+#define CLOCK_SGI_CYCLE			10
 #define CLOCK_TAI			11
 
 #define MAX_CLOCKS			16
#3 lore raw

Re: [tip:timers/core] mmtimer: Remove the SGI SN2 mmtimer driver

Quoted 1 line · tip-bot for Christoph Hellwig

Commit-ID: 07903ada96139ced48f2f893fe57a26a8fbc6043

Couple trivial comments:

Quoted 1 line

mmtimer: Remove the SGI SN2 mmtimer driver

[]

Quoted 2 lines
 drivers/char/mmtimer.c    | 858 ----------------------------------------------
 include/uapi/linux/time.h |   6 +-

[]

drivers/char/mmtimer.c line 1

Quoted 7 lines
drivers/char/mmtimer.c deleted +0 -1
deleted file mode 100644
index 0e7fcb0..0000000
@@ -1,858 +0,0 @@
-/*

[ etc...]

In the future, please use git format-patch -M to avoid listing the
contents of the file deletion.

include/uapi/linux/time.h

Quoted 1 line
include/uapi/linux/time.h +0 -0

[]

include/uapi/linux/time.h struct itimerval { · line 64

Quoted 13 lines
include/uapi/linux/time.h +5 -1
@@ -54,7 +54,11 @@ struct itimerval {
 #define CLOCK_BOOTTIME			7
 #define CLOCK_REALTIME_ALARM		8
 #define CLOCK_BOOTTIME_ALARM		9
-#define CLOCK_SGI_CYCLE			10	/* Hardware specific */
+/*
+ * The driver implementing this got removed. The clock ID is kept as a
+ * place holder. Do not reuse!
+ */
+#define CLOCK_SGI_CYCLE			10
 #define CLOCK_TAI			11
 
 #define MAX_CLOCKS			16

Here the "this" comment is a bit ambiguous.

It might be better to rename CLOCK_SGI_CYCLE as well. Maybe something like CLOCK_SGI_CYCLE_DELETED_DRIVER_DONT_REUSE.

#4 lore raw

PATCH 2/2 kernel: mark all struct k_clock instances const

In reply to Christoph Hellwig

And initialize the array statically at compile time. Originally
based on changes in the Grsecurity patch set, but redone for mainline to be slightly cleaner, and take the SGI mmtimer removal into account, which allows for a completely static initialization.

---
 include/linux/posix-timers.h   |   9 +-
 kernel/time/alarmtimer.c       |  27 +++---
 kernel/time/posix-clock.c      |   2 +-
 kernel/time/posix-cpu-timers.c |  34 +++-----
 kernel/time/posix-timers.c     | 191 +++++++++++++++++++----------------------
 5 files changed, 120 insertions(+), 143 deletions(-)
include/linux/posix-timers.h +5 -4
index 8c1e43ab14a9..b313ef2e7385 100644
@@ -105,10 +105,11 @@ struct k_clock {
 			   struct itimerspec64 *cur_setting);
 };
 
-extern struct k_clock clock_posix_cpu;
-extern struct k_clock clock_posix_dynamic;
-
-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
+extern const struct k_clock clock_posix_cpu;
+extern const struct k_clock clock_posix_dynamic;
+extern const struct k_clock clock_process;
+extern const struct k_clock clock_thread;
+extern const struct k_clock alarm_clock;
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
kernel/time/alarmtimer.c +12 -15
index 5cb5b0008d97..2914ead22a8d 100644
@@ -488,7 +488,7 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
 }
 EXPORT_SYMBOL_GPL(alarm_forward_now);
 
-
+#ifdef CONFIG_POSIX_TIMERS
 /**
  * clock2alarm - helper that converts from clockid to alarmtypes
  * @clockid: clockid.
@@ -860,6 +860,17 @@ static struct platform_driver alarmtimer_driver = {
 	}
 };
 
+const struct k_clock alarm_clock = {
+	.clock_getres	= alarm_clock_getres,
+	.clock_get	= alarm_clock_get,
+	.timer_create	= alarm_timer_create,
+	.timer_set	= alarm_timer_set,
+	.timer_del	= alarm_timer_del,
+	.timer_get	= alarm_timer_get,
+	.nsleep		= alarm_timer_nsleep,
+};
+#endif /* CONFIG_POSIX_TIMERS */
+
 /**
  * alarmtimer_init - Initialize alarm timer code
  *
@@ -871,23 +882,9 @@ static int __init alarmtimer_init(void)
 	struct platform_device *pdev;
 	int error = 0;
 	int i;
-	struct k_clock alarm_clock = {
-		.clock_getres	= alarm_clock_getres,
-		.clock_get	= alarm_clock_get,
-		.timer_create	= alarm_timer_create,
-		.timer_set	= alarm_timer_set,
-		.timer_del	= alarm_timer_del,
-		.timer_get	= alarm_timer_get,
-		.nsleep		= alarm_timer_nsleep,
-	};
 
 	alarmtimer_rtc_timer_init();
 
-	if (IS_ENABLED(CONFIG_POSIX_TIMERS)) {
-		posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
-		posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
-	}
-
 	/* Initialize alarm bases */
 	alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
 	alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
kernel/time/posix-clock.c +1 -1
index 31d588d37a17..7e453005e078 100644
@@ -434,7 +434,7 @@ static int pc_timer_settime(struct k_itimer *kit, int flags,
 	return err;
 }
 
-struct k_clock clock_posix_dynamic = {
+const struct k_clock clock_posix_dynamic = {
 	.clock_getres	= pc_clock_getres,
 	.clock_set	= pc_clock_settime,
 	.clock_get	= pc_clock_gettime,
kernel/time/posix-cpu-timers.c +13 -21
index 1370f067fb51..1a522b39f19d 100644
@@ -1413,7 +1413,7 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 	return posix_cpu_timer_create(timer);
 }
 
-struct k_clock clock_posix_cpu = {
+const struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
 	.clock_set	= posix_cpu_clock_set,
 	.clock_get	= posix_cpu_clock_get,
@@ -1425,24 +1425,16 @@ struct k_clock clock_posix_cpu = {
 	.timer_get	= posix_cpu_timer_get,
 };
 
-static __init int init_posix_cpu_timers(void)
-{
-	struct k_clock process = {
-		.clock_getres	= process_cpu_clock_getres,
-		.clock_get	= process_cpu_clock_get,
-		.timer_create	= process_cpu_timer_create,
-		.nsleep		= process_cpu_nsleep,
-		.nsleep_restart	= process_cpu_nsleep_restart,
-	};
-	struct k_clock thread = {
-		.clock_getres	= thread_cpu_clock_getres,
-		.clock_get	= thread_cpu_clock_get,
-		.timer_create	= thread_cpu_timer_create,
-	};
-
-	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+const struct k_clock clock_process = {
+	.clock_getres	= process_cpu_clock_getres,
+	.clock_get	= process_cpu_clock_get,
+	.timer_create	= process_cpu_timer_create,
+	.nsleep		= process_cpu_nsleep,
+	.nsleep_restart	= process_cpu_nsleep_restart,
+};
 
-	return 0;
-}
-__initcall(init_posix_cpu_timers);
+const struct k_clock clock_thread = {
+	.clock_getres	= thread_cpu_clock_getres,
+	.clock_get	= thread_cpu_clock_get,
+	.timer_create	= thread_cpu_timer_create,
+};
kernel/time/posix-timers.c +89 -102

286 lines not on this page · raw message

Signature · 1 line
2.11.0
#5 lore raw

Re: [PATCH 2/2] kernel: mark all struct k_clock instances const

Quoted 4 lines · Christoph Hellwig

And initialize the array statically at compile time. Originally
based on changes in the Grsecurity patch set, but redone for mainline to be slightly cleaner, and take the SGI mmtimer removal into account, which allows for a completely static initialization.

Maybe add k_clock to scripts/const_structs.checkpatch
---

$ git diff --stat -p scripts/const_structs.checkpatch
 scripts/const_structs.checkpatch | 1 +
 1 file changed, 1 insertion(+)
scripts/const_structs.checkpatch +0 -0
index ac5f1267151d..b2a2316964a8 100644
@@ -25,6 +25,7 @@ irq_domain_ops

 item_operations
 iwl_cfg
 iwl_ops
+k_clock
 kgdb_arch
 kgdb_io
 kset_uevent_ops

#6 lore raw

Re: [PATCH 2/2] kernel: mark all struct k_clock instances const

Quoted 7 lines · Joe Perches
Quoted 4 lines · Christoph Hellwig

And initialize the array statically at compile time. Originally
based on changes in the Grsecurity patch set, but redone for mainline to be slightly cleaner, and take the SGI mmtimer removal into account, which allows for a completely static initialization.

Maybe add k_clock to scripts/const_structs.checkpatch

Care to send a proper patch with changelog?

Quoted 18 lines

---

$ git diff --stat -p scripts/const_structs.checkpatch
 scripts/const_structs.checkpatch | 1 +
 1 file changed, 1 insertion(+)
scripts/const_structs.checkpatch +0 -0
index ac5f1267151d..b2a2316964a8 100644
@@ -25,6 +25,7 @@ irq_domain_ops

 item_operations
 iwl_cfg
 iwl_ops
+k_clock
 kgdb_arch
 kgdb_io
 kset_uevent_ops

#7 lore raw

Re: [PATCH 2/2] kernel: mark all struct k_clock instances const

Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Joe Perches
Quoted 4 lines · Christoph Hellwig

And initialize the array statically at compile time. Originally
based on changes in the Grsecurity patch set, but redone for mainline to be slightly cleaner, and take the SGI mmtimer removal into account, which allows for a completely static initialization.

Maybe add k_clock to scripts/const_structs.checkpatch

Care to send a proper patch with changelog?

After Christoph's patch is in -next so I can reference the proper commit SHA1.

#8 lore raw

[tip:timers/core] posix-timers: Make posix_clocks immutable

In reply to Christoph Hellwig
posix-timers: Make posix_clocks immutable
Commit-ID:  74377deb3c19639ab5c0a8c2b5301d67c45ba83c
Gitweb:     http://git.kernel.org/tip/74377deb3c19639ab5c0a8c2b5301d67c45ba83c
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Fri, 26 May 2017 12:03:11 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 26 May 2017 12:52:20 +0200

posix-timers: Make posix_clocks immutable

There are no more modular users providing a posix clock. The register function is now pointless so the posix clock array can be initialized statically at compile time and the array including the various k_clock structs can be marked 'const'.

Inspired by changes in the Grsecurity patch set, but done proper.

[ tglx: Massaged changelog ]

---
 include/linux/posix-timers.h   |   9 +-
 kernel/time/alarmtimer.c       |  27 +++---
 kernel/time/posix-clock.c      |   2 +-
 kernel/time/posix-cpu-timers.c |  34 +++-----
 kernel/time/posix-timers.c     | 191 +++++++++++++++++++----------------------
 5 files changed, 120 insertions(+), 143 deletions(-)
include/linux/posix-timers.h +5 -4
index 8c1e43a..b313ef2 100644
@@ -105,10 +105,11 @@ struct k_clock {
 			   struct itimerspec64 *cur_setting);
 };
 
-extern struct k_clock clock_posix_cpu;
-extern struct k_clock clock_posix_dynamic;
-
-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
+extern const struct k_clock clock_posix_cpu;
+extern const struct k_clock clock_posix_dynamic;
+extern const struct k_clock clock_process;
+extern const struct k_clock clock_thread;
+extern const struct k_clock alarm_clock;
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
kernel/time/alarmtimer.c +12 -15
index 5cb5b00..2914ead 100644
@@ -488,7 +488,7 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
 }
 EXPORT_SYMBOL_GPL(alarm_forward_now);
 
-
+#ifdef CONFIG_POSIX_TIMERS
 /**
  * clock2alarm - helper that converts from clockid to alarmtypes
  * @clockid: clockid.
@@ -860,6 +860,17 @@ static struct platform_driver alarmtimer_driver = {
 	}
 };
 
+const struct k_clock alarm_clock = {
+	.clock_getres	= alarm_clock_getres,
+	.clock_get	= alarm_clock_get,
+	.timer_create	= alarm_timer_create,
+	.timer_set	= alarm_timer_set,
+	.timer_del	= alarm_timer_del,
+	.timer_get	= alarm_timer_get,
+	.nsleep		= alarm_timer_nsleep,
+};
+#endif /* CONFIG_POSIX_TIMERS */
+
 /**
  * alarmtimer_init - Initialize alarm timer code
  *
@@ -871,23 +882,9 @@ static int __init alarmtimer_init(void)
 	struct platform_device *pdev;
 	int error = 0;
 	int i;
-	struct k_clock alarm_clock = {
-		.clock_getres	= alarm_clock_getres,
-		.clock_get	= alarm_clock_get,
-		.timer_create	= alarm_timer_create,
-		.timer_set	= alarm_timer_set,
-		.timer_del	= alarm_timer_del,
-		.timer_get	= alarm_timer_get,
-		.nsleep		= alarm_timer_nsleep,
-	};
 
 	alarmtimer_rtc_timer_init();
 
-	if (IS_ENABLED(CONFIG_POSIX_TIMERS)) {
-		posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
-		posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
-	}
-
 	/* Initialize alarm bases */
 	alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
 	alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
kernel/time/posix-clock.c +1 -1
index 31d588d..7e45300 100644
@@ -434,7 +434,7 @@ static int pc_timer_settime(struct k_itimer *kit, int flags,
 	return err;
 }
 
-struct k_clock clock_posix_dynamic = {
+const struct k_clock clock_posix_dynamic = {
 	.clock_getres	= pc_clock_getres,
 	.clock_set	= pc_clock_settime,
 	.clock_get	= pc_clock_gettime,
kernel/time/posix-cpu-timers.c +13 -21
index 1370f06..1a522b3 100644
@@ -1413,7 +1413,7 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 	return posix_cpu_timer_create(timer);
 }
 
-struct k_clock clock_posix_cpu = {
+const struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
 	.clock_set	= posix_cpu_clock_set,
 	.clock_get	= posix_cpu_clock_get,
@@ -1425,24 +1425,16 @@ struct k_clock clock_posix_cpu = {
 	.timer_get	= posix_cpu_timer_get,
 };
 
-static __init int init_posix_cpu_timers(void)
-{
-	struct k_clock process = {
-		.clock_getres	= process_cpu_clock_getres,
-		.clock_get	= process_cpu_clock_get,
-		.timer_create	= process_cpu_timer_create,
-		.nsleep		= process_cpu_nsleep,
-		.nsleep_restart	= process_cpu_nsleep_restart,
-	};
-	struct k_clock thread = {
-		.clock_getres	= thread_cpu_clock_getres,
-		.clock_get	= thread_cpu_clock_get,
-		.timer_create	= thread_cpu_timer_create,
-	};
-
-	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+const struct k_clock clock_process = {
+	.clock_getres	= process_cpu_clock_getres,
+	.clock_get	= process_cpu_clock_get,
+	.timer_create	= process_cpu_timer_create,
+	.nsleep		= process_cpu_nsleep,
+	.nsleep_restart	= process_cpu_nsleep_restart,
+};
 
-	return 0;
-}
-__initcall(init_posix_cpu_timers);
+const struct k_clock clock_thread = {
+	.clock_getres	= thread_cpu_clock_getres,
+	.clock_get	= thread_cpu_clock_get,
+	.timer_create	= thread_cpu_timer_create,
+};
kernel/time/posix-timers.c +89 -102

286 lines not on this page · raw message

#9 lore raw

[tip:timers/core] posix-timers: Make posix_clocks immutable

In reply to Christoph Hellwig
posix-timers: Make posix_clocks immutable
Commit-ID:  82def146e8f511c37d8d8934202491483dd09ca9
Gitweb:     http://git.kernel.org/tip/82def146e8f511c37d8d8934202491483dd09ca9
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Fri, 26 May 2017 12:03:11 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 26 May 2017 14:31:42 +0200

posix-timers: Make posix_clocks immutable

There are no more modular users providing a posix clock. The register function is now pointless so the posix clock array can be initialized statically at compile time and the array including the various k_clock structs can be marked 'const'.

Inspired by changes in the Grsecurity patch set, but done proper.

[ tglx: Massaged changelog and fixed the POSIX_TIMER=n case ]

---
 include/linux/posix-timers.h   |   9 +-
 kernel/time/alarmtimer.c       |  27 +++---
 kernel/time/posix-clock.c      |   2 +-
 kernel/time/posix-cpu-timers.c |  34 +++-----
 kernel/time/posix-timers.c     | 191 +++++++++++++++++++----------------------
 5 files changed, 120 insertions(+), 143 deletions(-)
include/linux/posix-timers.h +5 -4
index 8c1e43a..b313ef2 100644
@@ -105,10 +105,11 @@ struct k_clock {
 			   struct itimerspec64 *cur_setting);
 };
 
-extern struct k_clock clock_posix_cpu;
-extern struct k_clock clock_posix_dynamic;
-
-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
+extern const struct k_clock clock_posix_cpu;
+extern const struct k_clock clock_posix_dynamic;
+extern const struct k_clock clock_process;
+extern const struct k_clock clock_thread;
+extern const struct k_clock alarm_clock;
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
kernel/time/alarmtimer.c +12 -15
index 5cb5b00..7b5b7bf 100644
@@ -488,7 +488,7 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
 }
 EXPORT_SYMBOL_GPL(alarm_forward_now);
 
-
+#ifdef CONFIG_POSIX_TIMERS
 /**
  * clock2alarm - helper that converts from clockid to alarmtypes
  * @clockid: clockid.
@@ -846,6 +846,17 @@ out:
 	return ret;
 }
 
+const struct k_clock alarm_clock = {
+	.clock_getres	= alarm_clock_getres,
+	.clock_get	= alarm_clock_get,
+	.timer_create	= alarm_timer_create,
+	.timer_set	= alarm_timer_set,
+	.timer_del	= alarm_timer_del,
+	.timer_get	= alarm_timer_get,
+	.nsleep		= alarm_timer_nsleep,
+};
+#endif /* CONFIG_POSIX_TIMERS */
+
 
 /* Suspend hook structures */
 static const struct dev_pm_ops alarmtimer_pm_ops = {
@@ -871,23 +882,9 @@ static int __init alarmtimer_init(void)
 	struct platform_device *pdev;
 	int error = 0;
 	int i;
-	struct k_clock alarm_clock = {
-		.clock_getres	= alarm_clock_getres,
-		.clock_get	= alarm_clock_get,
-		.timer_create	= alarm_timer_create,
-		.timer_set	= alarm_timer_set,
-		.timer_del	= alarm_timer_del,
-		.timer_get	= alarm_timer_get,
-		.nsleep		= alarm_timer_nsleep,
-	};
 
 	alarmtimer_rtc_timer_init();
 
-	if (IS_ENABLED(CONFIG_POSIX_TIMERS)) {
-		posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
-		posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
-	}
-
 	/* Initialize alarm bases */
 	alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
 	alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
kernel/time/posix-clock.c +1 -1
index 31d588d..7e45300 100644
@@ -434,7 +434,7 @@ static int pc_timer_settime(struct k_itimer *kit, int flags,
 	return err;
 }
 
-struct k_clock clock_posix_dynamic = {
+const struct k_clock clock_posix_dynamic = {
 	.clock_getres	= pc_clock_getres,
 	.clock_set	= pc_clock_settime,
 	.clock_get	= pc_clock_gettime,
kernel/time/posix-cpu-timers.c +13 -21
index 1370f06..1a522b3 100644
@@ -1413,7 +1413,7 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 	return posix_cpu_timer_create(timer);
 }
 
-struct k_clock clock_posix_cpu = {
+const struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
 	.clock_set	= posix_cpu_clock_set,
 	.clock_get	= posix_cpu_clock_get,
@@ -1425,24 +1425,16 @@ struct k_clock clock_posix_cpu = {
 	.timer_get	= posix_cpu_timer_get,
 };
 
-static __init int init_posix_cpu_timers(void)
-{
-	struct k_clock process = {
-		.clock_getres	= process_cpu_clock_getres,
-		.clock_get	= process_cpu_clock_get,
-		.timer_create	= process_cpu_timer_create,
-		.nsleep		= process_cpu_nsleep,
-		.nsleep_restart	= process_cpu_nsleep_restart,
-	};
-	struct k_clock thread = {
-		.clock_getres	= thread_cpu_clock_getres,
-		.clock_get	= thread_cpu_clock_get,
-		.timer_create	= thread_cpu_timer_create,
-	};
-
-	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+const struct k_clock clock_process = {
+	.clock_getres	= process_cpu_clock_getres,
+	.clock_get	= process_cpu_clock_get,
+	.timer_create	= process_cpu_timer_create,
+	.nsleep		= process_cpu_nsleep,
+	.nsleep_restart	= process_cpu_nsleep_restart,
+};
 
-	return 0;
-}
-__initcall(init_posix_cpu_timers);
+const struct k_clock clock_thread = {
+	.clock_getres	= thread_cpu_clock_getres,
+	.clock_get	= thread_cpu_clock_get,
+	.timer_create	= thread_cpu_timer_create,
+};
kernel/time/posix-timers.c +89 -102

286 lines not on this page · raw message

#10 lore raw

[tip:timers/core] posix-timers: Make posix_clocks immutable

In reply to Christoph Hellwig
posix-timers: Make posix_clocks immutable
Commit-ID:  d346807445883732d530a62ebadb69af2f017e28
Gitweb:     http://git.kernel.org/tip/d346807445883732d530a62ebadb69af2f017e28
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Fri, 26 May 2017 12:03:11 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 26 May 2017 14:35:06 +0200

posix-timers: Make posix_clocks immutable

There are no more modular users providing a posix clock. The register function is now pointless so the posix clock array can be initialized statically at compile time and the array including the various k_clock structs can be marked 'const'.

Inspired by changes in the Grsecurity patch set, but done proper.

[ tglx: Massaged changelog and fixed the POSIX_TIMER=n case ]

---
 kernel/time/alarmtimer.c | 64 ++++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)
kernel/time/alarmtimer.c +32 -32
index 7b5b7bf..4f4cc35 100644
@@ -307,38 +307,6 @@ static int alarmtimer_resume(struct device *dev)
 }
 #endif
 
-static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
-{
-	struct alarm_base *base;
-	unsigned long flags;
-	ktime_t delta;
-
-	switch(type) {
-	case ALARM_REALTIME:
-		base = &alarm_bases[ALARM_REALTIME];
-		type = ALARM_REALTIME_FREEZER;
-		break;
-	case ALARM_BOOTTIME:
-		base = &alarm_bases[ALARM_BOOTTIME];
-		type = ALARM_BOOTTIME_FREEZER;
-		break;
-	default:
-		WARN_ONCE(1, "Invalid alarm type: %d\n", type);
-		return;
-	}
-
-	delta = ktime_sub(absexp, base->gettime());
-
-	spin_lock_irqsave(&freezer_delta_lock, flags);
-	if (!freezer_delta || (delta < freezer_delta)) {
-		freezer_delta = delta;
-		freezer_expires = absexp;
-		freezer_alarmtype = type;
-	}
-	spin_unlock_irqrestore(&freezer_delta_lock, flags);
-}
-
-
 /**
  * alarm_init - Initialize an alarm structure
  * @alarm: ptr to alarm to be initialized
@@ -489,6 +457,38 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
 EXPORT_SYMBOL_GPL(alarm_forward_now);
 
 #ifdef CONFIG_POSIX_TIMERS
+
+static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
+{
+	struct alarm_base *base;
+	unsigned long flags;
+	ktime_t delta;
+
+	switch(type) {
+	case ALARM_REALTIME:
+		base = &alarm_bases[ALARM_REALTIME];
+		type = ALARM_REALTIME_FREEZER;
+		break;
+	case ALARM_BOOTTIME:
+		base = &alarm_bases[ALARM_BOOTTIME];
+		type = ALARM_BOOTTIME_FREEZER;
+		break;
+	default:
+		WARN_ONCE(1, "Invalid alarm type: %d\n", type);
+		return;
+	}
+
+	delta = ktime_sub(absexp, base->gettime());
+
+	spin_lock_irqsave(&freezer_delta_lock, flags);
+	if (!freezer_delta || (delta < freezer_delta)) {
+		freezer_delta = delta;
+		freezer_expires = absexp;
+		freezer_alarmtype = type;
+	}
+	spin_unlock_irqrestore(&freezer_delta_lock, flags);
+}
+
 /**
  * clock2alarm - helper that converts from clockid to alarmtypes
  * @clockid: clockid.
#11 lore raw

[tip:timers/core] posix-timers: Make posix_clocks immutable

In reply to Christoph Hellwig
posix-timers: Make posix_clocks immutable
Commit-ID:  d3ba5a9a345b1243276f8a982e1bce557c2504fd
Gitweb:     http://git.kernel.org/tip/d3ba5a9a345b1243276f8a982e1bce557c2504fd
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Fri, 26 May 2017 12:03:11 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 27 May 2017 09:46:35 +0200

posix-timers: Make posix_clocks immutable

There are no more modular users providing a posix clock. The register function is now pointless so the posix clock array can be initialized statically at compile time and the array including the various k_clock structs can be marked 'const'.

Inspired by changes in the Grsecurity patch set, but done proper.

[ tglx: Massaged changelog and fixed the POSIX_TIMER=n case ]

---
 include/linux/posix-timers.h   |   9 +-
 kernel/time/alarmtimer.c       |  89 ++++++++++---------
 kernel/time/posix-clock.c      |   2 +-
 kernel/time/posix-cpu-timers.c |  34 +++-----
 kernel/time/posix-timers.c     | 191 +++++++++++++++++++----------------------
 5 files changed, 151 insertions(+), 174 deletions(-)
include/linux/posix-timers.h +5 -4
index 8c1e43a..b313ef2 100644
@@ -105,10 +105,11 @@ struct k_clock {
 			   struct itimerspec64 *cur_setting);
 };
 
-extern struct k_clock clock_posix_cpu;
-extern struct k_clock clock_posix_dynamic;
-
-void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
+extern const struct k_clock clock_posix_cpu;
+extern const struct k_clock clock_posix_dynamic;
+extern const struct k_clock clock_process;
+extern const struct k_clock clock_thread;
+extern const struct k_clock alarm_clock;
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
kernel/time/alarmtimer.c +43 -46

116 lines not on this page · raw message

kernel/time/posix-clock.c +1 -1
index 31d588d..7e45300 100644
@@ -434,7 +434,7 @@ static int pc_timer_settime(struct k_itimer *kit, int flags,
 	return err;
 }
 
-struct k_clock clock_posix_dynamic = {
+const struct k_clock clock_posix_dynamic = {
 	.clock_getres	= pc_clock_getres,
 	.clock_set	= pc_clock_settime,
 	.clock_get	= pc_clock_gettime,
kernel/time/posix-cpu-timers.c +13 -21
index 1370f06..1a522b3 100644
@@ -1413,7 +1413,7 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 	return posix_cpu_timer_create(timer);
 }
 
-struct k_clock clock_posix_cpu = {
+const struct k_clock clock_posix_cpu = {
 	.clock_getres	= posix_cpu_clock_getres,
 	.clock_set	= posix_cpu_clock_set,
 	.clock_get	= posix_cpu_clock_get,
@@ -1425,24 +1425,16 @@ struct k_clock clock_posix_cpu = {
 	.timer_get	= posix_cpu_timer_get,
 };
 
-static __init int init_posix_cpu_timers(void)
-{
-	struct k_clock process = {
-		.clock_getres	= process_cpu_clock_getres,
-		.clock_get	= process_cpu_clock_get,
-		.timer_create	= process_cpu_timer_create,
-		.nsleep		= process_cpu_nsleep,
-		.nsleep_restart	= process_cpu_nsleep_restart,
-	};
-	struct k_clock thread = {
-		.clock_getres	= thread_cpu_clock_getres,
-		.clock_get	= thread_cpu_clock_get,
-		.timer_create	= thread_cpu_timer_create,
-	};
-
-	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
-	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
+const struct k_clock clock_process = {
+	.clock_getres	= process_cpu_clock_getres,
+	.clock_get	= process_cpu_clock_get,
+	.timer_create	= process_cpu_timer_create,
+	.nsleep		= process_cpu_nsleep,
+	.nsleep_restart	= process_cpu_nsleep_restart,
+};
 
-	return 0;
-}
-__initcall(init_posix_cpu_timers);
+const struct k_clock clock_thread = {
+	.clock_getres	= thread_cpu_clock_getres,
+	.clock_get	= thread_cpu_clock_get,
+	.timer_create	= thread_cpu_timer_create,
+};
kernel/time/posix-timers.c +89 -102

286 lines not on this page · raw message