#uACPI - a portable and easy-to-integrate ACPI implementation

1 messages · Page 37 of 1

calm latch
#

Most of my servers are single threaded*, but I had plans to do this eventually (if it gets big I guess)

jaunty fox
#

i love this trick

calm latch
#

also, you don't have to deal with concurrency as much if you don't want to with microkernels

gentle peak
#

that's interesting

calm latch
#

now that I think of it

gentle peak
#

I wonder how the performance of the two approaches compare on modern hardware

jaunty fox
#

nowadays with ASIDs and assuming that most interdomain calls will be to do a small amount of work, i think more preferable is to try to call into a cpu local thread

#

i expect the overhead of migrating between processors will dominate the gain from not losing the l1 cache, which you may lose anyway if the system is loaded enough that the calling thread doesn't simply leave the core unburdened but is rather scheduled out

left orbit
#

would it be stupid to just use a stripped down linux as a base for a "microkernel" based operating system lol

#

i had this idea just now, just disable everything that can be disabled and implement everything in userspace meme

loud ice
#

you can't disable all that much on linux i think

mortal yoke
#

it would probably be a decent amount of work to expose the stuff you need to userspace and even if you strip away a lot of the config options its going to be monolithic having almost all of the syscalls

gentle peak
#

a lot of the abstractions that linux uses to expose info that drivers need to userspace rely on having fully functional drivers for those devices in the first place

left orbit
#

i dont care

gentle peak
#

plus it has no way to process IRQs fully in userspace, you need a hardirq handler for every device in kernel

left orbit
#

i just want pci in userspace

dense steppe
#

well Linux is open source. so you can fork it if you want to rewrite it into a microkernel

left orbit
#

exactly

#

i can just add my own stuff to it

dense steppe
#

but you would have to rewrite a lot

gentle peak
#

it'd probably be more effort than just writing a microkernel

mortal yoke
#

yeah its likely easier to design a kernel with it in mind from the start than to try converting linux

left orbit
#

:(

calm latch
#

small functional microkernel is like 10k LoC

leaden fox
#

uacpi in userspace

calm latch
#

and pci

left orbit
#

yeah i mean, you can do port io in userspace + you can map mmio so it's not that crazy

#

i like the idea of just using userspace apis for everything in uacpi tho lol

north hull
#

ok I mean

#

at least I beat Nyaux

gentle peak
#

I think that's slightly lower than what nyaux gets without ubsan actually

#

Idk how much has changed since then but when I fixed its allocator bug it got 1M

#

Might be due to cpu model though

north hull
#

oh

#

this is with -O0 and ubsan

#

lemme try optimized build

#

nvm im trolling

#

its O1

left orbit
#

ubsan had a decent hit in my kernel actually

north hull
#

so

#

not sure what to make of that

#

so it like

#

swings by 400k randomly

left orbit
#

bad timekeeping?

#

or are you running under wsl2?

north hull
#

I just changed to using hpet

gentle peak
#

Probably host system scheduling

north hull
slim panther
#

my kernel swings around 200k points from time to time

north hull
gentle peak
#

old proxima on my cpu has multiple performance ranges: 4.0-4.4M, 5.0-5.3M, 6.5-6.7M, 7.5-7.7M

north hull
gentle peak
#

I believe each range corresponds to a different host cpu speed setting

north hull
#

so now it swung by 700k+

gentle peak
north hull
#

I suppose yeah

#

probably host system stuff

slim panther
#

just take whatever is the highest meme

north hull
#

lol

#

I dont want to submit this as an actual score

#

im using a shitty heap I cooked up to see how much my heap is impacting perf

#

before using this heap I got 34k

gentle peak
#

Proxima's scores are the ~median of the highest performance range

north hull
#

so time to make a slab allocator ig

#

lol

calm latch
#

pmos has gotten 3.3M with dlmalloc, which is best-fit trl

#

on top of first fit vmm and segregated fit pmm in kernel

frank canopy
#

sadly i still dont have a new number with my new mm/alloc, thanks to my page allocator is panicking like halfway through init

north holly
#

was scrolling through my thread's old messages

fiery turtle
#

Lol

fiery turtle
vale isle
#

i don't remember which microkernel came up with it but there's microkernels where tasks can choose which vmm they want to use (which are also userspace

#

iirc fuchsia has that

fiery turtle
#

@vagrant hull btw did u figure out the ironclad bug on your laptop?

urban galleon
#

Can uACPI Generate aml

zenith crescent
urban galleon
#

Something like iASL

fiery turtle
#

Its not a compiler

urban galleon
#

ok

vale isle
#

yep

calm latch
#

It's very common for microkernels

#

Mach had it

#

I have it

vale isle
#

some designs have pagers per process, some have pagers shared across processes with a default pager

calm latch
#

But that's more of a pmm though

vale isle
#

i thought it handled paging in and out too?

calm latch
vale isle
#

ah

#

how does that work

calm latch
#

That's what I'll do

calm latch
vale isle
#

i don't really want to overengineer my pmm/vmm in my first attempt at a microkernel so I'll keep them in kernel and might move them out at some point

calm latch
#

Even Linux has it

vale isle
#

idk i never got to that point

#

I'll need to read that some papers

torpid root
#

hmmmmmmmmmmmmmmmmmmmmm

#

sus

#

both values

#

I don't return higher half address from any of my api functions

gentle peak
#

that's not higher half, that's kernel image

#

which is even more fucked

#

actually addr is supposed to be a physical address there so it's worse than i thought

torpid root
#

oof

#

yeah missed a few F s there lol

#

smh how can this even happen

rustic compass
#

whats the advantage of a per process vmm?

mortal yoke
#

?

rustic compass
#

was a question to a discussion further up the chat

north holly
#

*curses

#

**cursed

rustic compass
#

its the next generation os, a os for 128bit cpu's

torpid root
#

before unlock

#

so in do_write_register

#

hmm but I don't think that calls uacpi_kernel_map

#

definitely after line 533

#

@fiery turtle any tips? 🥺

north holly
#

Uncurse your kernel

fiery turtle
#

Printf debugging

#

Do write most likely dispatches into your api

calm latch
#

So that filesystems in userspace can read data on demand from disk and whatnot

torpid root
#

is it trying to execute the stack

#

smh

slim panther
torpid root
#

truer words have never been spoken

#

how the hell do I trace it if stack is trashed

calm latch
#

gdb?

#

(If it pagefaults in the same place, just put a watchpoint at that address)

torpid root
#

invalid opcode

calm latch
#

-fno-omit-framd-pointer and %rbp?

torpid root
#

just the last value of rip and then nothing

torpid root
#

watch is so slow

#

g_register_mappings+88 is being set to an address in stack

north holly
#

Is this the qemu blob?

torpid root
#

?

north holly
#

the one that breaks in your kernel

torpid root
#

yes

#

maybe, I haven't tested anything else

#

it broke after 1.0

north holly
#

idk maybe your kernel is cursed or smth

torpid root
north holly
#

or you have elves playing around with your computer

torpid root
#

this kernel can go and shit itself
I'm done smh

leaden fox
#

osdev gang just shilled uacpi to FreeBSD at fossdem

#

Upstream uacpi coming soon to the BSDs

fiery turtle
#

Lol for real?

leaden fox
slim panther
#

based

fiery turtle
#

Based af

vale isle
#

based af

#

imagine uacpi in bsds before uacpi in linux

#

i wonder what the BSDs would get in the leaderboards

#

ig what's left is uacpi in NT

#

imagine all major operating systems using uacpi

#

major operating systems include reactos and bsds and haiku

vale isle
#

I'm aware of that yes

#

darkfire should upstream it to microsoft

gentle peak
#

true

vale isle
#

:^3

#

uacpi will become the reference implementation

vale isle
#

yea that's 😎

#

i should play around with reactos one day

#

or potentially make my own NT clone

#

or hear me out: darwin clone?

fiery turtle
vale isle
#

cloning a proprietary os bug-for-bug (including driver interfaces and stuff) sounds fun

#

NT is the top candidate there sadly

left orbit
#

i am working on my own, sort of, nt clone

vale isle
#

because NT is already done kinda

#

with reactos

left orbit
#

i want an nt like architecture but native posix support

vale isle
#

take NT 4 and fix its posix subsystem

left orbit
#

idk how that last part is gonna work yet, but we'll see

vale isle
#

i wonder how unhappy windows drivers would get if they were ran in userspace

mortal yoke
#

at least amd gpu driver would not be happy lol

vale isle
left orbit
#

considering you provide enough apis it should just work

#

yes they do

#

well, i mean

vale isle
#

then why don't drivers just work in WoA?

left orbit
#

most stuff is abstracted away by the kernel itself already

#

probably because x86->aarch64 jit in kernel isn't that great of an idea

mortal yoke
vale isle
#

don't give me ideas

#

i had a x86 emulator and was thinking about adding dynarec to it

left orbit
#

you mean bad ideas?

vale isle
#

ye

left orbit
#

no problem

left orbit
#

right

#

you can probably patch these ahead of time

#

or when transpiling code

vale isle
left orbit
#

it's in the public kernel headers

vale isle
#

ah

left orbit
#

drivers use this

mortal yoke
#

yeah the driver kit headers contain this stuff

vale isle
#

I thought qwinci just broke an NDA

left orbit
#

the same shit is mapped in user mode at 0x7ffe0000

#

though as read only memory

#

in kernel it's mapped read write

#

for obvious reasons

vale isle
#

a clone could map it read write for drivers

#

NT clone but microkernel :3

left orbit
#

drivers can already write to it

#

in kernel space it's mapped read write

vale isle
#

no for running it in userspace

left orbit
#

oh

#

yeah good luck

#

you'll probably have to emulate it

vale isle
#

probably

#

sadge

#

I'm not doing this yet

left orbit
#

luckily you can catch exceptions when accessing addresses > user space end iirc

#

i mean i guess that is kinda obvious

vale isle
#

I know how hard would it be from reactos lol

jaunty fox
#

and under BSD tutelage uacpi remains an independent project

fiery turtle
left orbit
#

C

#

not yet

jaunty fox
#

rather than getting sucked up into the linux code and the beloved kernel api getting replaced with direct calls

fiery turtle
left orbit
#

i will probably put it on github the moment i have a working loader

frank canopy
#

oh hey same, though mine has already diverged a lot and is zig

#

more like nt-inspired than an nt clone

left orbit
#

yeah im just inspired by the nt architecture, i dont really aspire to be an actual nt clone

left orbit
#

not sure what it'll do just yet

fiery turtle
#

And thats loaded by limine?

left orbit
#

but i know i'll do the initial loading and mapping of kernel and some drivers

#

yeah, for now

fiery turtle
#

Like eir

left orbit
#

basically

fiery turtle
#

I see

left orbit
#

i want to have a pure efi loader at some point too

fiery turtle
#

Is your kernel a pe

left orbit
#

but not yet, that's a bit more work than limine :^)

#

nope

#

i use elf

fiery turtle
#

Ah

left orbit
#

while pe would be much easier to work with, and im more famiilar with it, i think i want to use elf

mortal yoke
#

one nice thing I discovered is that with clang you can use x86_64-unknown-windows-elf target to get the ms calling conv (as it doesn't support gcc's -mabi=ms) in an elf file

frank canopy
#

ive considered pe now that limine can boot it but zig cant get stack traces on pe without windows being there but it can iterate on the base pointer easily on elf

jaunty fox
#

gcc and clang are generating PEs with DWARF sections for debug info iirc

#

not the true and authentic format normally used for them

mortal yoke
#

stack unwinding is broken tho as gdb doesn't support seh and afaik they still generate seh unwind info

#

even with frame pointers enabled I couldn't get it to work nicely, stuff like finish or stepping out of a function just continued the execution and backtrace only showed the current frame (or the one directly before the current one if lucky)

frank canopy
#

yeah its a bit of a mess, thats why i dont try to use pe for my zig stuff too

fiery turtle
#

Also why not zig btw

left orbit
#

PE is just

here's a list of sections, load them into memory
here's a list of relocations, u have to implement like 3 types of relocations - done
here's a list of external functions i want and where to find them, pls put the addresses there

ELF is similar in some regards, it's not hard by any means, but i am not familiar with ELF relocations at all, and external symbols in ELF executables work different and i find it weird how they work, also there is two different types of relocations? rel and rela, from what i gathered it's just implicit addend vs explicit addend, but i prefer the way PE does thing

#

also i thought about zig for a moment but i don't want to fight the compiler, i just want to write working code meme

frank canopy
#

side note on the stack trace stuff, im really looking forward to https://github.com/ziglang/zig/pull/22077 so i can use the std stack trace printing and also get more info than i already have from the trace print

gentle peak
#

rel vs rela is easy, but each architecture has like 10 ways to calculate the relocated address

frank canopy
gentle peak
#

on one hand it allows for some very nice features (like ifunc) but on the other it is much more annoying to implement than pe relocation

left orbit
#

i haven't done that and i don't want to find out what it takes lol

mortal yoke
frank canopy
vagrant hull
fiery turtle
#

ah

#

have fun

vagrant hull
#

we shilled uACPI to obiwan after their FreeBSD modern standby talk

#

i like making fun of the ACPICA maintainer smashing the corvette

fiery turtle
vagrant hull
#

lol

dense steppe
#

I just imagine like Obi-Wan sitting in front of a computer and being like... I feel a disturbance in the VMM...

torpid root
#

I have uncursed my kernel and I hate myself even more now

#

when I added v1.0 api sized io functions, I kept my old one that had a switch with sizeof(type) cases. I passed 8, 16 and 32 as width instead of 1, 2 and 4 from the respective uacpi functions. I was calling fucking std::unreachable in default: case

fiery turtle
#

bruh

#

good job uncursing it!

torpid root
#

with v1 I get more points on my shitty cpu than on i7-13700k previously

#

but could a kind good cpu haver test it?

#
qemu-system-x86_64 -serial stdio -cpu host,migratable=off -M q35 -accel kvm -cdrom image-x86_64.iso
#

run a few times as difference can be a hundred thousand points

gentle peak
#

~4.1M/s on ryzen 5800x

torpid root
#

thank you

mortal yoke
#

I should also update to uacpi 1.0 and see what score I get

#

(on the nt thing, I implemented some of the stubbed uacpi apis like events/mutexes yesterday as I got around to implementing KeReleaseSemaphore/KeWaitForSingleObject)

torpid root
gentle peak
#

~4.9M

calm latch
#

I wonder how IA32 pmOS will perform (since AMD64 is just an insane mess) thonk

mortal yoke
torpid root
gentle peak
#

i can get an exact number to put on the leaderboard if you want

#

[00:00:00.002049] [info] uacpi: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 4906870/s)

fiery turtle
gentle peak
#

that's slightly less than proxima

#

by like 400k

fiery turtle
#

still pretty insane

#

didnt know your os was that fast

torpid root
#

monkuous is an osdev magician

fiery turtle
#

i think davix improvements also but they havent submitted them for the leaderboard yet

mortal yoke
#

maybe I should also get this thing on the leaderboard after I implement the rest of the functions (well its mostly just the pci stuff that's missing), though Ill have to also come up with a name for it and put it to git KEKW

#

I think a big factor to the score when compared to crescent is that I didn't spam cli;pushf;sti everywhere lol

dense steppe
#

also, it fluctuates between like 600K and 2M

#

might be host power management stuff

jaunty fox
#

i should submit a score to the leaderboard some day

fiery turtle
#

that would be a welcome addition

jaunty fox
#

unfortunately i haven't one yet as keyronex itself is missing high resolution time of day (that was only in the testbed kernel) and that's a task to be dealt with after i've done the driver framework work and some usb stuff

fiery turtle
#

makes sense

left orbit
#

intel W once again

#

i wonder if i could get a better score more reliably by running linux on bare metal

#

a tiny upgrade
[00:00:00.003999] [info] uacpi: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 5662213/s)

mortal yoke
fiery turtle
#

no like

#

are u gonna have both integrated or

gentle peak
#

@fiery turtle i think i found a uacpi bug, if in create_gpe_block any of the uacpi_map_gas_noalloc calls fail after gas_validate, the cleanup uninstall_gpe_block calls uacpi_unmap_gas_nofree on the register whose map call failed, which tries to call gas->unmap, which is null because the map call didn't fully complete

#

to reproduce this just make uacpi_kernel_io_map unconditionally return an error, calling uacpi_namespace_load will trigger the bug (with qemu's blob at least)

fiery turtle
#

doesnt it check for reg width before unmapping which would be zero there?

gentle peak
#

it's not zero because gas_validate succeeded

north holly
#

can reprod on obos

gentle peak
#

it happens when gas_validate succeeds and either of the map calls fail

fiery turtle
#

ah yeah ur right

#

these fields should not be filled on failure

#

ill fix it thx

north holly
fiery turtle
#

?

gentle peak
#

stack trace i assume

north holly
#

just a stack trace

fiery turtle
#

ah

mortal yoke
fiery turtle
#

are you using c++ btw?

torpid root
fiery turtle
#

which cpu

left orbit
#

i7-13700k

fiery turtle
#

sure

left orbit
#

i am slowly starting to dominate the uacpi benchmarking scene

#

with 4 scores being tested by me meme

slim panther
#

noooo im moving even lower

#

kms

left orbit
#

step it up smh

mortal yoke
#

its literally crescent but nt'fied troll

torpid root
slim panther
#

meanwhile i'm on -O3

torpid root
#

me too

left orbit
#

i am planning on having a decent IO + PnP subsystem so hopefully i can just have a pluggable acpi.sys

slim panther
#

for some reason i am faulting in uacpi now

calm latch
#

I'm not at home to submit the new build nooo

calm latch
slim panther
#

fym avx

left orbit
#

it's userspace

slim panther
#

oh

#

fair

gentle peak
#

that makes me wonder, would it be cheating to run uacpi as a single-threaded userspace server and take advantage of that by stubbing out mutexes

#

like you're not sacrificing capability

fiery turtle
#

sounds fair

calm latch
#

I can't avoid mutexes in malloc because I have a libc thread for every process koreablob

gentle peak
#

just make a uacpi-specific malloc implementation

fiery turtle
#

malloc server 💀

gentle peak
#

malloc implemented with ipc

#

actually that's just mmap with a lower granularity

north holly
#

bruh why is lto compiling out all uacpi's symbols

left orbit
#

why wouldn't it

north holly
#

nothing in my static library persists after enabling lto in uacpi

left orbit
#

they aren't needed

#

like most of them

#

oh trl

#

you dont enable lto in uacpi

#

you enable lto in your kernel

north holly
#

sounds fair

calm latch
left orbit
#

from what i understand he compiles uacpi and makes a static library out of it

#

which then he links into his kernel

north holly
#

yes

gentle peak
#

you do still need to enable lto for the static library

#

but you need to make sure to use gcc-ar instead of normal ar

left orbit
#

ah there u go

#

i thought lto is a linker arg

#

wasnt sure how it affects the compilation itself

gentle peak
#

it's both compiler and linker

north holly
#

lto is linker+compiler iirc

gentle peak
#

lto isn't possible unless the compiler generates IR instead of machine code

left orbit
#

ohh right

north holly
#

anyway I'll deal with that later

#

(never, I don't give a damn about lto atm)

#

I want to debug /bin/sleep

#

(it just hangs)

leaden fox
#

uacpi shilling to haiku done

fiery turtle
#

lmfao basesd

left orbit
#

holy based

slim panther
#

zased

#

what does haiku use atm

fiery turtle
#

haiku is nice although i know 0 about beos or whatever its basd on

fiery turtle
left orbit
#

🤢

#

acpica compat layer when

slim panther
#

haiku pr when

north holly
fiery turtle
#

when haiku maintainers get around to it meme

fiery turtle
# gentle peak <@353593948523986945> i think i found a uacpi bug, if in `create_gpe_block` any ...

can u let me know if this fixes it:

--- a/source/io.c
+++ b/source/io.c
@@ -838,10 +838,6 @@ uacpi_status uacpi_map_gas_noalloc(
     if (ret != UACPI_STATUS_OK)
         return ret;

-    out_mapped->access_bit_width = access_bit_width;
-    out_mapped->total_bit_width = total_width;
-    out_mapped->bit_offset = gas->register_bit_offset;
-
     if (gas->address_space_id == UACPI_ADDRESS_SPACE_SYSTEM_MEMORY) {
         out_mapped->mapping = uacpi_kernel_map(gas->address, total_width / 8);
         if (uacpi_unlikely(out_mapped->mapping == UACPI_NULL))
@@ -860,6 +856,10 @@ uacpi_status uacpi_map_gas_noalloc(
         out_mapped->unmap = unmap_gas_io;
     }

+    out_mapped->access_bit_width = access_bit_width;
+    out_mapped->total_bit_width = total_width;
+    out_mapped->bit_offset = gas->register_bit_offset;
+
     return UACPI_STATUS_OK;
 }
gentle peak
#

yeah, works now

fiery turtle
#

cool thanks for being vigilant lol

gentle peak
#

wasn't really a matter of being vigilant, i made a very small uacpi impl to test the performance of my rewritten kernel and ran into it

fiery turtle
#

ah

gentle peak
#

pretty much the same performance, which is what i expected and wanted, just wanted to make sure i didn't accidentally regress anything

fiery turtle
#

is that in kernel land still?

gentle peak
#

yes

fiery turtle
#

ah

#

are you keeping it this way?

gentle peak
#

no - this is temporary and small, just to test performance of basic kernel stuff. the only reason i did it was to check i didn't introduce any regressions compared to the prev rewrite

fiery turtle
#

makes sense

dense steppe
#

@fiery turtle is there a way to replace e.g. uacpi_kernel_alloc with my own definition, so that I can e.g. inline some stuff if __builtin_constant_p (size)?

gentle peak
#

lto

dense steppe
#

lto is kinda "meh" in this situation

mortal yoke
#

put the definition in uacpi_libc.h

#

its included in like all uacpi sources

gentle peak
#

that doesnt really work because kernel_api.h still defines the prototype

dense steppe
#

yep.

mortal yoke
#

how does it not work? the compiler will then see the definition

dense steppe
#

because multiple definitions of a global symbol

mortal yoke
#

you make it inline?

dense steppe
#

cannot change the definition in uacpi/kernel_api.h though

mortal yoke
#

I'd assume its enough if the definition is marked inline

dense steppe
#

basically this is my kmalloc:

mortal yoke
#

I think it would work if you'd just make it normal inline inside uacpi_libc.h (though then you need to also instantiate it once in some source file because the way inline works in c is stupid)

gentle peak
#

if you make it normal inline you'll get multiple definitions

hollow elm
#

in c++ you'd get sane inline behavior :^)

gentle peak
#

you do have to use static in that case

#

if it's included afterwards, you get a compiler error

mortal yoke
#

ah yeah

gentle peak
#

but like

dense steppe
#

it's the world biggest hack but it works

gentle peak
#

why isn't lto sufficient for this

dense steppe
#

but I won't use it, because it's too hacky

mortal yoke
#

how is it hacky

dense steppe
gentle peak
#

ah

dense steppe
#

I guess I can just

void *
uacpi_kernel_alloc (uacpi_size size)
{
        if (size == 32)
                return kmalloc (32);
        else
                return kmalloc (size);
}

so it will slightly optimise the common-case of allocating 32-byte objects

#

but there are bigger, more important performance improvements to do

hollow elm
#

maybe also add likely there?

dense steppe
#

nahh

#

the branch predictor is sufficient

#

also I don't want to move that other kmalloc to a cold section

gentle peak
#

__builtin_expect actually makes a pretty huge difference in performance

#

i forgot the exact numbers but it's very much not insignificant

dense steppe
#

which requires runtime allocation of CPU-local storage, the way I plan on doing it.

#

the thing is, since slab uses this dynamic runtime allocation of CPU-local storage, the implementation of dynamic runtime CPU-local storage allocation cannot use slab

#

though that's not a problem (just don't support free and it's fine)

hallow marten
#

solaris fixes this by allocating cpu-local storage using vmem

#

I'll probably do something similar

dense steppe
#

rustc (vmem shill)

hallow marten
#

the solaris allocation stack is very well made

#

there's a reason why everyone stole it meme

frank canopy
dense steppe
#

for now I'm just going to bump-allocate from a 16KiB or so statically allocated region. later I might reserve like 1MiB virtual address space and only actually populate it with physical pages when needed

#

(16KiB/CPU)

dense steppe
#

this is what the fastpath of my new slab allocator implementation will look like

#

sadly, it loses the ability to allocate memory in IRQ context

#

I can have a separate IRQ-safe allocator

vast kestrel
#

Don't you want to preempt_on even if num is zero

dense steppe
#

yeah... but that's done later

#

I should probably builtin_expect num to not be zero

dense steppe
#

I moved the initial preempt_off () to outside of the first branch

#

won't affect perf

#

will make code simpler

#

👍

#

ok... the fastpath for allocation should be like 20 instructions or so

#

but I gotta write the slowpath too

leaden fox
#

They have their own fork of ACPICA basically

#

No clue how much they changed

north holly
#

port uacpi to the apollo 10

#

space craft

fiery turtle
#

because u cant integrate it without forking

#

u have to change headers and stuff i think

leaden fox
#

Didn't know ACPICA was that bad

fiery turtle
#

lol

#

its just a different design decision

#

and it was made for linux ig

leaden fox
fiery turtle
#

sorta

#

acpica has native linux support scripts inside the repo

#

and headers as well

#

you can kind of upstream support with your headers if your os is popular

calm latch
#

(could someone with a fast CPU test it?)

gentle peak
#

1.35M on my 5800x

#

using qemu-system-x86_64 -accel kvm -cpu host,migratable=off -M q35,smm=off -drive format=raw,file=pmos-hyper.img (yes i know it's i386)

#

do you have an x86_64 image for comparison?

calm latch
#

no

#

i mean yes

#

i need to fix it

left orbit
#

on my system i get this

#

i think this one is a hard outlier meme

gentle peak
#

what the fuck that's faster than proxima and it's running in userspace

left orbit
#

hold on

fiery turtle
#

pmos i386 is now the top of the leaderboard lmfao

gentle peak
#

actually it probably wouldn't be faster than proxima if proxima didn't suffer from the intel lock cmpxchg shit

calm latch
#

i need to add fast (or rather not insanely slow) ipc stuff to x86_64 and check if it gets the same performance...

left orbit
#

it varies wildly but i think it's due to wsl, mostly consistent around 5.5-6M

calm latch
#

like to see if this performance is credible

gentle peak
#

i need to resume work on sirius (my i386 os) damn

fiery turtle
#

is this speedup really due to this being i386

#

like cache locality and stuff

gentle peak
#

probably not

fiery turtle
#

proxima doesnt use ipc at all and it gets less

calm latch
#

and also temp mapping are 2 tlb misses instead of 4

#

hold on let me fix x86_64 build

#

(I don't even know if it compiles)

#

Also I have some "temporary" chatgpt generated code in timers, so they could be broken

left orbit
#

☠️

fiery turtle
#

inb4 this is actually 800K

calm latch
#

It was giving about the same score as 64 bit build on my PC though

#

(about 1.3M on 5900X)

gentle peak
#

i'm looking at your malloc source code and it looks like you're using spinlocks for malloc

#

which could be where the speedup comes from, since spinlocks generally don't suffer from the intel cmpxchg shit

calm latch
#

i'm using spinlocks everywhere

calm latch
fiery turtle
#

dont spinlocks need cmpxchg as well

calm latch
#

It's slow on AMD

gentle peak
calm latch
#

oh

fiery turtle
gentle peak
#
while (!xchg(&lock->state, true)) pause();
fiery turtle
#

oh

gentle peak
#

also i have no idea why the difference between intel and amd is so huge there

#

like sure iretq's cpu is quite a bit better than ryzen 5xxx but it's not 7 times better

calm latch
#

some memory memes?

#

what if I use hhdm? thonk

#

(anyway, I'm trying to build the 64 bit image)

left orbit
#

how can you not use cmpxchg for spinlocks?

#

what difference does that make

left orbit
#

you still need to know if it was previously locked or not

calm latch
#

cache invalidation?

gentle peak
#

whatever intel's doing with cache coherence for lock cmpxchg absolutely destroys performance

left orbit
#

cmpxchg does the compare for you

fiery turtle
gentle peak
#

and it doesn't do the same for xchg

left orbit
#

cmpxchg compares and then exchanges them, so you dont get the old value but you get the flags

#

also i dont see why you couldn't use xchg for whatever else you want to implement

#

and i think that the slow down might come from the lock prefix, but i am unsure lol

gentle peak
#

xchg has implied lock

#

you're right that it comes from the prefix (normal cmpxchg doesn't have the problem) but xchg with a memory operand implies lock so

frank canopy
#

yep

#

xchg always has a lock per the docs

dense steppe
#

This is my memory allocator fastpath now. I haven't looked at the assembly for the old thing, but I'd assume it is a fair bit worse than this.

Anyway, this makes basically no difference in the benchmark 😭

frank canopy
#

and yeah xchg true works for a spinlock because if its already true then the swap has no semantic effect

left orbit
frank canopy
#

i use bit test things for mine because i want my spinlocks to be true 1-bit so i can have them ORd with an align > 1 pointer

calm latch
dense steppe
calm latch
gentle peak
#

that'd be interesting to compare

#

that one gives me the same score as the 32 bit image so i doubt it has much to do with bitness

dense steppe
#

world record

calm latch
#

do you have tsc on?

dense steppe
#

oh. forgot -cpu host,migratable=off

#

now it is more reasonable

#

sometimes getting speeds around 3.6M, sometimes 1.4M

#

host CPU scheduling skill issue

calm latch
#

Which CPU is it?

calm latch
hallow marten
#

mount the iso and copy the files

calm latch
#

windows is refusing to mount it

#

it's just a fat32 partition

gentle peak
#

which one is it?

calm latch
#

devicesd.elf

gentle peak
calm latch
#

thx

gentle peak
#

also idk if you're already aware but the 2nd partition on that image (the ext2 one) is malformed

#
[277050.930059] EXT4-fs (loop0p2): mounting ext2 file system using the ext4 subsystem
[277050.930062] EXT4-fs (loop0p2): bad geometry: block count 16384 exceeds size of device (16256 blocks)```
calm latch
#

i was not, but I didn't get to write the filesystems stuff yet

dense steppe
#

apparently half the cores (the ones with extra L3) run at a lower clock speed

#

but also my host runs some CPU cores at lower clock speeds when they are not under load, I think

#

This is a major source of Davix uACPI benchmark skill issues

left orbit
#

you can use taskset to pin a task to a certain cpu

#

BUT idk if that works with qemu kvm

dense steppe
#

yeah

calm latch
fiery turtle
dense steppe
#

I should probably setup libvirt

fiery turtle
#

a vpcu is just a thread

#

*vcpu

dense steppe
#

yeah

calm latch
left orbit
dense steppe
#

a vcpu is just a host thread that calls ioctl (kvmfd, KVM_RUN) or something

fiery turtle
#

thats pretty cool

fiery turtle
left orbit
#

close enough

calm latch
calm latch
left orbit
#

sure 1s

#

that an hdd image too?

calm latch
#

yes

fiery turtle
calm latch
#

No

left orbit
#

i get this pretty consistently

calm latch
#

Idk what does that mean

fiery turtle
#

how do u make sure u dont truncate anything when returning stuff to a 32-bit program

calm latch
#

The kernel knows that the process is 32 bits and expects arguments to be in different registers

calm latch
#

through registers

#

that fits into 32 bits registers as well

fiery turtle
#

yes but lets say it does an mmap

gentle peak
#

do you also do stuff like making sure pointers stay within 4G?

fiery turtle
#

u have to make sure to have an upper bound at 4g

gentle peak
#

damn nice

fiery turtle
#

yeah

calm latch
#

I have a function which checks the limit

#

(Which also changes for 3/4/5 paging levels with 64 bit stuff)

#

(on risc-v, since the x86_64 paging code is a mess and doesn't support that)

#

Like I do 3/1 split on 32 bit kernel, and full 4GB is available with 64 bit one

dense steppe
#

anyway I wrote some code to collect slab_alloc statistics, and here are the results. notably nr_expensive_free is very high.

#

I should totally write some code to only actually free objects in a background worker thread or something

#

I seem to be getting relatively consistent results in the 2.2M-2.3M range (so long as the guest is scheduled on the correct host CPU cores)

calm latch
#

(also this is the full build, which doesn't exit(1) after loading acpi namespace if someone's interested)

gentle peak
#

the PS2 driver seems nonoptimal

calm latch
#

idk interrupts are half-broken

gentle peak
#

i get 1.8M on that build

fiery turtle
#

maybe if u use spinlocks in your allocator youd speed proxima up on iretq's cpu as well

left orbit
#

you must optimize for intel

gentle peak
#

oh definitely

#

here's a main branch build with spinlock heap, and its results on my cpu:

uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 7933442/s)

#

oh that's with cmpxchg spinlocks so not even the best it can get

left orbit
#

7.9M is crazy

gentle peak
#

interestingly using just plain old xchg for spinlocks destroys perf on AMD

left orbit
#

lol classic

#

proxima malware

gentle peak
#

drat

dense steppe
#

jesus fkn christ I'm trying to upload an image of my kernel for you guys to test but am having severe network skill issue or something

#

it takes ages to upload a 10.27MB file

left orbit
#

WINDOWS SECURITY

#

AMAZING

#

BLACK BOX

#

I LOVE WINDOWS

dense steppe
#

can someone with less host cpu skill issues than me run this? qemu-system-x86_64 -cdrom bootable.iso -enable-kvm -cpu host,migratable=off -M q35 -debugcon stdio

#

finally it fkin uploaded

left orbit
#

weird

gentle peak
#

ah

#

how about the cmpxchg one? (the first one)

left orbit
#

WHY IS EVERYTHING A VIRUS TODAY

calm latch
dense steppe
left orbit
gentle peak
#

apparently yeah

dense steppe
# gentle peak

wtf how do you have more host cpu skill issues than me?

gentle peak
dense steppe
gentle peak
#

normal cmpxchg, apparently?

dense steppe
#

slowpath for completeness:

/**
 * Slowpath for spinlock acquisition. Implements TTAS semantics.
 */
static inline void
spin_lock_slowpath (spinlock_t *lock)
{
        for (;;) {
                do
                        arch_relax ();
                while (atomic_load_relaxed (&lock->value));

                if (spin_lock_fastpath (lock))
                        break;
        }
}
dense steppe
#

oh btw my allocator is lock-free in the fast-case (nr_quickbin_hit and nr_quickbin_free)

dense steppe
left orbit
#
[    0.128253] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6364623/s)
[    0.127614] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6361916/s)```
#

13700k

gentle peak
dense steppe
gentle peak
#

i thought that was an indicator that something was wrong which is why i included them

#

ah

dense steppe
#

but it doesn't matter since it doesn't execute any PCI stuff for the benchmark

left orbit
#
[    0.128499] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6210795/s)
[    0.129090] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6347728/s)
[    0.128887] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6377479/s)
[    0.127661] uACPI: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6365027/s)```
dense steppe
left orbit
#

pretty much consistent except for wsl mishaps as usual

#

but i filter those out

fiery turtle
#

bruh everyone is getting 7mil these days

dense steppe
#

yeah lol

fiery turtle
#

i remember when 400k was a lot

dense steppe
#

except on my CPU

calm latch
left orbit
#

oh i don't think so ☠️

#

i haven't managed to replicate that

#

tbh i haven't seen wsl issues affect the score positively

#

so that must have been a fluke on your side

#

idk how that could have happened though

gentle peak
#

@left orbit as a sanity check, could you test these two? the first is the latest non-rewrite CI build, and the second is the exact same except built on my machine

left orbit
#

man i just wish it wasn't a frickin virus 😢

#

let me just wget in wsl

gentle peak
#

they both get ~7.5M/s on my machine

gentle peak
#

anyway yeah i wish windows's "this might be a virus" notifications were based on more than just "oh this hash hasn't been downloaded a lot"

left orbit
#

they are though

dense steppe
#

this doesn't make much of a difference for me

#

(Ryzen 9 7950X3D)

#

(I also added builtin_expect to __spin_lock)

left orbit
#

anyway, both isos get me around 5.3-5.5M

gentle peak
#

what the fuck

#

does intel have some sort of special optimization for cmpxchg-store

#

none of these mutexes are contested, the only difference should be 1 cmpxchg 1 store vs 2 cmpxchg

#

last one before i give up looking for this issue: this one uses acquire for lock and release for unlock instead of acq-rel for both

#

i seriously doubt that'll do anything but it's the only thing i can think of

left orbit
#

this is like +50-100K

#

maybe less not very consistent

gentle peak
#

as i thought

#

i have one more thing to try but it's gonna take a bit to implement

#

let's see how this worked again

left orbit
#

holy

dense steppe
#

I haven't looked that much at the paper

#

but what I implemented with quickbins today is similar to how I imagine magazines to be

fiery turtle
#

10M here we come

dense steppe
#

1020M when

gentle peak
#

i think i'm gonna do per-thread magazines because my {enable,disable}_preempt is slow and it's not like i'm gonna keep this around when i'm already in the middle of a rewrite

left orbit
#

per thread?

#

wtf

fiery turtle
dense steppe
#

how would you allocate like the lists for storing objects?

gentle peak
#

i'll probably implement it in the new kernel as well but rn i'm working on the old one just trying to see how high i could get

dense steppe
#

just statically in struct task?

gentle peak
frank canopy
dense steppe
#

yep. ok

gentle peak
frank canopy
#

ah ok

gentle peak
#

unlocked cmpxchg is completely broken on any multiprocessor system

#

because it's not atomic

frank canopy
#

ah

dense steppe
fiery turtle
# dense steppe ~~10~~20M when

i could hit 20M with computed gotos in uacpi interpreter potentially, but thing is those are GCC specific i think and they require everything to be in a switch, which would destroy stack usage in debug mode

#

maybe some smart object caching could help, but i doubt it would win over a ~100ns allocator

dense steppe
#

wtf are computed gotos? I've probably heard of them but with a different name

gentle peak
frank canopy
dense steppe
frank canopy
#

called that because its an asm jump to a switch case

#

good for interpreter loops

gentle peak
# frank canopy ah

cmpxchg itself is atomic as in a single instruction, but not atomic as in other processors and/or devices only see either the full outcome or none of it

dense steppe
gentle peak
#

cmpxchg on multi-processor systems can spuriously succeed

frank canopy
dense steppe
frank canopy
#

iirc

dense steppe
#

quite a lot of nr_expensive_free

#

and those take a lock

fiery turtle
#

i like these stats u added

#

always appreciate detailed stuff like that

dense steppe
#

I just wanted to know how often the fastpath is hit

slim panther
#

oh wait

#

@fiery turtle does uacpi_kernel_io_map map unaligned addresses?

fiery turtle
#

it's an io address

#

like port io

gentle peak
dense steppe
#

the slowpath steals a page from the slab->pg_full_list and slab->pg_partial_list if there any one. otherwise it allocates one. then it populates the entire magazine and returns one object

dense steppe
#

well

#

it depends on how many slabs you have

gentle peak
#

i know

#

oh this is the number of objects in the magazine per slab

dense steppe
#

yeah

#

I have something similar

#

but I set it to min(31, objs_per_page - 1)

#

for reasons

gentle peak
#

so in total it's 3072 rounds

fiery turtle
#

thats a minigun magazine

dense steppe
#

hopefully it isn't too unreadable

dense steppe
# dense steppe

the slow case (nr_quickbin_miss and nr_expensive_free) is probably a lot slower than 20ns though

fiery turtle
#

nooo yet another tabs user

dense steppe
#

sorry :p

#

and also yet another tabs=8spaces user

#

but like wtf. why is my kernel getting like 6M on intel and 2M on AMD?

#

gotta do -mtune

calm latch
gentle peak
#

oh this is just my luck

#

with magazines it's slower because none of the init that runs before uacpi allocates objects from the same slab as uacpi mainly does

#

i can probably minimize the impact but it's certainly not going to be faster

calm latch
#

(that is 32 bit uACPI/devices server and 64 bit everything else)

hallow marten
#

for me magazines noticeably improved single-threaded performance

gentle peak
#

it probably does once your allocator has been used a bit

#

but uacpi inits too early for that to be the case

hallow marten
#

well then it's the same as allocating from a slab

#

then subsequent allocs will be from the cpu cache

gentle peak
#

do you allocate an entire magazine if the magazine is empty? i'm going off of the vmem paper which just lets it fill up as objects get allocated

hallow marten
#

I do whatever solaris does

dense steppe
#

well tbh they aren't that hard

gentle peak
#

my allocator is tiny it'd only take me like 10m to fully rewrite it

hallow marten
gentle peak
#

not that hard to add stuff onto

hallow marten
#

solaris does fancy dynamic resizing

#

based on lock contention

dense steppe
#

(will not do it regardless, because it seems hard)

hallow marten
#

so yea it likely improves performance

#

and memory usage

#

but this is for high scalability stuff, idk how useful it is here

dense steppe
#

I get like 2.4M vs 2.3M when the guest is scheduled properly by the host

gentle peak
#

ok i fully copied the strategy documented in the vmem paper and it did indeed improve performance

#

but not by much

#

it went from like 7.5M to 7.7M

#

if i init uacpi 10 times i get 9M on the final one

slim panther
#

💀

calm latch
#

vmem is cool though

gentle peak
#

if you want to see perf for the first of the eleven runs, -debugcon stdio

#

uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 9112238/s)
this is on my cpu

fiery turtle
#

Insane

gentle peak
#

the way i've implemented it (thread-local caches) is incredibly stupid if you want actual overall benefits, so i won't be pushing it to git and i won't be submitting it to the leaderboard

#

but it is technically leaderboard-valid so it's fun to see the performance

left orbit
#
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6390171/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6718073/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6768290/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6726713/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6456621/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6670396/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6754508/s)
uacpi: info: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 6782695/s)```
north holly
#

do you guys have nothing better to do for your OSes?

gentle peak
#

damn, that's worse than i expected

torpid root
gentle peak
fiery turtle
left orbit
#

hey it's an improvement over what it scored on my pc previously lmao

gentle peak
#

yeah but like

gentle peak
#

the later runs should take almost 0 locks in the allocator

left orbit
#

oh i just took the ones from debugcon

gentle peak
#

they're the right ones

#

dw

left orbit
#

ah

slim panther
#

okay uh

left orbit
#

well i mean i only get one run per boot so

gentle peak
#

only reason i said to use debugcon is because the older runs would get wrapped off of the screen

slim panther
#

@gentle peak you might want to see this

gentle peak
#

oh that shouldn't happen

slim panther
#

guess how fast it is on my machine

left orbit
#

oh ☠️

#

thats why

gentle peak
slim panther
#

13

gentle peak
#

DAMN

left orbit
#

hooooly

north holly
slim panther
fiery turtle
#

What the hell

slim panther
#

i thought i couldn't read correctly

gentle peak
#

it doesn't even have line numbers

left orbit
#

just look at the disassembly

#

ez

slim panther
#

yea okay there is literally no beating that lmfao

fiery turtle
#

Monkuous u should upstream this

gentle peak
#

now i wonder, what if i combine this with illegal techniques?

slim panther
fiery turtle
#

So no one can ever beat proxima

slim panther
#

if i do userspace uacpi do i get to use sse

gentle peak
#

yes

fiery turtle
#

Yeah

slim panther
#

😃

#

i think my current bottleneck is my PMM

#

it's a bitmap atm

fiery turtle
#

💀

slim panther
slim panther
gentle peak
#

i'm gonna try regardless

fiery turtle
#

Shouldn't have pinned it since monkuous ain't submitting it

slim panther
#

oh

#

removed

fiery turtle
#

Kinda

gentle peak
# left orbit oh ☠️

i might be completely wrong on this but just looking at the disassembly this might be a uacpi bug actually, because it's lock cmpxchg with dest=0, which shouldn't be possible unless uacpi locks a mutex or spinlock whose kernel api create call returned null

slim panther
#

i guess i should do a buddy allocator?

dense steppe
#

either buddy

#

or just a linked list

#

both are fine

fiery turtle
gentle peak
#

magazine memory usage idk

fiery turtle
#

Hm

#

If it is I wanna know where

gentle peak
#

it's in ensure_register_mapped.part.0.lto_priv.0 but i have no idea what that exactly means for the location

#

and as i said this build doesn't have line info

slim panther
gentle peak
#

it might also be memory corruption, i only realized this just now for some reason

dense steppe
#

though it is possible to implement bitmap buddies, although those are weird

gentle peak
#

@left orbit what qemu options did you use?

#

i wanna try and repro it locally

left orbit
#

qemu-system-x86_64 -debugcon stdio -cpu host,migratable=off -M q35 -enable-kvm -cdrom "proxima3.iso" | grep '1705 ops'

fiery turtle
#

I mean u did speedrun them basically lmao

gentle peak
#

ty

#

oh yeah repro

#

that's nice

fiery turtle
#

Nice

gentle peak
#

i wonder what triggers it since that's basically the same as my command line

#

ok with -M q35,smm=off it works

#

that's very strange

fiery turtle
#

💀

left orbit
#

good to know we found the cause

dense steppe
#

tbh I'm surprised that my allocator rewrite worked like the first time.

#

like

gentle peak
#

if you want to test perf that's the flag to use

left orbit
#

gaming rn

#

ill test later

gentle peak
#

alr

dense steppe
gentle peak
#

now the question: is this reproducible in debug mode

#

it is not

#

fuck

fiery turtle
#

Memory corruption nooo

#

Or ub ig

gentle peak
#

or (and this is very heavy cope) the slightly inflated kernel binary size triggered the oom

fiery turtle
#

Lol

gentle peak
#

oh wait no i lied it is reproducible in debug mode

#

i just accidentally passed smm=off

fiery turtle
gentle peak
#

not on TCG though unfortunately

#

still i can work with this

dense steppe
#

what if you give the VM absurd amounts of memory? like qemu -m 48G?

gentle peak
#

still happens so not an oom

fiery turtle
#

Just a guess but

#

Smm off might force qemu into acpi mode by default

#

So uacpi won't try to switch back on reset

#

Which would skip that path

gentle peak
#

don't think that's the case

#

also i found a typo: uacpi_deininitialize_registers

#

deininit

fiery turtle
#

Guess not

gentle peak
#

oh wait

#

i put a hlt loop in uacpi_initialize_registers and it doesn't get called in the second iter

#

ininit*

#

oh wait it just doesn't get to the second iter

#

nvm

fiery turtle
#

Tier?

#

Nvm

gentle peak
#

yeah ok i just confirmed it is indeed a uacpi bug

fiery turtle
#

Bruh not again

#

What is it

gentle peak
#

uacpi_deininitialize_registers gets called before uacpi_leave_acpi_mode, which uses g_reg_lock but that's already freed by said deinit

dense steppe
#

damn UAF

gentle peak
#

not really since deinit also sets it to null

dense steppe
#

ahh

#

still

fiery turtle
#

How does that not crash like always

gentle peak
#

but if it weren't for that it'd be uaf yeah

gentle peak
fiery turtle
#

My tests do

#

Oh wait

#

I pass NO_ACPI_MODE

gentle peak
#

do your tests simulate needing to leave acpi mode?

#

ah

fiery turtle
#

fuck

#

Good catch

gentle peak