/** * printk_timed_ratelimit - caller-controlled printk ratelimiting * @caller_jiffies: pointer to caller's state * @interval_msecs: minimum interval between prints * * printk_timed_ratelimit() returns true if more than @interval_msecs * milliseconds have elapsed since the last time printk_timed_ratelimit() * returned true. */ bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msecs) { if (*caller_jiffies == 0 || !time_in_range(jiffies, *caller_jiffies, *caller_jiffies + msecs_to_jiffies(interval_msecs))) { *caller_jiffies = jiffies; return true; } return false; }
END_TEST START_TEST(check_time_in_range) { timeval_t t1, t2, val; t1 = 0xFF000000; val = 0xFF0000FF; t2 = 0xFFFF0000; ck_assert_int_eq(time_in_range(val, t1, t2), 1); t1 = 0xFF000000; val = 0x80000000; t2 = 0xFFFF0000; ck_assert_int_eq(time_in_range(val, t1, t2), 0); t1 = 0xFF000000; val = 0xFF0000FF; t2 = 0xFFFF0000; ck_assert_int_eq(time_in_range(val, t2, t1), 0); t1 = 0xFF000000; val = 0x0000FFFF; t2 = 0x40000000; ck_assert_int_eq(time_in_range(val, t1, t2), 1); t1 = 0x1000; val = 0x2000; t2 = 0x1000; ck_assert_int_eq(time_in_range(val, t1, t2), 0); t1 = 0x1000; val = 0x1000; t2 = 0x1000; ck_assert_int_eq(time_in_range(val, t1, t2), 1); }
void cam_nplusone_decoder(struct decoder *d) { timeval_t t0, t1; int sync, trigger; decoder_state oldstate = d->state; disable_interrupts(); t0 = d->last_t0; t1 = d->last_t1; trigger = d->needs_decoding_t0; d->needs_decoding_t0 = 0; sync = d->needs_decoding_t1; d->needs_decoding_t1 = 0; enable_interrupts(); if (d->state == DECODER_NOSYNC && trigger) { if (d->current_triggers_rpm >= d->required_triggers_rpm) { d->state = DECODER_RPM; } else { d->current_triggers_rpm++; } } if (trigger && sync) { /* Which came first? */ if (time_in_range(t1, t0, current_time())) { trigger_update(d, t0); sync_update(d); } else { sync_update(d); trigger_update(d, t0); } } else if (trigger) { trigger_update(d, t0); } else { sync_update(d); } if (d->state == DECODER_SYNC) { d->valid = 1; d->last_trigger_time = t0; } else { if (oldstate == DECODER_SYNC) { /* We lost sync */ invalidate_decoder(); } } }
static void pnfs_layout_io_set_failed(struct pnfs_layout_hdr *lo, u32 iomode) { struct inode *inode = lo->plh_inode; struct pnfs_layout_range range = { .iomode = iomode, .offset = 0, .length = NFS4_MAX_UINT64, }; LIST_HEAD(head); spin_lock(&inode->i_lock); pnfs_layout_set_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); pnfs_mark_matching_lsegs_invalid(lo, &head, &range); spin_unlock(&inode->i_lock); pnfs_free_lseg_list(&head); dprintk("%s Setting layout IOMODE_%s fail bit\n", __func__, iomode == IOMODE_RW ? "RW" : "READ"); } static bool pnfs_layout_io_test_failed(struct pnfs_layout_hdr *lo, u32 iomode) { unsigned long start, end; int fail_bit = pnfs_iomode_to_fail_bit(iomode); if (test_bit(fail_bit, &lo->plh_flags) == 0) return false; end = jiffies; start = end - PNFS_LAYOUTGET_RETRY_TIMEOUT; if (!time_in_range(lo->plh_retry_timestamp, start, end)) { /* It is time to retry the failed layoutgets */ pnfs_layout_clear_fail_bit(lo, fail_bit); return false; } return true; }