2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2010 Fabio Checconi
5 * Copyright (c) 2009-2010 Luigi Rizzo, Universita` di Pisa
8 * Redistribution and use in source and binary forms, with or without
9 * 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 the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * Header for the geom_sched class (userland library and kernel part).
38 * See g_sched.c for documentation.
39 * The userland code only needs the three G_SCHED_* values below.
42 #define G_SCHED_CLASS_NAME "SCHED"
43 #define G_SCHED_VERSION 0
44 #define G_SCHED_SUFFIX ".sched."
47 #define G_SCHED_DEBUG(lvl, ...) do { \
48 if (me.gs_debug >= (lvl)) { \
49 printf("GEOM_SCHED"); \
50 if (me.gs_debug > 0) \
51 printf("[%u]", lvl); \
53 printf(__VA_ARGS__); \
58 #define G_SCHED_LOGREQ(bp, ...) do { \
59 if (me.gs_debug >= 2) { \
60 printf("GEOM_SCHED[2]: "); \
61 printf(__VA_ARGS__); \
68 LIST_HEAD(g_hash, g_sched_class);
71 * Descriptor of a scheduler.
72 * In addition to the obvious fields, sc_flushing and sc_pending
73 * support dynamic switching of scheduling algorithm.
74 * Normally, sc_flushing is 0, and requests that are scheduled are
75 * also added to the sc_pending queue, and removed when we receive
78 * When we are transparently inserted on an existing provider,
79 * sc_proxying is set. The detach procedure is slightly different.
81 * When switching schedulers, sc_flushing is set so requests bypass us,
82 * and at the same time we update the pointer in the pending bios
83 * to ignore us when they return up.
84 * XXX it would be more efficient to implement sc_pending with
85 * a generation number: the softc generation is increased when
86 * we change scheduling algorithm, we store the current generation
87 * number in the pending bios, and when they come back we ignore
88 * the done() call if the generation number do not match.
90 struct g_sched_softc {
92 * Generic fields used by any scheduling algorithm:
93 * a mutex, the class descriptor, flags, list of pending
94 * requests (used when flushing the module) and support
95 * for hash tables where we store per-flow queues.
98 struct g_gsched *sc_gsched; /* Scheduler descriptor. */
99 int sc_pending; /* Pending requests. */
100 int sc_flags; /* Various flags. */
103 * Hash tables to store per-flow queues are generally useful
104 * so we handle them in the common code.
105 * sc_hash and sc_mask are parameters of the hash table,
106 * the last two fields are used to periodically remove
107 * expired items from the hash table.
109 struct g_hash *sc_hash;
111 int sc_flush_ticks; /* Next tick for a flush. */
112 int sc_flush_bucket; /* Next bucket to flush. */
115 * Pointer to the algorithm's private data, which is the value
116 * returned by sc_gsched->gs_init() . A NULL here means failure.
117 * XXX intptr_t might be more appropriate.
122 #define G_SCHED_PROXYING 1
123 #define G_SCHED_FLUSHING 2
127 #endif /* _G_SCHED_H_ */