Commit Graph
100 Commits
Author SHA1 Message Date
Augustin Cavalier 2168280fac Storage Kit: Streamline CharStream and make it use BString. 2026-04-07 17:57:19 -04:00
Augustin Cavalier 104eaabf01 Storage Kit: Move most MIME sniffer headers into src/.
There's no reason to keep these in the private headers directory
that I can see.
2026-04-07 17:57:19 -04:00
Augustin Cavalier 645c71a9a9 Devices: Fix typo. 2026-04-07 13:57:58 -04:00
Augustin Cavalier bc501624e2 configure: HDS now needs Python 3.10+.
3.9 is end-of-life as of 2025/10 anyway.
2026-04-07 13:51:33 -04:00
Augustin Cavalier 248735d5a2 kernel/vm: Split the page writer into its own file and queue subclass.
This paves the way for there being more than one modified queue,
e.g. for each KDiskDevice.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 62b8be7e22 kernel/vm: DaemonCondition is really just a basic binary semaphore.
So split it off into its own file. This will make it easier to
split the page writer off into a separate file.
2026-04-06 22:23:26 -04:00
Augustin Cavalier f091a24ee2 AreaKeeper: Move to kernel/util.
This seems more consistent with how the directories are laid out.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 2448a77520 kernel/vm: Move a number of init-related methods to a new vm_init.cpp.
This gets around 450 lines of code out of vm.cpp.

No behavioral change intended.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 6e55e6942f pthread: PTHREAD_RECURSIVE_MUTEX_INITIALIZER is non-POSIX.
So add the _NP suffix like glibc does.

Pointed out by sortie.
2026-03-30 20:44:36 -04:00
Augustin Cavalier cc9cae1908 BString: memrchr is nonstandard and not available on macOS.
We use BString in the build platform, so we need it to work
everywhere. Add a fallback for non-Haiku targets (though glibc and
others do have memrchr and so could keep this, if we added some
more logic here.)
2026-03-30 19:21:33 -04:00
Augustin Cavalier d6c0df2394 kernel/guarded_heap: allocate_meta may fail with certain flags set.
May fix #20014.
2026-03-30 18:33:23 -04:00
Augustin Cavalier 75b91674e9 BString: Use memchr and memrchr to optimize two Find routines.
All BString tests are still passing.
2026-03-30 18:30:32 -04:00
Augustin Cavalier 53b69c0037 driver_settings: Use strchrnul to skip comments.
More optimized than just the simple loop.
2026-03-30 18:21:49 -04:00
Augustin Cavalier 40205ec46a kernel/cache: Add test for #18390 and related issues.
Change-Id: I873df21c54d4df4ea85904eabd186a36e55e13d9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10629
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 28e6329e8e kernel/vm: Add assert to VMCache::MarkPageUnbusy.
Change-Id: Iec29bdfa5f0a25d9f255c6eee1937bc7c9cc4c3a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10628
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 5554f0b829 kernel/vm: Fix a TODO about page I/O leaving pages in ACCESS state.
It turns out PAGE_ACCESS assertions could be tripped in other cases,
e.g. when resizing a cache while pages were being read in. So,
properly unset ACCESS (and just leave 'busy' set) in the places
where pages are read in, and re-enable the check.

Change-Id: I22ac5c8cb432c87613bb85e82703a0c1aeb55d86
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10627
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 05772630b8 kernel/file_cache: Recheck size in the do_cache_io loop.
Since we unlock the cache at various points in this loop,
we need to periodically recheck the size here, as otherwise
we might try to insert pages past the end.

This amends 4f8eaff87f. Re-tested
using the case described in that commit.

Change-Id: Id65e309f986a9b7f3e701d2b99c4f318a4eefbd3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10626
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier b37e0a513d kernel/vm: Clear busy_io along with the other page flags.
Change-Id: I796e6d01678e46eda9815c1c290b56975b6dbdfe
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10625
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 5eaf967479 kernel/cache: Use vm_page::busy_io in the file_cache.
This allows the VMCache to remove these pages pending the I/O
completion.

Combined with the following commits, confirmed to fix #18390.

Change-Id: I9630a00d70a9d6ac5b36e6de70475a6032390806
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10591
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 2b9d1bb9c2 kernel/vm: Rename vm_page::busy_writing to busy_io.
This way, it's clear that it can be used for more than just writing.

Change-Id: Ifd0928f0e8ec7b5eeb312795ceaae6e3fd266257
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10590
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier dcf4948bff kernel/vm: Add better handling for busy-writing pages on cache resizes.
Previously, busy-writing pages just stayed in the cache until
I/O finished. This wasn't right, as they should've been unmapped
(and removed) immediately, as a TODO in the PageWriteWrapper noted.

Now they are, and they're moved into a queue on the cache pending
the I/O completing.

This paves the way for fixing #18390.

Change-Id: I51778ba1cfc1d26f34dd44f1ee293381be59937f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8627
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 15594f62fe DoublyLinkedList: Make DoublyLinkedListCLink more useful.
Before, it just used a hardcoded Element::link member. Now,
it uses whatever one is specified based on the template
arguments.

No source compatibility breakage intended.

Change-Id: I62128921766df0b705488eb64402f902334f2ed0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10589
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier d22a7a3355 kernel/debug: Allow quotations to pass through early safemode settings.
The guarded heap override logic wants to see them at least.

Change-Id: I89c5c7a7b03e52f4bc42d71cba66775c213256e9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10597
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 18:23:31 +00:00
Augustin Cavalier 2b3a46cc1b kernel/debug: Use strchrnul and memchr in parsing.
Slight efficiency improvement, and simplifies the code a bit too.

Change-Id: I502409a9aee260c3d0ad1c9003567e46c03b241b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10596
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 18:23:31 +00:00
Augustin Cavalier e6d9dc2731 kqueue: Don't notify B_EVENT_INVALID for FDs.
It isn't sent at all on FreeBSD.

Found while testing #19969: the disconnection was reported twice.

Change-Id: Icaf7abef7c3c3a61fccf5eb9e827e0a6a0fa1228
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10580
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 01:13:34 +00:00
Augustin Cavalier 498d92cbd7 kernel/guarded_heap: Add an init comment. 2026-03-26 17:53:15 -04:00
Augustin Cavalier 34e74e0556 kernel/vm: Pages in the store should be in the commitment.
Otherwise we won't reserve memory/swap for swapped-out pages.
2026-03-26 17:49:56 -04:00
Augustin Cavalier 33dc47cb2c kernel/vm: Move committed_size to the cache implementations.
This fixes a long-standing TODO, and a major inconsistency
that for different caches, "commitment" reserves from different
pools, so any two aren't necessarily convertible.

The new system introduces a virtual method "TakeCommitmentFrom",
which allows the VM's cut_area routine to behave as it did
previously.
2026-03-26 17:36:27 -04:00
Augustin Cavalier 0a5cd96093 kernel/vm: Preparations for VMCache::committed_size removal.
Includes some cleanup to the organization of VMCache.h.
2026-03-26 17:25:05 -04:00
Augustin Cavalier 76af6f4c98 kernel/vm: Update/add some documentation comments and drop some old files.
They mostly contained descriptions of functions' operations, not
what they're for, so they weren't so useful. I've added some of
the remarks they had (or ones with a similar purpose) inline
as documentation comments, and deleted the rest.
2026-03-26 16:43:52 -04:00
Augustin Cavalier 222c477cf0 docs: Update the VM swap documentation.
It was mostly up-to-date technically; a few details have been
amended where things have changed, and the "personal" stuff
dropped.
2026-03-26 14:54:05 -04:00
Augustin Cavalier 030b7c1426 kernel/vm: Clarify locking of VMArea and drop old documentation.
The documentation file hadn't been updated in a very long time,
and referred to locks and paradigms that have long since been
dropped (e.g. sMappingLock was removed in 2010, in
afed2658f4ef3e3df5ff8390d1d7a51b5b897a9e.)

Add a few "protected by" comments in VMArea to clarify things,
but otherwise this document looks entirely obsolete (I went
through all of it.)
2026-03-26 14:11:23 -04:00
Augustin Cavalier b10415b7cc kernel/fs: Update comments in EntryCache.
Make the concurrency model slightly clearer.
2026-03-26 14:08:57 -04:00
Augustin Cavalier acde38ead3 freebsd_network: Update comment in kernel_malloc.
bus_dmamem_alloc doesn't need this behavior anymore.
2026-03-26 14:01:54 -04:00
Augustin Cavalier eb097f749b kernel/slab: Use (1 << x) to define cache flag bits.
No functional change intended.
2026-03-26 12:26:22 -04:00
Augustin Cavalier bb1c367a6d kqueue: Add a no-op EV_ENABLE definition.
EV_ADD implies ENABLE, so this isn't needed, but a lot of applications
try to specify it anyway. So this extends source compatibility.

If in the future we ever implement EV_DISABLE, we can just add a
real definition for it then, and since ADD implies ENABLE existing
applications shouldn't break.
2026-03-26 12:25:41 -04:00
Augustin Cavalier 5ac1c21e5f kernel/vm: Set the memory type on cloned device cache areas.
If the source area is now mapped write-combining, so will the
target area.

May fix some problems or slowness that occurred after the
framebuffers refactor commits.
2026-03-25 12:50:57 -04:00
Augustin Cavalier 7240f3762f kernel: Add mechanism to replace specific object caches with the guarded heap.
This allows the guarded heap to be used in a much more targeted way,
if it's suspected specific object_caches have problems.

Enabled by default for KDEBUG. The new safemode/kernel option is
"guarded_heap_for_object_caches". This accepts a comma-separated
list of quoted strings, optionally with * at beginning and/or end
(but not middle.) Examples:

mbufs*   # matches caches starting with "mbufs"
*jumbo9*	# matches caches containing "jumbo9"
"*jumbo9 chunks","mbufs*" # matches caches ending with "jumbo9 chunks"
                          # or starting with "mbufs"

This should help with diagnosing #19973, among others, without needing
to compile custom versions of drivers or anything like that.

Unfortunately it is not possible to use this mechanism to selectively
replace parts of the slab malloc. The slab malloc free() relies on
the MemoryManager to figure out what cache an object belongs to, which
doesn't work if objects of some size classes aren't known to the
MemoryManager at all.
2026-03-24 18:10:10 -04:00
Augustin Cavalier 90ac9e6538 kernel/vm: Overhaul swap cache commitments.
Before this commit, swap space was committed entirely orthogonally
from memory commitments. This was not handled at all correctly
when cutting areas (the area cutting logic tries to migrate commitments
between caches, but in the case of swapping caches, it didn't,
and couldn't, take the separate fCommittedSwapSize into account.)

Even without that problem, totally separate swap and memory commitments
caused other problems. For instance, suppose a setup with 4GB of RAM
and 4GB of swap. Many caches are created, and all 4GB of swap gets
reserved, but the caches with this swap reserved have no or few pages
in them. Then, all 4GB of RAM gets used up. The page daemon runs, and
looks for things to swap out, but it can't find anything because all
our swappable caches with pages have no swap reservations, so all it
can do is flush out cached pages, which just degrades performance.

Or, consider what would happen if the 4GB of swap was released, but
the 4GB of RAM was still in use, and then the kernel tried to
allocate memory. It would get OOM errors, because none of the
caches have swap commitments and so nothing can be written out.

Under this new system, the specific swap space reservation only happens
just before the page is first written out, so both these cases should
be handled smoothly, and swap should be used in a much more sensible
fashion overall.

This change seems to be more in line with what other OSes do (Windows
Task Manager's "Committed" clearly is RAM+swap, for instance.)

The only potential downside to this change is that swappable caches
may temporarily go over their commitment when reading or writing
out pages to swap, before the page daemon has a chance to come by
and free the page or the swap space. But as that is a temporary state
and should always be resolved by the page daemon, I think it's
probably an acceptable trade-off.

Change-Id: I928f4b4cacbec26ed6315179476eaff1a7f626c8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10305
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:02:52 +00:00
Augustin Cavalier 9be0e148a2 vesa & framebuffer: Clone the framebuffer instead of having it be user-accessible.
This begins paving the way for removal of user access to kernel
address space.

After the previous commits, BDirectWindow and BWindowScreen
still function properly.

Part of #19990.

Change-Id: I8477e43cd517ba67383755a4cb60b00bc117f5d7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10559
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier 95ace7f374 kernel/vm: Introduce methods to change the cache of all an area's clones.
This will be useful in the case of cloned device caches based
around physical memory, e.g. for framebuffers.

Change-Id: If2b864208e86f436e91379b73c4b866b0bd5e1d7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10558
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier 861f644f19 app_server & BWindowScreen: Do away with AS_GET_FRAME_BUFFER_CONFIG.
It can't work if the framebuffer is mapped per-application.
Instead, use the accelerant hook to get the framebuffer.

The BScreen methods this disables were deprecated and marked
private already, so no Haiku applications should be affected.
(If really necessary they could be reimplemented with BWindowScreen.)

Remove first _GetCardInfo in BWindowScreen; we invoke it
later, closer to where the buffer is actually used.

Tested with ParticlesII (which uses BWindowScreen) on VESA
with the new user-only-mapping accelerant.

Change-Id: I405bcfa8cb1eb2d0c346fafbc6233bef15196134
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10572
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier f6be811473 BDirectWindow: Clone the framebuffer from app_server, if necessary.
This paves the way for accelerants to map the framebuffer in
user memory, not kernel memory. It uses the ServerMemoryAllocator
in order to avoid mapping the framebuffer multiple times in
client applications.

While at it, clean up some names.

Tested with DirectWindowStars and GLTeapot, both work.

Change-Id: I4e0c003fae99891044af0a5e6e1d6a4506da6430
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10571
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier ede14380e5 kernel/slab: Run slab_object automatically when the 0xdeadbeef assert fails. 2026-03-23 23:11:40 -04:00
Augustin Cavalier a277043c1f kernel: Overhaul debug heaps system.
Instead of the kernel heap being a compile-time parameter, make it
a runtime parameter (if DEBUG_HEAPS is specified, at least; otherwise
we're hardwired to the slab heap as before.)

This is similar to what's done in userland: there LD_PRELOAD and
MALLOC_DEBUG control the heaps, here "kernel_malloc" and then
"guarded_heap_options" kernel settings control the heap.

While at it, apply fixes to the guarded and debug heaps to ensure
a minimum alignment of sizeof(void*), if no specific alignment
is requested.

Tested with a lot of build configurations (DEBUG_HEAPS 0, 1;
DEBUG_HEAPS_DEFAULT slab, guarded; USE_DEBUG_HEAPS_FOR_OBJECT_CACHE
0, 1) and with various parameters specified in the bootloader.
2026-03-23 23:01:26 -04:00
Augustin Cavalier 4fd16356e0 kernel: Move the debug heap to a separate file in the debug directory. 2026-03-23 23:01:26 -04:00
Augustin Cavalier 0e5639ad74 L2CAP: Remove dependency on userland bdaddrUtils.h.
And do some other code cleanup too.
2026-03-23 14:35:09 -04:00
Augustin Cavalier 7e813b6181 bluetooth: Drop unused int128.
This should be done using __int128 if necessary.
2026-03-23 14:34:25 -04:00
Augustin Cavalier 3c05f06edb kernel/user_mutex: Add missing get after allocating contexts.
Fixes a potential KDL.
2026-03-23 14:34:10 -04:00
Augustin Cavalier 54ad26255c kernel/vm: Fix set_memory_protection syscall.
check_protection adds kernel flags, so we need to do that after
checking the already-set flags.

Fixes #19988.
2026-03-23 14:31:51 -04:00
Augustin Cavalier 935941e772 kernel/vm: Drop team argument from vm_set_area_protection.
It's not needed and just creates confusion. Permissions checks
are done with the current team and the "kernel" parameter.
2026-03-23 14:31:00 -04:00
Augustin Cavalier c977e8a221 libroot/locale: Handle current_locale() being called early in initialization.
Fixes #19954.
2026-03-23 14:24:32 -04:00
Augustin Cavalier 89c3592b51 BBlockCache: Initialize the mutex unconditionally.
Otherwise we may get assertion failures under the debug heaps.
2026-03-23 14:07:18 -04:00
waddlesplash 4660bcfbab Revert "ImageRules: do not include catalogs from .so in dependencies"
This reverts commit 368cac3c9d.

Actually excluded catalogs for .so in all cases, not just
dependencies.

Change-Id: I6f8997073c71a6a9fa3fa875e971242bc8487666
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10562
Reviewed-by: waddlesplash <[email protected]>
2026-03-22 02:14:02 +00:00
Augustin Cavalier cafe26877f kernel: Actually fix call_all_cpus to invoke the method with interrupts disabled.
sICIEnabled is never set if sNumCPUs == 1.

Actually fixes #19983.

Change-Id: I3c50d118bb44ba4a2289586d4305d663a3a7900a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10561
Reviewed-by: waddlesplash <[email protected]>
2026-03-22 01:48:40 +00:00
Augustin Cavalier d3c2dd6c14 kernel/vm: Commit changes missed in previous commit. 2026-03-21 13:47:13 -04:00
Augustin Cavalier e13a6e6ec2 kernel/lock: Assert that a write lock isn't held in switch_from_read_lock. 2026-03-21 13:37:13 -04:00
Augustin Cavalier 5811e4bf6f kernel/vm: Pass the kernel parameter down in transfer_area() properly. 2026-03-21 13:18:28 -04:00
Augustin Cavalier 5fffbbfc48 kernel/vm: Minor API changes for consistency in VMCache.
* Insert/Remove can't fail, so drop status_t return values.

 * "TransferAreas" is really "TakeAreasFrom", so rename it. This
   avoids confusion with the "transfer_area" API call, which moves
   an area to another address space (keeping the same cache.)
2026-03-21 12:30:02 -04:00
Augustin Cavalier 05f1182cca kernel/vm: Overhaul protection checks and fixup.
* Give arch_vm_supports_protection a team_id argument (primarily
   to allow the kernel address space to be more restricted than
   user ones.)

 * Move invocation of arch_vm_supports_protection to a static method,
   and also call fix_protection from there.

 * Consolidate protection checks.
2026-03-21 09:26:44 -04:00
Augustin Cavalier a01f1a3da8 usb_asix: Delete.
Now provided by asix88xxx instead.
2026-03-18 13:54:26 -04:00
Augustin Cavalier 231ecae98b kernel/scheduler: Skip setting invoke_scheduler in scheduler_reschedule_ici.
It isn't needed now that it's set before sending the ICI. Saves
a lot (hundreds, in some basic testing of compile jobs) of
unnecessary scheduler invocations.
2026-03-17 20:25:53 -04:00
Augustin Cavalier 87e0daf0a1 kernel: Include <smp.h> in VMTranslationMap.
RISC-V at least doesn't implicitly include it.
2026-03-17 14:49:13 -04:00
Augustin Cavalier 1b6efe284a kernel/smp: Avoid calling cpu_pause() if test-and-set works on first try. 2026-03-17 14:48:53 -04:00
Augustin Cavalier 14b78e205c kernel/smp: call_all_cpus should run with interrupts disabled.
For consistency. And so should call_single_cpu.

Fixes #19983.
2026-03-17 14:23:58 -04:00
Augustin Cavalier 89c81c2ac1 kernel: Fix copy/paste error from previous commit. 2026-03-17 13:37:04 -04:00
Augustin Cavalier cf2179fa35 kernel: Add invalidation utility routines to VMTranslationMap.
These allow us to move a lot of the basic logic out of the
TranslationMaps. In the process, it extends the fix applied
to x86 in the previous commit to all the other maps.
2026-03-17 13:30:11 -04:00
Augustin Cavalier b4546a49f0 kernel/x86: Don't spuriously set the current CPU bit in Flush().
We may be called from the page daemon, which may be running on
a different CPU than the one this map is active on. So don't
bother flushing unnecessarily if we can avoid it.
2026-03-17 13:19:31 -04:00
Augustin Cavalier d4817afe36 kernel/smp: Use a single-CPU ICI if multicasting to only one CPU.
This avoids the broadcast mailbox (and the incrementing of
other CPU's counters) entirely in this case.

As this is used for TLB invalidation, processes that are only
running two threads at once will benefit immensely from this.
It also seems to be triggered by the kernel's "idle_scan_active_pages"
logic, which sometimes sends invalidations to CPUs besides its own.

On the VM setup, this path was hit around 200 times during boot,
around 600 times during a rebuild of HaikuDepot + mime_db, and
50,000+ times while running Iceweasel (Firefox). On bare metal,
it was hit around 300 times during boot, 300 times during a rebuild,
and 90,000+ times while running Iceweasel (over a different length
of time, though.)
2026-03-17 13:06:35 -04:00
Augustin Cavalier 9c08c836bf kernel/smp: Use read spinlocks when prepending broadcast messages.
Some brief testing shows that concurrency is unlikely here, but
we might as well.
2026-03-17 12:08:59 -04:00
Augustin Cavalier b6447046fc kernel/smp: De-indent smp_send_ici.
No functional change intended.
2026-03-17 11:54:27 -04:00
Augustin Cavalier 19bcb3be0a kernel/scheduler: Make invoke_scheduler atomic to skip unnecessary ICIs.
Following upon a KDL reported by atomozero, on wait-for-free-SMP-messages
on an unblock occurring with interrupts disabled.

In changing cpu_ent, move disabled to the beginning to avoid
enlarging the structure unncessarily.

On a 4-core VM, this skips around 200 sends during boot, and
over 3000 during a rebuild of HaikuDepot + mime_db (cold). On
bare metal (i3, 2x2), it skips around 150 during boot, and a bit
below 3000 during a rebuild of HaikuDepot + mime_db (over a much
longer time than in the VM, as the hardware is slower.)

Performance in the VM doesn't look much different. But this might
help in VirtualBox, or other situations where ICI latency is far
above what it should be.
2026-03-17 11:25:36 -04:00
Augustin Cavalier d5a5f22579 pegasus: Replace with the upstream FreeBSD version.
Fixes #19745.

Change-Id: Ie540beecbf9f0a998f016f015357a38d1fa95bfd
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9599
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2026-03-16 21:30:32 +00:00
Augustin Cavalier 924599c310 L2CAP: Change from SOCK_STREAM to SOCK_SEQPACKET.
This is the same as what FreeBSD does.
2026-03-16 13:21:46 -04:00
Augustin Cavalier 7512053757 kernel/smp: Refactor ICI broadcast/multicast to invoke the current CPU too.
Since the methods now don't just "send", the names are changed
also (which is fitting since they're now API-incompatible.)

The changes in the TranslationMaps to adopt this fixes a correctness
issue: previously TLB invalidations would be done either with or
without interrupts enabled depending on how they were invoked.
Now, they'll always be done with interrupts disabled. (This is
the same fix that was recently done to x86.)

The idea with processing the ICIs on the current CPU too is
that presumably the other CPUs will take just as much, if not
more, time processing the ICI than the sending CPU. So, we might
as well do the processing while we wait, rather than before or after.

Testing shows this to indeed be the case. On a bare metal i3, kernel
map invalidations (with global invalidations always forced) across
a boot-to-desktop go from around ~60.8ms cumulative before,
to ~51.8ms cumulative after this change.

Change-Id: Icd0343d462de7cf11043e6438f47b02f6b88bb8b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10472
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-16 13:41:00 +00:00
Augustin Cavalier 000c32a568 asix88xxx: Import drivers from FreeBSD to replace usb_asix.
The homegrown usb_asix was partially based on the upstream FreeBSD
driver anyway, and hasn't seen much maintenance in recent years.
We might as well replace it with the FreeBSD version. In the process,
also add the "axge" driver, supporting the Gigabit version of this
hardware.

Tested by smrobtzz with the AX88179A: "it seems to work perfectly".

Change-Id: I37fdfc2cef6100916d6034817f117286f7f443b2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9600
Reviewed-by: waddlesplash <[email protected]>
2026-03-16 13:17:57 +00:00
Augustin Cavalier 9936387223 freebsd_network: Add everything needed for USB ethernet drivers.
Change-Id: I152d3fcdb50b9473f06c2164b9abb38b7c9d7e40
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9598
Reviewed-by: waddlesplash <[email protected]>
2026-03-16 13:17:57 +00:00
Augustin Cavalier d59105d001 freebsd_network: Synchronize some mbuf routines with upstream FreeBSD.
Also delete an OpenBSD compatibility section that isn't used.

This includes a fix to mbufq_full (made in 2019 in FreeBSD)
to allow for mbufqs of unlimited size, apparently needed by
some drivers, found by @smrobtzz while testing USB ethernet
drivers.
2026-03-16 08:50:43 -04:00
Augustin Cavalier 913f501fbd kernel: Use uint64 for seconds in datetime conversion routines. 2026-03-16 08:35:51 -04:00
Augustin Cavalier a2e4f9f75f kernel/x86: Use call_single_cpu_sync in get_cpuid.
Sends a more targeted ICI than a broadcast.
2026-03-10 17:55:12 -04:00
Augustin Cavalier 1d740a6700 kernel/smp: find_free_message expects interrupts enabled.
Use thread_pin instead of disable_interrupts in the call_*
methods.
2026-03-10 17:54:33 -04:00
Augustin Cavalier e867e95538 kernel/smp: Deduplicate call_*_cpu.
* Rename call_single_cpu for consistency.

 * Combine call_all_cpus implementations into one, like call_single_cpu.
2026-03-10 15:33:33 -04:00
Augustin Cavalier 334e90a2ac kernel/smp: Just return free messages using a write spinlock.
There isn't much value in using extra atomics here.
2026-03-10 15:21:27 -04:00
Augustin Cavalier 3c28d298f7 kernel: Don't fail if the private string.h is included under GCC2. 2026-03-10 13:10:25 -04:00
Augustin Cavalier 918b2dfaab BMessage: Eliminate UsePrivateHeaders kernel. 2026-03-10 13:10:25 -04:00
Augustin Cavalier b350405e06 kernel/smp: Refactor smp_msg structure allocation.
The SMP_MAX_CPUS * 4 fixed pool size apparently goes all the way
back to NewOS, which supported only 4 CPUs max. As ours is now
64, this means the fixed pool size was very large even on systems
with only a few cores. So, instead, allocate 4 messages per CPU
(though often more, due to rounding up to the page size; e.g.
on x86_64, 1 page fits 56 smp_msgs.)

Also, put them a dedicated area, to keep them a bit more segmented
from the kernel heap, in case of problems.
2026-03-10 13:04:46 -04:00
Augustin Cavalier 10d0685a9e EFI: Fix some more instances of memcpy on other architectures. 2026-03-10 12:20:00 -04:00
Augustin Cavalier 69499b0e00 kernel: Use compiler-builtin memset, memcpy, memmove, memcmp.
Since the kernel is built with -ffreestanding, and thus -fno-builtin,
the compiler ignores the function names and doesn't perform optimizations
(e.g. inlining for small values) that it otherwise could. So, here,
we add a string.h that supplements the default, and uses #define to
reinstate the builtins, and thus the optimizations.

Linux and FreeBSD at least apparently do the same. A quick compile
benchmark in a VM doesn't show much difference, maybe a slight
decrease in sys time.
2026-03-10 12:00:59 -04:00
Augustin Cavalier ff861e0ea3 kernel, lib, drivers: Prepare for use of builtin string.h operations.
This fixes various -Werror=class-memaccess that are triggered
when using the builtins.
2026-03-10 12:00:59 -04:00
Augustin Cavalier 2adbc5705a Eliminate "UsePrivateHeaders kernel" from most of userland.
Now that the DoublyLinkedList and other classes are in a "util"
directory, this isn't needed.
2026-03-10 12:00:58 -04:00
Augustin Cavalier 103ca61228 bluetooth: Eliminate the need for kernel headers in userland. 2026-03-10 12:00:57 -04:00
Augustin Cavalier 18c93b9569 PPP: Eliminate the need for kernel headers in userland.
Also fix some -Werrors.
2026-03-10 12:00:57 -04:00
Augustin Cavalier dd2eeb7dff kernel/smp: Style fixes.
No functional change intended.
2026-03-09 21:08:52 -04:00
Augustin Cavalier dd24eecac1 kernel/smp: Distinguish CPUSet::GetBit from GetBitAtomic.
I checked all invocations of GetBit; as far as I can tell,
only the two adjusted here in smp.cpp are done while the Set
may be concurrently modified, and even then I don't know
that they really need to be atomics, anyway.
2026-03-09 20:58:54 -04:00
Augustin Cavalier 97a65a027d kernel/smp: Use rw_spinlocks for ICI locks.
This allows read spinlocks to be used in check_for_message
and return_free_message.

On a 4-core VM, there don't seem to often be concurrent readers
(a counter I setup got only about 400-500 hits for booting up
and starting a web browser, at most.) But on bare metal (i3,
2 cores x 2 hyperthreads) we get it a lot more: 30,000+ times
during boot alone.

Kernel map invalidation (with a hack to invalidate all every time)
across boot-to-desktop takes a cumulative ~68.0ms before this change,
and ~61.0ms after, on the bare metal system. (On the VM it's also lower
after this change.)

Presumably on systems with more CPUs it will get hit even more
often still. So this optimization seems worth it.
2026-03-09 20:58:54 -04:00
Augustin Cavalier de74304510 kernel/x86: Always call arch_cpu_global_tlb_invalidate with interrupts disabled.
Fixes a race. Discovered by SED4906.

Change-Id: I2b267312e9f3ff32bafa2ac2784f5d4a9905e24e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10416
Reviewed-by: waddlesplash <[email protected]>
2026-03-09 17:37:05 +00:00
Augustin Cavalier 767d7cf9fa libroot & kernel: Replace strchr, strcpy with musl's versions.
They call out to other library functions, which are better optimized
than the old naive implementations.

Add -fno-builtin to the musl strings Jamfile, otherwise GCC
generates infinite recursion in strcpy, apparently.
2026-03-05 17:31:30 -05:00
Augustin Cavalier fb0556ae2b BFS: Remove the inode from the Removed list with the transaction lock held.
Fixes #19953.
2026-03-05 15:58:28 -05:00
Augustin Cavalier 26f8f18b1c BFS: Assert in RemovedInodes(), don't just have a comment.
This would've caught the cause of #19953.
2026-03-05 15:56:48 -05:00
Augustin Cavalier 11280e1b51 kernel/device_manager: Remove unnecessary includes of Locker.h. 2026-03-05 13:35:14 -05:00