dsched - import the I/O scheduler framework dsched
[dragonfly.git] / sys / sys / dsched.h
CommitLineData
b80a9543
AH
1/*
2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
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 *
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
16 * distribution.
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.
20 *
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
32 * SUCH DAMAGE.
33 */
34#ifndef _SYS_DSCHED_H_
35#define _SYS_DSCHED_H_
36
37#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
38
39#ifndef _SYS_QUEUE_H_
40#include <sys/queue.h>
41#endif
42#ifndef _SYS_BIO_H_
43#include <sys/bio.h>
44#endif
45#ifndef _SYS_BIOTRACK_H_
46#include <sys/biotrack.h>
47#endif
48#ifndef _SYS_LOCK_H_
49#include <sys/lock.h>
50#endif
51#ifndef _SYS_CONF_H_
52#include <sys/conf.h>
53#endif
54#ifndef _SYS_MSGPORT_H_
55#include <sys/msgport.h>
56#endif
57
58#define DSCHED_POLICY_NAME_LENGTH 64
59
60#define dsched_set_disk_priv(dp, x) ((dp)->d_dsched_priv1 = (x))
61#define dsched_get_disk_priv(dp) ((dp)?((dp)->d_dsched_priv1):NULL)
62#define dsched_set_proc_priv(pp, x) ((pp)->p_dsched_priv1 = (x))
63#define dsched_get_proc_priv(pp) ((pp)?((pp)->p_dsched_priv1):NULL)
64
65#define dsched_set_thread_priv(td, x) ((td)->td_dsched_priv1 = (x))
66#define dsched_get_thread_priv(td) ((td)?((td)->td_dsched_priv1):NULL)
67
68#define dsched_set_buf_priv(bp, x) ((bp)->b_iosched = (x))
69#define dsched_get_buf_priv(bp) ((bp)?((bp)->b_iosched):NULL)
70#define dsched_clr_buf_priv(bp) ((bp)->b_iosched = NULL)
71#define dsched_is_clear_buf_priv(bp) ((bp)->b_iosched == NULL)
72
73
74#define dsched_set_bio_dp(bio, x) ((bio)->bio_caller_info1.ptr = (x))
75#define dsched_get_bio_dp(bio) ((bio)?((bio)->bio_caller_info1.ptr):NULL)
76#define dsched_set_bio_priv(bio, x) ((bio)->bio_caller_info2.ptr = (x))
77#define dsched_get_bio_priv(bio) ((bio)?((bio)->bio_caller_info2.ptr):NULL)
78#define dsched_set_bio_stime(bio, x) ((bio)->bio_caller_info3.lvalue = (x))
79#define dsched_get_bio_stime(bio) ((bio)?((bio)->bio_caller_info3.lvalue):0)
80
81
82typedef int dsched_prepare_t(struct disk *dp);
83typedef void dsched_teardown_t(struct disk *dp);
84typedef void dsched_flush_t(struct disk *dp, struct bio *bio);
85typedef void dsched_cancel_t(struct disk *dp);
86typedef int dsched_queue_t(struct disk *dp, struct bio *bio);
87typedef void dsched_new_buf_t(struct buf *bp);
88typedef void dsched_new_proc_t(struct proc *p);
89typedef void dsched_new_thread_t(struct thread *td);
90typedef void dsched_exit_proc_t(struct proc *p);
91typedef void dsched_exit_thread_t(struct thread *td);
92
93struct dsched_ops {
94 struct {
95 char name[DSCHED_POLICY_NAME_LENGTH];
96 uint64_t uniq_id;
97 int ref_count;
98 } head;
99
100 dsched_prepare_t *prepare;
101 dsched_teardown_t *teardown;
102 dsched_flush_t *flush;
103 dsched_cancel_t *cancel_all;
104 dsched_queue_t *bio_queue;
105
106 dsched_new_buf_t *new_buf;
107 dsched_new_proc_t *new_proc;
108 dsched_new_thread_t *new_thread;
109 dsched_exit_proc_t *exit_proc;
110 dsched_exit_thread_t *exit_thread;
111};
112
113struct dsched_policy {
114 TAILQ_ENTRY(dsched_policy) link;
115
116 struct dsched_ops *d_ops;
117};
118
119struct dsched_object
120{
121 struct disk *dp;
122 struct bio *bio;
123 int pid;
124 struct thread *thread;
125 struct proc *proc;
126};
127
128TAILQ_HEAD(dschedq, dsched_object);
129TAILQ_HEAD(dsched_policy_head, dsched_policy);
130
131void dsched_create(struct disk *dp, const char *head_name, int unit);
132void dsched_destroy(struct disk *dp);
133void dsched_queue(struct disk *dp, struct bio *bio);
134int dsched_register(struct dsched_ops *d_ops);
135int dsched_unregister(struct dsched_ops *d_ops);
136int dsched_switch(struct disk *dp, struct dsched_ops *new_ops);
137void dsched_set_policy(struct disk *dp, struct dsched_ops *new_ops);
138struct dsched_policy *dsched_find_policy(char *search);
139struct disk *dsched_find_disk(char *search);
140struct dsched_policy *dsched_policy_enumerate(struct dsched_policy *pol);
141struct disk *dsched_disk_enumerate(struct disk *dp, struct dsched_ops *ops);
142void dsched_cancel_bio(struct bio *bp);
143void dsched_strategy_raw(struct disk *dp, struct bio *bp);
144void dsched_strategy_sync(struct disk *dp, struct bio *bp);
145void dsched_strategy_async(struct disk *dp, struct bio *bp, biodone_t *done, void *priv);
146int dsched_debug(int level, char *fmt, ...);
147dsched_new_buf_t dsched_new_buf;
148dsched_new_proc_t dsched_new_proc;
149dsched_new_thread_t dsched_new_thread;
150
151dsched_exit_proc_t dsched_exit_proc;
152dsched_exit_thread_t dsched_exit_thread;
153
154#endif /* _KERNEL || _KERNEL_STRUCTURES */
155
156
157#define DSCHED_NAME_LENGTH 64
158#define DSCHED_SET_DEVICE_POLICY _IOWR('d', 1, struct dsched_ioctl)
159#define DSCHED_LIST_DISKS _IOWR('d', 2, struct dsched_ioctl)
160#define DSCHED_LIST_DISK _IOWR('d', 3, struct dsched_ioctl)
161#define DSCHED_LIST_POLICIES _IOWR('d', 4, struct dsched_ioctl)
162
163struct dsched_ioctl {
164 uint16_t num_elem;
165 char dev_name[DSCHED_NAME_LENGTH];
166 char pol_name[DSCHED_NAME_LENGTH];
167};
168
169#endif /* _SYS_DSCHED_H_ */