dschedctl: G/C some unneeded headers
[dragonfly.git] / sys / sys / dsched.h
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
82 typedef int     dsched_prepare_t(struct disk *dp);
83 typedef void    dsched_teardown_t(struct disk *dp);
84 typedef void    dsched_flush_t(struct disk *dp, struct bio *bio);
85 typedef void    dsched_cancel_t(struct disk *dp);
86 typedef int     dsched_queue_t(struct disk *dp, struct bio *bio);
87 typedef void    dsched_new_buf_t(struct buf *bp);
88 typedef void    dsched_new_proc_t(struct proc *p);
89 typedef void    dsched_new_thread_t(struct thread *td);
90 typedef void    dsched_exit_buf_t(struct buf *bp);
91 typedef void    dsched_exit_proc_t(struct proc *p);
92 typedef void    dsched_exit_thread_t(struct thread *td);
93
94
95 struct dsched_policy {
96         char                    name[DSCHED_POLICY_NAME_LENGTH];
97         uint64_t                uniq_id;
98         int                     ref_count;
99
100         TAILQ_ENTRY(dsched_policy) link;
101
102         dsched_prepare_t        *prepare;
103         dsched_teardown_t       *teardown;
104         dsched_flush_t          *flush;
105         dsched_cancel_t         *cancel_all;
106         dsched_queue_t          *bio_queue;
107
108         dsched_new_buf_t        *new_buf;
109         dsched_new_proc_t       *new_proc;
110         dsched_new_thread_t     *new_thread;
111         dsched_exit_buf_t       *exit_buf;
112         dsched_exit_proc_t      *exit_proc;
113         dsched_exit_thread_t    *exit_thread;
114 };
115
116 TAILQ_HEAD(dsched_policy_head, dsched_policy);
117
118 void    dsched_disk_create_callback(struct disk *dp, const char *head_name, int unit);
119 void    dsched_disk_destroy_callback(struct disk *dp);
120 void    dsched_queue(struct disk *dp, struct bio *bio);
121 int     dsched_register(struct dsched_policy *d_policy);
122 int     dsched_unregister(struct dsched_policy *d_policy);
123 int     dsched_switch(struct disk *dp, struct dsched_policy *new_policy);
124 void    dsched_set_policy(struct disk *dp, struct dsched_policy *new_policy);
125 struct dsched_policy *dsched_find_policy(char *search);
126 struct disk     *dsched_find_disk(char *search);
127 struct dsched_policy *dsched_policy_enumerate(struct dsched_policy *pol);
128 struct disk     *dsched_disk_enumerate(struct disk *dp, struct dsched_policy *policy);
129 void    dsched_cancel_bio(struct bio *bp);
130 void    dsched_strategy_raw(struct disk *dp, struct bio *bp);
131 void    dsched_strategy_sync(struct disk *dp, struct bio *bp);
132 void    dsched_strategy_async(struct disk *dp, struct bio *bp, biodone_t *done, void *priv);
133 int     dsched_debug(int level, char *fmt, ...) __printflike(2, 3);
134 dsched_new_buf_t        dsched_new_buf;
135 dsched_new_proc_t       dsched_new_proc;
136 dsched_new_thread_t     dsched_new_thread;
137 dsched_exit_buf_t       dsched_exit_buf;
138 dsched_exit_proc_t      dsched_exit_proc;
139 dsched_exit_thread_t    dsched_exit_thread;
140
141 #endif /* _KERNEL || _KERNEL_STRUCTURES */
142
143
144 #define DSCHED_NAME_LENGTH              64
145 #define DSCHED_SET_DEVICE_POLICY        _IOWR('d', 1, struct dsched_ioctl)
146 #define DSCHED_LIST_DISKS               _IOWR('d', 2, struct dsched_ioctl)
147 #define DSCHED_LIST_DISK                _IOWR('d', 3, struct dsched_ioctl)
148 #define DSCHED_LIST_POLICIES            _IOWR('d', 4, struct dsched_ioctl)
149
150 struct dsched_ioctl {
151         uint16_t        num_elem;
152         char            dev_name[DSCHED_NAME_LENGTH];
153         char            pol_name[DSCHED_NAME_LENGTH];
154 };
155
156 #endif /* _SYS_DSCHED_H_ */