git: fea89a2804ad - main - Add sched_ithread_prio to set the base priority of an interrupt thread.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 14 Jul 2022 20:15:34 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=fea89a2804ad89f5342268a8546a3f9b515b5e6c

commit fea89a2804ad89f5342268a8546a3f9b515b5e6c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-07-14 20:13:10 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-07-14 20:13:10 +0000

    Add sched_ithread_prio to set the base priority of an interrupt thread.
    
    Use it instead of sched_prio when setting the priority of an interrupt
    thread.
    
    Reviewed by:    kib, markj
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D35642
---
 sys/kern/kern_intr.c          |  2 +-
 sys/kern/kern_timeout.c       |  2 +-
 sys/kern/sched_4bsd.c         |  9 +++++++++
 sys/kern/sched_ule.c          | 12 ++++++++++++
 sys/kern/subr_busdma_bounce.c |  2 +-
 sys/sys/proc.h                |  1 +
 sys/sys/sched.h               |  1 +
 7 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c
index 3637b556af5d..693c5595ba31 100644
--- a/sys/kern/kern_intr.c
+++ b/sys/kern/kern_intr.c
@@ -205,7 +205,7 @@ ithread_update(struct intr_thread *ithd)
 	sched_clear_tdname(td);
 #endif
 	thread_lock(td);
-	sched_prio(td, pri);
+	sched_ithread_prio(td, pri);
 	thread_unlock(td);
 }
 
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 2f0705998158..621ea258f21c 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -391,7 +391,7 @@ start_softclock(void *dummy)
 		cc->cc_thread = td;
 		thread_lock(td);
 		sched_class(td, PRI_ITHD);
-		sched_prio(td, PI_SOFTCLOCK);
+		sched_ithread_prio(td, PI_SOFTCLOCK);
 		TD_SET_IWAIT(td);
 		thread_lock_set(td, (struct mtx *)&cc->cc_lock);
 		thread_unlock(td);
diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index 3715402854c7..779e1a7b4ef5 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -924,6 +924,15 @@ sched_prio(struct thread *td, u_char prio)
 		turnstile_adjust(td, oldprio);
 }
 
+void
+sched_ithread_prio(struct thread *td, u_char prio)
+{
+	THREAD_LOCK_ASSERT(td, MA_OWNED);
+	MPASS(td->td_pri_class == PRI_ITHD);
+	td->td_base_ithread_pri = prio;
+	sched_prio(td, prio);
+}
+
 void
 sched_user_prio(struct thread *td, u_char prio)
 {
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 14d6e689081d..c4eb46944b43 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -1962,6 +1962,18 @@ sched_prio(struct thread *td, u_char prio)
 		turnstile_adjust(td, oldprio);
 }
 
+/*
+ * Set the base interrupt thread priority.
+ */
+void
+sched_ithread_prio(struct thread *td, u_char prio)
+{
+	THREAD_LOCK_ASSERT(td, MA_OWNED);
+	MPASS(td->td_pri_class == PRI_ITHD);
+	td->td_base_ithread_pri = prio;
+	sched_prio(td, prio);
+}
+
 /*
  * Set the base user priority, does not effect current running priority.
  */
diff --git a/sys/kern/subr_busdma_bounce.c b/sys/kern/subr_busdma_bounce.c
index 81a8f1046485..d6c50d83bbe7 100644
--- a/sys/kern/subr_busdma_bounce.c
+++ b/sys/kern/subr_busdma_bounce.c
@@ -439,7 +439,7 @@ busdma_thread(void *dummy __unused)
 
 	thread_lock(curthread);
 	sched_class(curthread, PRI_ITHD);
-	sched_prio(curthread, PI_SWI(SWI_BUSDMA));
+	sched_ithread_prio(curthread, PI_SWI(SWI_BUSDMA));
 	thread_unlock(curthread);
 	for (;;) {
 		mtx_lock(&bounce_lock);
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 5521f8321e2b..bc2d90355b82 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -257,6 +257,7 @@ struct thread {
 #define	td_siglist	td_sigqueue.sq_signals
 	u_char		td_lend_user_pri; /* (t) Lend user pri. */
 	u_char		td_allocdomain;	/* (b) NUMA domain backing this struct thread. */
+	u_char		td_base_ithread_pri; /* (t) Base ithread pri */
 	struct kmsan_td	*td_kmsan;	/* (k) KMSAN state */
 
 /* Cleared during fork1() */
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
index a9598767e4cb..e0556d29f0db 100644
--- a/sys/sys/sched.h
+++ b/sys/sys/sched.h
@@ -95,6 +95,7 @@ void	sched_ap_entry(void);
 void	sched_exit_thread(struct thread *td, struct thread *child);
 u_int	sched_estcpu(struct thread *td);
 void	sched_fork_thread(struct thread *td, struct thread *child);
+void	sched_ithread_prio(struct thread *td, u_char prio);
 void	sched_lend_prio(struct thread *td, u_char prio);
 void	sched_lend_user_prio(struct thread *td, u_char pri);
 void	sched_lend_user_prio_cond(struct thread *td, u_char pri);