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 	void			*fn2;
21 	u64			expire;
22 };
23 
24 /* Amount to buffer up on a percpu counter */
25 #define IO_CLOCK_PCPU_SECTORS	128
26 
27 typedef DEFINE_MIN_HEAP(struct io_timer *, io_timer_heap)	io_timer_heap;
28 
29 struct io_clock {
30 	atomic64_t		now;
31 	u16 __percpu		*pcpu_buf;
32 	unsigned		max_slop;
33 
34 	spinlock_t		timer_lock;
35 	io_timer_heap		timers;
36 };
37 
38 #endif /* _BCACHEFS_CLOCK_TYPES_H */
39