[tests] lib/libc/gen:assert_test: undefine `NDEBUG`
In the event `NDEBUG` was defined, `assert` would become a no-op,
breaking some of the expectations in `assert_test` around `assert(..)`
failing generating a coredump.
This is a better approach than the previous one committed in 6f3445006a
as it continues to test the `assert(..)` function instead of just
skipping it if `NDEBUG` was defined.
Suggested by: kevans
MFC after: 4 days
MFC with: 6f3445006a
Fixes: 6f3445006a
Differential Revision: https://reviews.freebsd.org/D60253
libc/stdlib/getenv.c: always allocate new environment
in particular, if the old environment is NULL.
Among making it less surprising for userspace to observe NULL environ,
the change also prevents NULL deref in __rebuild_environ() when
terminating the empty as NULL environment with the NULL pointer.
Reported by: Leo Bicknell <bicknell at ufp.org>
PR: 298747
Reviewed by: emaste, markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D59996
route/fib_algo: Fix nexthop index collision across families
fib_algo indexes its idx->nhop array by the nexthop index with
assumption of its uniqueness. Which is true except for IPv4 over
IPv6 nexthops.
Give each index space its own segment within the same array and
offset the index by the segment base. Segments are created on demand
and sized independently, so the rib's own family keeps base 0 and
tables without cross-family nexthops index exactly as before.
Reviewed by: melifaro
Discussed with: markj
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D59552
(cherry picked from commit 63343822430453f4add20bcbfa134c99132361df)
pf: do not leak a source hash row lock in the netlink dump
pf_handle_get_srcnodes() returns with the lock of a source hash row
held when it cannot start the message for a source node. Unlock the
row there, as the other error exit of the loop does.
Reviewed by: kp
Approved by: kp (mentor)
Fixes: 9c125336727b ("pf: convert DIOCGETSRCNODES to netlink")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60251
sched_ule: fix invalid tdq_slice() and sched_slice_min
sched_slice_min should always to be greater than zero. When modifying
sched_slice through sysctl, if the new value is less than
SCHED_SLICE_MIN_DIVISOR, sched_slice_min is computed to zero. Add
imax(1, ...) to prevent this.
tdq_slice() should not return a value less than sched_slice_min since
that will cause integer underflow of ts2->ts_slice in
sched_ule_fork_thread. SCHED_SLICE_MIN_DIVISOR is currently set to 6 so
when load is 5 and sched_slice is 4, the two if conditions in
tdq_slice() will pass and the function will return zero. Thus use imax()
so tdq_slice returns sched_slice_min at minimum.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59408
[2 lines not shown]
sched_ule: fix comment on ts_slice
In ULE ts_slice stores the number of ticks of slice passed not
remaining.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59407
(cherry picked from commit 872074c50e99ab8858c2defe255d716f8f75f15b)
sched_4bsd: fix vague comment
The comment "was incremented in schedcpu()" doesn't give enough
background for decrementing ts_slptime by 1 (thus ignoring decay_cpu()
for 1 ts_slptime). More accurately, ts_slptime is decremented by 1
because decay_cpu() has already executed once in schedcpu() when
ts_slptime was 1.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59406
(cherry picked from commit cd33abbce5a5c3b454f00ca3d0ecd71c2234106c)
sched_4bsd: fix comment in maybe_preempt()
The comment says the new thread's priority is not a realtime priority
while the code states pri > PRI_MAX_ITHD which is interrupt priorities
not realtime.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59402
(cherry picked from commit 351f6733180cebdc83585f9a00677f4998f6c6f1)
sched_4bsd: remove obsolete comment
In old Unix, the whole process address space including scheduler-related
data was paged out to disk. We now allocate thread-related data with UMA
on wired memory which never page out. Thus this comment is now obsolete.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59398
(cherry picked from commit 46416a57eb7b6d74fda13cc6e40a43bdfa6b7da9)
sched_ule: remove unused KTR_ULE
Commit 62fa74d95a16 ("Add support for the new cpu...") removed all uses
of KTR_ULE, leaving the macro unused.
Reviewed by: olce
Approved by: olce (mentor)
Fixes: 62fa74d95a16 ("Add support for the new cpu...")
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59399
(cherry picked from commit 7997d2a18150a449b563c87490e8d440bb1023f3)
sched_4bsd: remove dumping from maybe_preempt()
'dumping' is true only when kernel is dumping after crash (see
minidumpsys()) so KERNEL_PANICKED() will catch this.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59395
(cherry picked from commit 1dfefffcbdc652ee88a3baa284182f96e20faf17)
sched_4bsd: update function name in comment
In b43179fbe815 ("Create a new scheduler api..."), schedclock() was
renamed to sched_clock() but the function name in the comment remained
still. Update the comment to reflect up-to-date name for schedclock().
Reviewed by: olce
Approved by: olce (mentor)
Fixes: b43179fbe815 ("Create a new scheduler api...")
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59397
(cherry picked from commit 5d67118d2c7388bdc065e640719553ff4d9eea89)
sched_4bsd: add static assertion for nice weight
When NICE_WEIGHT * (PRIO_MAX - PRIO_MIN) exceeds the timeshare range,
two CPU-bound threads with different nice values can have the same
priority as their nice values are clamped to the timeshare range limit.
Add static assertion on NICE_WEIGHT to ensure that there is always
enough room for nice values in the both end of the timeshare priority
range.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59396
(cherry picked from commit e90be6fdf08526624f407923d003b66efa23d304)
sched_4bsd: remove kern.sched.4bsd.followon
kern.sched.4bsd.followon was enabled only for KSE. It was never compiled
since ad1e7d285ab1 and KSE was removed years ago. Now it's time to
remove this tunable.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59394
(cherry picked from commit d29c9f5aca3463e3c7f2fa2263795a78c6430d2d)
sched: rename sched_schedcpu() to sched_sysinit()
sched_schedcpu() is called only during SYSINIT to start kthread that
calls schedcpu() every second in 4BSD, but its name implies it's doing
what 4BSD's schedcpu() does. Rename this function to sched_sysinit() to
mark that schedulers can use it for its own SYSINIT routine. Note that
their SYSINIT routine does not necessarily need to be similar to 4BSD's
decay in schedcpu().
The scheduler.9 man page is planned to be rewritten from scratch, so no
change to it for now.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59437
(cherry picked from commit 962125aef24b55b4bb8808dcab335abc4b3f0d4e)
sched_ule: fix invalid tdq_slice() and sched_slice_min
sched_slice_min should always to be greater than zero. When modifying
sched_slice through sysctl, if the new value is less than
SCHED_SLICE_MIN_DIVISOR, sched_slice_min is computed to zero. Add
imax(1, ...) to prevent this.
tdq_slice() should not return a value less than sched_slice_min since
that will cause integer underflow of ts2->ts_slice in
sched_ule_fork_thread. SCHED_SLICE_MIN_DIVISOR is currently set to 6 so
when load is 5 and sched_slice is 4, the two if conditions in
tdq_slice() will pass and the function will return zero. Thus use imax()
so tdq_slice returns sched_slice_min at minimum.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59408
[2 lines not shown]
sched_4bsd: fix comment in maybe_preempt()
The comment says the new thread's priority is not a realtime priority
while the code states pri > PRI_MAX_ITHD which is interrupt priorities
not realtime.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59402
(cherry picked from commit 351f6733180cebdc83585f9a00677f4998f6c6f1)
sched_ule: fix comment on ts_slice
In ULE ts_slice stores the number of ticks of slice passed not
remaining.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59407
(cherry picked from commit 872074c50e99ab8858c2defe255d716f8f75f15b)
sched_4bsd: fix vague comment
The comment "was incremented in schedcpu()" doesn't give enough
background for decrementing ts_slptime by 1 (thus ignoring decay_cpu()
for 1 ts_slptime). More accurately, ts_slptime is decremented by 1
because decay_cpu() has already executed once in schedcpu() when
ts_slptime was 1.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59406
(cherry picked from commit cd33abbce5a5c3b454f00ca3d0ecd71c2234106c)
sched_4bsd: remove obsolete comment
In old Unix, the whole process address space including scheduler-related
data was paged out to disk. We now allocate thread-related data with UMA
on wired memory which never page out. Thus this comment is now obsolete.
Reviewed by: olce
Approved by: olce (mentor)
MFC after: 2 weeks
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59398
(cherry picked from commit 46416a57eb7b6d74fda13cc6e40a43bdfa6b7da9)