1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_CLOCK_TYPES_H
3 #define _BCACHEFS_CLOCK_TYPES_H
4 
5 #include "util.h"
6 
7 #define NR_IO_TIMERS		(BCH_SB_MEMBERS_MAX * 3)
8 
9 /*
10  * Clocks/timers in units of sectors of IO:
11  *
12  * Note - they use percpu batching, so they're only approximate.
13  */
14 
15 struct io_timer;
16 typedef void (*io_timer_fn)(struct io_timer *);
17 
18 struct io_timer {
19 	io_timer_fn		fn;
20 	unsigned long		expire;
21 };
22 
23 /* Amount to buffer up on a percpu counter */
24 #define IO_CLOCK_PCPU_SECTORS	128
25 
26 typedef HEAP(struct io_timer *)	io_timer_heap;
27 
28 struct io_clock {
29 	atomic64_t		now;
30 	u16 __percpu		*pcpu_buf;
31 	unsigned		max_slop;
32 
33 	spinlock_t		timer_lock;
34 	io_timer_heap		timers;
35 };
36 
37 #endif /* _BCACHEFS_CLOCK_TYPES_H */
38