dschedctl: G/C some unneeded headers
[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);
aa166ad1 90typedef void dsched_exit_buf_t(struct buf *bp);
b80a9543
AH
91typedef void dsched_exit_proc_t(struct proc *p);
92typedef void dsched_exit_thread_t(struct thread *td);
93
0160356d
AH
94
95struct 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;
b80a9543
AH
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;
aa166ad1 111 dsched_exit_buf_t *exit_buf;
b80a9543
AH
112 dsched_exit_proc_t *exit_proc;
113 dsched_exit_thread_t *exit_thread;
114};
115
b80a9543
AH
116TAILQ_HEAD(dsched_policy_head, dsched_policy);
117
0160356d
AH
118void dsched_disk_create_callback(struct disk *dp, const char *head_name, int unit);
119void dsched_disk_destroy_callback(struct disk *dp);
b80a9543 120void dsched_queue(struct disk *dp, struct bio *bio);
0160356d
AH
121int dsched_register(struct dsched_policy *d_policy);
122int dsched_unregister(struct dsched_policy *d_policy);
123int dsched_switch(struct disk *dp, struct dsched_policy *new_policy);
124void dsched_set_policy(struct disk *dp, struct dsched_policy *new_policy);
b80a9543
AH
125struct dsched_policy *dsched_find_policy(char *search);
126struct disk *dsched_find_disk(char *search);
127struct dsched_policy *dsched_policy_enumerate(struct dsched_policy *pol);
0160356d 128struct disk *dsched_disk_enumerate(struct disk *dp, struct dsched_policy *policy);
b80a9543
AH
129void dsched_cancel_bio(struct bio *bp);
130void dsched_strategy_raw(struct disk *dp, struct bio *bp);
131void dsched_strategy_sync(struct disk *dp, struct bio *bp);
132void dsched_strategy_async(struct disk *dp, struct bio *bp, biodone_t *done, void *priv);
fcefa6f2 133int dsched_debug(int level, char *fmt, ...) __printflike(2, 3);
b80a9543
AH
134dsched_new_buf_t dsched_new_buf;
135dsched_new_proc_t dsched_new_proc;
136dsched_new_thread_t dsched_new_thread;
aa166ad1 137dsched_exit_buf_t dsched_exit_buf;
b80a9543
AH
138dsched_exit_proc_t dsched_exit_proc;
139dsched_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
150struct 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_ */