FreeBSD kernel CAM code
cam_iosched.h
Go to the documentation of this file.
1/*-
2 * CAM IO Scheduler Interface
3 *
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 2015 Netflix, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * 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
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31
32#ifndef _CAM_CAM_IOSCHED_H
33#define _CAM_CAM_IOSCHED_H
34
35/* No user-serviceable parts in here. */
36#ifdef _KERNEL
37
38/* Forward declare all structs to keep interface thin */
40struct sysctl_ctx_list;
41struct sysctl_oid;
42union ccb;
43struct bio;
44
45/*
46 * For 64-bit platforms, we know that uintptr_t is the same size as sbintime_t
47 * so we can store values in it. For 32-bit systems, however, uintptr_t is only
48 * 32-bits, so it won't fit. For those systems, store 24 bits of fraction and 8
49 * bits of seconds. This allows us to measure an interval of up to ~256s, which
50 * is ~200x what our current uses require. Provide some convenience functions to
51 * get the time, subtract two times and convert back to sbintime_t in a safe way
52 * that can be centralized.
53 */
54#ifdef __LP64__
55#define CAM_IOSCHED_TIME_SHIFT 0
56#else
57#define CAM_IOSCHED_TIME_SHIFT 8
58#endif
59static inline uintptr_t
61{
62
63 /* Cast here is to avoid right shifting a signed value */
64 return (uintptr_t)((uint64_t)sbinuptime() >> CAM_IOSCHED_TIME_SHIFT);
65}
66
67static inline uintptr_t
68cam_iosched_delta_t(uintptr_t then)
69{
70
71 /* Since the types are identical, wrapping works correctly */
72 return (cam_iosched_now() - then);
73}
74
75static inline sbintime_t
76cam_iosched_sbintime_t(uintptr_t delta)
77{
78
79 /* Cast here is to widen the type so the left shift doesn't lose precision */
80 return (sbintime_t)((uint64_t)delta << CAM_IOSCHED_TIME_SHIFT);
81}
82
83typedef void (*cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *);
84
85int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph);
87void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *);
88struct bio *cam_iosched_next_trim(struct cam_iosched_softc *isc);
89struct bio *cam_iosched_get_trim(struct cam_iosched_softc *isc);
90struct bio *cam_iosched_next_bio(struct cam_iosched_softc *isc);
91void cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp);
92void cam_iosched_flush(struct cam_iosched_softc *isc, struct devstat *stp, int err);
93void cam_iosched_schedule(struct cam_iosched_softc *isc, struct cam_periph *periph);
96void cam_iosched_put_back_trim(struct cam_iosched_softc *isc, struct bio *bp);
97void cam_iosched_set_sort_queue(struct cam_iosched_softc *isc, int val);
98int cam_iosched_has_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
99void cam_iosched_set_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
100void cam_iosched_clr_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
102int cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp, union ccb *done_ccb);
104void cam_iosched_set_trim_goal(struct cam_iosched_softc *isc, int goal);
105void cam_iosched_set_trim_ticks(struct cam_iosched_softc *isc, int ticks);
106#endif
107#endif
struct bio * cam_iosched_next_trim(struct cam_iosched_softc *isc)
Definition: cam_iosched.c:1414
void cam_iosched_clr_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
Definition: cam_iosched.c:1780
void cam_iosched_set_latfcn(struct cam_iosched_softc *isc, cam_iosched_latfcn_t, void *)
Definition: cam_iosched.c:1263
static uintptr_t cam_iosched_delta_t(uintptr_t then)
Definition: cam_iosched.h:68
void cam_iosched_finish_trim(struct cam_iosched_softc *isc)
void cam_iosched_set_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
Definition: cam_iosched.c:1774
void cam_iosched_flush(struct cam_iosched_softc *isc, struct devstat *stp, int err)
Definition: cam_iosched.c:1313
void cam_iosched_set_trim_goal(struct cam_iosched_softc *isc, int goal)
Definition: cam_iosched.c:1294
struct bio * cam_iosched_get_trim(struct cam_iosched_softc *isc)
Definition: cam_iosched.c:1440
int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph)
Definition: cam_iosched.c:1136
void cam_iosched_trim_done(struct cam_iosched_softc *isc)
Definition: cam_iosched.c:1682
void cam_iosched_put_back_trim(struct cam_iosched_softc *isc, struct bio *bp)
Definition: cam_iosched.c:1393
int cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp, union ccb *done_ccb)
Definition: cam_iosched.c:1693
void cam_iosched_set_trim_ticks(struct cam_iosched_softc *isc, int ticks)
Definition: cam_iosched.c:1301
static uintptr_t cam_iosched_now(void)
Definition: cam_iosched.h:60
void cam_iosched_fini(struct cam_iosched_softc *)
Definition: cam_iosched.c:1176
void cam_iosched_schedule(struct cam_iosched_softc *isc, struct cam_periph *periph)
Definition: cam_iosched.c:1671
void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *)
Definition: cam_iosched.c:1201
void cam_iosched_set_sort_queue(struct cam_iosched_softc *isc, int val)
Definition: cam_iosched.c:1761
void cam_iosched_submit_trim(struct cam_iosched_softc *isc)
Definition: cam_iosched.c:1751
struct bio * cam_iosched_next_bio(struct cam_iosched_softc *isc)
Definition: cam_iosched.c:1505
int cam_iosched_has_work_flags(struct cam_iosched_softc *isc, uint32_t flags)
Definition: cam_iosched.c:1768
static sbintime_t cam_iosched_sbintime_t(uintptr_t delta)
Definition: cam_iosched.h:76
void cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp)
Definition: cam_iosched.c:1574
void(* cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *)
Definition: cam_iosched.h:83
#define CAM_IOSCHED_TIME_SHIFT
Definition: cam_iosched.h:57
Definition: cam_ccb.h:1345