freebsd with flexible iflib nic queues
Go to file
Mark Johnston 6d3f74a14a 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 686bcb5c14 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:		686bcb5c14 ("schedlock 4/4")
Reviewed by:	mav, kib, jhb
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35736
2022-07-14 10:27:51 -04:00
.cirrus-ci Cirrus-CI: add some timing info on pkg install failure 2021-08-04 15:02:00 -04:00
.github .github: Attempt to fix and increase robustness of macOS action 2022-06-30 21:03:26 +01:00
bin date: attempt to more accurately describe year limitations with -v 2022-06-27 22:54:13 -05:00
cddl zfs: merge openzfs/zfs@cb01da680 2022-07-08 00:02:36 +02:00
contrib unbound: Vendor import 1.16.1 2022-07-13 12:30:14 -07:00
crypto OpenSSL: Merge OpenSSL 1.1.1q 2022-07-05 11:47:01 -04:00
etc Enable -Wwrite-strings 2022-06-29 14:08:54 -07:00
gnu libdialog: Bump shared library version to 10. 2021-10-27 09:30:24 -07:00
include Import OpenSSL 1.1.1q 2022-07-05 11:27:51 -04:00
kerberos5 pkgbase: Create a FreeBSD-kerberos package 2021-09-07 10:23:14 +02:00
lib msun: Rewrite function definitions with identifier lists 2022-07-12 13:17:47 +08:00
libexec rtld-elf: Fix leaks and wild frees in origin_subst 2022-07-12 17:47:47 +01:00
release release: increase IMAGE_SIZE for arm, arm64, riscv 2022-07-13 14:36:22 -04:00
rescue Fix conflict between libnvpair and libnv when building rescue binaries. 2022-05-24 23:59:33 +03:00
sbin ifconfig.8: cleanup reminiscence about long gone ppp(4) 2022-07-11 11:53:54 +07:00
secure OpenSSL: Regen manual pages for OpenSSL 1.1.1q 2022-07-05 12:01:07 -04:00
share inet.4 tcp.4 udp.4: Replace *CTL_* OID macro names with sysctl names 2022-07-14 08:50:13 -05:00
stand loader.efi: faults could try to print out call trace 2022-07-14 15:59:26 +03:00
sys sched_ule: Fix racy loads of pc_curthread 2022-07-14 10:27:51 -04:00
targets bintrans: move files to a new directory 2022-04-18 10:53:11 +02:00
tests pf tests: support packet size range in pft_ether.py 2022-07-11 19:55:26 +02:00
tools git-arc: Fix the -y option 2022-07-13 09:30:17 -04:00
usr.bin Improve usability of head(1) and tail(1): 2022-07-12 21:14:25 -07:00
usr.sbin certctl: Introduce a new -d <distbase> option 2022-07-14 01:23:42 +01:00
.arcconfig Remove history.immutable from .arcconfig 2021-04-13 12:36:25 +01:00
.arclint
.cirrus.yml Cirrus-CI: update image to FreeBSD 13.1 (latest release) 2022-06-02 15:25:36 -04:00
.clang-format clang-format: Add bitset loop macros 2021-09-21 12:08:01 -04:00
.gitattributes Add a basic clang-format configuration file 2019-06-07 15:23:52 +00:00
.gitignore gitignore: Ignore compile_commands.events.json 2022-05-30 10:43:25 -04:00
COPYRIGHT Welcome 2022, update copyrights. 2022-01-01 09:49:49 -07:00
LOCKS
MAINTAINERS Remove myself from bhyve maintenance; ENOTIME. 2021-11-19 07:09:30 +10:00
Makefile Switch to GCC 9 for the GCC tinderbox. 2022-05-20 10:16:57 -07:00
Makefile.inc1 Makefile.inc1: Fix -DNO_ROOT distributeworld certctl usage 2022-07-14 01:25:50 +01:00
Makefile.libcompat libcompat: Use WORLDTMP sysroot 2022-07-01 08:33:16 +01:00
Makefile.sys.inc
ObsoleteFiles.inc ObsoleteFiles: flowtable header deleted in 2017 2022-06-27 12:31:36 -07:00
README.md README.md: update gnu directory description 2021-12-17 08:45:31 -05:00
RELNOTES RELNOTES: Add an entry for boottrace(4) 2022-03-29 13:35:14 +02:00
UPDATING LinuxKPI: move pm_message_t from kernel.h to pm.h 2022-06-10 14:05:12 +00:00

FreeBSD Source:

This is the top level of the FreeBSD source directory.

FreeBSD is an operating system used to power modern servers, desktops, and embedded platforms. A large community has continually developed it for more than thirty years. Its advanced networking, security, and storage features have made FreeBSD the platform of choice for many of the busiest web sites and most pervasive embedded networking and storage devices.

For copyright information, please see the file COPYRIGHT in this directory. Additional copyright information also exists for some sources in this tree - please see the specific source directories for more information.

The Makefile in this directory supports a number of targets for building components (or all) of the FreeBSD source tree. See build(7), config(8), FreeBSD handbook on building userland, and Handbook for kernels for more information, including setting make(1) variables.

Source Roadmap:

Directory Description
bin System/user commands.
cddl Various commands and libraries under the Common Development and Distribution License.
contrib Packages contributed by 3rd parties.
crypto Cryptography stuff (see crypto/README).
etc Template files for /etc.
gnu Commands and libraries under the GNU General Public License (GPL) or Lesser General Public License (LGPL). Please see gnu/COPYING and gnu/COPYING.LIB for more information.
include System include files.
kerberos5 Kerberos5 (Heimdal) package.
lib System libraries.
libexec System daemons.
release Release building Makefile & associated tools.
rescue Build system for statically linked /rescue utilities.
sbin System commands.
secure Cryptographic libraries and commands.
share Shared resources.
stand Boot loader sources.
sys Kernel sources.
sys/arch/conf Kernel configuration files. GENERIC is the configuration used in release builds. NOTES contains documentation of all possible entries.
tests Regression tests which can be run by Kyua. See tests/README for additional information.
tools Utilities for regression testing and miscellaneous tasks.
usr.bin User commands.
usr.sbin System administration commands.

For information on synchronizing your source tree with one or more of the FreeBSD Project's development branches, please see FreeBSD Handbook.