clockevents: Manage device's state separately for core
cover clockevents: Manage device's state separately for core
Hi Thomas/Ingo,
This is in response to the suggestions Ingo gave [1] on the shortcomings of clockevents core's state machine.
This first separates out the RESUME functionality from other states as its a special case. Then it defines a new enum to map possible states of a clockevent device.
Ideally it should only be available for the core, but as bL switcher is using it today, it is exposed in clockchips.h. That dependency will go away after applying the Thomas's work (Sent out be Peter) and then we can move this enum to somewhere in kernel/time/.
The last patch moves the legacy check to the legacy code.
Please see if this meets your expectation or if you have some suggestions on it.
Rebased of tip/master as there were some dependencies:575daeea39a3 Merge branch 'tools/kvm'
This along with migration of few clockevents drivers is pushed here:git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git clkevt/manage-state
--
Viresh
[1] https://lkml.org/lkml/2015/2/20/107
Viresh Kumar (3):
clockevents: Handle tick device's resume separately
clockevents: Manage device's state separately for the core
clockevents: Don't validate dev->mode against CLOCK_EVT_MODE_UNUSED
for new interface
arch/arm/common/bL_switcher.c | 8 +-- include/linux/clockchips.h | 48 +++++++++++------ kernel/time/clockevents.c | 118 ++++++++++++++++++++++++------------------ kernel/time/tick-broadcast.c | 22 ++++---- kernel/time/tick-common.c | 9 ++-- kernel/time/tick-internal.h | 1 + kernel/time/tick-oneshot.c | 6 +-- kernel/time/timer_list.c | 16 +++--- 8 files changed, 134 insertions(+), 94 deletions(-)
Signature · 1 line
2.3.0.rc0.44.ga94655d
PATCH 1/3 clockevents: Handle tick device's resume separately
Next commit will redefine possible states of a clockevent device. The RESUME mode is a special case only for tick's clockevent devices. In future it can be replaced by ->resume() callback already available for clockevent devices.
Lets handle it separately so that clockevents_set_mode() only handles states valid across all devices. This also renames set_mode_resume() to tick_resume() to make it more explicit.
--- include/linux/clockchips.h | 4 ++-- kernel/time/clockevents.c | 30 +++++++++++++++++++++--------- kernel/time/tick-broadcast.c | 2 +- kernel/time/tick-common.c | 2 +- kernel/time/tick-internal.h | 1 + kernel/time/timer_list.c | 4 ++-- 6 files changed, 28 insertions(+), 15 deletions(-)
include/linux/clockchips.h +2 -2
@@ -87,7 +87,7 @@ enum clock_event_mode {* @set_mode_periodic: switch mode to periodic, if !set_mode * @set_mode_oneshot: switch mode to oneshot, if !set_mode * @set_mode_shutdown: switch mode to shutdown, if !set_mode -* @set_mode_resume: resume clkevt device, if !set_mode +* @tick_resume: resume clkevt device, if !set_mode * @broadcast: function to broadcast events * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
@@ -125,7 +125,7 @@ struct clock_event_device {int (*set_mode_periodic)(struct clock_event_device *);int (*set_mode_oneshot)(struct clock_event_device *);int (*set_mode_shutdown)(struct clock_event_device *); -int (*set_mode_resume)(struct clock_event_device *); +int (*tick_resume)(struct clock_event_device *);void (*broadcast)(const struct cpumask *mask);void (*suspend)(struct clock_event_device *);
kernel/time/clockevents.c +21 -9
@@ -100,7 +100,7 @@ static int __clockevents_set_mode(struct clock_event_device *dev,/* Transition with legacy set_mode() callback */ if (dev->set_mode) {/* Legacy callback doesn't support new modes */ -if (mode >CLOCK_EVT_MODE_RESUME ) +if (mode >CLOCK_EVT_MODE_ONESHOT )return -ENOSYS ; dev->set_mode (mode, dev);return 0 ;
@@ -133,13 +133,6 @@ static int __clockevents_set_mode(struct clock_event_device *dev,return -ENOSYS ;return dev->set_mode_oneshot (dev); -case CLOCK_EVT_MODE_RESUME : -/* Optional callback */ -if (dev->set_mode_resume) -return dev->set_mode_resume (dev); -else -return 0 ; -default :return -ENOSYS ; }
@@ -184,6 +177,25 @@ void clockevents_shutdown(struct clock_event_device *dev) dev->next_event.tv64 =KTIME_MAX ; } +/** +* clockevents_tick_resume - Resume the tick device before using it again +* @dev: device to resume +*/ +int clockevents_tick_resume (struct clock_event_device *dev) +{ +int ret =0 ; + +if (dev->set_mode) + dev->set_mode (CLOCK_EVT_MODE_RESUME , dev); +else if (dev->tick_resume) + ret = dev->tick_resume (dev); + +if (likely (!ret)) + dev->mode =CLOCK_EVT_MODE_RESUME ; + +return ret; +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST /* Limit min_delta to a jiffie */
@@ -433,7 +445,7 @@ static int clockevents_sanity_check(struct clock_event_device *dev)if (dev->set_mode) {/* We shouldn't be supporting new modes now */ WARN_ON (dev->set_mode_periodic || dev->set_mode_oneshot || - dev->set_mode_shutdown || dev->set_mode_resume); + dev->set_mode_shutdown || dev->tick_resume);return 0 ; }
kernel/time/tick-broadcast.c +1 -1
@@ -464,7 +464,7 @@ int tick_resume_broadcast(void) bc = tick_broadcast_device.evtdev;if (bc) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_RESUME ); +clockevents_tick_resume (bc);switch (tick_broadcast_device.mode) {case TICKDEV_MODE_PERIODIC :
kernel/time/tick-common.c +1 -1
@@ -384,7 +384,7 @@ void tick_resume(void)struct tick_device *td =this_cpu_ptr (&tick_cpu_device);int broadcast =tick_resume_broadcast (); -clockevents_set_mode (td->evtdev,CLOCK_EVT_MODE_RESUME ); +clockevents_tick_resume (td->evtdev);if (!broadcast) {if (td->mode ==TICKDEV_MODE_PERIODIC )
kernel/time/tick-internal.h +1 -0
@@ -32,6 +32,7 @@ extern bool tick_check_replacement(struct clock_event_device *curdev,extern void tick_install_replacement (struct clock_event_device *dev);extern void clockevents_shutdown (struct clock_event_device *dev); +extern int clockevents_tick_resume (struct clock_event_device *dev);extern ssize_t sysfs_get_uname (const char *buf,char *dst,size_t cnt);
kernel/time/timer_list.c +2 -2
@@ -251,9 +251,9 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)SEQ_printf (m,"\n" ); } -if (dev->set_mode_resume) { +if (dev->tick_resume) {SEQ_printf (m," resume: " ); -print_name_offset (m, dev->set_mode_resume); +print_name_offset (m, dev->tick_resume);SEQ_printf (m,"\n" ); } }
Signature · 1 line
2.3.0.rc0.44.ga94655d
PATCH 2/3 clockevents: Manage device's state separately for the core
In reply to Viresh Kumar'enum clock_event_mode' is used for two purposes today:
- to pass mode to the driver of clockevent device::set_mode().
- for managing state of the device for clockevents core.
For supporting new modes/states we have moved away from the legacy set_mode() callback to new per-mode/state callbacks. New modes/states shouldn't be exposed to the legacy (now OBSOLOTE) callbacks and so we shouldn't add new states to 'enum clock_event_mode'.
Lets have separate enums for the two use cases mentioned above. Keep using the earlier enum for legacy set_mode() callback and mark it OBSOLETE. And add another enum to clearly specify the possible states of a clockevent device.
This also renames the newly added per-mode callbacks to reflect state changes.
We haven't got rid of 'mode' member of 'struct clock_event_device' as it is used by some of the clockevent drivers and it would automatically die down once we migrate those drivers to the new interface. It ('mode') is only updated now for the drivers using the legacy interface.
--- arch/arm/common/bL_switcher.c | 8 ++-- include/linux/clockchips.h | 44 +++++++++++++------ kernel/time/clockevents.c | 99 +++++++++++++++++++++++-------------------- kernel/time/tick-broadcast.c | 20 ++++----- kernel/time/tick-common.c | 7 +-- kernel/time/tick-oneshot.c | 6 +-- kernel/time/timer_list.c | 12 +++--- 7 files changed, 111 insertions(+), 85 deletions(-)
arch/arm/common/bL_switcher.c +4 -4
@@ -152,7 +152,7 @@ static int bL_switch_to(unsigned int new_cluster_id)unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;struct completion inbound_alive;struct tick_device *tdev; -enum clock_event_mode tdev_mode; +enum clock_event_state tdev_state;long volatile *handshake_ptr;int ipi_nr, ret;
@@ -223,8 +223,8 @@ static int bL_switch_to(unsigned int new_cluster_id)if (tdev && !cpumask_equal (tdev->evtdev->cpumask,cpumask_of (this_cpu))) tdev =NULL ;if (tdev) { - tdev_mode = tdev->evtdev->mode; -clockevents_set_mode (tdev->evtdev,CLOCK_EVT_MODE_SHUTDOWN ); + tdev_state = tdev->evtdev->state; +clockevents_set_state (tdev->evtdev,CLOCK_EVT_STATE_SHUTDOWN ); } ret =cpu_pm_enter ();
@@ -252,7 +252,7 @@ static int bL_switch_to(unsigned int new_cluster_id) ret =cpu_pm_exit ();if (tdev) { -clockevents_set_mode (tdev->evtdev, tdev_mode); +clockevents_set_state (tdev->evtdev, tdev_state);clockevents_program_event (tdev->evtdev, tdev->evtdev->next_event,1 ); }
include/linux/clockchips.h +31 -13
87 lines not on this page · raw message
kernel/time/clockevents.c +53 -46
245 lines not on this page · raw message
kernel/time/tick-broadcast.c +10 -10
@@ -303,7 +303,7 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)/* * The device is in periodic mode. No reprogramming necessary: */ -if (dev->mode ==CLOCK_EVT_MODE_PERIODIC ) +if (dev->state ==CLOCK_EVT_STATE_PERIODIC ) goto unlock;/*
@@ -532,8 +532,8 @@ static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu, {int ret; -if (bc->mode !=CLOCK_EVT_MODE_ONESHOT ) -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +if (bc->state !=CLOCK_EVT_STATE_ONESHOT ) +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT ); ret =clockevents_program_event (bc, expires, force);if (!ret)
@@ -543,7 +543,7 @@ static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu,int tick_resume_broadcast_oneshot (struct clock_event_device *bc) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT );return 0 ; }
@@ -562,8 +562,8 @@ void tick_check_oneshot_broadcast_this_cpu(void)* switched over, leave the device alone. */ if (td->mode ==TICKDEV_MODE_ONESHOT ) { -clockevents_set_mode (td->evtdev, -CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (td->evtdev, +CLOCK_EVT_STATE_ONESHOT ); } } }
@@ -666,7 +666,7 @@ static void broadcast_shutdown_local(struct clock_event_device *bc,if (dev->next_event.tv64 < bc->next_event.tv64)return ; } -clockevents_set_mode (dev,CLOCK_EVT_MODE_SHUTDOWN ); +clockevents_set_state (dev,CLOCK_EVT_STATE_SHUTDOWN ); }static void broadcast_move_bc (int deadcpu)
@@ -741,7 +741,7 @@ int tick_broadcast_oneshot_control(unsigned long reason)cpumask_clear_cpu (cpu, tick_broadcast_oneshot_mask); }else {if (cpumask_test_and_clear_cpu (cpu, tick_broadcast_oneshot_mask)) { -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );/* * The cpu which was handling the broadcast * timer marked this cpu in the broadcast
@@ -842,7 +842,7 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc)/* Set it up only once ! */ if (bc->event_handler != tick_handle_oneshot_broadcast) { -int was_periodic = bc->mode ==CLOCK_EVT_MODE_PERIODIC ; +int was_periodic = bc->state ==CLOCK_EVT_STATE_PERIODIC ; bc->event_handler = tick_handle_oneshot_broadcast;
@@ -858,7 +858,7 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc) tick_broadcast_oneshot_mask, tmpmask);if (was_periodic && !cpumask_empty (tmpmask)) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT );tick_broadcast_init_next_event (tmpmask, tick_next_period);tick_broadcast_set_event (bc, cpu, tick_next_period,1 );
kernel/time/tick-common.c +4 -3
@@ -102,7 +102,7 @@ void tick_handle_periodic(struct clock_event_device *dev)tick_periodic (cpu); -if (dev->mode !=CLOCK_EVT_MODE_ONESHOT ) +if (dev->state !=CLOCK_EVT_STATE_ONESHOT )return ;for (;;) {/*
@@ -140,7 +140,7 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast)if ((dev->features &CLOCK_EVT_FEAT_PERIODIC ) && !tick_broadcast_oneshot_active ()) { -clockevents_set_mode (dev,CLOCK_EVT_MODE_PERIODIC ); +clockevents_set_state (dev,CLOCK_EVT_STATE_PERIODIC ); }else {unsigned long seq;ktime_t next;
@@ -150,7 +150,7 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast) next = tick_next_period; }while (read_seqretry (&jiffies_lock, seq)); -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );for (;;) {if (!clockevents_program_event (dev, next, false))
@@ -365,6 +365,7 @@ void tick_shutdown(unsigned int *cpup)* Prevent that the clock events layer tries to call * the set mode function! */ + dev->state =CLOCK_EVT_STATE_DETACHED ; dev->mode =CLOCK_EVT_MODE_UNUSED ;clockevents_exchange_device (dev,NULL ); dev->event_handler = clockevents_handle_noop;
kernel/time/tick-oneshot.c +3 -3
@@ -38,7 +38,7 @@ void tick_resume_oneshot(void) {struct clock_event_device *dev =__this_cpu_read (tick_cpu_device.evtdev); -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );clockevents_program_event (dev,ktime_get (), true); }
@@ -50,7 +50,7 @@ void tick_setup_oneshot(struct clock_event_device *newdev, ktime_t next_event) { newdev->event_handler = handler; -clockevents_set_mode (newdev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (newdev,CLOCK_EVT_STATE_ONESHOT );clockevents_program_event (newdev, next_event, true); }
@@ -81,7 +81,7 @@ int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)) td->mode =TICKDEV_MODE_ONESHOT ; dev->event_handler = handler; -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );tick_broadcast_switch_to_oneshot ();return 0 ; }
kernel/time/timer_list.c +6 -6
@@ -233,21 +233,21 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)print_name_offset (m, dev->set_mode);SEQ_printf (m,"\n" ); }else { -if (dev->set_mode_shutdown) { +if (dev->set_state_shutdown) {SEQ_printf (m," shutdown: " ); -print_name_offset (m, dev->set_mode_shutdown); +print_name_offset (m, dev->set_state_shutdown);SEQ_printf (m,"\n" ); } -if (dev->set_mode_periodic) { +if (dev->set_state_periodic) {SEQ_printf (m," periodic: " ); -print_name_offset (m, dev->set_mode_periodic); +print_name_offset (m, dev->set_state_periodic);SEQ_printf (m,"\n" ); } -if (dev->set_mode_oneshot) { +if (dev->set_state_oneshot) {SEQ_printf (m," oneshot: " ); -print_name_offset (m, dev->set_mode_oneshot); +print_name_offset (m, dev->set_state_oneshot);SEQ_printf (m,"\n" ); }
Signature · 1 line
2.3.0.rc0.44.ga94655d
PATCH 3/3 clockevents: Don't validate dev->mode against CLOCK_EVT_MODE_UNUSED for new interface
In reply to Viresh KumarIt was a requirement in the legacy interface that drivers must initialize ->mode field to 'CLOCK_EVT_MODE_UNUSED'. This field isn't used anymore by the new interface and so should be only checked for the legacy interface.
Probably it can be dropped as well as core doesn't rely on it anymore, but lets keep it to support legacy interface.
--- kernel/time/clockevents.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/clockevents.c +2 -1
@@ -450,6 +450,8 @@ static int clockevents_sanity_check(struct clock_event_device *dev)/* We shouldn't be supporting new modes now */ WARN_ON (dev->set_state_periodic || dev->set_state_oneshot || dev->set_state_shutdown || dev->tick_resume); + +BUG_ON (dev->mode !=CLOCK_EVT_MODE_UNUSED );return 0 ; }
@@ -479,7 +481,6 @@ void clockevents_register_device(struct clock_event_device *dev) {unsigned long flags; -BUG_ON (dev->mode !=CLOCK_EVT_MODE_UNUSED );BUG_ON (clockevents_sanity_check (dev));/* Initialize state to DETACHED */
Signature · 1 line
2.3.0.rc0.44.ga94655d
Quoted 27 lines · Viresh Kumar
Hi Thomas/Ingo,
This is in response to the suggestions Ingo gave [1] on the shortcomings of clockevents core's state machine.
This first separates out the RESUME functionality from other states as its a special case. Then it defines a new enum to map possible states of a clockevent device.
Ideally it should only be available for the core, but as bL switcher is using it today, it is exposed in
clockchips.h. That dependency will go away after applying the Thomas's work (Sent out be Peter) and then we can move this enum to somewhere inkernel/time/.The last patch moves the legacy check to the legacy code.
Please see if this meets your expectation or if you have some suggestions on it.
Rebased of tip/master as there were some dependencies:
575daeea39a3Merge branch 'tools/kvm'This along with migration of few clockevents drivers is pushed here:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.gitclkevt/manage-state--
Viresh
Quoted 7 lines
[1] https://lkml.org/lkml/2015/2/20/107
Viresh Kumar (3):
clockevents: Handle tick device's resume separately
clockevents: Manage device's state separately for the core
clockevents: Don't validatedev->modeagainstCLOCK_EVT_MODE_UNUSED
for new interface
Ingo,
Gentle reminder ping...
Ingo Molnar
maintainerQuoted 36 lines · Viresh Kumar
Quoted 27 lines · Viresh Kumar
Hi Thomas/Ingo,
This is in response to the suggestions Ingo gave [1] on the shortcomings of clockevents core's state machine.
This first separates out the RESUME functionality from other states as its a special case. Then it defines a new enum to map possible states of a clockevent device.
Ideally it should only be available for the core, but as bL switcher is using it today, it is exposed in
clockchips.h. That dependency will go away after applying the Thomas's work (Sent out be Peter) and then we can move this enum to somewhere inkernel/time/.The last patch moves the legacy check to the legacy code.
Please see if this meets your expectation or if you have some suggestions on it.
Rebased of tip/master as there were some dependencies:
575daeea39a3Merge branch 'tools/kvm'This along with migration of few clockevents drivers is pushed here:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.gitclkevt/manage-state--
VireshQuoted 7 lines
[1] https://lkml.org/lkml/2015/2/20/107
Viresh Kumar (3):
clockevents: Handle tick device's resume separately
clockevents: Manage device's state separately for the core
clockevents: Don't validatedev->modeagainstCLOCK_EVT_MODE_UNUSED
for new interface
Quoted 3 lines
Ingo,
Gentle reminder ping...
Yeah, so I'd like PeterZ to ACK/NAK this approach before I move forward with the patches - but he's on the road right now, so it will take a week I suspect.
Thanks,
Ingo
Peter Zijlstra
Acked-byQuoted 3 lines · Ingo Molnar
Yeah, so I'd like PeterZ to ACK/NAK this approach before I move forward with the patches - but he's on the road right now, so it will take a week I suspect.
I stared at it between sessions today and it looks ok, so
Thanks!
Quoted 3 lines · Ingo Molnar
Yeah, so I'd like PeterZ to ACK/NAK this approach before I move forward with the patches - but he's on the road right now, so it will take a week I suspect.
Hi Ingo,
Now that Peter has already Acked them, will you be taking these as is or want some rework to be done before that ?
--
viresh
Quoted 10 lines · Viresh Kumar
Quoted 3 lines · Ingo Molnar
Yeah, so I'd like PeterZ to ACK/NAK this approach before I move forward with the patches - but he's on the road right now, so it will take a week I suspect.
Hi Ingo,
Now that Peter has already Acked them, will you be taking these as is or want some rework to be done before that ?
Hi Ingo,
Gentle reminder ping !! :)
--
viresh
tip-bot for Viresh Kumar
merge bot[tip:timers/core] clockevents: Handle tick device' s resume separately
In reply to Viresh Kumarclockevents: Handle tick device's resume separately
Commit-ID: 554ef3876c6acdff1331feab10275e9e9e0adb84 Gitweb: http://git.kernel.org/tip/554ef3876c6acdff1331feab10275e9e9e0adb84 Author: Viresh Kumar <[email protected]> AuthorDate: Fri, 27 Feb 2015 17:21:32 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 27 Mar 2015 10:26:19 +0100
clockevents: Handle tick device's resume separately
Upcoming patch will redefine possible states of a clockevent device. The RESUME mode is a special case only for tick's clockevent devices. In future it can be replaced by ->resume() callback already available for clockevent devices.
Lets handle it separately so that clockevents_set_mode() only handles states valid across all devices. This also renames set_mode_resume() to tick_resume() to make it more explicit.
--- include/linux/clockchips.h | 4 ++-- kernel/time/clockevents.c | 30 +++++++++++++++++++++--------- kernel/time/tick-broadcast.c | 2 +- kernel/time/tick-common.c | 2 +- kernel/time/tick-internal.h | 1 + kernel/time/timer_list.c | 4 ++-- 6 files changed, 28 insertions(+), 15 deletions(-)
include/linux/clockchips.h +2 -2
@@ -87,7 +87,7 @@ enum clock_event_mode {* @set_mode_periodic: switch mode to periodic, if !set_mode * @set_mode_oneshot: switch mode to oneshot, if !set_mode * @set_mode_shutdown: switch mode to shutdown, if !set_mode -* @set_mode_resume: resume clkevt device, if !set_mode +* @tick_resume: resume clkevt device, if !set_mode * @broadcast: function to broadcast events * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
@@ -125,7 +125,7 @@ struct clock_event_device {int (*set_mode_periodic)(struct clock_event_device *);int (*set_mode_oneshot)(struct clock_event_device *);int (*set_mode_shutdown)(struct clock_event_device *); -int (*set_mode_resume)(struct clock_event_device *); +int (*tick_resume)(struct clock_event_device *);void (*broadcast)(const struct cpumask *mask);void (*suspend)(struct clock_event_device *);
kernel/time/clockevents.c +21 -9
@@ -100,7 +100,7 @@ static int __clockevents_set_mode(struct clock_event_device *dev,/* Transition with legacy set_mode() callback */ if (dev->set_mode) {/* Legacy callback doesn't support new modes */ -if (mode >CLOCK_EVT_MODE_RESUME ) +if (mode >CLOCK_EVT_MODE_ONESHOT )return -ENOSYS ; dev->set_mode (mode, dev);return 0 ;
@@ -133,13 +133,6 @@ static int __clockevents_set_mode(struct clock_event_device *dev,return -ENOSYS ;return dev->set_mode_oneshot (dev); -case CLOCK_EVT_MODE_RESUME : -/* Optional callback */ -if (dev->set_mode_resume) -return dev->set_mode_resume (dev); -else -return 0 ; -default :return -ENOSYS ; }
@@ -184,6 +177,25 @@ void clockevents_shutdown(struct clock_event_device *dev) dev->next_event.tv64 =KTIME_MAX ; } +/** +* clockevents_tick_resume - Resume the tick device before using it again +* @dev: device to resume +*/ +int clockevents_tick_resume (struct clock_event_device *dev) +{ +int ret =0 ; + +if (dev->set_mode) + dev->set_mode (CLOCK_EVT_MODE_RESUME , dev); +else if (dev->tick_resume) + ret = dev->tick_resume (dev); + +if (likely (!ret)) + dev->mode =CLOCK_EVT_MODE_RESUME ; + +return ret; +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST /* Limit min_delta to a jiffie */
@@ -433,7 +445,7 @@ static int clockevents_sanity_check(struct clock_event_device *dev)if (dev->set_mode) {/* We shouldn't be supporting new modes now */ WARN_ON (dev->set_mode_periodic || dev->set_mode_oneshot || - dev->set_mode_shutdown || dev->set_mode_resume); + dev->set_mode_shutdown || dev->tick_resume);return 0 ; }
kernel/time/tick-broadcast.c +1 -1
@@ -464,7 +464,7 @@ int tick_resume_broadcast(void) bc = tick_broadcast_device.evtdev;if (bc) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_RESUME ); +clockevents_tick_resume (bc);switch (tick_broadcast_device.mode) {case TICKDEV_MODE_PERIODIC :
kernel/time/tick-common.c +1 -1
@@ -384,7 +384,7 @@ void tick_resume(void)struct tick_device *td =this_cpu_ptr (&tick_cpu_device);int broadcast =tick_resume_broadcast (); -clockevents_set_mode (td->evtdev,CLOCK_EVT_MODE_RESUME ); +clockevents_tick_resume (td->evtdev);if (!broadcast) {if (td->mode ==TICKDEV_MODE_PERIODIC )
kernel/time/tick-internal.h +1 -0
@@ -32,6 +32,7 @@ extern bool tick_check_replacement(struct clock_event_device *curdev,extern void tick_install_replacement (struct clock_event_device *dev);extern void clockevents_shutdown (struct clock_event_device *dev); +extern int clockevents_tick_resume (struct clock_event_device *dev);extern ssize_t sysfs_get_uname (const char *buf,char *dst,size_t cnt);
kernel/time/timer_list.c +2 -2
@@ -251,9 +251,9 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)SEQ_printf (m,"\n" ); } -if (dev->set_mode_resume) { +if (dev->tick_resume) {SEQ_printf (m," resume: " ); -print_name_offset (m, dev->set_mode_resume); +print_name_offset (m, dev->tick_resume);SEQ_printf (m,"\n" ); } }
tip-bot for Viresh Kumar
merge bot[tip:timers/core] clockevents: Manage device' s state separately for the core
In reply to Viresh Kumarclockevents: Manage device's state separately for the core
Commit-ID: 77e32c89a7117614ab3d66d20c1088de721abfaa Gitweb: http://git.kernel.org/tip/77e32c89a7117614ab3d66d20c1088de721abfaa Author: Viresh Kumar <[email protected]> AuthorDate: Fri, 27 Feb 2015 17:21:33 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 27 Mar 2015 10:26:19 +0100
clockevents: Manage device's state separately for the core
'enum clock_event_mode' is used for two purposes today:
- to pass mode to the driver of clockevent device::set_mode().
- for managing state of the device for clockevents core.
For supporting new modes/states we have moved away from the legacy set_mode() callback to new per-mode/state callbacks. New modes/states shouldn't be exposed to the legacy (now OBSOLOTE) callbacks and so we shouldn't add new states to 'enum clock_event_mode'.
Lets have separate enums for the two use cases mentioned above. Keep using the earlier enum for legacy set_mode() callback and mark it OBSOLETE. And add another enum to clearly specify the possible states of a clockevent device.
This also renames the newly added per-mode callbacks to reflect state changes.
We haven't got rid of 'mode' member of 'struct clock_event_device' as it is used by some of the clockevent drivers and it would automatically die down once we migrate those drivers to the new interface. It ('mode') is only updated now for the drivers using the legacy interface.
--- arch/arm/common/bL_switcher.c | 8 ++-- include/linux/clockchips.h | 44 +++++++++++++------ kernel/time/clockevents.c | 99 +++++++++++++++++++++++-------------------- kernel/time/tick-broadcast.c | 20 ++++----- kernel/time/tick-common.c | 7 +-- kernel/time/tick-oneshot.c | 6 +-- kernel/time/timer_list.c | 12 +++--- 7 files changed, 111 insertions(+), 85 deletions(-)
arch/arm/common/bL_switcher.c +4 -4
@@ -152,7 +152,7 @@ static int bL_switch_to(unsigned int new_cluster_id)unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;struct completion inbound_alive;struct tick_device *tdev; -enum clock_event_mode tdev_mode; +enum clock_event_state tdev_state;long volatile *handshake_ptr;int ipi_nr, ret;
@@ -223,8 +223,8 @@ static int bL_switch_to(unsigned int new_cluster_id)if (tdev && !cpumask_equal (tdev->evtdev->cpumask,cpumask_of (this_cpu))) tdev =NULL ;if (tdev) { - tdev_mode = tdev->evtdev->mode; -clockevents_set_mode (tdev->evtdev,CLOCK_EVT_MODE_SHUTDOWN ); + tdev_state = tdev->evtdev->state; +clockevents_set_state (tdev->evtdev,CLOCK_EVT_STATE_SHUTDOWN ); } ret =cpu_pm_enter ();
@@ -252,7 +252,7 @@ static int bL_switch_to(unsigned int new_cluster_id) ret =cpu_pm_exit ();if (tdev) { -clockevents_set_mode (tdev->evtdev, tdev_mode); +clockevents_set_state (tdev->evtdev, tdev_state);clockevents_program_event (tdev->evtdev, tdev->evtdev->next_event,1 ); }
include/linux/clockchips.h +31 -13
87 lines not on this page · raw message
kernel/time/clockevents.c +53 -46
245 lines not on this page · raw message
kernel/time/tick-broadcast.c +10 -10
@@ -303,7 +303,7 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev)/* * The device is in periodic mode. No reprogramming necessary: */ -if (dev->mode ==CLOCK_EVT_MODE_PERIODIC ) +if (dev->state ==CLOCK_EVT_STATE_PERIODIC ) goto unlock;/*
@@ -532,8 +532,8 @@ static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu, {int ret; -if (bc->mode !=CLOCK_EVT_MODE_ONESHOT ) -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +if (bc->state !=CLOCK_EVT_STATE_ONESHOT ) +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT ); ret =clockevents_program_event (bc, expires, force);if (!ret)
@@ -543,7 +543,7 @@ static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu,int tick_resume_broadcast_oneshot (struct clock_event_device *bc) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT );return 0 ; }
@@ -562,8 +562,8 @@ void tick_check_oneshot_broadcast_this_cpu(void)* switched over, leave the device alone. */ if (td->mode ==TICKDEV_MODE_ONESHOT ) { -clockevents_set_mode (td->evtdev, -CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (td->evtdev, +CLOCK_EVT_STATE_ONESHOT ); } } }
@@ -666,7 +666,7 @@ static void broadcast_shutdown_local(struct clock_event_device *bc,if (dev->next_event.tv64 < bc->next_event.tv64)return ; } -clockevents_set_mode (dev,CLOCK_EVT_MODE_SHUTDOWN ); +clockevents_set_state (dev,CLOCK_EVT_STATE_SHUTDOWN ); }static void broadcast_move_bc (int deadcpu)
@@ -741,7 +741,7 @@ int tick_broadcast_oneshot_control(unsigned long reason)cpumask_clear_cpu (cpu, tick_broadcast_oneshot_mask); }else {if (cpumask_test_and_clear_cpu (cpu, tick_broadcast_oneshot_mask)) { -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );/* * The cpu which was handling the broadcast * timer marked this cpu in the broadcast
@@ -842,7 +842,7 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc)/* Set it up only once ! */ if (bc->event_handler != tick_handle_oneshot_broadcast) { -int was_periodic = bc->mode ==CLOCK_EVT_MODE_PERIODIC ; +int was_periodic = bc->state ==CLOCK_EVT_STATE_PERIODIC ; bc->event_handler = tick_handle_oneshot_broadcast;
@@ -858,7 +858,7 @@ void tick_broadcast_setup_oneshot(struct clock_event_device *bc) tick_broadcast_oneshot_mask, tmpmask);if (was_periodic && !cpumask_empty (tmpmask)) { -clockevents_set_mode (bc,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (bc,CLOCK_EVT_STATE_ONESHOT );tick_broadcast_init_next_event (tmpmask, tick_next_period);tick_broadcast_set_event (bc, cpu, tick_next_period,1 );
kernel/time/tick-common.c +4 -3
@@ -102,7 +102,7 @@ void tick_handle_periodic(struct clock_event_device *dev)tick_periodic (cpu); -if (dev->mode !=CLOCK_EVT_MODE_ONESHOT ) +if (dev->state !=CLOCK_EVT_STATE_ONESHOT )return ;for (;;) {/*
@@ -140,7 +140,7 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast)if ((dev->features &CLOCK_EVT_FEAT_PERIODIC ) && !tick_broadcast_oneshot_active ()) { -clockevents_set_mode (dev,CLOCK_EVT_MODE_PERIODIC ); +clockevents_set_state (dev,CLOCK_EVT_STATE_PERIODIC ); }else {unsigned long seq;ktime_t next;
@@ -150,7 +150,7 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast) next = tick_next_period; }while (read_seqretry (&jiffies_lock, seq)); -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );for (;;) {if (!clockevents_program_event (dev, next, false))
@@ -365,6 +365,7 @@ void tick_shutdown(unsigned int *cpup)* Prevent that the clock events layer tries to call * the set mode function! */ + dev->state =CLOCK_EVT_STATE_DETACHED ; dev->mode =CLOCK_EVT_MODE_UNUSED ;clockevents_exchange_device (dev,NULL ); dev->event_handler = clockevents_handle_noop;
kernel/time/tick-oneshot.c +3 -3
@@ -38,7 +38,7 @@ void tick_resume_oneshot(void) {struct clock_event_device *dev =__this_cpu_read (tick_cpu_device.evtdev); -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );clockevents_program_event (dev,ktime_get (), true); }
@@ -50,7 +50,7 @@ void tick_setup_oneshot(struct clock_event_device *newdev, ktime_t next_event) { newdev->event_handler = handler; -clockevents_set_mode (newdev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (newdev,CLOCK_EVT_STATE_ONESHOT );clockevents_program_event (newdev, next_event, true); }
@@ -81,7 +81,7 @@ int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)) td->mode =TICKDEV_MODE_ONESHOT ; dev->event_handler = handler; -clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT ); +clockevents_set_state (dev,CLOCK_EVT_STATE_ONESHOT );tick_broadcast_switch_to_oneshot ();return 0 ; }
kernel/time/timer_list.c +6 -6
@@ -233,21 +233,21 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)print_name_offset (m, dev->set_mode);SEQ_printf (m,"\n" ); }else { -if (dev->set_mode_shutdown) { +if (dev->set_state_shutdown) {SEQ_printf (m," shutdown: " ); -print_name_offset (m, dev->set_mode_shutdown); +print_name_offset (m, dev->set_state_shutdown);SEQ_printf (m,"\n" ); } -if (dev->set_mode_periodic) { +if (dev->set_state_periodic) {SEQ_printf (m," periodic: " ); -print_name_offset (m, dev->set_mode_periodic); +print_name_offset (m, dev->set_state_periodic);SEQ_printf (m,"\n" ); } -if (dev->set_mode_oneshot) { +if (dev->set_state_oneshot) {SEQ_printf (m," oneshot: " ); -print_name_offset (m, dev->set_mode_oneshot); +print_name_offset (m, dev->set_state_oneshot);SEQ_printf (m,"\n" ); }
tip-bot for Viresh Kumar
merge bot[tip:timers/core] clockevents: Don't validate dev-> mode against CLOCK_EVT_MODE_UNUSED for new interface
In reply to Viresh Kumarclockevents: Don't validate dev->mode against CLOCK_EVT_MODE_UNUSED for new interface
Commit-ID: de81e64b250d3865a75d221a80b4311e3273670a Gitweb: http://git.kernel.org/tip/de81e64b250d3865a75d221a80b4311e3273670a Author: Viresh Kumar <[email protected]> AuthorDate: Fri, 27 Feb 2015 17:21:34 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 27 Mar 2015 10:26:20 +0100
clockevents: Don't validate dev->mode against CLOCK_EVT_MODE_UNUSED for new interface
It was a requirement in the legacy interface that drivers must initialize ->mode field to 'CLOCK_EVT_MODE_UNUSED'. This field isn't used anymore by the new interface and so should be only checked for the legacy interface.
Probably it can be dropped as well as core doesn't rely on it anymore, but lets keep it to support legacy interface.
--- kernel/time/clockevents.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/clockevents.c +2 -1
@@ -450,6 +450,8 @@ static int clockevents_sanity_check(struct clock_event_device *dev)/* We shouldn't be supporting new modes now */ WARN_ON (dev->set_state_periodic || dev->set_state_oneshot || dev->set_state_shutdown || dev->tick_resume); + +BUG_ON (dev->mode !=CLOCK_EVT_MODE_UNUSED );return 0 ; }
@@ -479,7 +481,6 @@ void clockevents_register_device(struct clock_event_device *dev) {unsigned long flags; -BUG_ON (dev->mode !=CLOCK_EVT_MODE_UNUSED );BUG_ON (clockevents_sanity_check (dev));/* Initialize state to DETACHED */