cam_iosched.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef _CAM_CAM_IOSCHED_H
  32. #define _CAM_CAM_IOSCHED_H
  33. /* No user-serviceable parts in here. */
  34. #ifdef _KERNEL
  35. /* Forward declare all structs to keep interface thin */
  36. struct cam_iosched_softc;
  37. struct sysctl_ctx_list;
  38. struct sysctl_oid;
  39. union ccb;
  40. struct bio;
  41. /*
  42. * For 64-bit platforms, we know that uintptr_t is the same size as sbintime_t
  43. * so we can store values in it. For 32-bit systems, however, uintptr_t is only
  44. * 32-bits, so it won't fit. For those systems, store 24 bits of fraction and 8
  45. * bits of seconds. This allows us to measure an interval of up to ~256s, which
  46. * is ~200x what our current uses require. Provide some convenience functions to
  47. * get the time, subtract two times and convert back to sbintime_t in a safe way
  48. * that can be centralized.
  49. */
  50. #ifdef __LP64__
  51. #define CAM_IOSCHED_TIME_SHIFT 0
  52. #else
  53. #define CAM_IOSCHED_TIME_SHIFT 8
  54. #endif
  55. static inline uintptr_t
  56. cam_iosched_now(void)
  57. {
  58. /* Cast here is to avoid right shifting a signed value */
  59. return (uintptr_t)((uint64_t)sbinuptime() >> CAM_IOSCHED_TIME_SHIFT);
  60. }
  61. static inline uintptr_t
  62. cam_iosched_delta_t(uintptr_t then)
  63. {
  64. /* Since the types are identical, wrapping works correctly */
  65. return (cam_iosched_now() - then);
  66. }
  67. static inline sbintime_t
  68. cam_iosched_sbintime_t(uintptr_t delta)
  69. {
  70. /* Cast here is to widen the type so the left shift doesn't lose precision */
  71. return (sbintime_t)((uint64_t)delta << CAM_IOSCHED_TIME_SHIFT);
  72. }
  73. typedef void (*cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *);
  74. int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph);
  75. void cam_iosched_fini(struct cam_iosched_softc *);
  76. void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *);
  77. struct bio *cam_iosched_next_trim(struct cam_iosched_softc *isc);
  78. struct bio *cam_iosched_get_trim(struct cam_iosched_softc *isc);
  79. struct bio *cam_iosched_next_bio(struct cam_iosched_softc *isc);
  80. void cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp);
  81. void cam_iosched_flush(struct cam_iosched_softc *isc, struct devstat *stp, int err);
  82. void cam_iosched_schedule(struct cam_iosched_softc *isc, struct cam_periph *periph);
  83. void cam_iosched_finish_trim(struct cam_iosched_softc *isc);
  84. void cam_iosched_submit_trim(struct cam_iosched_softc *isc);
  85. void cam_iosched_put_back_trim(struct cam_iosched_softc *isc, struct bio *bp);
  86. void cam_iosched_set_sort_queue(struct cam_iosched_softc *isc, int val);
  87. int cam_iosched_has_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
  88. void cam_iosched_set_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
  89. void cam_iosched_clr_work_flags(struct cam_iosched_softc *isc, uint32_t flags);
  90. void cam_iosched_trim_done(struct cam_iosched_softc *isc);
  91. int cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp, union ccb *done_ccb);
  92. void cam_iosched_set_latfcn(struct cam_iosched_softc *isc, cam_iosched_latfcn_t, void *);
  93. void cam_iosched_set_trim_goal(struct cam_iosched_softc *isc, int goal);
  94. void cam_iosched_set_trim_ticks(struct cam_iosched_softc *isc, int ticks);
  95. #endif
  96. #endif