Linux Audio

Check our new training course

Loading...
v6.8
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/*
 3 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
 4 *
 5 * This file is released under the GPL.
 6 */
 7
 8#ifndef DM_IO_TRACKER_H
 9#define DM_IO_TRACKER_H
10
11#include <linux/jiffies.h>
12
13struct dm_io_tracker {
14	spinlock_t lock;
15
16	/*
17	 * Sectors of in-flight IO.
18	 */
19	sector_t in_flight;
20
21	/*
22	 * The time, in jiffies, when this device became idle
23	 * (if it is indeed idle).
24	 */
25	unsigned long idle_time;
26	unsigned long last_update_time;
27};
28
29static inline void dm_iot_init(struct dm_io_tracker *iot)
30{
31	spin_lock_init(&iot->lock);
32	iot->in_flight = 0ul;
33	iot->idle_time = 0ul;
34	iot->last_update_time = jiffies;
35}
36
37static inline bool dm_iot_idle_for(struct dm_io_tracker *iot, unsigned long j)
38{
39	bool r = false;
40
41	spin_lock_irq(&iot->lock);
42	if (!iot->in_flight)
43		r = time_after(jiffies, iot->idle_time + j);
44	spin_unlock_irq(&iot->lock);
45
46	return r;
47}
48
49static inline unsigned long dm_iot_idle_time(struct dm_io_tracker *iot)
50{
51	unsigned long r = 0;
52
53	spin_lock_irq(&iot->lock);
54	if (!iot->in_flight)
55		r = jiffies - iot->idle_time;
56	spin_unlock_irq(&iot->lock);
57
58	return r;
59}
60
61static inline void dm_iot_io_begin(struct dm_io_tracker *iot, sector_t len)
62{
63	spin_lock_irq(&iot->lock);
64	iot->in_flight += len;
65	spin_unlock_irq(&iot->lock);
66}
67
68static inline void dm_iot_io_end(struct dm_io_tracker *iot, sector_t len)
69{
70	unsigned long flags;
71
72	if (!len)
73		return;
74
75	spin_lock_irqsave(&iot->lock, flags);
76	iot->in_flight -= len;
77	if (!iot->in_flight)
78		iot->idle_time = jiffies;
79	spin_unlock_irqrestore(&iot->lock, flags);
80}
81
82#endif
v6.2
 
 1/*
 2 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
 3 *
 4 * This file is released under the GPL.
 5 */
 6
 7#ifndef DM_IO_TRACKER_H
 8#define DM_IO_TRACKER_H
 9
10#include <linux/jiffies.h>
11
12struct dm_io_tracker {
13	spinlock_t lock;
14
15	/*
16	 * Sectors of in-flight IO.
17	 */
18	sector_t in_flight;
19
20	/*
21	 * The time, in jiffies, when this device became idle
22	 * (if it is indeed idle).
23	 */
24	unsigned long idle_time;
25	unsigned long last_update_time;
26};
27
28static inline void dm_iot_init(struct dm_io_tracker *iot)
29{
30	spin_lock_init(&iot->lock);
31	iot->in_flight = 0ul;
32	iot->idle_time = 0ul;
33	iot->last_update_time = jiffies;
34}
35
36static inline bool dm_iot_idle_for(struct dm_io_tracker *iot, unsigned long j)
37{
38	bool r = false;
39
40	spin_lock_irq(&iot->lock);
41	if (!iot->in_flight)
42		r = time_after(jiffies, iot->idle_time + j);
43	spin_unlock_irq(&iot->lock);
44
45	return r;
46}
47
48static inline unsigned long dm_iot_idle_time(struct dm_io_tracker *iot)
49{
50	unsigned long r = 0;
51
52	spin_lock_irq(&iot->lock);
53	if (!iot->in_flight)
54		r = jiffies - iot->idle_time;
55	spin_unlock_irq(&iot->lock);
56
57	return r;
58}
59
60static inline void dm_iot_io_begin(struct dm_io_tracker *iot, sector_t len)
61{
62	spin_lock_irq(&iot->lock);
63	iot->in_flight += len;
64	spin_unlock_irq(&iot->lock);
65}
66
67static inline void dm_iot_io_end(struct dm_io_tracker *iot, sector_t len)
68{
69	unsigned long flags;
70
71	if (!len)
72		return;
73
74	spin_lock_irqsave(&iot->lock, flags);
75	iot->in_flight -= len;
76	if (!iot->in_flight)
77		iot->idle_time = jiffies;
78	spin_unlock_irqrestore(&iot->lock, flags);
79}
80
81#endif