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_DRAIN_CANCEL 0x1
59 #define FQ_DRAIN_FLUSH 0x2
65 struct dsched_disk_ctx head;
67 struct thread *td; /* dispatcher thread td */
68 struct thread *td_balance; /* balancer thread td */
69 int avg_rq_time; /* XXX: not yet used */
70 int32_t incomplete_tp; /* IOs issued but not completed */
71 int idle; /* disk idle ? */
72 struct timeval start_idle; /* disk idleness start time */
73 int idle_time; /* aggregate idle time in interval */
74 int die; /* flag to kill related threads */
75 struct timeval start_interval; /* current interval start time */
77 int prev_full; /* disk >90% busy during prev. to last
79 int last_full; /* disk >90% busy during last interval */
80 int disk_busy; /* disk >90% busy during cur. interval */
81 int64_t budgetpb[FQ_PRIO_MAX+1];/* next interval budget for each thread
86 struct dsched_thread_io head;
88 int32_t transactions; /* IOs completed so far during current interval */
89 int32_t avg_latency; /* avg latency for current interval IOs */
90 int32_t interval_transactions; /* IOs completed during last interval */
91 int32_t interval_avg_latency; /* avg latency for last interval IOs */
92 int32_t max_tp; /* rate limit of transactions per interval */
93 int32_t issued; /* IOs issued to disk (but not completed) */
95 int rebalance; /* thread needs to rebalance w/ fq_balance_self */
100 void fq_balance_thread(struct fq_disk_ctx *diskctx);
101 void fq_dispatcher(struct fq_disk_ctx *diskctx);
102 biodone_t fq_completed;
104 void fq_dispatch(struct fq_disk_ctx *diskctx, struct bio *bio,
105 struct fq_thread_io *tdio);
106 void fq_drain(struct fq_disk_ctx *diskctx, int mode);
107 void fq_balance_self(struct fq_thread_io *tdio);
108 #endif /* _KERNEL || _KERNEL_STRUCTURES */
111 struct dsched_fq_stats {
112 int32_t procs_limited;
114 int32_t transactions;
115 int32_t transactions_completed;
119 #endif /* _DSCHED_FQ_H_ */