2 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
7 #ifndef DM_IO_TRACKER_H
8 #define DM_IO_TRACKER_H
10 #include <linux/jiffies.h>
12 struct dm_io_tracker {
16 * Sectors of in-flight IO.
21 * The time, in jiffies, when this device became idle
22 * (if it is indeed idle).
24 unsigned long idle_time;
25 unsigned long last_update_time;
28 static inline void dm_iot_init(struct dm_io_tracker *iot)
30 spin_lock_init(&iot->lock);
33 iot->last_update_time = jiffies;
36 static inline bool dm_iot_idle_for(struct dm_io_tracker *iot, unsigned long j)
40 spin_lock_irq(&iot->lock);
42 r = time_after(jiffies, iot->idle_time + j);
43 spin_unlock_irq(&iot->lock);
48 static inline unsigned long dm_iot_idle_time(struct dm_io_tracker *iot)
52 spin_lock_irq(&iot->lock);
54 r = jiffies - iot->idle_time;
55 spin_unlock_irq(&iot->lock);
60 static inline void dm_iot_io_begin(struct dm_io_tracker *iot, sector_t len)
62 spin_lock_irq(&iot->lock);
63 iot->in_flight += len;
64 spin_unlock_irq(&iot->lock);
67 static inline void dm_iot_io_end(struct dm_io_tracker *iot, sector_t len)
74 spin_lock_irqsave(&iot->lock, flags);
75 iot->in_flight -= len;
77 iot->idle_time = jiffies;
78 spin_unlock_irqrestore(&iot->lock, flags);