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

Function maybe_preempt

freebsd/kern/sched_4bsd.c:319–368  ·  view source on GitHub ↗

* This function is called when a thread is about to be put on run queue * because it has been made runnable or its priority has been adjusted. It * determines if the new thread should preempt the current thread. If so, * it sets td_owepreempt to request a preemption. */

Source from the content-addressed store, hash-verified

317 * it sets td_owepreempt to request a preemption.
318 */
319int
320maybe_preempt(struct thread *td)
321{
322#ifdef PREEMPTION
323 struct thread *ctd;
324 int cpri, pri;
325
326 /*
327 * The new thread should not preempt the current thread if any of the
328 * following conditions are true:
329 *
330 * - The kernel is in the throes of crashing (panicstr).
331 * - The current thread has a higher (numerically lower) or
332 * equivalent priority. Note that this prevents curthread from
333 * trying to preempt to itself.
334 * - The current thread has an inhibitor set or is in the process of
335 * exiting. In this case, the current thread is about to switch
336 * out anyways, so there's no point in preempting. If we did,
337 * the current thread would not be properly resumed as well, so
338 * just avoid that whole landmine.
339 * - If the new thread's priority is not a realtime priority and
340 * the current thread's priority is not an idle priority and
341 * FULL_PREEMPTION is disabled.
342 *
343 * If all of these conditions are false, but the current thread is in
344 * a nested critical section, then we have to defer the preemption
345 * until we exit the critical section. Otherwise, switch immediately
346 * to the new thread.
347 */
348 ctd = curthread;
349 THREAD_LOCK_ASSERT(td, MA_OWNED);
350 KASSERT((td->td_inhibitors == 0),
351 ("maybe_preempt: trying to run inhibited thread"));
352 pri = td->td_priority;
353 cpri = ctd->td_priority;
354 if (KERNEL_PANICKED() || pri >= cpri /* || dumping */ ||
355 TD_IS_INHIBITED(ctd))
356 return (0);
357#ifndef FULL_PREEMPTION
358 if (pri > PRI_MAX_ITHD && cpri < PRI_MIN_IDLE)
359 return (0);
360#endif
361
362 CTR0(KTR_PROC, "maybe_preempt: scheduling preemption");
363 ctd->td_owepreempt = 1;
364 return (1);
365#else
366 return (0);
367#endif
368}
369
370/*
371 * Constants for digital decay and forget:

Callers 2

sched_addFunction · 0.85
sched_4bsd.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected