2 * Copyright (c) 2009, 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
40 #include <sys/queue.h>
45 #ifndef _SYS_BIOTRACK_H_
46 #include <sys/biotrack.h>
48 #ifndef _SYS_SPINLOCK_H_
49 #include <sys/spinlock.h>
52 #define FQ_IOQ_INIT(x) lockinit(&(x)->fq_lock, "fqioq", 0, LK_CANRECURSE)
53 #define FQ_IOQ_LOCK(x) lockmgr(&(x)->fq_lock, LK_EXCLUSIVE)
54 #define FQ_IOQ_UNLOCK(x) lockmgr(&(x)->fq_lock, LK_RELEASE)
57 #define FQ_FQMP_LOCKINIT(x) spin_init(&(x)->lock)
58 #define FQ_FQP_LOCKINIT(x) spin_init(&(x)->lock)
59 #define FQ_DPRIV_LOCKINIT(x) spin_init(&(x)->lock)
60 #define FQ_GLOBAL_FQMP_LOCKINIT(x) spin_init(&fq_fqmp_lock)
63 #define FQ_FQMP_LOCK(x) fq_reference_mpriv((x)); \
64 spin_lock_wr(&(x)->lock)
66 #define FQ_FQP_LOCK(x) fq_reference_priv((x)); \
67 spin_lock_wr(&(x)->lock)
69 #define FQ_DPRIV_LOCK(x) fq_reference_dpriv((x)); \
70 spin_lock_wr(&(x)->lock)
72 #define FQ_GLOBAL_FQMP_LOCK(x) spin_lock_wr(&fq_fqmp_lock)
75 #define FQ_FQMP_UNLOCK(x) spin_unlock_wr(&(x)->lock); \
76 fq_dereference_mpriv((x))
78 #define FQ_FQP_UNLOCK(x) spin_unlock_wr(&(x)->lock); \
79 fq_dereference_priv((x))
81 #define FQ_DPRIV_UNLOCK(x) spin_unlock_wr(&(x)->lock); \
82 fq_dereference_dpriv((x))
84 #define FQ_GLOBAL_FQMP_UNLOCK(x) spin_unlock_wr(&fq_fqmp_lock)
86 #define FQ_REBALANCE_TIMEOUT 1 /* in seconds */
87 #define FQ_TOTAL_DISK_TIME 1000000*FQ_REBALANCE_TIMEOUT /* in useconds */
90 #define FQ_INNERQ_INIT(x) spin_init(&(x)->lock)
91 #define FQ_INNERQ_UNINIT(x) spin_uninit(&(x)->lock)
92 #define FQ_INNERQ_LOCK(x) spin_lock_wr(&(x)->lock)
93 #define FQ_INNERQ_UNLOCK(x) spin_unlock_wr(&(x)->lock)
94 #define FQ_INNERQ_SLEEP(x,y,z) ssleep((x), &(x)->lock, 0, y, z)
101 #define FQP_LINKED_DPRIV 0x01
102 #define FQP_LINKED_FQMP 0x02
104 struct dsched_fq_priv {
105 TAILQ_ENTRY(dsched_fq_priv) link;
106 TAILQ_ENTRY(dsched_fq_priv) dlink;
107 TAILQ_HEAD(, bio) queue;
109 struct spinlock lock;
111 struct dsched_fq_dpriv *dpriv;
112 struct dsched_fq_mpriv *fqmp;
119 int32_t transactions;
125 struct dsched_fq_dpriv {
128 struct spinlock lock;
131 int avg_rq_time; /* XXX: unused */
132 int32_t incomplete_tp;
135 struct timeval start_idle;
138 /* list contains all fq_priv for this disk */
139 TAILQ_HEAD(, dsched_fq_priv) fq_priv_list;
140 TAILQ_ENTRY(dsched_fq_dpriv) link;
143 struct dsched_fq_mpriv {
147 struct spinlock lock;
149 TAILQ_HEAD(, dsched_fq_priv) fq_priv_list;
150 TAILQ_ENTRY(dsched_fq_mpriv) link;
157 struct dsched_fq_bucket {
158 struct lock bucket_lock;
165 TAILQ_HEAD(, dsched_fq_mpriv) fq_mpriv_list;
169 #define FQ_PRIO_BIAS 5
170 #define FQ_PRIO_MAX 10
171 #define FQ_PRIO_MIN 1
172 #define FQ_PRIO_IDLE -1
173 #define FQ_BUCKET_ACTIVE 0x01
177 struct dsched_fq_priv *fq_alloc_priv(struct disk *dp);
178 struct dsched_fq_dpriv *fq_alloc_dpriv(struct disk *dp);
179 struct dsched_fq_mpriv *fq_alloc_mpriv(struct proc *p);
180 void fq_balance_thread(struct dsched_fq_dpriv *dpriv);
181 void fq_dispatcher(struct dsched_fq_dpriv *dpriv);
182 biodone_t fq_completed;
184 void fq_reference_dpriv(struct dsched_fq_dpriv *dpriv);
185 void fq_reference_priv(struct dsched_fq_priv *fqp);
186 void fq_reference_mpriv(struct dsched_fq_mpriv *fqmp);
187 void fq_dereference_dpriv(struct dsched_fq_dpriv *dpriv);
188 void fq_dereference_priv(struct dsched_fq_priv *fqp);
189 void fq_dereference_mpriv(struct dsched_fq_mpriv *fqmp);
190 void fq_dispatch(struct dsched_fq_dpriv *dpriv, struct bio *bio,
191 struct dsched_fq_priv *fqp);
192 #endif /* _KERNEL || _KERNEL_STRUCTURES */
195 struct dsched_fq_stats {
196 int32_t fqmp_allocations;
197 int32_t fqp_allocations;
198 int32_t dpriv_allocations;
200 int32_t procs_limited;
202 int32_t transactions;
203 int32_t transactions_completed;
214 #endif /* _DSCHED_FQ_H_ */