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

1 messages Β· Page 15 of 1

fiery turtle
#

especially since most stuff is stubbed to a no-op

dusky glade
#

i have a feline

#

feeling*

#

not cat

#

wtf

fiery turtle
#

lol

slim panther
#

what do i pass to table_find

vagrant hull
#

thing is

#

i do not have a monotonic timer

fiery turtle
slim panther
#

doesn't work

fiery turtle
#

show code

vagrant hull
#

i should maybe just return rdtsc

dusky glade
#

@slim panther

fiery turtle
slim panther
fiery turtle
#

_by_signature

dusky glade
#

uacpi_table_find_by_signature

slim panther
#

ah

dusky glade
slim panther
#

wait and how do i convert this to the actual table

vagrant hull
#
    panic("The Nyaux Kernel does not support Devices without a HPET\nThe "
          "Reason for this is becausei hate tsc with a burning desire. pr in a "
          "different calibration timer if u want one so bad lol");```lol
slim panther
#

is there a hpet_table struct?

dusky glade
#

😑

fiery turtle
north holly
dusky glade
#

was i on a sleep tablet when i wrote that

#

πŸ’€

fiery turtle
#

were you high when writing that

dusky glade
#

no

#

but the sleep med i take before i go to sleep

#

gives me a eurphoic response as a side effect

#

before it makes me sleepy

vagrant hull
#

i had cleaner hpet code in some other project

#

i need to find it

fiery turtle
#

hpet works but tsc + kvm_clock is lightning fast and accurate

vagrant hull
#

ok not that clean

dusky glade
#

im cold

vagrant hull
#

im hot

dusky glade
#

im hotter

#

:^)

vagrant hull
#

i am actually hot tho

dusky glade
#

damn

#

how

#

its winter lol

vagrant hull
#

yeah

#

i started wearing a heavier tshirt than usual

#

and it doesn't take much for me to start feeling hot

dusky glade
#

oh understandable

#

mint do u have portal 2

vagrant hull
#

i think so

dusky glade
#

play co-op with me

vagrant hull
#

no i need to wire this hpet thing in

dusky glade
#

no one is gonna play co-op with me

north holly
rustic compass
#

does uacpi have a stripped down version that only contains the table api? i want to put uacpi in userspace but need some tables at boot and dont want to have uacpi two times

fiery turtle
#

well early_table_access mode exists, which only needs map and unmap, but there isn't a mode which removes references to other apis

#

i had that feature idea for later

rustic compass
#

its still a bit until i need uacpi, maybe by the time thats supported

fiery turtle
#

right now u can stub out all other api to just be unimplemented and it will work fine technically

#

if you use LTO it will probably remove all other code

rustic compass
#

does uacpi move the tables or just copies them to an internal buffer?

fiery turtle
#

neither

#

the internal buffer stores state needed to access those tables

#

like the virtual address where they're mapped, reference count etc

rustic compass
#

so it preserves the tables in memory?

fiery turtle
#

yeah

rustic compass
#

so that two instances could access it

fiery turtle
#

yeah ofc

vagrant hull
#

is 100MHz the right hpet freq for qemu?

dusky glade
#

idk about mhz but for nanoseconds for me its 1 hpet tick per 10ns

slim panther
#

@fiery turtle success! need to impl the rest

fiery turtle
#

nice nice

mortal yoke
vagrant hull
#

ty

fiery turtle
#

bro good thing i decided to integrate uacpi into linux

#

it found actually important warnings

#

like functions that should be static not being static

vagrant hull
#

i do believe this is accurate

loud ice
#

5M? nice

#

damn

vagrant hull
#

well sort of

#

i have mutexes stubbed out

loud ice
#

ahhhh

#

that's gonna be a massive difference

vagrant hull
#

eh idk

#

i don't even have mutexes in this kernel

loud ice
#

but you do have spinlocks right?

vagrant hull
#

yeah

fiery turtle
vagrant hull
#

wdym how?

loud ice
#

what if you take a spinlock instead of a real mutex acquire

median crest
#

Mint secretelt has a phd

fiery turtle
vagrant hull
vagrant hull
fiery turtle
#

wtf

#

do u have a fast memcpy?

vagrant hull
#

it's the most simple C memcpy ever lol

loud ice
#

something seems not quite right

fiery turtle
#

^

vagrant hull
#

i am returning time like this, idk, maybe it's an issue? c uacpi_u64 uacpi_kernel_get_nanoseconds_since_boot(void) { return hpet_read_counter() / (1000000000 / hpet_frequency); }

#

hpet_frequency is in Hz

#

read_counter() reads the main hpet counter straight from mmio

dusky glade
vagrant hull
#

what's the issue?

loud ice
#

your calculation seems to be a little bit off

loud ice
#

oh wait

#

thats ns not us

vagrant hull
#

yeah

loud ice
#

your clock runs 100 times fast

vagrant hull
#

how come

dusky glade
#

this is how i do it

#

@vagrant hull

vagrant hull
#

hm

#

i already have the frequency in Hz though

dusky glade
#

ctr clock period is in nanoseconds

vagrant hull
#
    uint64_t counter_clk_period = tmp >> 32;
    hpet_frequency = 1000000000000000 / counter_clk_period;```
dusky glade
#

i use this division

vagrant hull
#

qwinci said it's right

#

it's in femtoseconds no?

dusky glade
#

yea

vagrant hull
#

then it's right?

dusky glade
#

huh

loud ice
dusky glade
#

wait thats not volatile

#

mmio gets weird when stuff isnt volatile

#

i would know

vagrant hull
#

it's volatile

dusky glade
#

okay

vagrant hull
loud ice
#

the correct way to calculate it is hpet_ticks() * ticks_per_ns

dusky glade
#

^

loud ice
#

ticks_per_ns = 1e9 / freq_in_hz

dusky glade
loud ice
#

so the correct value is hpet_ticks() * 1e9 / freq_in_hz

fiery turtle
#

omg uacpi leaked so may internal symbols

#

thank god i tried linux

dusky glade
#

fix them infy

#

lol

fiery turtle
#
ld: (.text+0x6331f3): undefined reference to `uacpi_kernel_free'
ld: (.text+0x633205): undefined reference to `uacpi_kernel_free'
ld: (.text+0x633216): undefined reference to `uacpi_kernel_free'
ld: (.text+0x633223): undefined reference to `uacpi_kernel_free'
ld: (.text+0x63337a): undefined reference to `uacpi_kernel_alloc'
ld: vmlinux.o: in function `uacpi_free_namespace_node_info':
(.text+0x6334aa): undefined reference to `uacpi_kernel_free'
ld: vmlinux.o: in function `uacpi_device_matches_pnp_id':
(.text+0x633550): undefined reference to `uacpi_kernel_free'
ld: (.text+0x633578): undefined reference to `uacpi_kernel_free'
ld: (.text+0x633585): undefined reference to `uacpi_kernel_free'
ld: vmlinux.o: in function `uacpi_get_pci_routing_table':
(.text+0x633a75): undefined reference to `uacpi_kernel_alloc'
ld: (.text+0x633bd1): undefined reference to `uacpi_kernel_free'
ld: vmlinux.o: in function `uacpi_free_pci_routing_table':
(.text+0x633dea): undefined reference to `uacpi_kernel_free'
ld: vmlinux.o: in function `uacpi_free_dynamic_string':
(.text+0x633e1a): undefined reference to `uacpi_kernel_free'
dusky glade
#

oh my god

fiery turtle
#

now to implement these

fiery turtle
dusky glade
loud ice
#

uACPICA when

slim panther
#

i have this lol

        return hpet.regs->main_counter * (hpet.period / 1000000);
dusky glade
#

im not saying oh my god to that

dusky glade
#

😎

loud ice
#

though i'd calculate hpet.period / 1... statically

#

the best way to do it is to do what i do iirc

fiery turtle
#
drivers/acpi/uACPI/source/utilities.c:931:26: error: no previous prototype for β€˜find_one_device’ [-Werror=missing-prototypes]
  931 | uacpi_iteration_decision find_one_device(
      |                          ^~~~~~~~~~~~~~~

This warning should really be enabled everywhere

loud ice
#

or actually idk if i do it

median crest
#

Just use kvmclock and get a free nanosecond clock troll

dusky glade
loud ice
slim panther
dusky glade
#

NYAUX IS CLOSE TO YOU

vagrant hull
#

not sure

fiery turtle
#

now thats more accurate

loud ice
dusky glade
#

HEAR ME ROAR MINT NYAUX WILL DESTROY CYNIX INTO THE GROUND

vagrant hull
#

seems a bit low

slim panther
#

i will submit a benchmark later

loud ice
#

theres no way you are doing 5 million though

fiery turtle
#

^

vagrant hull
#

i mean i am also surprised if i do 5 mil

#

but 50k seems a bit low too lol

#

both values seem off

dusky glade
fiery turtle
#

with a bitmap allocator its imaginable

dusky glade
#

with nyaux

#

and obos

loud ice
#

yeah i'd assume thats why its slow

dusky glade
#

btw nyaux has a optimized memcpy and memset

#

well for x86

#

obos could never

slim panther
#

menix has phd memcpy

dusky glade
mortal yoke
slim panther
dusky glade
loud ice
#

its a phd memcpy so it must be good

#

also lets go pitust shitos 10000 uacpi race edition

#

how do i make an iso again

mortal yoke
vagrant hull
#

the timer seems 10 times off

#

10x off

#

but whatever i have to go

#

bbiab

loud ice
#

bye

median crest
#

Cya

dusky glade
dusky glade
mortal yoke
#

it doesn't really matter

dusky glade
#

what if statement should i check for how big of a count

mortal yoke
#

though tbf the rep overhead for small copies doesn't likely matter that much anyway

dusky glade
#

so

dusky glade
#

anwer

#

bro i cannot spell

#

help

median crest
#

Just rely on memory being already initalized with the values you want and panic otherwise

mortal yoke
#

probably something around 128 or whatever

dusky glade
#

easy

torpid root
dusky glade
#

basically

loud ice
#

okay step 1 hello world OS works

#

time for step 2 uacpi os

dusky glade
#

bro forgot step 1.5

#

do u know step 1.5

#

actually no u need to do step 0.5

loud ice
#

i know your step 1.5 of adding 10 memory corruption bugs

dusky glade
dusky glade
#

everyone had that phase ngl

#

or ask chatgpt to generate ur entire kernel

torpid root
#

my step 0.5 was learning c

dusky glade
north holly
dusky glade
#

😑

north holly
#

I have an optimized memcpy, memset, and memcmp

#

As well as a stable kernel

median crest
#

Stable

north holly
#

Stable enough

#

Rather

#

Doesn't crash when you blow on it once

#

Only when you mess with code that you shouldn't mess with

#

Or mess with code with // Abandon all hope, ye who enter here

dusky glade
#

😑

north holly
#

Plus I am optimizing this soon

#

As in profiling the kernel

#

To see what is so slow

fiery turtle
#

i think most submissions are now done so I'll probably close the initial list in like 3-4 hours

loud ice
#

lmfao rust's shitty compiler-builtins doesnt support __popcountdi2 because its not called by llvm apparantly?

#

lmao

mortal yoke
#

(when its not supported natively, if there is the popcnt instruction then it will use that)

loud ice
#

oh huh

#

interesting

#

i just called rust count_ones

#

which doesnt generate the call

#

i think

#

hopefully lol

#

okay

#

i now have uacpistub os

fiery turtle
#

that could actually be very useful

loud ice
#

lol torture test

dusky glade
#

why rust @loud ice

fiery turtle
#

he wants his os optimized out

torpid root
#

when the compiler inlines everything into a single function

loud ice
loud ice
#

least schizo rust code

torpid root
#

It will make my score surpass managarm!

fiery turtle
#

i can wait for a bit if you're actually serious

torpid root
#

I wish I was

#

technically I am but I don't think much will be changed

fiery turtle
#

u can always add in the updated score later

#

but if u actually finish it today ill add it

north holly
fiery turtle
#

no

#

stubbed apis are not allowed

north holly
#

Meh

#

Bah

vast kestrel
#

I wonder if its possible to somehow hack it so uacpi will have an arena

fiery turtle
#

i mean if u make a private heap for uacpi probably

vast kestrel
#

well, some things change global context

north holly
#

Wassan arena

vast kestrel
#

I guess not really, since anything changing the namespace will have to be kept

fiery turtle
#

yea

dusky glade
north holly
#

Obos will beat you all!!1!!!!!!!!11

#

(soon enough)

torpid root
#

osdev teams up to get obos to be faster than managarm

fiery turtle
#

microsoft with 1B dollar sponsorship to get obos to 5M/s

mortal yoke
#

just run it on a good enough computer meme

north holly
#

And so do I

#

I avoid reading most obos code

mortal yoke
#

lol

loud ice
fiery turtle
#

Big

mortal yoke
# mortal yoke lol

I think my "worst" code is my page allocator mostly because originally it had fine-grained locking but then I just slapped a giant lock over the whole thing after I realized there were issues with the locking

#

but otherwise its fine I think

north holly
#

My worst looking code is probably everything

median crest
#

My biggest issue is vmm and mutex probably

loud ice
north holly
north holly
#

In the part that loads kernel symbols into a tree

mortal yoke
#

I like this part of my kernel troll

mortal yoke
#

jump to higher half + stack pointer adjust for hhdm

loud ice
#

lmfao

#

wait

#

what

#

oh

#

ohhhh

#

but why

#

this is maximum ub

#

unless arch_start is an assembly self-relocator

gentle peak
#

I'm pretty sure there's a double-release bug here

#

don't see how it could be an issue in my kernel, but can anyone confirm? seems like it happens if uacpi_kernel_install_interrupt_handler unconditionally returns an error

mortal yoke
# loud ice unless arch_start is an assembly self-relocator

the way it works is that I rely on the compiler generating relocation-less pie code with -fno-PIE for the entry code (before that asm) and the base of the kernel is set to higher half in the linker script so the functions/globals after that are at the correct addresses

north holly
#

*mutex

#

Wait I don't

vagrant hull
#

whatever i'm back

north holly
#

I just return success if the lock is already released

gentle peak
fiery turtle
mortal yoke
# loud ice bad

it works tho, idk if there would have been any other way to do it without needing a prekernel

gentle peak
#

This one has all the line numbers

fiery turtle
#

Thanks for spotting

vagrant hull
mortal yoke
fiery turtle
#

So u get 500k/s?

#

Granted your mutexes are stubbed

vagrant hull
#

i wouldn't say that yet

#

but i believe so

#

i need to make sure i am doing time properly

gentle peak
#

anyway, i'm pretty satisfied with this performance considering i started this kernel rewrite literally today

loud ice
#

500k sounds fine i think

fiery turtle
#

Wanna get added to notable projects?

loud ice
#

@fiery turtle am i allowed to call the handler immediatly in uacpi_kernel_schedule_work?

slim panther
loud ice
#

assuming im not in an irq context

vagrant hull
loud ice
#

did you do the "spin in a loop for 1 second worth of hpet ticks" thing

vagrant hull
#

i am just printing it over and over and it does 1 billion ticks per second

fiery turtle
#

I think I designed it specifically so lazy impl like that should work

gentle peak
fiery turtle
#

Ah ok

vagrant hull
#

that it does 1 billion ticks a second

fiery turtle
#

He prints frequency in his logs

#

It does

vagrant hull
#

alrighty

#

if i do nothing uacpi uses the memcpy and friends i provide right?

fiery turtle
#

So yeah its probably the bitmap holding you back

fiery turtle
vagrant hull
#

so how do i make it use my memcpy

fiery turtle
#

Take a look at libc.h

vagrant hull
#

tedium

slim panther
#

why not ship a hyper optimized memcpy KEKW

fiery turtle
#

Indeed

vagrant hull
#

do i really have to do -Duacpi_memcpy=memcpy???

fiery turtle
#

No

#

Make a uacpi_libc.h

mortal yoke
fiery turtle
#

^

vagrant hull
#

πŸ’€

fiery turtle
#

What lol

vagrant hull
#

a bit clunky

#

but sure

fiery turtle
#

Taking suggestions

vagrant hull
#

like i wouldn't provide the impls at all

#

everyone should realistically have those functions anyways

loud ice
#

yeah

#

its also forbidden to not have those functions afaik

#

because gcc/clang will call them anyway

vagrant hull
#

the mem* ones yes

fiery turtle
#

Maybe but whenever I want to port uacpi its annoying af to implement all missing ones

loud ice
#

for memcpy on gcc i believe theres some funny meme you can do

vagrant hull
#

then at least do that for the mem* ones

fiery turtle
#

Id rather have my own trusted ones by default than have some beginner complain about uacpi bugs

slim panther
#

aren't you forced to have memcpy for struct derefs?

loud ice
#

yeah

#

you are

slim panther
#

because

my_struct = *struct_ptr;

invokes memcpy

fiery turtle
#

Yeah its called implicitly for some stuff

#

Which uacpi doesnt do

loud ice
#

imo you should default to calling memcpy anyway

fiery turtle
#

Yup

vagrant hull
#

you know what may slow down my impl

#

a lot

#

the fact that i memset allocations to 0 always

#

and that i poison frees

fiery turtle
#

Definitely

loud ice
#

probably lol

vagrant hull
#

and that the memset is naive

loud ice
#

do you have profiles?

vagrant hull
#

no

#

i mean i can use the qemu profiler actually

#

i have it here in the repo handy

#

let's see

fiery turtle
#

Oh nice

#

First actual profile

#

Everyone else has been improving by trial and error LULW

loud ice
#

lol

#

damn i should have kept it to myself

fiery turtle
#

True

median crest
#

I wanted to use that shell script profiler but uacpi was too fast

loud ice
#

do it in a loop meme

fiery turtle
#

U can technically

#

Idk if that would confuse qemus firmware or not

vagrant hull
#

idk

#

uacpi and my kernel as well are too fast for this script, mathew is right lol

loud ice
#

tbh yeah

#

i think llenotre's qemu instrumentation thing might work?

#

idk

#

or alternatively you could try copious amounts of dtrace?

vagrant hull
#

or try without kvm actually lol

fiery turtle
#

Yeah actually

vagrant hull
#

it seems like a lot of time is spent in vmm.c

fiery turtle
vagrant hull
fiery turtle
#

i dont understand why it enters this branch

vagrant hull
#

what's weirder is that tcg does 44k?

#

how can tcg do 44k and kvm 50k lol

fiery turtle
#

that means u cause a lot of vmexits probably

vagrant hull
#

yeah

#

which is kinda weird honestly

fiery turtle
#

usually kvm vs non-kvm is 10x

#

for this bench

median crest
#

Check for lots of cr8 writes or something

slim panther
#

@fiery turtle why is thread_id a void*?

fiery turtle
#

its whatever u set it to

#

platform/arch_helpers.h or whatever

slim panther
#

ah

#

where is it used

fiery turtle
#

recursive mutexes

#

why do u ask btw, are your thread-ids non representable as void*?

gentle peak
slim panther
#

no they are, they're just usizes and i thought maybe you want a thread pointer

fiery turtle
vagrant hull
#

replacing the mem functions with rep movsb and friends barely made any difference

fiery turtle
#

thanks

slim panther
#

ah no, different problem

#

the scheduler doesn't run at that point

#

so no tids

fiery turtle
slim panther
gentle peak
fiery turtle
gentle peak
#

i'm logging all calls to unimplemented functions, and that's the only one that gets logged, and it gets logged right before the panic

fiery turtle
#

install_interrupt_handler is called during uacpi_initialize()

#

strange

gentle peak
#

set a breakpoint, this is the very first call to the function

fiery turtle
#

nvm i dont know how uacpi works apparently lmao

#

fair enough i must've moved it at some point

#

will fix it shortly

vagrant hull
#

ok i made it not poison on frees and not zero on allocs when not needed, and now it's 64k

#

idk, i have a feeling the allocator is not the issue

median crest
#

Stub out some uneeded you figure out whats the issue functions one by one until

slim panther
#

@fiery turtle how can i wire up an interrupt handler? the function signature doesn't match the one from uacpi

vagrant hull
#

realistically, how allocation heavy is this?

slim panther
#

but that only works for one handler?

fiery turtle
vagrant hull
#

is this allocation heavy to the point where things like cache locality and whatnot start to matter?

loud ice
#

holy shit my kernel is so fast!1!!!!11

fiery turtle
fiery turtle
loud ice
#

(i always return 0 in my timer shit)

loud ice
#

lol

slim panther
#

probably not

loud ice
#

ok whats the default tsc rate

gentle peak
#

whatever your host is

fiery turtle
slim panther
#

i do i think

vagrant hull
#

i had a slab allocator but i removed it because i figured i did not need it

slim panther
#

probably wrong

fiery turtle
#

Whats data?

slim panther
#

priv basically

fiery turtle
#

Thats fine

slim panther
#

okay

loud ice
#

okay i have a real timer

#

debug build is at 50kops

#

time to stick -O3 on it

loud ice
#

doesnt help

fiery turtle
fiery turtle
median crest
#

I had seen no diff between O2 and O3 in astral too

loud ice
#

i was at -Copt-level=1 before tbh

#

so its not super shocking

#

also i have stubbed mutexes still

fiery turtle
#

Ah

loud ice
#

and i think i have some UB somewhere

#

okay i turned off spammy e9 logging and now its at 83

#

this is all tcg btw

fiery turtle
#

Try kvm?

loud ice
#

gotta move it to my other laptop first

fiery turtle
#

Should be about 800k

loud ice
#

okay time for the memcpy meme

fiery turtle
#

Not bad for a 3 hour old kernel

loud ice
#

lmfao

vagrant hull
loud ice
#

its full of stubs

vagrant hull
loud ice
#

im on 909

fiery turtle
loud ice
#

i wonder how much of that is just my shit ass malloc

#

which isnt optimized for performance by far

vagrant hull
#

run-to-run variance

loud ice
#

holy shit the variance of this is bad yeah

#

okay then lets kill factorio

#

i think this is the most i see

#

probably just the fact that my cpu is worse than mint's at least somewhat

#

and my probably worse allocator

vagrant hull
#

the slab allocator i backported still zeroes out on all allocs so

loud ice
#

oh and i fill allocations

#

ah yeah same

#

actually i double clear on zeroed allocs

#

but yeah this is kinda a bad test just because its way too fast

vagrant hull
#

maybe with more AML

#

i'll try ovmf

loud ice
#

do they have more?

#

ugh i dont want to deal with ovmf

#

and i dont want to deal with graphics rendering either

median crest
#

Mint's cpu and qwinci's cpu are 3x faster than mine on the benchmark lol

vagrant hull
#

eh i just tried, it's about the same

#

with ovmf

loud ice
#

how much do i get? qemu-system-x86_64 -hda bs/reblast.iso -M q35,smm=off -cpu host,tsc-frequency=1000000000 -d int -accel kvm -debugcon stdio

vagrant hull
#

on mine?

loud ice
#

yeah

vagrant hull
#

aight one sec

loud ice
#

thanks

vagrant hull
#

uacpi: successfully loaded 1 AML blob, 1702 ops in 0ms (avg 1854648/s)

loud ice
#

damn

#

thats the power of stubbing absolutely everything, i guess

calm latch
#

Btw, linux (https://www.kernel.org/doc/Documentation/virt/kvm/timekeeping.txt) says this

The TSC is a CPU-local clock in most implementations. This means, on SMP
platforms, the TSCs of different CPUs may start at different times depending
on when the CPUs are powered on. Generally, CPUs on the same die will share
the same clock, however, this is not always the case.

loud ice
#

okay so now question

#

how do people make their shit faster

#

i guess faster malloc?

#

hmm lets try that

vagrant hull
#

i actually don't even remember why i removed the slab allocator

#

damn i get 1.6 mil consistently now

#

all i did compared to before is allow 2048 byte allocs to also go via slabs

gentle peak
#

qemu kvm: 1705 ops, 1088140 ops/s
real hw (haswell mobile cpu): 4962 ops, 122947 ops/s
i wonder why the difference is so big?

loud ice
#

you dont do as many expensive ops on real hw

#

also wtf my code is broke now

gentle peak
vagrant hull
#

does uACPI map and unmap the same regions often?

gentle peak
#

does that really just come down to how much better my host system's cpu is?

loud ice
fiery turtle
loud ice
#

any reason you cant do that?

fiery turtle
#

A lot of factors

fiery turtle
loud ice
#

oh i guess you need to actually make sure its mapped

gentle peak
loud ice
#

just map all of physmem

gentle peak
#

but yeah probably just firmware devs being as good at writing AML as they are at writing firmware (not very)

vagrant hull
# loud ice any reason you cant do that?

well, as per base revision 3 of the Limine protocol, and because of the fact that you should always map stuff that isn't usable memory and friends, i do map it, in hhdm, but i do map it

fiery turtle
#

Yeah thats why we test on qemu so we have the same aml for all

slim panther
#

@fiery turtle in kernel_install_interrupt_handler, is ctx optional?

vagrant hull
#

so yeah i was wondering that because checking if it was already mapped and not mapping it in that case may speed things up

#

if the same regions are mapped over and over

fiery turtle
#

Its uacpics context for that irq

slim panther
#

i probably have to modify my irq implementation, right? i can only pass one thing as a context

#

i'm confused

fiery turtle
#

That it wants to be passed to its handler

fiery turtle
vagrant hull
#

alright i get 2.5 mil now

#

does that beat astral yet?

gentle peak
fiery turtle
vagrant hull
#

slab allocator + allow 2k slabs + don't zero out unless calloc

fiery turtle
gentle peak
#

yeah pretty close

fiery turtle
#

Depends on the blob I guess

vagrant hull
#

yeah it's about the same as astral

#

no mutexes though

fiery turtle
#

3M+ is PhD territory

gentle peak
#

I do think QEMU uses faster ops because it's faster even though anything that would be a vmexit on there is much cheaper on actual hw

fiery turtle
vagrant hull
#

idk what my mutexes would even be, other than spinlocks without cli/sti

fiery turtle
#

Once you implement them

vagrant hull
#

because there are no kernel facilities atm

#

yeah

fiery turtle
#

Yeah

vagrant hull
#

slab allocators are pretty cool

fiery turtle
#

Indeed

slim panther
#

what exactly does the interrupt handler return

fiery turtle
#

Handled/not handled

slim panther
#

ah

#

i did this

loud ice
#

how do you select the slab bucket?

fiery turtle
#

Ever heard of a thing called struct lol

loud ice
#

im gonna assume its something smarter than just a loop?

vagrant hull
#

lol

loud ice
#

ah huh

slim panther
#

tbh i could also do a [static 2]

loud ice
#

wtf why is my slab so much worse then

#

or what else is the problem?

#

maybe my malloc is crap?

vagrant hull
#

sloob

#

i may honestly just make the code public idc

fiery turtle
#

Pog

vagrant hull
#

it's not much but it's honest work

calm latch
#

Where do I look for documentation on kvm-clock?

#

I hope it's not linux source

fiery turtle
#

Mathwend recently implemented it you might want to ask him

slim panther
#

womp womp

fiery turtle
fiery turtle
median crest
slim panther
#
[    0.080972] [      0] acpi: successfully loaded 1 AML blob, 1816 ops in 50ms (avg 36304/s)
#

woe

calm latch
vagrant hull
fiery turtle
vagrant hull
#

no license, all rights reserved :^)

fiery turtle
#

I like how it just has uacpi libc in root

vagrant hull
#

yeah

gentle peak
vagrant hull
#

i thought it was mmio

fiery turtle
#

pio ofc

vagrant hull
#

damn

#

so like

#

how

#

then what the hell is it the same for kernel_io_map?

#

that makes no sense

gentle peak
#

kernel_io_map is for probably for platforms where "PIO" is just MMIO with an offset

vagrant hull
#

so is io_map supposed to be a no-op in my case?

fiery turtle
#

For kernel level x86 drivers yeah

vagrant hull
#

the thing is that io is quite confusing, if it was pio i would've understood it better, but io could be mmio

fiery turtle
#

Well there's already a memory read

vagrant hull
#

(i thought it was mmio)

#

i mean sure

#

i just thought it was more of the same :^)

fiery turtle
#

Its called SystemIO in ACPI

#

So I just went with it

#

But yeah

vagrant hull
#

meh

#

MS isn't the best at naming

fiery turtle
#

Tru

#

Now to rewrite your manual rsdp walk code ultrameme

slim panther
#

what does uacpi use the pci_{read,write} fns for?

fiery turtle
#

PCI_Config opregions

#

Basically aml

slim panther
#

can i guarantee that these functions will be called after e.g. mcfg enumeration

fiery turtle
#

They won't be called before namespace_load

slim panther
#

okay good

fiery turtle
#

During namespace load its only allowed to read bus 0

#

After that from any other

slim panther
#

get owned

torpid root
#

that shrimply doesn't work on my kernel

#

some addresses are not mapped, or I forgot to map them somewhere

median crest
#

I play safe and barely rely on the hhdm outside of physical memory

slim panther
#

i forgot to have a mapping api for the kernel

calm latch
gentle peak
#

from the docs it seems like it's something that can be triggered by AML

#

(the raw_io family explicitly says it can't be triggered by AML, and the normal io family does not)

calm latch
torpid root
slim panther
#

@fiery turtle what page protection does kernel_map need? RW?

calm latch
#

RO crashes it

slim panther
#

k

#

we're up to 63k

fiery turtle
slim panther
loud ice
#

tcg?

slim panther
#

what's that

loud ice
#

are you using qemu with TCG on

slim panther
#

i'm getting a pretty consistent average of 90k

loud ice
#

or KVM

slim panther
#

kvm

loud ice
#

holy fuck what are you doing

#

im getting 90k on TCG

#

admittedly i cant call my thing a kernel

slim panther
#

how do i do tcg

loud ice
#

-accel tcg

#

its the slow one

slim panther
loud ice
#

lol

loud ice
#

more like 900k

#

are you sure your timer logic is correct?

slim panther
#

weird

#

p much

#

let me time

loud ice
#

does it match rdtsc with -cpu host,tsc-frequency=1000000000 (which makes it a nanosecond-precision timer)

calm latch
#

uACPI: cutting edge timer stress test

slim panther
#

actually, maybe the timer is a bit slow

#

it's like 80% real time

#

it's not very precise lol

#

i told it to wait 1 second

#

maybe it's the printing

loud ice
#

your drift is 1ms per second?

#

so margin of error

slim panther
#

ah yea via serial is much better

loud ice
#

thats 200us yeah

#

you are sleeping comparing against TSC?

slim panther
#

hpet meme

loud ice
#

ah

slim panther
#

my timer is accurate so far though

#

idk why it's so slow :(

#

@loud ice what's your qemu command

loud ice
slim panther
#

nope, still 90k

#

funnily enough with fb enabled it's faster somehow

#

over serial it's only 36k

#

yea no, i can't get past 90k

#

without kvm i get 30k

gentle peak
#

is the irq passed to uacpi_kernel_install_interrupt_handler a GSI or an ISA IRQ? if it's GSI, how do you determine whether it's active low/high and level/edge triggered?

north holly
#

*gsi

#

And the ioapic redirection table entry things tell you

#

The trigger mode and polarity

gentle peak
#

like, the ones already in the ioapic registers, which were written by firmware?

#

i'd prefer not to rely on those if possible

gentle peak
#

interrupt source overrides? those are only for isa irqs

mortal yoke
#

usually the irq passed to that function is an isa irq

#

I think its also allowed to be a gsi tho (likely only on platforms where there is no legacy pic at all)

north holly
#

Eas

#

*was

mortal yoke
fiery turtle
#

Its usually overridden in madt so be careful

gentle peak
#

alright thanks

#

yeah that's why i asked, i wanted to know if i needed to check the isos

fiery turtle
#

Usually the polarity changes

#

I think

gentle peak
#

on qemu it seems to be active-high

#

but it does change it to level triggered

fiery turtle
#

sounds correct

dusky glade
#

@calm latch pmOS powerbutton works just fine

fiery turtle
# gentle peak set a breakpoint, this is the very first call to the function
--- a/source/namespace.c
+++ b/source/namespace.c
@@ -194,11 +194,14 @@ uacpi_status uacpi_initialize_namespace(void)

 void uacpi_deinitialize_namespace(void)
 {
+    uacpi_status ret;
     uacpi_namespace_node *current, *next = UACPI_NULL;
     uacpi_u32 depth = 1;

     current = uacpi_namespace_root();

+    ret = uacpi_namespace_write_lock();
+
     while (depth) {
         next = next == UACPI_NULL ? current->child : next->next;

@@ -233,6 +236,9 @@ void uacpi_deinitialize_namespace(void)
         // This node has no children, move on to its peer
     }

+    if (ret == UACPI_STATUS_OK)
+        uacpi_namespace_write_unlock();
+
     uacpi_object_unref(g_uacpi_rt_ctx.root_object);

can you please test if this fix works

gentle peak
#

yep, that fixed it

fiery turtle
#

nice

gentle peak
#

one interesting thing i noticed: when booting with ovmf instead of seabios, uacpi is consistently faster by ~100k-200k ops/s (consistently 1.2-1.3M/s on ovmf, 900k-1.1M/s on seabios)

fiery turtle
#

different aml perhaps?

gentle peak
#

doubt it, they both have exactly the same number of ops (1705)

fiery turtle
#

ohh

#

then its probably an artifact of memory map layout differences

fiery turtle
#

This is the final call for anyone who wants to make it to the initial uacpi notable project & leaderboard list

#

ill be finalizing that pr shortly

#

@jaunty fox would you like to be mentioned? you have a pretty good score meme

jaunty fox
#

though i am wondering what the test methodology is

#

who carries them out?

fiery turtle
#

the person with the fastest cpu ideally

#

aka leo

slim panther
fiery turtle
#

1M+ i guess

slim panther
#

what are the bottlenecks again

fiery turtle
#

u can see current results in the pr

#

allocator and mem* seem to affect it the most

mortal yoke
#

also ubsan

slim panther
#

wait memset too?

#

omw to phd memset

#

but tbh my allocator might be my bottleneck

#

shitty little slab

north holly
#

Is mimalloc any good

slim panther
#

wait

#

is there any kernel api function invoked during parsing?

fiery turtle
#

u mean namespace_load?

slim panther
#

during the benchmark test or w/e

fiery turtle
#

like every

slim panther
#

because if so i know what's bottlenecking it lmao

#

im printing a todo message on every call

#

rofl

fiery turtle
#

that costs a lot yeah

slim panther
#

let me remove it

loud ice
north holly
#

Hmm maybe I will try porting it to obos

#

To see the speed difference

slim panther
#

@fiery turtle that did it

#

me when i bottleneck myself meme

torpid root
#

nice

#

you have a bit more ops than others though

#

generally it's 1704/1705

slim panther
#

could that because i have some qemu devices?

torpid root
#

if they interface with acpi then probably yes

slim panther
#
qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.4m.fd -machine q35 -cpu max -name "menix x86_64" -serial stdio -no-reboot -no-shutdown -m 2G -smp 16 -drive format=raw,file=fat:rw:build/install,if=none,id=fatfs -device virtio-gpu -netdev user,id=net0 -device virtio-net,disable-modern=on,netdev=net0 -device nvme,serial=deadbeef,drive=fatfs -enable-kvm
fiery turtle
slim panther
slim panther
fiery turtle
#

kinda, yeah

#

not actually implementing an api is sort of cheating

#

because u avoid quite a lot of work

slim panther
#

i think i have everything besides mutexes

#

because i don't have mutexes

fiery turtle
#

even io read and stuff?

torpid root
#

is it cheating if I do something like not zero out allocated memory when trying to get the highest score possible?

#

but keep that memset in the kernel afterwards

gentle peak
#

like, not zero out memory allocated by calloc?

slim panther
#

i have allocations, raw mem rw, raw io rw, pci rw, io map, timer, spin, interrupts

torpid root
gentle peak
#

i don't think that'd be cheating, normal malloc isn't required to be zeroed

torpid root
slim panther
#

lol

#

idk how to design a nice mutex interface

#

though a mutex makes little sense at the time where i'm calling uacpi_init

#

it's the only process that's running then

#

1.9 mil meme

north holly
#

damn me

fiery turtle
slim panther
#

idk

#

maybe the timer is being bad again

#

oh yea no it tried to configure lapic without hpet galaxybrain

#

okay 1.9 might have been bogus, but i can reliably get 1.1-1.4M

calm latch
#

Why CPU do you have?

slim panther
#

ryzen 7700x

#

actually, i should probably also phd the memset

mortal yoke
#

if you have a rep movsb/stosb for them then doing anything else is unlikely to make them a lot faster

slim panther
#

i dont

#

i had a for loop

#

i set bytes so the address is qword aligned, then i do qword copies for memcpy

loud ice
#

dont bother aligning

#

afaik its slower to spend time aligning than you actually gain

slim panther
#

does that work on arm

loud ice
#

yea

mortal yoke
#

with mmu + cache enabled yes

loud ice
#

if you have the mmu or caches off what the fuck are you doing

#

i believe windows does this btw

mortal yoke
loud ice
mortal yoke
#

yes but if you want to do that in eg. c/c++ or whatever

loud ice
#

you cant

mortal yoke
#

you can

loud ice
#

you cant while writing sound code

#

compilers are allowed to perform unaligned reads

mortal yoke
#

you can disable that

#

-mno-unaligned-access

loud ice
#

cringe

#

and a perf penalty for the whole kernel

#

for the 1 line you save for caches

#

i believe its only caches too

slim panther
#

okay the new memset got me +100k

gentle peak
#

for anyone trying to maximize their score, here's some very rudimentary profiling data

slim panther
#

howd you do that

loud ice
#

so alloc, calloc, free

#

plus memcpy and memset

gentle peak
loud ice
#

now record the call stack and see what allocates the most meme

gentle peak
#

worth doing tbh but i feel like at that point it'd be easier to hook up a proper profiler

loud ice
#

its not really super feasible sadly

#

just because your sample rate is way too low

mortal yoke
# loud ice i believe its only caches too

maybe I should move the cache code to the startup asm in my kernel KEKW I could also implement the entire thing in asm (so I wouldn't have to rely on the compiler generating relocation-less pie code) but I don't like writing paging code in asm

gentle peak
loud ice
#

but its entry only i believe

#

i use it btw

gentle peak
loud ice
#

idk its -Zinstrument-mcount in rust

#

so i figure its something like that in c

mortal yoke
gentle peak
mortal yoke
#

they don't

gentle peak
#

ah it's -finstrument-functions

loud ice
#

ah

slim panther
#

okay i believe now it's just my allocator slowing things down :(

north holly
#

and I don't really know how to get it to work

#

in a kernel

#

properly

jaunty fox
#

if i log in uacpi_kernel_map it cuts me from
[uacpi]: successfully loaded 1 AML blob, 2356 ops in 1ms (avg 1857465/s)
immediately to
[uacpi]: successfully loaded 1 AML blob, 2356 ops in 2ms (avg 836618/s)

slim panther
#

yea i had the same issue

#

i was dangling around 60k because i logged "todo" on every unimplemented fn

#

without i'm at 1.3mil

gentle peak
#

so i believe i avoided that in the data

#

but yeah it's a huge perf drain if you're logging a lot

#

for anyone that wants to make their own profiling data, here's the code i used: https://hst.sh/uqegidozov.cpp
it's not particularly optimized because i just wanted to get it implemented quickly, but none of the expensive parts are measured in the actual data (unless your profiled functions call other profiled functions)

gentle peak
#

fixed a bug that caused the heap to expand on each allocation, and uh...

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

#

that's a bigger improvement than i thought it'd be

slim panther
#

wtf

gentle peak
#

this is with 0 stubs btw, each kernel api func is fully implemented

slim panther
#

what allocator do you use?

fiery turtle
#

u sure your time keeping is accurate?

gentle peak
fiery turtle
#

how are you so fast

fiery turtle
kindred beacon
fiery turtle
#

whats your cpu?

gentle peak
# slim panther what allocator do you use?

pmm: simple free list, not even buddy (all physical allocations that are more than 1 page use a separate api that only works during early boot)
heap (objects <=PAGE_SIZE): allocations are rounded to the next highest power of two (using __builtin_clzl). a separate free list is maintained for each power of two, which is expanded directly from the pmm
heap (objects >PAGE_SIZE): allocations are rounded to a multiple of PAGE_SIZE, vmm does the rest (irrelevant for this benchmark since there's only 1 "large" allocation that uses this)

slim panther
#

oh okay

gentle peak
slim panther
#

i'm using a (less opimal) slab allocator

gentle peak
# fiery turtle how are you so fast

i think the speed is a combination of four factors:

  • good cpu
  • my allocators are designed to only do the bare minimum required to be usable and reliable, which makes them simple and fast
  • memcpy/memmove/memset are rep movsb and rep stosb
  • my kernel does a lot of allocating and freeing before uacpi init, so my small object allocator's free lists are already populated. i suspect it can always or almost always go through its fast path
slim panther
#

hm

#

what's this rep movsb memcpy i keep seeing?

vagrant hull
#

that's weird

gentle peak
#

"modern" cpus (this was introduced over a decade ago) have a feature that optimizes rep stosb and rep movsb

#

they're pretty much the fastest memcpy/memset you can get (excluding SIMD which isn't usable in kernels)

gentle peak
vagrant hull
#

ah

gentle peak
gentle peak
fiery turtle
#

ah

#

well congrats on the first place with insane lead

dusky glade
#

bro beats phd code

gentle peak
frank canopy
#

incredible

gentle peak
#

still, managarm is a microkernel, isn't it? if that 3.2M figure is uacpi running in userspace, that's more impressive than my monolithic stuff imo

vagrant hull
#

i don't think it's in userspace

vagrant hull
#

not sure, but i clearly remember lai being in thor

fiery turtle
#

@gentle peak would you post your iso so people can test on different cpus?

jaunty fox
#

my best result yet is [uacpi]: successfully loaded 1 AML blob, 2356 ops in 0ms (avg 2586007/s) but usually it's more 1.8 to 1.9mil

slim panther
#

i'm getting a very reliable 1.3mil

gentle peak
#

some real hw benchmarks:

  • Haswell laptop (Intel i5-4200M): 579037/s
  • Same system as before but on bare metal (Ryzen 5800X): 3880858/s (I suspect the lower result is because linux puts the CPU onto a higher frequency)
jaunty fox
slim panther
#

yea

vagrant hull
#

it's what was mentioned before

#

like different firmware AML doing different things (and definitely more than QEMU's AML)

jaunty fox
#

he should be someone that runs probably gnu/linux so KVM can be used and he should have an invariant TSC

vagrant hull
#

he?

jaunty fox
fiery turtle
#

leo meme

#

leo's cpu doubled astral numbers last time

median crest
#

astral?

fiery turtle
#

was it not astral?

jaunty fox
#

leo is also acceptable

median crest
#

leo had worse perf

fiery turtle
#

oh damn

median crest
#

did you mean qwinci

fiery turtle
#

qwinci had the highest?

median crest
#

qwinci and mint left me at 2.4mil

fiery turtle
#

i mean the leaderboard specifies which cpu was used so its not like super unfair

slim panther
#

still not really useful

#

there might also be other factors in play

jaunty fox
gentle peak
#

The command line I used for measuring was qemu-system-x86_64 -accel kvm -cpu host,migratable=off -M q35,smm=off -cdrom proxima.iso

fiery turtle
#

but if qwinci or mint are down to measure everyone's iso i dont mind it

vagrant hull
#

i can

jaunty fox
#

with keyronex tests i see a lot of intertest variability (probably the same will be true of other kernels, i will check this proxima one next) so whoever is testing should be mindful of it

slim panther
#

i don't have an iso sadmeme

gentle peak
vagrant hull
gentle peak
#

in case it makes a difference for comparison

fiery turtle
#

this is probably important as well

jaunty fox
fiery turtle
#

now im sad its proprietary

gentle peak
#

its like, extremely simple

fiery turtle
#

but i guess can still be on the leaderboard