-#define BASEPRI_RTQUEUES (BASEPRI_REALTIME + 1) /* 97 */
-#define BASEPRI_REALTIME (MAXPRI - (NRQS / 4) + 1) /* 96 */
-
-#define MAXPRI_KERNEL (BASEPRI_REALTIME - 1) /* 95 */
-#define BASEPRI_PREEMPT (MAXPRI_KERNEL - 2) /* 93 */
-#define BASEPRI_KERNEL (MINPRI_KERNEL + 1) /* 81 */
-#define MINPRI_KERNEL (MAXPRI_KERNEL - (NRQS / 8) + 1) /* 80 */
-
-#define MAXPRI_RESERVED (MINPRI_KERNEL - 1) /* 79 */
-#define MINPRI_RESERVED (MAXPRI_RESERVED - (NRQS / 8) + 1) /* 64 */
-
-#define MAXPRI_USER (MINPRI_RESERVED - 1) /* 63 */
-#define BASEPRI_CONTROL (BASEPRI_DEFAULT + 17) /* 48 */
-#define BASEPRI_FOREGROUND (BASEPRI_DEFAULT + 16) /* 47 */
-#define BASEPRI_BACKGROUND (BASEPRI_DEFAULT + 15) /* 46 */
-#define BASEPRI_DEFAULT (MAXPRI_USER - (NRQS / 4)) /* 31 */
-#define MAXPRI_THROTTLE (MINPRI + 4) /* 4 */
-#define MINPRI_USER MINPRI /* 0 */
-
-#ifdef CONFIG_EMBEDDED
-#define DEPRESSPRI MAXPRI_THROTTLE
-#else
-#define DEPRESSPRI MINPRI /* depress priority */
-#endif
+#define BASEPRI_RTQUEUES (BASEPRI_REALTIME + 1) /* 97 */
+#define BASEPRI_REALTIME (MAXPRI - (NRQS_MAX / 4) + 1) /* 96 */
+
+#define MAXPRI_KERNEL (BASEPRI_REALTIME - 1) /* 95 */
+#define BASEPRI_PREEMPT_HIGH (BASEPRI_PREEMPT + 1) /* 93 */
+#define BASEPRI_PREEMPT (MAXPRI_KERNEL - 3) /* 92 */
+#define BASEPRI_VM (BASEPRI_PREEMPT - 1) /* 91 */
+
+#define BASEPRI_KERNEL (MINPRI_KERNEL + 1) /* 81 */
+#define MINPRI_KERNEL (MAXPRI_KERNEL - (NRQS_MAX / 8) + 1) /* 80 */
+
+#define MAXPRI_RESERVED (MINPRI_KERNEL - 1) /* 79 */
+#define BASEPRI_GRAPHICS (MAXPRI_RESERVED - 3) /* 76 */
+#define MINPRI_RESERVED (MAXPRI_RESERVED - (NRQS_MAX / 8) + 1) /* 64 */
+
+#define MAXPRI_USER (MINPRI_RESERVED - 1) /* 63 */
+#define BASEPRI_CONTROL (BASEPRI_DEFAULT + 17) /* 48 */
+#define BASEPRI_FOREGROUND (BASEPRI_DEFAULT + 16) /* 47 */
+#define BASEPRI_BACKGROUND (BASEPRI_DEFAULT + 15) /* 46 */
+#define BASEPRI_USER_INITIATED (BASEPRI_DEFAULT + 6) /* 37 */
+#define BASEPRI_DEFAULT (MAXPRI_USER - (NRQS_MAX / 4)) /* 31 */
+#define MAXPRI_SUPPRESSED (BASEPRI_DEFAULT - 3) /* 28 */
+#define BASEPRI_UTILITY (BASEPRI_DEFAULT - 11) /* 20 */
+#define MAXPRI_THROTTLE (MINPRI + 4) /* 4 */
+#define MINPRI_USER MINPRI /* 0 */
+
+#define DEPRESSPRI (MINPRI) /* depress priority */
+
+#define MAXPRI_PROMOTE (MAXPRI_KERNEL) /* ceiling for mutex promotion */
+#define MINPRI_RWLOCK (BASEPRI_BACKGROUND) /* floor when holding rwlock count */
+#define MINPRI_EXEC (BASEPRI_DEFAULT) /* floor when in exec state */
+#define MINPRI_WAITQ (BASEPRI_DEFAULT) /* floor when in waitq handover state */
+
+#define NRQS (BASEPRI_REALTIME) /* Non-realtime levels for runqs */
+
+/* Ensure that NRQS is large enough to represent all non-realtime threads; even promoted ones */
+_Static_assert((NRQS == (MAXPRI_PROMOTE + 1)), "Runqueues are too small to hold all non-realtime threads");
+
+/* Type used for thread->sched_mode and saved_mode */
+typedef enum {
+ TH_MODE_NONE = 0, /* unassigned, usually for saved_mode only */
+ TH_MODE_REALTIME, /* time constraints supplied */
+ TH_MODE_FIXED, /* use fixed priorities, no decay */
+ TH_MODE_TIMESHARE, /* use timesharing algorithm */
+} sched_mode_t;
+
+/*
+ * Since the clutch scheduler organizes threads based on the thread group
+ * and the scheduling bucket, its important to not mix threads from multiple
+ * priority bands into the same bucket. To achieve that, in the clutch bucket
+ * world, there is a scheduling bucket per QoS effectively.
+ */
+
+/* Buckets used for load calculation */
+typedef enum {
+ TH_BUCKET_FIXPRI = 0, /* Fixed-priority */
+ TH_BUCKET_SHARE_FG, /* Timeshare thread above BASEPRI_DEFAULT */
+#if CONFIG_SCHED_CLUTCH
+ TH_BUCKET_SHARE_IN, /* Timeshare thread between BASEPRI_USER_INITIATED and BASEPRI_DEFAULT */
+#endif /* CONFIG_SCHED_CLUTCH */
+ TH_BUCKET_SHARE_DF, /* Timeshare thread between BASEPRI_DEFAULT and BASEPRI_UTILITY */
+ TH_BUCKET_SHARE_UT, /* Timeshare thread between BASEPRI_UTILITY and MAXPRI_THROTTLE */
+ TH_BUCKET_SHARE_BG, /* Timeshare thread between MAXPRI_THROTTLE and MINPRI */
+ TH_BUCKET_RUN, /* All runnable threads */
+ TH_BUCKET_SCHED_MAX = TH_BUCKET_RUN, /* Maximum schedulable buckets */
+ TH_BUCKET_MAX,
+} sched_bucket_t;