+// SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h"
#include "clock.h"
size_t i;
spin_lock(&clock->timer_lock);
+
+ if (time_after_eq((unsigned long) atomic64_read(&clock->now),
+ timer->expire)) {
+ spin_unlock(&clock->timer_lock);
+ timer->fn(timer);
+ return;
+ }
+
for (i = 0; i < clock->timers.used; i++)
if (clock->timers.data[i] == timer)
goto out;
}
__set_current_state(TASK_RUNNING);
- del_singleshot_timer_sync(&wait.cpu_timer);
+ del_timer_sync(&wait.cpu_timer);
destroy_timer_on_stack(&wait.cpu_timer);
bch2_io_timer_del(clock, &wait.io_timer);
}
return ret;
}
-void bch2_increment_clock(struct bch_fs *c, unsigned sectors, int rw)
+void __bch2_increment_clock(struct io_clock *clock, unsigned sectors)
{
- struct io_clock *clock = &c->io_clock[rw];
struct io_timer *timer;
- unsigned long now;
+ unsigned long now = atomic64_add_return(sectors, &clock->now);
- /* Buffer up one megabyte worth of IO in the percpu counter */
- preempt_disable();
+ while ((timer = get_expired_timer(clock, now)))
+ timer->fn(timer);
+}
- if (likely(this_cpu_add_return(*clock->pcpu_buf, sectors) <
- IO_CLOCK_PCPU_SECTORS)) {
- preempt_enable();
- return;
- }
+void bch2_io_timers_to_text(struct printbuf *out, struct io_clock *clock)
+{
+ unsigned long now;
+ unsigned i;
- sectors = this_cpu_xchg(*clock->pcpu_buf, 0);
- preempt_enable();
- now = atomic_long_add_return(sectors, &clock->now);
+ out->atomic++;
+ spin_lock(&clock->timer_lock);
+ now = atomic64_read(&clock->now);
- while ((timer = get_expired_timer(clock, now)))
- timer->fn(timer);
+ for (i = 0; i < clock->timers.used; i++)
+ prt_printf(out, "%ps:\t%li\n",
+ clock->timers.data[i]->fn,
+ clock->timers.data[i]->expire - now);
+ spin_unlock(&clock->timer_lock);
+ --out->atomic;
}
void bch2_io_clock_exit(struct io_clock *clock)
int bch2_io_clock_init(struct io_clock *clock)
{
- atomic_long_set(&clock->now, 0);
+ atomic64_set(&clock->now, 0);
spin_lock_init(&clock->timer_lock);
+ clock->max_slop = IO_CLOCK_PCPU_SECTORS * num_possible_cpus();
+
clock->pcpu_buf = alloc_percpu(*clock->pcpu_buf);
if (!clock->pcpu_buf)
- return -ENOMEM;
+ return -BCH_ERR_ENOMEM_io_clock_init;
if (!init_heap(&clock->timers, NR_IO_TIMERS, GFP_KERNEL))
- return -ENOMEM;
+ return -BCH_ERR_ENOMEM_io_clock_init;
return 0;
}