#
e24a6552 |
| 29-Jul-2024 |
Mark Johnston <markj@FreeBSD.org> |
thread: Remove kernel stack swapping support, part 4
- Remove the IS_SWAPPED thread inhibitor state. - Remove all uses of TD_IS_SWAPPED() in the kernel. - Remove the TDF_CANSWAP flag. - Remove the P
thread: Remove kernel stack swapping support, part 4
- Remove the IS_SWAPPED thread inhibitor state. - Remove all uses of TD_IS_SWAPPED() in the kernel. - Remove the TDF_CANSWAP flag. - Remove the P_SWAPPINGOUT and P_SWAPPINGIN flags.
Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46115
show more ...
|
Revision tags: release/14.1.0, release/13.3.0 |
|
#
aeff15b3 |
| 09-Feb-2024 |
Olivier Certner <olce@FreeBSD.org> |
sched: Simplify sched_lend_user_prio_cond()
If 'td_lend_user_pri' has the expected value, there is no need to check the fields that sched_lend_user_prio() modifies, they either are already good or s
sched: Simplify sched_lend_user_prio_cond()
If 'td_lend_user_pri' has the expected value, there is no need to check the fields that sched_lend_user_prio() modifies, they either are already good or soon will be ('td->td_lend_user_pri' has just been changed by a concurrent update).
Reviewed by: kib Approved by: emaste (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D44050
show more ...
|
#
6a3c02bc |
| 16-Jan-2024 |
Olivier Certner <olce@FreeBSD.org> |
sched: sched_switch(): Factorize sleepqueue flags
Avoid duplicating common flags for the preempted and non-preempted cases, making it clear that they are the same without resorting to formatting.
N
sched: sched_switch(): Factorize sleepqueue flags
Avoid duplicating common flags for the preempted and non-preempted cases, making it clear that they are the same without resorting to formatting.
No functional change.
Approved by: markj (mentor) MFC after: 3 days Sponsored by: The FreeBSD Foundation
show more ...
|
#
0a713948 |
| 22-Nov-2023 |
Alexander Motin <mav@FreeBSD.org> |
Replace random sbuf_printf() with cheaper cat/putc.
|
Revision tags: release/14.0.0 |
|
#
685dc743 |
| 16-Aug-2023 |
Warner Losh <imp@FreeBSD.org> |
sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
|
#
4d846d26 |
| 10-May-2023 |
Warner Losh <imp@FreeBSD.org> |
spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of
spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause.
Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
show more ...
|
Revision tags: release/13.2.0 |
|
#
1029dab6 |
| 09-Feb-2023 |
Mitchell Horne <mhorne@FreeBSD.org> |
mi_switch(): clean up switch types and their usage
Overall, this is a non-functional change, except for kernels built with SCHED_STATS. However, the switch types are useful for communicating the int
mi_switch(): clean up switch types and their usage
Overall, this is a non-functional change, except for kernels built with SCHED_STATS. However, the switch types are useful for communicating the intent of the caller.
1. Ensure that every caller provides a type. In most cases, we upgrade the basic yield to sched_relinquish() aka SWT_RELINQUISH. 2. The case of sched_bind() is distinct, so add a new switch type SWT_BIND. 3. Remove the two unused types, SWT_PREEMPT and SWT_SLEEPQTIMO. 4. Remove SWT_NONE altogether and assert that callers always provide a type flag. 5. Reference the mi_switch(9) man page in the comments, as these flags will be documented there.
Reviewed by: kib, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38184
show more ...
|
Revision tags: release/12.4.0 |
|
#
c6d31b83 |
| 18-Jul-2022 |
Konstantin Belousov <kib@FreeBSD.org> |
AST: rework
Make most AST handlers dynamically registered. This allows to have subsystem-specific handler source located in the subsystem files, instead of making subr_trap.c aware of it. For inst
AST: rework
Make most AST handlers dynamically registered. This allows to have subsystem-specific handler source located in the subsystem files, instead of making subr_trap.c aware of it. For instance, signal delivery code on return to userspace is now moved to kern_sig.c.
Also, it allows to have some handlers designated as the cleanup (kclear) type, which are called both at AST and on thread/process exit. For instance, ast(), exit1(), and NFS server no longer need to be aware about UFS softdep processing.
The dynamic registration also allows third-party modules to register AST handlers if needed. There is one caveat with loadable modules: the code does not make any effort to ensure that the module is not unloaded before all threads processed through AST handler in it. In fact, this is already present behavior for hwpmc.ko and ufs.ko. I do not think it is worth the efforts and the runtime overhead to try to fix it.
Reviewed by: markj Tested by: emaste (arm64), pho Discussed with: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D35888
show more ...
|
#
bd980ca8 |
| 18-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Ensure we hold the thread lock when modifying td_flags
The load balancer may force a running thread to reschedule and pick a new CPU. To do this it sets some flags in the thread running
sched_ule: Ensure we hold the thread lock when modifying td_flags
The load balancer may force a running thread to reschedule and pick a new CPU. To do this it sets some flags in the thread running on a loaded CPU. But the code assumed that a running thread's lock is the same as that of the corresponding runqueue, and there are small windows where this is not true. In this case, we can end up with non-atomic modifications to td_flags.
Since this load balancing is best-effort, simply give up if the thread's lock doesn't match; in this case the thread is about to enter the scheduler anyway.
Reviewed by: kib Reported by: glebius Fixes: e745d729be60 ("sched_ule(4): Improve long-term load balancer.") MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35821
show more ...
|
#
6eeba7db |
| 16-Jul-2022 |
Mateusz Guzik <mjg@FreeBSD.org> |
ule: unbreak UP builds
Sponsored by: Rubicon Communications, LLC ("Netgate")
|
#
954cffe9 |
| 14-Jul-2022 |
John Baldwin <jhb@FreeBSD.org> |
ule: Simplistic time-sharing for interrupt threads.
If an interrupt thread runs for a full quantum without yielding the CPU, demote its priority and schedule a preemption to give other ithreads a tu
ule: Simplistic time-sharing for interrupt threads.
If an interrupt thread runs for a full quantum without yielding the CPU, demote its priority and schedule a preemption to give other ithreads a turn.
Reviewed by: kib, markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D35644
show more ...
|
#
fea89a28 |
| 14-Jul-2022 |
John Baldwin <jhb@FreeBSD.org> |
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
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
show more ...
|
#
6cbc4ceb |
| 14-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Use the correct atomic_load variant for tdq_lowpri
Reported by: tuexen Fixes: 11484ad8a2b0 ("sched_ule: Use explicit atomic accesses for tdq fields")
|
#
11484ad8 |
| 14-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Use explicit atomic accesses for tdq fields
Different fields in the tdq have different synchronization protocols. Some are constant, some are accessed only while holding the tdq lock, som
sched_ule: Use explicit atomic accesses for tdq fields
Different fields in the tdq have different synchronization protocols. Some are constant, some are accessed only while holding the tdq lock, some are modified with the lock held but accessed without the lock, some are accessed only on the tdq's CPU, and some are not synchronized by the lock at all.
Convert ULE to stop using volatile and instead use atomic_load_* and atomic_store_* to provide the desired semantics for lockless accesses. This makes the intent of the code more explicit, gives more freedom to the compiler when accesses do not need to be qualified, and lets KCSAN intercept unlocked accesses.
Thus: - Introduce macros to provide unlocked accessors for certain fields. - Use atomic_load/store for all accesses of tdq_cpu_idle, which is not synchronized by the mutex. - Use atomic_load/store for accesses of the switch count, which is updated by sched_clock(). - Add some comments to fields of struct tdq describing how accesses are synchronized.
No functional change intended.
Reviewed by: mav, kib MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35737
show more ...
|
#
0927ff78 |
| 14-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Enable preemption of curthread in the load balancer
The load balancer executes from statclock and periodically tries to move threads among CPUs in order to balance load. It may move a th
sched_ule: Enable preemption of curthread in the load balancer
The load balancer executes from statclock and periodically tries to move threads among CPUs in order to balance load. It may move a thread to the current CPU (the loader balancer always runs on CPU 0). When it does so, it may need to schedule preemption of the interrupted thread. Use sched_setpreempt() to do so, same as sched_add().
PR: 264867 Reviewed by: mav, kib, jhb MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35744
show more ...
|
#
6d3f74a1 |
| 14-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Fix racy loads of pc_curthread
Thread switching used to be atomic with respect to the current CPU's tdq lock. Since commit 686bcb5c14ab that is no longer the case. Now sched_switch() do
sched_ule: Fix racy loads of pc_curthread
Thread switching used to be atomic with respect to the current CPU's tdq lock. Since commit 686bcb5c14ab that is no longer the case. Now sched_switch() does this:
1. lock tdq (might already be locked) 2. maybe put the current thread in the tdq, choose a new thread to run 2a. update tdq_lowpri 3. unlock tdq 4. switch CPU context, update curthread
Some code paths in ULE will load pc_curthread from a remote CPU with that CPU's tdq lock held, usually to inspect its priority. But, as of the aforementioned commit this is racy.
The problem I noticed is in tdq_notify(), which optionally sends an IPI to a remote CPU when a new thread is added to its runqueue. If the new thread's priority is higher (lower) than the currently running thread's priority, then we deliver an IPI. But inspecting pc_curthread->td_priority doesn't work, since pc_curthread might be between steps 3 and 4 above. If pc_curthread's priority is higher than that of the newly added thread, but pc_curthread is switching to a lower-priority thread, then tdq_notify() might fail to deliever an IPI, leaving a high priority thread stuck on the runqueue for longer than it should. This can cause multi-millisecond stalls in interactive/ithread/realtime threads.
Fix this problem by modifying tdq_add() and tdq_move() to return the value of tdq_lowpri before the addition of the new thread. This ensures that tdq_notify() has the correct priority value to compare against.
The other two uses of pc_curthread are susceptible to the same race. To fix the one in sched_rem()->tdq_setlowpri() we need to have an exact value for curthread. Thus, introduce a new tdq_curthread field to the tdq which gets updated any time a new thread is selected to run on the CPU. Because this field is synchronized by the thread lock, its priority reflects the correct lowpri value for the tdq.
PR: 264867 Fixes: 686bcb5c14ab ("schedlock 4/4") Reviewed by: mav, kib, jhb MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35736
show more ...
|
#
ba71333f |
| 11-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Fix a typo in a comment
PR: 226107 MFC after: 1 week
|
#
ef80894c |
| 05-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Purge an obsolete comment
The referenced bitmask was removed in commit 62fa74d95a1.
MFC after: 1 week Sponsored by: The FreeBSD Foundation
|
#
35dd6d6c |
| 05-Jul-2022 |
Mark Johnston <markj@FreeBSD.org> |
sched_ule: Eliminate a superfluous local variable in tdq_move()
No functional change intended.
MFC after: 1 week Sponsored by: The FreeBSD Foundation
|
Revision tags: release/13.1.0 |
|
#
4aec1984 |
| 14-Apr-2022 |
John Baldwin <jhb@FreeBSD.org> |
sched_ule: Inline value of ts in sched_thread_priority.
This avoids a set but unused warning in kernels without SMP where TDQ_CPU() doesn't use its argument.
|
Revision tags: release/12.3.0 |
|
#
15b5c347 |
| 19-Nov-2021 |
Gordon Bergling <gbe@FreeBSD.org> |
sched_ule(4): Fix two typo in source code comments
- s/conditons/conditions/ - s/unconditonally/unconditionally/
MFC after: 3 days
|
#
6a8ea6d1 |
| 04-Nov-2021 |
Kyle Evans <kevans@FreeBSD.org> |
sched: split sched_ap_entry() out of sched_throw()
sched_throw() can no longer take a NULL thread, APs enter through sched_ap_entry() instead. This completely removes branching in the common case a
sched: split sched_ap_entry() out of sched_throw()
sched_throw() can no longer take a NULL thread, APs enter through sched_ap_entry() instead. This completely removes branching in the common case and cleans up both paths. No functional change intended.
Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D32829
show more ...
|
#
589aed00 |
| 02-Nov-2021 |
Kyle Evans <kevans@FreeBSD.org> |
sched: separate out schedinit_ap()
schedinit_ap() sets up an AP for a later call to sched_throw(NULL).
Currently, ULE sets up some pcpu bits and fixes the idlethread lock with a call to sched_throw
sched: separate out schedinit_ap()
schedinit_ap() sets up an AP for a later call to sched_throw(NULL).
Currently, ULE sets up some pcpu bits and fixes the idlethread lock with a call to sched_throw(NULL); this results in a window where curthread is setup in platforms' init_secondary(), but it has the wrong td_lock. Typical platform AP startup procedure looks something like:
- Setup curthread - ... other stuff, including cpu_initclocks_ap() - Signal smp_started - sched_throw(NULL) to enter the scheduler
cpu_initclocks_ap() may have callouts to process (e.g., nvme) and attempt to sched_add() for this AP, but this attempt fails because of the noted violated assumption leading to locking heartburn in sched_setpreempt().
Interrupts are still disabled until cpu_throw() so we're not really at risk of being preempted -- just let the scheduler in on it a little earlier as part of setting up curthread.
Reviewed by: alfredo, kib, markj Triage help from: andrew, markj Smoke-tested by: alfredo (ppc), kevans (arm64, x86), mhorne (arm) Differential Revision: https://reviews.freebsd.org/D32797
show more ...
|
#
1c119e17 |
| 02-Oct-2021 |
Alexander Motin <mav@FreeBSD.org> |
sched_ule(4): Fix possible significance loss.
Before this change kern.sched.interact sysctl setting above 32 gave all interactive threads identical priority of PRI_MIN_INTERACT due to ((PRI_MAX_INTE
sched_ule(4): Fix possible significance loss.
Before this change kern.sched.interact sysctl setting above 32 gave all interactive threads identical priority of PRI_MIN_INTERACT due to ((PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) / sched_interact) turning zero. Setting the sysctl lower reduced the range of used priority levels up to half, that is not great either.
Change of the operations order should fix the issue, always using full range of priorities, while overflow is impossible there since both score and priority values are small. While there, make the variables unsigned as they really are.
MFC after: 1 month
show more ...
|
#
08063e9f |
| 26-Sep-2021 |
Alexander Motin <mav@FreeBSD.org> |
sched_ule(4): Fix hang with steal_thresh < 2.
e745d729be60 caused infinite loop with interrupts disabled in load stealing code if steal_thresh set below 2. Such configuration should not generally b
sched_ule(4): Fix hang with steal_thresh < 2.
e745d729be60 caused infinite loop with interrupts disabled in load stealing code if steal_thresh set below 2. Such configuration should not generally be used, but appeared some people are using it to workaround some problems.
To fix the problem explicitly pass to sched_highest() minimum number of transferrable threads, supported by the caller, instead of guessing.
MFC after: 25 days
show more ...
|