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

1 messages · Page 23 of 1

left orbit
gentle peak
#

then your cpu doesn't support the same features as mine

left orbit
#

How

gentle peak
#

it's compiled with -march=native -mtune=native and a hardcoded xcr0 value after all

left orbit
#

i mean maybe if u enable avx512 or some shit

fiery turtle
left orbit
#

i do

fiery turtle
#

Also wsl2 disables some stuff

left orbit
#

fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni vnmi umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities

#

it does avx2

#

sse4_2

fiery turtle
#

Hm

#

Thats wsl2 right

#

Not the nested vm

left orbit
#

yeah

gentle peak
#

xcr0 state enabled: x87, sse, avx, pkru

left orbit
#

but i don't imagine any of that disappears when it is nested

#

wtf is a pkru

gentle peak
#

idk something my generic xsave code detected my cpu supports

left orbit
#

lmao

gentle peak
#

so it became the thing i hardcoded

fiery turtle
#

Private key something

#

Lmao

left orbit
#

yeah that works

#

10.4M

fiery turtle
#

L cpu

#

Broooo

gentle peak
#

hmmm what more can i stub out

fiery turtle
#

Can u boot into Linux and run under native kvm?

fiery turtle
gentle peak
#

i think i've stubbed out everything i can that still gets called during uacpi init

#

now time to try the uacpi_reset trick

fiery turtle
#

Just reset in a loop until the score is satisfactory trl

left orbit
#

10.79M

#

dangerously close to 11M

gentle peak
#

that definitely did something but it's supposed to warm up 10 times before doing the final init

gentle peak
#

thats what im trying to figure out

left orbit
#

12M lol

fiery turtle
#

Inb4 uACPI bug again

#

New record lmao

gentle peak
#

ah its both a uacpi bug and a proxima bug

left orbit
fiery turtle
#

Whats the bug?

north holly
left orbit
#

proxima

#

time to take this iso onto bare metal

north holly
fiery turtle
#

This is avx in kernel

left orbit
#

or do you want me to wait for a new one?

gentle peak
#

uacpi bug: uacpi_state_reset doesn't uninstall the sci interrupt handler (i set a breakpoint in uacpi_kernel_uninstall_interrupt_handler and it never got triggered)
proxima bug: pic_install_vector only works the first time it's called

#

or well

#

alloc_irq_vectors to be exact

gentle peak
#

yeah now its just this (running in debug mode + tcg that's why the numbers are low)

fiery turtle
#

Still hangs?

gentle peak
#

see the last message

fiery turtle
#

Ah

#

U can stub this for the purposes of testing tbh

gentle peak
#

yeah i'm adding a manual uninstall in the warmup code

winter orbit
#

it is

fiery turtle
#

Nice

gentle peak
#

seems after the first time it has minimal impact

left orbit
#

lmao thanks for reassuring

dusky glade
fiery turtle
left orbit
#

record!!

gentle peak
#

oh no absolutely not

fiery turtle
gentle peak
#

this is incredibly hacky

fiery turtle
#

Lmao

dusky glade
#

no 2

#

i never ran finalize gpe init

#

do i nee dto run that

gentle peak
#

legacy, ioapic, etc

dusky glade
#

oh okay

left orbit
gentle peak
#

i dont know if its necessary but i do it

left orbit
#

what could go wrong.

dusky glade
fiery turtle
fiery turtle
dusky glade
fiery turtle
#

Monkuous laptop has them, but its an old mechanism

#

They're also needed for suspend etc

dusky glade
gentle peak
dusky glade
#

i dont have uacpi_finalize_gpe in scope

fiery turtle
gentle peak
dusky glade
gentle peak
dusky glade
#

thanks

fiery turtle
#

Bro can't git grep

dusky glade
#

there we go

left orbit
#

bare metal proxima

dusky glade
#

bro doesnt know im in his walls

left orbit
#

lots of tables

#

ALASKA

fiery turtle
gentle peak
#

but yeah solid

north holly
gentle peak
#

i wonder what it's like on my dev system

fiery turtle
#

12 blobs and 30k ops

left orbit
#

i wanna run the final image u sent.

gentle peak
#

is that the mutex stub + half-leaking allocator + AVX2 in kernel ISO or is it the normal one

fiery turtle
#

Probably a better bench than qemus blob

#

But alas

left orbit
dusky glade
gentle peak
dusky glade
#

i actually added something that i think will make nyaux faster tho

#

hold on lemme pull out ze iso

#

if im wrong hang me to the floorboards

fiery turtle
#

Inb4 100/s

gentle peak
#

@fiery turtle do you thinnk i should rip out the 10+ inits before testing this on bare metal or do i just go for it

north holly
#

rip out the 10+ inits

fiery turtle
#

Worst case it reboots

#

Nothing a power cycle won't solve

north holly
left orbit
north holly
fiery turtle
#

If its a pc I wouldnt worry tooooo much

north holly
#

most laptops' blobs are delusion right?

fiery turtle
left orbit
#

nah i ain't rebooting now

fiery turtle
#

Its just precautions

left orbit
#

too lazy

fiery turtle
dusky glade
#

bench nyaux or begone ur c-c-c-car!

north holly
#

when will I be able to run nyaux in my car

dusky glade
#

soon ™️

gentle peak
#

I'll bench nyaux once I've tested all 3 variants of proxima bare metal

dusky glade
dusky glade
#

monkuous W

median crest
#

my new astral lock is almost done.... soon:tm;

dusky glade
#

im going to steal it

#

™️

fiery turtle
median crest
#

finishing release and will just add a quick lock try later

fiery turtle
#

Which is possible

median crest
#

release is super annoying

left orbit
#

cool i can't even check how fast it went

dusky glade
left orbit
#

serial works

#

uacpi: successfully loaded 1 AML blob, 1705 ops in 101ms (avg 16838/s)

#

how the fufck do u manage that

dusky glade
#

hax

fiery turtle
dusky glade
median crest
dusky glade
#

told u i improved nyaux

#

properity technology

#

properietory

fiery turtle
#

How many orders of magnitude is that from proximas score

dusky glade
#

20c

#

20x*

left orbit
#

about 8

fiery turtle
#

Not bad

dusky glade
#

times

#

faster

left orbit
#

revolutionary

#

BIG

dusky glade
#

!!!!

left orbit
#

nyaux supremacy

dusky glade
#

frfr!!!!

fiery turtle
#

Indeed

gentle peak
#

normal (iso straight from GitHub actions): 10097 ops, 4,737,793/s
crazy (everything except the 10 warmup inits): 6,373,181/s
crazy² (everything): 6,313,331/s

north holly
#

infy can you update me score

gentle peak
#

yes

fiery turtle
#

Damn

left orbit
#

aml fears this man

fiery turtle
#

I wonder if executing it this fast can reveal bugs with missing waits etc

north holly
left orbit
#

yes

#

doesn't everybody use uacpi for that?

gentle peak
gentle peak
#

and right now flexing rights

left orbit
#

either that or runtime allocator tests :^)

north holly
dusky glade
#

im afraid ive been lying to you all...

#

this is the real nyaux score

north holly
#

🤯

dusky glade
#

🤯

fiery turtle
#

Doesnt count

#

Pci unimplemeted

dusky glade
median crest
#

trolled

fiery turtle
#

You'll get em next time

gentle peak
#

on my cpu with kvm: uacpi: successfully loaded 1 AML blob, 1705 ops in 73ms (avg 23342/s)

#

thats nyaux btw

north holly
fiery turtle
#

Thanks for clarifying KEKW

north holly
#

test obos 🥺

fiery turtle
gentle peak
fiery turtle
left orbit
dusky glade
#

i wonder if there is a way to profile nyaux

median crest
#

obos faster than astral before I got my shit together

north holly
dusky glade
dusky glade
median crest
dusky glade
#

a difference in ze skill

left orbit
dusky glade
#

oohhh

north holly
dusky glade
#

im gonna throw the profiler he has in lib

gentle peak
north holly
#

it fluctuate

#

try again

gentle peak
#

no this is consistent

north holly
#

bru

fiery turtle
gentle peak
#

i'll try it on bare metal

fiery turtle
#

Inb4 blows up

north holly
#

I think if I undo my last commit

#

it should speed up

gentle peak
fiery turtle
#

What did u do there

north holly
#

allocator changes

gentle peak
#

but really if 11 uacpi inits don't brick my machine what will

fiery turtle
#

True

gentle peak
fiery turtle
#

Is this also amd?

gentle peak
#

same machine so yeah

#

5800x

fiery turtle
#

Obos doesnt like amd computers

north holly
#

yeah idk why

gentle peak
#

the only Intel I have is my Haswell laptop

#

I'll try it on there

north holly
#

sure

#

all my machines are haswell

fiery turtle
#

Haswell gang

north holly
#

I genuniely have no idea what's so special about amd that it triples before even getting to gdt init

dusky glade
#

yo he good

north holly
#
Arch_KernelEntryBootstrap:
    cmp rsi, 0x554c5442
    je .ok ; should triple fault on failure
    xor rax,rax
    jmp rax ; All hope is lost.
.ok:
    push rdi
    push rsi
; Get a hardware-generated random value.
; If both methods are unsupported, it will fallback to using the default value used.
.rdrand:
    mov eax, 1
    xor ecx,ecx
    cpuid
    bt ecx, 30
    jnc .rdseed
    rdrand rax
    jnc .rdrand
    jmp .move
.rdseed:
    mov eax, 7
    xor ecx,ecx
    cpuid
    bt ebx, 18
    jnc .done
    rdseed rax
    jnc .rdseed```
dusky glade
north holly
#

it does some cpuid

north holly
#

then disables the pic

fiery turtle
north holly
#

sets cr0.wp

#

so I need to wait until the fb gets sober?

fiery turtle
#

Yes

gentle peak
# north holly sure

on said laptop it just hangs until eventually getting to the "insert system disk in drive" bios prompt

#

im beginning to think i fucked up the usb

dusky glade
north holly
gentle peak
dusky glade
#

let me try and add the flag hold on

north holly
#

try uefi ig

gentle peak
#

yeah im on uefi

#

ah. that'd probably be why.

fiery turtle
#

💀

gentle peak
#

it's empty in the iso as well

dusky glade
#

even with the flag @gentle peak

north holly
#

wtf

gentle peak
#

crazy that my main pc triple faults when there's no efi boot image available

gentle peak
fiery turtle
gentle peak
#

idk

dusky glade
#

and i only imported this

#

nothing else

gentle peak
#

those last 2 things are supposed to be in your task_t struct or equivalent

#

but idk what could be causing the syntax error

dusky glade
north holly
#

tho

dusky glade
#

before kentry

north holly
#

and with ovmf

#

cursed iso

gentle peak
dusky glade
#

i dont think clang likes any of this

#

even my language server is not happy

gentle peak
#

i use clang myself

dusky glade
#

its just saying its not allowing the function defination here

gentle peak
#

@north holly now it's stuck on Using AGING PRA

north holly
#

bruh

#

vmm hang

#

it's after the vmm actually

#

I'm gonna send an iso with more logs wait

gentle peak
#

@dusky glade apparently there's a } missing at the end of prof_stop. oops

dusky glade
#

nvm

gentle peak
#

and missing ) at the cursor here

#

i really should've implemented prof_start/prof_stop in my ide instead of in the github gist editor

dusky glade
#

yea

#

current task is not defined

#

last thing its complaining about

gentle peak
#

since you're using global frames/cur_frame just remove the current_task-> parts

dusky glade
#

okay

gentle peak
#

they're supposed to be task-local since they represent the call stack

dusky glade
#

like this?

gentle peak
#

yeah

dusky glade
#

okay

#

that solved it

#

thanks @gentle peak

#

i will now test the profiler

gentle peak
#

@north holly

north holly
#

fuck

#

it hangs in PCI

dusky glade
#

uhhh oop

gentle peak
#

that's what happens when you put them in the header instead of prof.c

dusky glade
#

okay

#

i have an idea

#

called

#

#pragma once

gentle peak
#

that wouldn't fix it

#

you'd still have one declaration per source file

dusky glade
#

nvm ur right

gentle peak
#

and i have that in the form of #ifndef+#define+#endif

dusky glade
#

no 1

#

it died

#

no 2

#

wha

#

why

gentle peak
#

addr2line time

dusky glade
#

i mean i stopped the prof

#

okay hold on

north holly
#

through lspci

gentle peak
dusky glade
#

starting in kentry

north holly
#

that's an hid

#

it's on 00:14.00

gentle peak
#

oh

north holly
#

n'stuff

gentle peak
#

that's USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI (rev 04)

north holly
dusky glade
north holly
#

like bars

#

lspci -v

dusky glade
#

is it something with ze profiler idk

#

also nothing came out of debugcon

#

oh wait need to call prof show

gentle peak
# north holly `lspci -v`
00:14.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI (rev 04) (prog-if 30 [XHCI])
        Subsystem: Toshiba Corporation Device 0001
        Flags: bus master, fast devsel, latency 0, IRQ 28
        Memory at e4620000 (64-bit, non-prefetchable) [size=64K]
        Capabilities: [70] Power Management version 2
        Capabilities: [80] MSI: Enable+ Count=1/8 Maskable- 64bit+
        Kernel driver in use: xhci_hcd
north holly
#

interesting

#

the first thing it does

#

is discovering BARs

#

so that's probably where it hagns

gentle peak
#

it's bar0 if i'm reading lspci -vv correctly

north holly
#

since there should be more logs around the bars of that device

dusky glade
#

@gentle peak this is the results of the nyaux profile before it page faults dying in the scheduler, uhhhh the first function is acpi.c:line 9???

north holly
#

then it hangs reading bar0 thinkong

gentle peak
#

anyway that's sorted by ns/call

dusky glade
#

why is uacpi taking so much ns

#

acpi.c line 9??

gentle peak
#
#!/usr/bin/env python3
import os
import re
import subprocess

with open('dump.txt', 'r') as f:
    text = f.read()

def translate(matchobj):
    addr = matchobj.group(0)
    out = subprocess.check_output(['addr2line', '-f', '-e', 'hydrogen/kernel/hydrogen', addr], stderr=subprocess.DEVNULL).decode().strip().split('\n')
    func = out[0]
    path = out[1].split(':')[0]
    file = os.path.basename(path)
    line = out[1].split(':')[1]
    return f'{func} ({file}:{line} {addr})'

text = re.sub(r'(0x[0-9a-f]*)', translate, text)
print(text)
gentle peak
dusky glade
#

ohhh

gentle peak
gentle peak
#

alright just making sure you didn't miss it

north holly
#

I suspect it hangs reading the size

#

of the BAR

dusky glade
#

more readable

gentle peak
#

here's some alternative impls for pred in prof.c btw ```c
attribute((no_instrument_function)) static bool pred(record_t *a, record_t *b) {
return a->total < b->total; // total time, high to low
}

attribute((no_instrument_function)) static bool pred(record_t *a, record_t *b) {
return a->calls < b->calls; // number of calls, high to low
}```

dusky glade
#

slab allocator is slow?

#

it seems?

gentle peak
#

the time unit there is tsc ticks

#

you may want to add -cpu tsc-frequency=1000000000 to turn it into nanoseconds

dusky glade
#

kinda slow too

#

init hpet is SUPER slow lol

#

anyways we know that nyaux isnt a complete dumpster fire

#

its just

#

slab allocator is REALLY ass

#

like

#

REALLY

#

REALLY REALLY

dusky glade
#

well i was kinda expecting it to be my allocators, not that i have a reason why it would be

#

but

#

it prob cause my code is ass or smt

#

idfk

gentle peak
#

i personally find sorting by total time spent in function more useful, because it also indicates how necessary it is to optimize a given function

dusky glade
#

this shouldnt be THAT slow tho

dusky glade
#
void* slab_alloc(cache* mod)
{
    if (mod->slabs == NULL || mod->size == 0)
    {
        return NULL;
    }
    slab* cur = (slab*)mod->slabs;
    assert(cur);
    while (true)
    {
        if (cur->freelist == NULL)
        {
            if (cur->next != NULL)
            {
                cur = (slab*)cur->next;

                continue;
            }
            break;
        }
        assert(cur != NULL);
        void* guy = cur->freelist;
        cur->freelist = ((pnode*)cur->freelist)->next;
        memset(guy, 0, mod->size);
        return guy;
    };
    assert(cur);
    cur->next = (struct slab*)init_slab(mod->size);
    cur = (slab*)cur->next;
    assert(cur);
    void* guy = cur->freelist;
    cur->freelist = ((pnode*)cur->freelist)->next;
    memset(guy, 0, mod->size);
    return guy;
}
#

like

#

its really just this code

north holly
#

while(true)

dusky glade
#

what u have a better idea

north holly
#

simple != fast

dusky glade
gentle peak
north holly
#

wut

gentle peak
#

acpi init benchmark scrolled away though

#

it got to the panic while trying to load /init

north holly
#

all I did was add more logs thinkong

north holly
#

and send you an iso

dusky glade
gentle peak
north holly
#

only one way to find out

#

maybe it was just a one-time thing, sometimes obos randomly hangs in stuff where it usually doesn't

#

which is usually solved by a reboot

gentle peak
#

it's now having at [ DEBUG ] updating bar 0

#

hanging*

north holly
#

well I'll be damned

#

could this be timing-related?

gentle peak
#

possibly

#

you should add in all the previous messages except replace \n with \r

#

stays on a single line while still doing all the printing

north holly
#

before I do that I want to test something
maybe I get an irq in the middle of the bar being in a weird state, causing a hang

gentle peak
#

i doubt that'd be this consistent

dusky glade
#

i got slab alloc to be a tiny bit faster by removing not needed if statement

#

statements

#

151 instead of 171

#

now

gentle peak
#

what you really have to think about is what the common path is and how much work it's doing on that path

gentle peak
dusky glade
#

it seems the -finstrument flag is causing nyaux to die

gentle peak
dusky glade
#

yea maybe its messing something up with the scheduler

#

and something to be fair

north holly
#

try this

dusky glade
#

nyaux is a TINY bit faster on tcg

#

trying kvm nopw

gentle peak
#

78964/s

north holly
#

yeah the only changes I added there was masking irqs while getting the bar size

dusky glade
#

nyaux running on kvm

gentle peak
north holly
#

maybe it's because of an LAPIC timer IRQ

#

or hpet irq

#

which happen pretty consistently in my kernel

dusky glade
north holly
#

so yeah obos boots on intel cpus, but hates AMD cpus

#

how interesting

gentle peak
#

even more interesting that it works on AMD in KVM

north holly
#

yeah

gentle peak
#

because that functions almost exactly the same as AMD bare metal

north holly
#

the only thing I could think of doing is digging through the AMD SDM

#

for instructions behaving differently

dusky glade
dusky glade
gentle peak
# dusky glade ```C void* slab_alloc(cache* mod) { if (mod->slabs == NULL || mod->size == 0...

refactored it a bit, this does exactly the same but is much cleaner code imo and easier to analyze and reason about and thus easier to optimize ```c
void *slab_alloc(cache *mod) {
if (mod->slabs == NULL || mod->size == 0) return NULL;

slab *cur = (slab *)mod->slabs;
assert(cur != NULL);

while (cur->freelist == NULL) {
    if (cur->next == NULL) {
        cur->next = (struct slab *)init_slab(mod->size);
    }
    
    cur = (slab *)cur->next;
    assert(cur != NULL);
}

void *ptr = cur->freelist;
cur->freelist = ((pnode *)cur->freelist)->next;
memset(ptr, 0, mod->size);
return ptr;

}```

gentle peak
north holly
#

if you wanna do that we can

gentle peak
# dusky glade will try

it should function and perform the exact same, it's just a lot easier to read, analyze, and optimize

gentle peak
north holly
#

it's np

dusky glade
#

nvm its not consisent

gentle peak
#

anyway

#

due to that refactor, i can tell you that the common path should be cur->freelist != NULL

#

so your performance issues are most likely due to something causing that to never happen

#

or almost never anyway

#

is it open source so i can take a look at more of the allocator?

dusky glade
dusky glade
#

heres the link

gentle peak
#

awesome

north hull
dusky glade
gentle peak
#

i think i'm gonna need a debugger for this because i really can't analyze this code purely by source

north hull
#

the low res trollface is fucked

dusky glade
#

for love of god do not look at ioapic.c for love of god do not look at ioapic.c

median crest
#

bruh using my new locks barely changed anything at all wtf is this

north hull
#

DONT LOOK AT SCHED.C

median crest
#

it goes all over the place

gentle peak
#

why does git submodule update --init --recursive not even work

dusky glade
dusky glade
#

i do have a .gitsubmodules

#

dont know why it doesnt work tho

north hull
#

I didnt even do that

#

i just cloned it and it worked

median crest
#

can anyone try this I'm coping that its my computer being bad

#

qemu-system-x86_64 -cdrom astral.iso -M q35 -enable-kvm -cpu host,migratable=off

gentle peak
#

right well the sources are apparently here without updating the submodules so i'm just gonna ignore that

north hull
#

I can throw it on my server

#

sec

dusky glade
#

if u have any questions ping me

median crest
#

bruh it made it even worse

dusky glade
#

oops

median crest
#

kms

gentle peak
#

is the compile_commands.json supposed to be fucked

dusky glade
#

run bear -- make

#

it usually works after that

#

its generated by bear

gentle peak
#
+ clone_repo_commit https://github.com/osdev0/cc-runtime.git cc-runtime 9c281448fe40498a6341d74f55c9af4f642c0b1d
+ test -d cc-runtime/.git
+ test -d cc-runtime
+ set +x
error: 'cc-runtime' is not a Git repository
make: *** [GNUmakefile:161: kernel-deps] Error 1``` fun
#

i just removed the dir

#

works now

lilac knoll
#

this whole thread is really manifesting goodhart's law

north hull
#

@median crest

#

does ur kernel do serial logs by any chance

#

cuz my server is headless

#

lol

median crest
#

I can do e9

#

hold on

north hull
#

❤️

north hull
gentle peak
#

wow it was surprisingly painless to get a vscode debug configuration working

north hull
#

ikr

#

I did it once

#

but then I realized how unergonomic it actually is

median crest
#

kinda funny how my new lock is much better than the old one but did not even affect speed

#

still keeping it though, having a word sized lock is great

gentle peak
#

nyaux with -O0 how fast will it be

north hull
#

how do I get the serial logs to showup again

median crest
#

-debugcon stdio

north hull
#

ah

#

i tried -serial stdio

zenith crescent
#

e9 isn't serial

north hull
#

yeah yeah

north hull
dusky glade
median crest
north hull
#

unfortunate

median crest
#

I need to get a serial driver one dya

zenith crescent
north hull
gentle peak
#

i think make run is tcg too so

median crest
north hull
#

ah

#

wonder why

dusky glade
median crest
#

cuz there is no nvme set up lol

north hull
#

right

#

but why does it require it

median crest
#

its in the boot options

gentle peak
median crest
#

theres also an initrd option but I only shippsed the bare minimum there to make it small

#

bare minimum being not even enough to boot

north hull
#

oh uacpi was loaded

#

im dumb

north hull
gentle peak
#

god okay this is worse than i thought

#

i fixed the main bug causing the slab to be slow

#

(the bug was that each slab only had at most one object on its freelist)

#

but that exposed a bug where too-small slabs were getting picked for allocations, which wasn't caught before since due to the aforementioned bug each allocation was effectively 4k

#

so i fixed that

#

and now there's ANOTHER bug

#

which i haven't investigated yet

dusky glade
#

TF??/

#

explain the bug

gentle peak
#

right so in init_slab you build a new freelist right

#

but you were doing new->next = cur; cur = new; and then not ultimately setting hdr->freelist to cur at the end

#

so effectively the entire freelist was just the first object

gentle peak
#

i fixed it in a slightly different way so that the ascending address order is preserved

left orbit
#

is that nyaux?

gentle peak
#

yes

left orbit
#

damn monkuous turned into a nyaux developer

gentle peak
#

now i'm getting a bunch of USELESS SLAB messages which are (i assume) ruining perf

left orbit
#

that means nyaux is the new kernel we should all be working on

gentle peak
#

@dusky glade with that + the selecting slab bug fixed + removing USELESS SLAB, i get 146061/s on -O0 + KVM

#

on -O2 this is now uacpi: successfully loaded 1 AML blob, 1705 ops in 3ms (avg 505754/s)

dusky glade
#

oh my god.

left orbit
#

holy fuck what

#

how is nyaux doing THIS WELL

#

successfully loaded 1 AML blob, 1705 ops in 3ms (avg 443800/s)

#

how am i slower 😭😭

hollow elm
#

LMFAO

gentle peak
#

here's the patch ```patch
diff --git a/kernel/src/mem/pmm.c b/kernel/src/mem/pmm.c
index 838b4e5..a69ea75 100644
--- a/kernel/src/mem/pmm.c
+++ b/kernel/src/mem/pmm.c
@@ -119,7 +119,8 @@ slab* init_slab(uint64_t size)
for (uint64_t i = 1; i < obj_amount; i++)
{
pnode* new = (pnode*)((uint64_t)first + (i * size));

  •    new->next = (struct pnode*)cur;
    
  •    new->next = NULL;
    
  •    cur->next = (struct pnode*)new;
       cur = new;
    

    };
    return hdr;
    @@ -158,7 +159,7 @@ void* slab_alloc(cache* mod)
    }

       cur = (slab*)cur->next;
    
  •    // assert(cur != NULL);
    
  •    assert(cur != NULL);
    

    }

    void* ptr = cur->freelist;
    @@ -173,7 +174,7 @@ void* slaballocate(uint64_t amount)
    for (int i = 0; i != 7; i++)
    {
    cache* c = &caches[i];

  •    assert(c->size != 0);
    
  •    if (c->size < amount) continue;
       return slab_alloc(c);
    
    }
    return NULL;
    @@ -257,6 +258,6 @@ void slabfree(void* addr)
    }
    if (howmanynodes == guy->obj_ammount)
    {
  •    kprintf("USELESS SLAB\n");
    
  •    //kprintf("USELESS SLAB\n");
    
    }
    }
zenith crescent
left orbit
#

successfully loaded 1 AML blob, 1705 ops in 2ms (avg 809178/s)

#

there we go.

dusky glade
gentle peak
#

yeah

left orbit
zenith crescent
#

oh

#

I didn't read properly

left orbit
#

but like there is a lot of factors at play

gentle peak
#

i figured that was some debug message you put in as a pseudo assert

dusky glade
gentle peak
#

turns out it was more like a todo

dusky glade
#

SLOWED NYAUX INTO ASS

dusky glade
#

thank you @gentle peak

#

actually.

#

2 lines of code

#

slowed down nyaux like crazy

#

your a very smart developer.

left orbit
#

if those kinds of bugs are "hiding" in nyaux

#

literally hiding in plain sight

#

i wonder what other kinds of bugs there are

dusky glade
#

lol

left orbit
#

no like im not even being mean at this point

#

sorry if it sounds like it

dusky glade
#

no u arent dw

#

even im surprised

gentle peak
#

fun fact

#

this is actually the exact same bug i had in one of the first iterations of proxima

#

and fixing it made my perf go from 1.1M to 4.5M

lilac knoll
#

so this is basically an allocator benchmark?

#

did someone try with a bump allocator already

gentle peak
#

slower than proxima due to all allocations being in cold memory

lilac knoll
#

damn

#

that's very surprising

hollow elm
gentle peak
#

@dusky glade is the profiler code in the git repo? or did you take it out before pushing

#

ah nvm found it

left orbit
#

successfully loaded 1 AML blob, 1705 ops in 1ms (avg 956441/s)

#

compiling out all the asserts

#

because for some reason i didn't do that in !debug meme

lilac knoll
north holly
#

if this profiler was able to fix nyaux

gentle peak
north holly
#

surely it can fix me

lilac knoll
#

like roughly, megabytes?

north holly
#

iirc only a few hundred kb

left orbit
#

1835534

#

bytes

#

so about 2mb for the qemu q35 blob

lilac knoll
#

so really a bump allocator is slower nooo

even prefetching the entire memory blob ahead of time?

left orbit
#

or, well, all memory needed to parse the tables and dsdt

dusky glade
#

on tcg

#

oh no

#

on kvm

#

its triple faulting

#

oh fuck

gentle peak
#

so

dusky glade
#

@gentle peak any idea?

gentle peak
#

depends

#

what changes did you make

dusky glade
#

i just applied the patch

#

is all

#

it just triple faults

#

on kvm

#

here

#

consistently

gentle peak
#

like, with git apply?

dusky glade
#

yea

gentle peak
#

then you have the exact same source as me and i'm not getting the bug

dusky glade
gentle peak
#

what command are you using to run?

#

this is my command

lilac knoll
dusky glade
gentle peak
#

bump certainly can't be slower for the allocating itself so the speed diff must be due to cache

dusky glade
#

i dont know whats going on

#

running make clean

#

yep

gentle peak
#

@dusky glade only happens with -smp 20

dusky glade
#

triple faults

gentle peak
#

if it's with -smp 1 it's fine

dusky glade
gentle peak
#

so it's probably a race condition

dusky glade
#

tf...

gentle peak
#

i noticed that your allocator has no locking? or at least none that i could see

dusky glade
#

it does have

#

in kmalloc.c

#

just a global memory lock

lilac knoll
#

and your bump allocator was literally, get a block and increment pointer each time?

I would also try to populate the tlb since tlb refills will be quite slow inside kvm

#

and a bit of prefetching to warm things up

#

that's quite intruiging though, almost makes me want to whip out the performance counters

gentle peak
#

as for prefetching & stuff

#

we tried double init using uacpi_state_reset in between

#

did noticeably improve performance

#

but obv not useful in real world

lilac knoll
#

improve better than the slab?

gentle peak
#

i didn't try that together with bump

#

only together with slab

lilac knoll
#

it is worth checking the performance counters in general though, might reveal useful info

dusky glade
#

this is weird

#

maybe its the same bug that the scheduler to die when u run the profiler

gentle peak
#

@dusky glade your create_region gets called from other cpus and bypasses the global memory lock

dusky glade
#

i dont know

gentle peak
#

at least i think it bypasses the lock

dusky glade
#

u need to call kvm_region_calloc

#

alloc*

#

to call that

#

u need to go through the mem lock

gentle peak
#

ah ok

#

oh for fucks sake kvm why aren't you giving me the rip of the cpu that triple faulted

#

wait @dusky glade that 500k/s measurement was with UBSan enabled, with it disabled it's 1,459,252/s

lilac knoll
#

stonks

dusky glade
#

but we still have a bug

#

cringe triple fault

gentle peak
#

ok i managed to reproduce the triple fault with TCG

#

so i can now actually inspect state

dusky glade
#

how did u reproduce it

gentle peak
#

-smp 255

dusky glade
#

oh i see

gentle peak
#

ran it a few times

left orbit
left orbit
#

don’t u worry

#

but now time for eep

dusky glade
#

get eepy

gentle peak
#

gonna go to sleep now as well

dusky glade
#

general protection fault

#

i see

#

in flanterm @gentle peak ??

#

huh

#

and now its suddenly a segment related issue

#

crazy

hollow elm
#

the address is not likely to match between builds

dusky glade
#

probs not

#

bros some UB

north holly
#

it causes all code to get corrupted, it seems

gentle peak
dusky glade
#

wtf

north holly
#

yeah I did

dusky glade
#

i had a similar issue in which there was something wrong with the far return

#

and it also faulted on that instruction

#

that is solved now

gentle peak
#

#GP(selector) If the source selector points to a segment that is not a TSS or to one for a task that is already busy.

#

the two gdt entries at that selector:

  • 0x00908ba5802c0067
  • 0x00000000ffff8000
dusky glade
#

first one looks so fucking weird

#

tf

#

memory corruption?

#

yea looking at the bit sitself

#

first one is corrupted

#

i think

#

nvm second one looks weirder

gentle peak
#

keep in mind this is a tss descriptor

#

2nd one is top 32 bits of base zero extended to 64 bits

#

base 0xffff800000a5802c
limit 0x67
attr 0b1001
pres 1
dpl 0
type 0xb

#

yeah so the tss is busy

dusky glade
#

that is not at all correct

#

at all

gentle peak
#

everything except the type is correct for a tss

dusky glade
#

im really suspecting memory corruption

#

as i do set the correct bits in gdt_init

gentle peak
#

yeah no this is just a race condition

dusky glade
#

wdym

gentle peak
#

you're setting the correct bits in gdt_init yes, but you're setting them in a global shared variable without locking said variable

#

multiple cpus are running gdt_init at the same time and setting the same memory

dusky glade
#

hold on

#

ur right

#

i will put a lock and tes tit

#

no it still triple faults

north holly
dusky glade
#

yea

#

to be fair u need to go to sleep

gentle peak
# dusky glade no it still triple faults

here's the patch i used which successfully fixes it ```patch
diff --git a/kernel/src/arch/x86_64/gdt/gdt.c b/kernel/src/arch/x86_64/gdt/gdt.c
index 218233d..09759db 100644
--- a/kernel/src/arch/x86_64/gdt/gdt.c
+++ b/kernel/src/arch/x86_64/gdt/gdt.c
@@ -3,6 +3,7 @@
#include <stdint.h>

#include "sched/sched.h"
+#include "utils/basic.h"

typedef struct
{
@@ -10,11 +11,13 @@ typedef struct
uint64_t offset;
} attribute((packed)) GDTR;
uint64_t gdt[11];
+static spinlock_t gdt_lock;
extern void gdt_flush(void*);
GDTR gptr = {};

void init_gdt()
{

  • spinlock_lock(&gdt_lock);
    gdt[0] = 0x0;
    gdt[1] = 0x00009a000000ffff;
    gdt[2] = 0x000093000000ffff;
    @@ -44,6 +47,7 @@ void init_gdt()
    gptr.size = sizeof(gdt) - 1;

    gdt_flush(&gptr);

  • spinlock_unlock(&gdt_lock);
    }
    void change_rsp0(uint64_t stackaddr)
    {

gentle peak
#

good night

north holly
dusky glade
#

wait

#

nvm

#

forgot to run make

#

goodnight monkuous have a goodnights rest

#

thanks for the stupid race condition u caught as well!

median crest
#

oh wtf booting with 64 mbs of memory gives a huge boost to performance what

#

I go from 900k to 1.4mil-1.5mil consistently

#

on my crap laptop

dusky glade
#

😎

median crest
#

neat

dusky glade
#

no like actually

#

without ubsan

#

it runs 1m ops

#

ish

#

500k with ubsan

#

because of one slab allocator bug lol

#

@fiery turtle update my score when u wake up

median crest
#

seems like running with over 2 gbs of memory slows it down

#

wonder why

#

if I run with 2.9gb it gets the consistent ~1.4mil and with 3 gb it gets 1 mil wtf??

zenith crescent
fiery turtle
#

Bruh wtf have I missed

gentle peak
#

nyaux is 1.5M/s if you change 3 lines of code and disable ubsan

fiery turtle
#

Nyaux single handedly fixed by monkuous

fiery turtle
left orbit
#

slab was broken basically

fiery turtle
#

Oberrow missed his chance at getting obos decursed as well

#

Now its last place

gentle peak
#

every time a slab was allocated only the first object was put onto its freelist so effectively every allocation went to the pmm

fiery turtle
#

Ah

left orbit
#

also @\infy if you're still curious about zig's ability, you can take ghostty (the zig terminal emulator) and actually effortlessly cross compile it on linux for windows, which i find kinda cool that it just produces a working windows binary with no dependencies other than zig, everything including the C/C++ dependencies is built by zig and statically linked into the final binary

gentle peak
#

oh btw @dusky glade i figured out why the profiler caused a page fault: when creating a task your scheduler sets its rsp to the top of the stack, but the sysv abi expects the return address to be stored at rsp, so when it tried to read the return address it page faulted

fiery turtle
#

Oh yeah that's pretty nice, I know people who do osses in zig literally compile elf on windows

gentle peak
#

fixed by just subtracting 8 from the top of the stack when creating a task

left orbit
fiery turtle
#

Bruh inb4 nyaux beats proxima trl

left orbit
#

xorriso for windows is another beast

fiery turtle
#

Xorriso is kind of insane yeah

left orbit
#

i don't think i've seen a working version

#

but it's out there supposedly

gentle peak
#

i've used a working xorriso for windows multiple times

fiery turtle
#

I want to try it out for sure, you've shilled it enough LULW

gentle peak
fiery turtle
#

Surprisingly its from a guy with fake os

gentle peak
#

seems like it's just a cygwin build though

left orbit
fiery turtle
#

Yeah

torpid root
#

damn I gotta pump my numbers up

#

step 1: figure out how

#

step 2: give up

#

that concludes the work, goodbye

left orbit
#

i wonder what the numbers will look like if infy decides to work on a kernel of his own

fiery turtle
#

Im shit at algorithms sooo

#

At the bottom with obos

north hull
#

I will soon join obos at the bottom

torpid root
#

my kernel refuses to get above 1.5mil

#

on a slowish cpu of course

fiery turtle
left orbit
#

can't wait

#

(i need a good project to contribute to)

fiery turtle
#

well proxima

#

or astral

#

or managarm

#

or obos lol

left orbit
#

lol obos

fiery turtle
#

obos has suspend which is cool

left orbit
#

astral and obos nah because of code quality, my "ocd" makes it impossible to work with code like that

#

sadly

fiery turtle
#

oh yeah astral code style is uhhh

vagrant hull
#

mfw no ironclad

fiery turtle
#

hardtocomprehend

left orbit
#

it's ada lol

#

but for others sure

vagrant hull
#

contribute to cynix or something, there is not much so it's not a good project

fiery turtle
#

oh ye

vagrant hull
#

it's just a project

fiery turtle
#

forgot about it

left orbit
#

autohell makes me wanna cry but i'll look

vagrant hull
#

it doesn't even use autohell

left orbit
#

then what

#

plain makefile?

vagrant hull
#

yeah

left orbit
#

close enough

#

surprised you didn't do autotools

vagrant hull
#

bear it up :p

fiery turtle
#

implement enough in cynix so it can be put on the leaderboard

#

iirc it scored very high

vagrant hull
#

i don't like autotools

#

it does 4M/s on my system

fiery turtle
#

tahts probably with old uacpi too

vagrant hull
#

yeah

left orbit
# fiery turtle well proxima

i didn't really look at proxima so it could be a target, and managarm is phd code so i'd rather blow my head off than try to wrap my head around all the async hell :^)

vagrant hull
#

the thing with Cynix compared with the other examples there is that despite there not being much to show, admittedly, i have tried to keep the code really clean and there is no technical debt

fiery turtle
#

my main problem with managarm is its hard to build

#

u need a sequence of commands, files, edit stuff

mortal yoke
#

if I ever get this PE kernel anywhere I am going to try uacpi on it, can also do sse because the call conv saves them iirc (so using it in interrupts is not a problem)

left orbit
fiery turtle
#

proxima and cynix are both pretty clean i think

vagrant hull
#

whose project is Proxima again, sorry?

#

i forgor

left orbit
#

@\monkuous

fiery turtle
#

monkuous

vagrant hull
#

oh right

#

the fast boi

fiery turtle
#

they single handedly fixed nyaux

#

now it gets 1.5M

left orbit
strong heath
#

Ironclad is unironically the best to contribute, its reasonably stable, very low technical debt, very self contained, very documented, easy to test, it just has a single problem, and that is knowing Ada

left orbit
#

i like how PE does imports/exports

#

compare to ELF

#

it actually has a dedicated thing for that, which is awesome

mortal yoke
#

yeah

fiery turtle
#

PE is also built with reloc in mind

left orbit
#

yup

fiery turtle
#

not as an afterthought

left orbit
#

my plan was to have a loader that boots with limine and gets the kernel + some modules passed as limine modules, does some simple memory management, loads kernel + module into the memory and passes control to the kernel

#

but i hate C build systems

calm latch
left orbit
#

probably not, as long as you add it to llvm

vagrant hull
#

PE support to Limine would honestly be a welcome addition

fiery turtle
#

building llvm 💀

left orbit
vagrant hull
#

yeah

left orbit
#

i mean i could do that but

#

limine boot protocol doesn't really do PE

vagrant hull
#

the protocol itself is literally 100% executable agnostic

left orbit
#

is it?

vagrant hull
#

so no, that's untrue

#

yes

left orbit
#

hmm i thought it was ELF specific lol

#

my bad

slim panther
#

doesnt the protocol mandate e.g. ET_DYN

vagrant hull
#

never mentions ELF once

#

nope

#

not at all

calm latch
left orbit
#

it actually doesn't, wow

fiery turtle
#

limelfline

vagrant hull
#

i took care specifically of never making the protocol in any way ELF specific

slim panther
#

cool

#

when a.out support

vagrant hull
#

it can

left orbit
#

The executable, loaded at or above 0xffffffff80000000, sees all of its segments mapped using write-back (WB) caching at the page tables level.

#

segments

#

very nice

#

PE support is very doable then, i guess

fiery turtle
#

clearly this means GDT segments meme

slim panther
left orbit
#

especially since i don't have to do imports/exports

mortal yoke
left orbit
#

only load the PE into memory and do relocs

slim panther
vagrant hull
#

segments in here isn't referring to ELF segments specifically, rather just executable image segments

left orbit
#

yeah i get that, i just like the fact that it's format agnostic

vagrant hull
#

and there can be only 1 segment, for those formats (or really lack thereof) that don't have segmentation

left orbit
#

also technically we could implement a dynamic linker for PE into limine lol

vagrant hull
#

eh

#

we don't have that for ELF either

left orbit
#

it's piss easy as it's just loading multiple PE files and resolving imports

#

yeah but ELF is a bit more complicated in that regard

#

but true, feature parity would be nice

vagrant hull
#

it's not something we couldn't do

left orbit
vagrant hull
#

yeah i don't think it's that useful honestly

slim panther
#

it requires extensive kernel support

vagrant hull
#

i'd worry about plain PE support first

mortal yoke
#

and for things like kernel modules the kernel can also do that itself if it wants

left orbit
#

so you can just dynamically link ur kernel and drop the modules in /boot

slim panther
#

well, how do you make sure it's mapped where the kernel won't complain

left orbit
#

relocations have a size

#

but the IAT is just a table of addresses

#

so it won't complain

#

different story for elf maybe, i guess

#

idk how dynamic linking works in the ELF land

slim panther
#

it's not that bad

#

i have a dynamic ELF linking impl already

left orbit
#

well so does mlibc

#

but it's kinda poop lol

#

well, not mlibc

#

but elf dynamic linking in general

slim panther
#

i need your opinion on my coding style KEKW

left orbit
#

show

slim panther
left orbit
#

kernel%2Fsystem%2Fmodule.c

#

wtf is github cooking

slim panther
#

banger

left orbit
#

looks properly formatted

fiery turtle
#

tabs are L