1 |
/* $MidnightBSD$ */ |
2 |
/*- |
3 |
* Copyright (c) 2009-2010 Fabio Checconi |
4 |
* Copyright (c) 2009-2010 Luigi Rizzo, Universita` di Pisa |
5 |
* All rights reserved. |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions |
9 |
* are met: |
10 |
* 1. Redistributions of source code must retain the above copyright |
11 |
* notice, this list of conditions and the following disclaimer. |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the distribution. |
15 |
* |
16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND |
17 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE |
20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 |
* SUCH DAMAGE. |
27 |
*/ |
28 |
|
29 |
#ifndef _G_SCHED_H_ |
30 |
#define _G_SCHED_H_ |
31 |
|
32 |
/* |
33 |
* $Id$ |
34 |
* $FreeBSD: stable/10/sys/geom/sched/g_sched.h 206552 2010-04-13 09:56:17Z luigi $ |
35 |
* |
36 |
* Header for the geom_sched class (userland library and kernel part). |
37 |
* See g_sched.c for documentation. |
38 |
* The userland code only needs the three G_SCHED_* values below. |
39 |
*/ |
40 |
|
41 |
#define G_SCHED_CLASS_NAME "SCHED" |
42 |
#define G_SCHED_VERSION 0 |
43 |
#define G_SCHED_SUFFIX ".sched." |
44 |
|
45 |
#ifdef _KERNEL |
46 |
#define G_SCHED_DEBUG(lvl, ...) do { \ |
47 |
if (me.gs_debug >= (lvl)) { \ |
48 |
printf("GEOM_SCHED"); \ |
49 |
if (me.gs_debug > 0) \ |
50 |
printf("[%u]", lvl); \ |
51 |
printf(": "); \ |
52 |
printf(__VA_ARGS__); \ |
53 |
printf("\n"); \ |
54 |
} \ |
55 |
} while (0) |
56 |
|
57 |
#define G_SCHED_LOGREQ(bp, ...) do { \ |
58 |
if (me.gs_debug >= 2) { \ |
59 |
printf("GEOM_SCHED[2]: "); \ |
60 |
printf(__VA_ARGS__); \ |
61 |
printf(" "); \ |
62 |
g_print_bio(bp); \ |
63 |
printf("\n"); \ |
64 |
} \ |
65 |
} while (0) |
66 |
|
67 |
LIST_HEAD(g_hash, g_sched_class); |
68 |
|
69 |
/* |
70 |
* Descriptor of a scheduler. |
71 |
* In addition to the obvious fields, sc_flushing and sc_pending |
72 |
* support dynamic switching of scheduling algorithm. |
73 |
* Normally, sc_flushing is 0, and requests that are scheduled are |
74 |
* also added to the sc_pending queue, and removed when we receive |
75 |
* the 'done' event. |
76 |
* |
77 |
* When we are transparently inserted on an existing provider, |
78 |
* sc_proxying is set. The detach procedure is slightly different. |
79 |
* |
80 |
* When switching schedulers, sc_flushing is set so requests bypass us, |
81 |
* and at the same time we update the pointer in the pending bios |
82 |
* to ignore us when they return up. |
83 |
* XXX it would be more efficient to implement sc_pending with |
84 |
* a generation number: the softc generation is increased when |
85 |
* we change scheduling algorithm, we store the current generation |
86 |
* number in the pending bios, and when they come back we ignore |
87 |
* the done() call if the generation number do not match. |
88 |
*/ |
89 |
struct g_sched_softc { |
90 |
/* |
91 |
* Generic fields used by any scheduling algorithm: |
92 |
* a mutex, the class descriptor, flags, list of pending |
93 |
* requests (used when flushing the module) and support |
94 |
* for hash tables where we store per-flow queues. |
95 |
*/ |
96 |
struct mtx sc_mtx; |
97 |
struct g_gsched *sc_gsched; /* Scheduler descriptor. */ |
98 |
int sc_pending; /* Pending requests. */ |
99 |
int sc_flags; /* Various flags. */ |
100 |
|
101 |
/* |
102 |
* Hash tables to store per-flow queues are generally useful |
103 |
* so we handle them in the common code. |
104 |
* sc_hash and sc_mask are parameters of the hash table, |
105 |
* the last two fields are used to periodically remove |
106 |
* expired items from the hash table. |
107 |
*/ |
108 |
struct g_hash *sc_hash; |
109 |
u_long sc_mask; |
110 |
int sc_flush_ticks; /* Next tick for a flush. */ |
111 |
int sc_flush_bucket; /* Next bucket to flush. */ |
112 |
|
113 |
/* |
114 |
* Pointer to the algorithm's private data, which is the value |
115 |
* returned by sc_gsched->gs_init() . A NULL here means failure. |
116 |
* XXX intptr_t might be more appropriate. |
117 |
*/ |
118 |
void *sc_data; |
119 |
}; |
120 |
|
121 |
#define G_SCHED_PROXYING 1 |
122 |
#define G_SCHED_FLUSHING 2 |
123 |
|
124 |
/* |
125 |
* Temporary- our own version of the disksort, because the |
126 |
* version in 7.x and 8.x before march 2009 is buggy. |
127 |
*/ |
128 |
void gs_bioq_init(struct bio_queue_head *); |
129 |
void gs_bioq_remove(struct bio_queue_head *, struct bio *); |
130 |
void gs_bioq_flush(struct bio_queue_head *, struct devstat *, int); |
131 |
void gs_bioq_insert_head(struct bio_queue_head *, struct bio *); |
132 |
void gs_bioq_insert_tail(struct bio_queue_head *, struct bio *); |
133 |
struct bio *gs_bioq_first(struct bio_queue_head *); |
134 |
struct bio *gs_bioq_takefirst(struct bio_queue_head *); |
135 |
void gs_bioq_disksort(struct bio_queue_head *, struct bio *); |
136 |
|
137 |
#endif /* _KERNEL */ |
138 |
|
139 |
#endif /* _G_SCHED_H_ */ |