Skip to content

Commit

Permalink
ktime: Cleanup ktime_set() usage
Browse files Browse the repository at this point in the history
ktime_set(S,N) was required for the timespec storage type and is still
useful for situations where a Seconds and Nanoseconds part of a time value
needs to be converted. For anything where the Seconds argument is 0, this
is pointless and can be replaced with a simple assignment.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
  • Loading branch information
KAGA-KOKO committed Dec 25, 2016
1 parent 2456e85 commit 8b0e195
Show file tree
Hide file tree
Showing 56 changed files with 84 additions and 95 deletions.
3 changes: 1 addition & 2 deletions arch/powerpc/kvm/book3s_hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,8 +1872,7 @@ static void kvmppc_set_timer(struct kvm_vcpu *vcpu)
}
dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC
/ tb_ticks_per_sec;
hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec),
HRTIMER_MODE_REL);
hrtimer_start(&vcpu->arch.dec_timer, dec_nsec, HRTIMER_MODE_REL);
vcpu->arch.timer_running = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/oprofile/cell/spu_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static enum hrtimer_restart profile_spus(struct hrtimer *timer)
smp_wmb(); /* insure spu event buffer updates are written */
/* don't want events intermingled... */

kt = ktime_set(0, profiling_interval);
kt = profiling_interval;
if (!spu_prof_running)
goto stop;
hrtimer_forward(timer, timer->base->get_time(), kt);
Expand All @@ -204,7 +204,7 @@ int start_spu_profiling_cycles(unsigned int cycles_reset)
ktime_t kt;

pr_debug("timer resolution: %lu\n", TICK_NSEC);
kt = ktime_set(0, profiling_interval);
kt = profiling_interval;
hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
hrtimer_set_expires(&timer, kt);
timer.function = profile_spus;
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/kvm/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
return 0;

__set_cpu_idle(vcpu);
hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL);
hrtimer_start(&vcpu->arch.ckc_timer, sltime, HRTIMER_MODE_REL);
VCPU_EVENT(vcpu, 4, "enabled wait: %llu ns", sltime);
no_timer:
srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
now = ktime_get();
remaining = ktime_sub(apic->lapic_timer.target_expiration, now);
if (ktime_to_ns(remaining) < 0)
remaining = ktime_set(0, 0);
remaining = 0;

ns = mod_64(ktime_to_ns(remaining), apic->lapic_timer.period);
tmcct = div64_u64(ns,
Expand Down Expand Up @@ -2057,7 +2057,7 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
apic->lapic_timer.tscdeadline = 0;
if (apic_lvtt_oneshot(apic)) {
apic->lapic_timer.tscdeadline = 0;
apic->lapic_timer.target_expiration = ktime_set(0, 0);
apic->lapic_timer.target_expiration = 0;
}
atomic_set(&apic->lapic_timer.pending, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,
* This will be replaced with the stats tracking code, using
* 'avg_completion_time / 2' as the pre-sleep target.
*/
kt = ktime_set(0, nsecs);
kt = nsecs;

mode = HRTIMER_MODE_REL;
hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode);
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/power/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void device_pm_move_last(struct device *dev)

static ktime_t initcall_debug_start(struct device *dev)
{
ktime_t calltime = ktime_set(0, 0);
ktime_t calltime = 0;

if (pm_print_times_enabled) {
pr_info("calling %s+ @ %i, parent: %s\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/power/wakeup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ static int print_wakeup_source_stats(struct seq_file *m,
prevent_sleep_time = ktime_add(prevent_sleep_time,
ktime_sub(now, ws->start_prevent_time));
} else {
active_time = ktime_set(0, 0);
active_time = 0;
}

seq_printf(m, "%-12s\t%lu\t\t%lu\t\t%lu\t\t%lu\t\t%lld\t\t%lld\t\t%lld\t\t%lld\t\t%lld\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/null_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)

static void null_cmd_end_timer(struct nullb_cmd *cmd)
{
ktime_t kt = ktime_set(0, completion_nsec);
ktime_t kt = completion_nsec;

hrtimer_start(&cmd->timer, kt, HRTIMER_MODE_REL);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/dma/dmatest.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ static int dmatest_func(void *data)
int dst_cnt;
int i;
ktime_t ktime, start, diff;
ktime_t filltime = ktime_set(0, 0);
ktime_t comparetime = ktime_set(0, 0);
ktime_t filltime = 0;
ktime_t comparetime = 0;
s64 runtime = 0;
unsigned long long total_len = 0;
u8 align = 0;
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/amd/amdgpu/dce_virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ static enum hrtimer_restart dce_virtual_vblank_timer_handle(struct hrtimer *vbla

drm_handle_vblank(ddev, amdgpu_crtc->crtc_id);
dce_virtual_pageflip(adev, amdgpu_crtc->crtc_id);
hrtimer_start(vblank_timer, ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD),
hrtimer_start(vblank_timer, DCE_VIRTUAL_VBLANK_PERIOD,
HRTIMER_MODE_REL);

return HRTIMER_NORESTART;
Expand All @@ -772,11 +772,11 @@ static void dce_virtual_set_crtc_vblank_interrupt_state(struct amdgpu_device *ad
hrtimer_init(&adev->mode_info.crtcs[crtc]->vblank_timer,
CLOCK_MONOTONIC, HRTIMER_MODE_REL);
hrtimer_set_expires(&adev->mode_info.crtcs[crtc]->vblank_timer,
ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD));
DCE_VIRTUAL_VBLANK_PERIOD);
adev->mode_info.crtcs[crtc]->vblank_timer.function =
dce_virtual_vblank_timer_handle;
hrtimer_start(&adev->mode_info.crtcs[crtc]->vblank_timer,
ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD), HRTIMER_MODE_REL);
DCE_VIRTUAL_VBLANK_PERIOD, HRTIMER_MODE_REL);
} else if (!state && adev->mode_info.crtcs[crtc]->vsync_timer_enabled) {
DRM_DEBUG("Disable software vsync timer\n");
hrtimer_cancel(&adev->mode_info.crtcs[crtc]->vblank_timer);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/intel_uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fw_domain_arm_timer(struct intel_uncore_forcewake_domain *d)
{
d->wake_count++;
hrtimer_start_range_ns(&d->timer,
ktime_set(0, NSEC_PER_MSEC),
NSEC_PER_MSEC,
NSEC_PER_MSEC,
HRTIMER_MODE_REL);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/nouveau/nouveau_fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ nouveau_fence_wait_legacy(struct dma_fence *f, bool intr, long wait)
__set_current_state(intr ? TASK_INTERRUPTIBLE :
TASK_UNINTERRUPTIBLE);

kt = ktime_set(0, sleep_time);
kt = sleep_time;
schedule_hrtimeout(&kt, HRTIMER_MODE_REL);
sleep_time *= 2;
if (sleep_time > NSEC_PER_MSEC)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/tilcdc/tilcdc_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ static void tilcdc_crtc_off(struct drm_crtc *crtc, bool shutdown)
}

drm_flip_work_commit(&tilcdc_crtc->unref_work, priv->wq);
tilcdc_crtc->last_vblank = ktime_set(0, 0);
tilcdc_crtc->last_vblank = 0;

tilcdc_crtc->enabled = false;
mutex_unlock(&tilcdc_crtc->enable_lock);
Expand Down
5 changes: 2 additions & 3 deletions drivers/iio/trigger/iio-trig-hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ssize_t iio_hrtimer_store_sampling_frequency(struct device *dev,
return -EINVAL;

info->sampling_frequency = val;
info->period = ktime_set(0, NSEC_PER_SEC / val);
info->period = NSEC_PER_SEC / val;

return len;
}
Expand Down Expand Up @@ -141,8 +141,7 @@ static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name)
trig_info->timer.function = iio_hrtimer_trig_handler;

trig_info->sampling_frequency = HRTIMER_DEFAULT_SAMPLING_FREQUENCY;
trig_info->period = ktime_set(0, NSEC_PER_SEC /
trig_info->sampling_frequency);
trig_info->period = NSEC_PER_SEC / trig_info->sampling_frequency;

ret = iio_trigger_register(trig_info->swt.trigger);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/joystick/walkera0701.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void walkera0701_irq_handler(void *handler_data)
RESERVE + BIN1_PULSE - BIN0_PULSE) /* frame sync .. */
w->counter = 0;

hrtimer_start(&w->timer, ktime_set(0, BIN_SAMPLE), HRTIMER_MODE_REL);
hrtimer_start(&w->timer, BIN_SAMPLE, HRTIMER_MODE_REL);
}

static enum hrtimer_restart timer_handler(struct hrtimer
Expand Down
3 changes: 1 addition & 2 deletions drivers/mailbox/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ static void msg_submit(struct mbox_chan *chan)

if (!err && (chan->txdone_method & TXDONE_BY_POLL))
/* kick start the timer immediately to avoid delays */
hrtimer_start(&chan->mbox->poll_hrt, ktime_set(0, 0),
HRTIMER_MODE_REL);
hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL);
}

static void tx_tick(struct mbox_chan *chan, int r)
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/dvb-core/dmxdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
struct dmxdev_filter *filter,
struct dmxdev_feed *feed)
{
ktime_t timeout = ktime_set(0, 0);
ktime_t timeout = 0;
struct dmx_pes_filter_params *para = &filter->params.pes;
dmx_output_t otype;
int ret;
Expand Down
6 changes: 2 additions & 4 deletions drivers/media/pci/cx88/cx88-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);

cx88_ir_handle_key(ir);
missed = hrtimer_forward_now(&ir->timer,
ktime_set(0, ir->polling * 1000000));
missed = hrtimer_forward_now(&ir->timer, ir->polling * 1000000);
if (missed > 1)
ir_dprintk("Missed ticks %ld\n", missed - 1);

Expand All @@ -199,8 +198,7 @@ static int __cx88_ir_start(void *priv)
if (ir->polling) {
hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
ir->timer.function = cx88_ir_work;
hrtimer_start(&ir->timer,
ktime_set(0, ir->polling * 1000000),
hrtimer_start(&ir->timer, ir->polling * 1000000,
HRTIMER_MODE_REL);
}
if (ir->sampling) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/pt3/pt3.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static int pt3_fetch_thread(void *data)

pt3_proc_dma(adap);

delay = ktime_set(0, PT3_FETCH_DELAY * NSEC_PER_MSEC);
delay = PT3_FETCH_DELAY * NSEC_PER_MSEC;
set_current_state(TASK_UNINTERRUPTIBLE);
freezable_schedule_hrtimeout_range(&delay,
PT3_FETCH_DELAY_DELTA * NSEC_PER_MSEC,
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/can/softing/softing_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static void softing_initialize_timestamp(struct softing *card)
ovf = 0x100000000ULL * 16;
do_div(ovf, card->pdat->freq ?: 16);

card->ts_overflow = ktime_add_us(ktime_set(0, 0), ovf);
card->ts_overflow = ktime_add_us(0, ovf);
}

ktime_t softing_raw2ktime(struct softing *card, u32 raw)
Expand Down Expand Up @@ -647,7 +647,7 @@ int softing_startstop(struct net_device *dev, int up)
open_candev(netdev);
if (dev != netdev) {
/* notify other busses on the restart */
softing_netdev_rx(netdev, &msg, ktime_set(0, 0));
softing_netdev_rx(netdev, &msg, 0);
++priv->can.can_stats.restarts;
}
netif_wake_queue(netdev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/can/softing/softing_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static int softing_handle_1(struct softing *card)
/* a dead bus has no overflows */
continue;
++netdev->stats.rx_over_errors;
softing_netdev_rx(netdev, &msg, ktime_set(0, 0));
softing_netdev_rx(netdev, &msg, 0);
}
/* prepare for other use */
memset(&msg, 0, sizeof(msg));
Expand Down
5 changes: 2 additions & 3 deletions drivers/net/ethernet/ec_bhf.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static enum hrtimer_restart ec_bhf_timer_fun(struct hrtimer *timer)
if (!netif_running(priv->net_dev))
return HRTIMER_NORESTART;

hrtimer_forward_now(timer, ktime_set(0, polling_frequency));
hrtimer_forward_now(timer, polling_frequency);
return HRTIMER_RESTART;
}

Expand Down Expand Up @@ -427,8 +427,7 @@ static int ec_bhf_open(struct net_device *net_dev)

hrtimer_init(&priv->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
priv->hrtimer.function = ec_bhf_timer_fun;
hrtimer_start(&priv->hrtimer, ktime_set(0, polling_frequency),
HRTIMER_MODE_REL);
hrtimer_start(&priv->hrtimer, polling_frequency, HRTIMER_MODE_REL);

return 0;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/marvell/mvpp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4913,7 +4913,7 @@ static void mvpp2_timer_set(struct mvpp2_port_pcpu *port_pcpu)

if (!port_pcpu->timer_scheduled) {
port_pcpu->timer_scheduled = true;
interval = ktime_set(0, MVPP2_TXDONE_HRTIMER_PERIOD_NS);
interval = MVPP2_TXDONE_HRTIMER_PERIOD_NS;
hrtimer_start(&port_pcpu->tx_done_timer, interval,
HRTIMER_MODE_REL_PINNED);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/tile/tilegx.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ static void tile_net_schedule_tx_wake_timer(struct net_device *dev,
&info->mpipe[instance].tx_wake[priv->echannel];

hrtimer_start(&tx_wake->timer,
ktime_set(0, TX_TIMER_DELAY_USEC * 1000UL),
TX_TIMER_DELAY_USEC * 1000UL,
HRTIMER_MODE_REL_PINNED);
}

Expand All @@ -770,7 +770,7 @@ static void tile_net_schedule_egress_timer(void)

if (!info->egress_timer_scheduled) {
hrtimer_start(&info->egress_timer,
ktime_set(0, EGRESS_TIMER_DELAY_USEC * 1000UL),
EGRESS_TIMER_DELAY_USEC * 1000UL,
HRTIMER_MODE_REL_PINNED);
info->egress_timer_scheduled = true;
}
Expand Down
9 changes: 4 additions & 5 deletions drivers/net/ieee802154/at86rf230.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ at86rf230_async_state_delay(void *context)
case STATE_TRX_OFF:
switch (ctx->to_state) {
case STATE_RX_AACK_ON:
tim = ktime_set(0, c->t_off_to_aack * NSEC_PER_USEC);
tim = c->t_off_to_aack * NSEC_PER_USEC;
/* state change from TRX_OFF to RX_AACK_ON to do a
* calibration, we need to reset the timeout for the
* next one.
Expand All @@ -519,7 +519,7 @@ at86rf230_async_state_delay(void *context)
goto change;
case STATE_TX_ARET_ON:
case STATE_TX_ON:
tim = ktime_set(0, c->t_off_to_tx_on * NSEC_PER_USEC);
tim = c->t_off_to_tx_on * NSEC_PER_USEC;
/* state change from TRX_OFF to TX_ON or ARET_ON to do
* a calibration, we need to reset the timeout for the
* next one.
Expand All @@ -539,8 +539,7 @@ at86rf230_async_state_delay(void *context)
* to TX_ON or TRX_OFF.
*/
if (!force) {
tim = ktime_set(0, (c->t_frame + c->t_p_ack) *
NSEC_PER_USEC);
tim = (c->t_frame + c->t_p_ack) * NSEC_PER_USEC;
goto change;
}
break;
Expand All @@ -552,7 +551,7 @@ at86rf230_async_state_delay(void *context)
case STATE_P_ON:
switch (ctx->to_state) {
case STATE_TRX_OFF:
tim = ktime_set(0, c->t_reset_to_off * NSEC_PER_USEC);
tim = c->t_reset_to_off * NSEC_PER_USEC;
goto change;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/usb/cdc_ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
/* start timer, if not already started */
if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop)))
hrtimer_start(&ctx->tx_timer,
ktime_set(0, ctx->timer_interval),
ctx->timer_interval,
HRTIMER_MODE_REL);
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/ralink/rt2x00/rt2800usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
if (rt2800usb_txstatus_pending(rt2x00dev)) {
/* Read register after 1 ms */
hrtimer_start(&rt2x00dev->txstatus_timer,
ktime_set(0, TXSTATUS_READ_INTERVAL),
TXSTATUS_READ_INTERVAL,
HRTIMER_MODE_REL);
return false;
}
Expand All @@ -204,7 +204,7 @@ static void rt2800usb_async_read_tx_status(struct rt2x00_dev *rt2x00dev)

/* Read TX_STA_FIFO register after 2 ms */
hrtimer_start(&rt2x00dev->txstatus_timer,
ktime_set(0, 2*TXSTATUS_READ_INTERVAL),
2 * TXSTATUS_READ_INTERVAL,
HRTIMER_MODE_REL);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/pci/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e0d, quirk_intel_ntb);
static ktime_t fixup_debug_start(struct pci_dev *dev,
void (*fn)(struct pci_dev *dev))
{
ktime_t calltime = ktime_set(0, 0);
ktime_t calltime = 0;

dev_dbg(&dev->dev, "calling %pF\n", fn);
if (initcall_debug) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/platform/x86/msi-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static int __init msi_wmi_input_setup(void)
if (err)
goto err_free_keymap;

last_pressed = ktime_set(0, 0);
last_pressed = 0;

return 0;

Expand Down
2 changes: 1 addition & 1 deletion drivers/power/reset/ltc2952-poweroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void ltc2952_poweroff_kill(void)

static void ltc2952_poweroff_default(struct ltc2952_poweroff *data)
{
data->wde_interval = ktime_set(0, 300L*1E6L);
data->wde_interval = 300L * 1E6L;
data->trigger_delay = ktime_set(2, 500L*1E6L);

hrtimer_init(&data->timer_trigger, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
Expand Down
Loading

0 comments on commit 8b0e195

Please sign in to comment.