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_PRIO_BIAS 5
53 #define FQ_PRIO_MAX 10
55 #define FQ_PRIO_IDLE -1
56 #define FQ_BUCKET_ACTIVE 0x01
58 #define FQ_DISPATCH_SML_ARRAY_SZ 128
59 #define FQ_DISPATCH_ARRAY_SZ 512
61 #define FQ_DRAIN_CANCEL 0x1
62 #define FQ_DRAIN_FLUSH 0x2
68 struct dsched_disk_ctx head;
70 struct thread *td; /* dispatcher thread td */
71 struct thread *td_balance; /* balancer thread td */
72 int avg_rq_time; /* XXX: not yet used */
73 int32_t incomplete_tp; /* IOs issued but not completed */
74 int idle; /* disk idle ? */
75 struct timeval start_idle; /* disk idleness start time */
76 int idle_time; /* aggregate idle time in interval */
77 int die; /* flag to kill related threads */
78 struct timeval start_interval; /* current interval start time */
80 int prev_full; /* disk >90% busy during prev. to last
82 int last_full; /* disk >90% busy during last interval */
83 int disk_busy; /* disk >90% busy during cur. interval */
84 int64_t budgetpb[FQ_PRIO_MAX+1];/* next interval budget for each thread
89 struct dsched_thread_io head;
91 int32_t transactions; /* IOs completed so far during current interval */
92 int32_t avg_latency; /* avg latency for current interval IOs */
93 int32_t interval_transactions; /* IOs completed during last interval */
94 int32_t interval_avg_latency; /* avg latency for last interval IOs */
95 int32_t max_tp; /* rate limit of transactions per interval */
96 int32_t issued; /* IOs issued to disk (but not completed) */
98 int rebalance; /* thread needs to rebalance w/ fq_balance_self */
101 struct dispatch_prep {
102 struct fq_thread_io *tdio;
107 void fq_balance_thread(struct fq_disk_ctx *diskctx);
108 void fq_dispatcher(struct fq_disk_ctx *diskctx);
109 biodone_t fq_completed;
111 void fq_dispatch(struct fq_disk_ctx *diskctx, struct bio *bio,
112 struct fq_thread_io *tdio);
113 void fq_drain(struct fq_disk_ctx *diskctx, int mode);
114 void fq_balance_self(struct fq_thread_io *tdio);
115 #endif /* _KERNEL || _KERNEL_STRUCTURES */
118 struct dsched_fq_stats {
119 int32_t procs_limited;
121 int32_t transactions;
122 int32_t transactions_completed;
126 #endif /* _DSCHED_FQ_H_ */