On 05/19/2014 01:48 PM, Viresh Kumar wrote:
There is a requirement to add another mode: CLOCK_EVT_MODE_ONESHOT_STOPPED (lkml.org/lkml/2014/5/9/508) to clockevent devices and clockevent-drivers may or maynot support it. Drivers that don't support it can return failure codes on a call to ->set_mode(), which has a return type of 'void' currently.
Following steps are suggested (by tglx) to get this fixed:
- Add another callback ->set_dev_mode(), with return type 'int'.
- Covert clockevent drivers to use ->set_dev_mode() instead of ->set_mode().
- Once all are converted, remove support for ->set_mode().
This patch implements 'part 1' of this approach. It also marks ->set_mode() deprecated as ->set_dev_mode() should be used instead.
In order to propagate error codes to callers of clockevents_set_mode(), change its return type to 'int'. For now just add a WARN_ON() inside clockevents_set_mode() and don't explicitly handle any error codes at call sites, as the current modes are not expected/allowed to fail.
Reviewed-by: Preeti U Murthy preeti@linux.vnet.ibm.com Signed-off-by: Viresh Kumar viresh.kumar@linaro.org
include/linux/clockchips.h | 7 +++++-- kernel/time/clockevents.c | 29 ++++++++++++++++++++++++----- kernel/time/timer_list.c | 9 +++++++-- 3 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h index 2e4cb67..bf902bf 100644 --- a/include/linux/clockchips.h +++ b/include/linux/clockchips.h @@ -81,7 +81,8 @@ enum clock_event_mode {
- @mode: operating mode assigned by the management code
- @features: features
- @retries: number of forced programming retries
- @set_mode: set mode function
- @set_dev_mode: set dev mode function
- @set_mode: set mode function (deprecated, use set_dev_mode instead)
- @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
@@ -109,6 +110,8 @@ struct clock_event_device { unsigned long retries;
void (*broadcast)(const struct cpumask *mask);
- int (*set_dev_mode)(enum clock_event_mode mode,
struct clock_event_device *);
May be you can use the deprecated attribute also ?
int (*set_dev_mode)(enum clock_event_mode mode, struct clock_event_device *) __deprecated;
So a warning will appear at compile time (with CONFIG_ENABLE_WARN_DEPRECATED=y), letting people to know they have to migrate to the new API. But if you migrate all of them in the two next patches, 'deprecated' does not make sense.
void (*set_mode)(enum clock_event_mode mode, struct clock_event_device *); void (*suspend)(struct clock_event_device *); @@ -160,7 +163,7 @@ extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
extern void clockevents_exchange_device(struct clock_event_device *old, struct clock_event_device *new); -extern void clockevents_set_mode(struct clock_event_device *dev, +extern int clockevents_set_mode(struct clock_event_device *dev, enum clock_event_mode mode); extern int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, bool force); diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index ad362c2..087a5aa 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -101,11 +101,20 @@ EXPORT_SYMBOL_GPL(clockevent_delta2ns);
- Must be called with interrupts disabled !
*/ -void clockevents_set_mode(struct clock_event_device *dev, +int clockevents_set_mode(struct clock_event_device *dev, enum clock_event_mode mode) { if (dev->mode != mode) {
dev->set_mode(mode, dev);
if (dev->set_dev_mode) {
int ret = dev->set_dev_mode(mode, dev);
/* Currently available modes are not allowed to fail */
if (WARN_ON(ret))
return ret;
Why WARN_ON ? Is it acceptable to have a warning each time this function is called and fails ? Is this so important to have a WARN ?
} else {
dev->set_mode(mode, dev);
}
dev->mode = mode;
/*
@@ -119,6 +128,8 @@ void clockevents_set_mode(struct clock_event_device *dev, } } }
return 0; }
/**
@@ -441,15 +452,23 @@ EXPORT_SYMBOL_GPL(clockevents_config_and_register);
int __clockevents_update_freq(struct clock_event_device *dev, u32 freq) {
int ret = 0;
clockevents_config(dev, freq);
if (dev->mode == CLOCK_EVT_MODE_ONESHOT) return clockevents_program_event(dev, dev->next_event, false);
- if (dev->mode == CLOCK_EVT_MODE_PERIODIC)
dev->set_mode(CLOCK_EVT_MODE_PERIODIC, dev);
- if (dev->mode == CLOCK_EVT_MODE_PERIODIC) {
if (dev->set_dev_mode) {
ret = dev->set_dev_mode(CLOCK_EVT_MODE_PERIODIC, dev);
WARN_ON(ret);
} else {
dev->set_mode(CLOCK_EVT_MODE_PERIODIC, dev);
}
- }
- return 0;
- return ret; }
Please update the caller function header description. It assumes that will return -ETIME on error. Did you check the impact regarding the new error code ? And by the way what will be this error code ?
/** diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index 61ed862..3d854aa 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c @@ -228,8 +228,13 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu) print_name_offset(m, dev->set_next_event); SEQ_printf(m, "\n");
- SEQ_printf(m, " set_mode: ");
- print_name_offset(m, dev->set_mode);
if (dev->set_dev_mode) {
SEQ_printf(m, " set_dev_mode: ");
print_name_offset(m, dev->set_dev_mode);
} else {
SEQ_printf(m, " set_mode: ");
print_name_offset(m, dev->set_mode);
} SEQ_printf(m, "\n");
SEQ_printf(m, " event_handler: ");