MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sched_thread_priority

Function sched_thread_priority

freebsd/kern/sched_ule.c:1748–1797  ·  view source on GitHub ↗

* Adjust the priority of a thread. Move it to the appropriate run-queue * if necessary. This is the back-end for several priority related * functions. */

Source from the content-addressed store, hash-verified

1746 * functions.
1747 */
1748static void
1749sched_thread_priority(struct thread *td, u_char prio)
1750{
1751 struct td_sched *ts;
1752 struct tdq *tdq;
1753 int oldpri;
1754
1755 KTR_POINT3(KTR_SCHED, "thread", sched_tdname(td), "prio",
1756 "prio:%d", td->td_priority, "new prio:%d", prio,
1757 KTR_ATTR_LINKED, sched_tdname(curthread));
1758 SDT_PROBE3(sched, , , change__pri, td, td->td_proc, prio);
1759 if (td != curthread && prio < td->td_priority) {
1760 KTR_POINT3(KTR_SCHED, "thread", sched_tdname(curthread),
1761 "lend prio", "prio:%d", td->td_priority, "new prio:%d",
1762 prio, KTR_ATTR_LINKED, sched_tdname(td));
1763 SDT_PROBE4(sched, , , lend__pri, td, td->td_proc, prio,
1764 curthread);
1765 }
1766 ts = td_get_sched(td);
1767 THREAD_LOCK_ASSERT(td, MA_OWNED);
1768 if (td->td_priority == prio)
1769 return;
1770 /*
1771 * If the priority has been elevated due to priority
1772 * propagation, we may have to move ourselves to a new
1773 * queue. This could be optimized to not re-add in some
1774 * cases.
1775 */
1776 if (TD_ON_RUNQ(td) && prio < td->td_priority) {
1777 sched_rem(td);
1778 td->td_priority = prio;
1779 sched_add(td, SRQ_BORROWING | SRQ_HOLDTD);
1780 return;
1781 }
1782 /*
1783 * If the thread is currently running we may have to adjust the lowpri
1784 * information so other cpus are aware of our current priority.
1785 */
1786 if (TD_IS_RUNNING(td)) {
1787 tdq = TDQ_CPU(ts->ts_cpu);
1788 oldpri = td->td_priority;
1789 td->td_priority = prio;
1790 if (prio < tdq->tdq_lowpri)
1791 tdq->tdq_lowpri = prio;
1792 else if (tdq->tdq_lowpri == oldpri)
1793 tdq_setlowpri(tdq, td);
1794 return;
1795 }
1796 td->td_priority = prio;
1797}
1798
1799/*
1800 * Update a thread's priority when it is lent another thread's

Callers 3

sched_lend_prioFunction · 0.85
sched_unlend_prioFunction · 0.85
sched_prioFunction · 0.85

Calls 5

td_get_schedFunction · 0.85
tdq_setlowpriFunction · 0.85
sched_tdnameFunction · 0.70
sched_remFunction · 0.70
sched_addFunction · 0.70

Tested by

no test coverage detected