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

1 messages ยท Page 20 of 1

left orbit
#

its all compile time

frank canopy
#

ive got intrusive singly and doubly linked lists in zig in my kernel under bsd 0-clause btw, separate license from the rest of the project

#

yeah its great

#

you cant put decls on types at comptime only fields but its still great

left orbit
#

only downside is you can't add declarationss

#

aaa too slow

fiery turtle
#

Are there macros

left orbit
#

nope

frank canopy
#

no macros only comptime

left orbit
#

no new functions on types

frank canopy
#

decls are type-scoped things that arent fields

fiery turtle
#

Hm

left orbit
#

yeah that lol

#

but i haven't really found myself needing that

frank canopy
#

you cant create a type with reflection that has decls is the only major limit

left orbit
#

and if you do you can somewhat easily work around that

frank canopy
#

and yeah ive never needed it either

fiery turtle
#

Is that like a compiler limitation or on purpose

left orbit
#

if i had to guess i'd say both

frank canopy
#

technically a not implemented but it looks like itll be made on purpose yeah

#

theres an open gh issue with a debate on whether to implement it or make it actually illegal

left orbit
#

i can't think of a way to create functions at compile time

fiery turtle
#

Interesting

left orbit
#

and functions are decls so

frank canopy
#

theres a proposed builtin called unrollArgumentTuple that would take a function with a tuple argument and return a function with one argument per tuple element

fiery turtle
#

Ill definitely try writing something in zig tomorrow just to see how it feels

frank canopy
#

and you can use a comptime switch to implement it yourself

left orbit
#

day 0 of asking for an ultra rewrite in zig

fiery turtle
frank canopy
#

the other thing to note with zig is that varargs only exist for c binding compat - to make a varargs zig function you take a tuple and use anytype to let it specialize per tuple combination

left orbit
#

now implement everything else

north holly
#

day 0 of asking for ultra

left orbit
#

and make it run wayland

fiery turtle
#

Bash before obos

frank canopy
#

the downside of that tuples for varargs bit is that std fmt generates generic specializations for every combination of argument types which can cause some binary size bloat - theres an open issue there too iirc

left orbit
#

let's make it happen ๐Ÿ”ฅ

left orbit
#

lmao

frank canopy
left orbit
#

it's still probably better than std::format lmao

north holly
#

assuming ttys aren't too confusing, I should get bash by the new year

fiery turtle
#

Lfg 2026 LETSFUCKINGGOOOOOO

left orbit
#

iostream is a disgrace to humanity

north holly
frank canopy
fiery turtle
#

Iostream is truly disgusting

frank canopy
#

it really is lol

left orbit
#

petition to the c++ committee to remove iostream in c++29 or whatever

median crest
north holly
#

what dumbass in the C++ committee decided to add it in the first place

north holly
#

and what dumbass(es) decided to accept it

median crest
left orbit
#

they are TERRIBLE

#

the api is dogshit lol

fiery turtle
#

Why do you want both ? And a pointer

frank canopy
left orbit
#

.? is like rust unwrap

north holly
frank canopy
left orbit
#

you can have ?T which is a nullable T

fiery turtle
#

Ah so there's no hidden fields there?

frank canopy
#

so ?* is more like a nullable pointer than it is an optional-of-pointer

median crest
#

tty.c in astral is 550 lines ~~if you ignore the 611 lines signal.c and 430 lines of jobctl.c meme ~~

frank canopy
#

an optional not-pointer requires one extra hidden field but optional pointers dont

left orbit
#

and you can also have !T which is an error union, basically T with an addiitonal error value passed together

fiery turtle
#

Makes sense

north holly
#

what if I don't implement TTYs, but always return false from sys_isatty

slim panther
#

that's what i do

median crest
frank canopy
#

technically SomeErrorSet!T is an error union, !T by itself infers the error set

left orbit
#

and E!T is a T with an explicit error union type

#

they are user defined

#

you can return error.MyError

fiery turtle
#

Hm

#

Like an enum?

left orbit
#

and it adds MyError to the global error set, which is the default

#

yeah but it's a global enum sort of

fiery turtle
#

Wait u can do that

frank canopy
#

an error set is a subset of the global error set which is every error in the program

fiery turtle
#

What if I make a typo and add a new bogus error

left orbit
#

every type that doesnt use an explicit error set uses the global error set anyerror

left orbit
#

const MyErrorSet = error { A, B, C };

fiery turtle
#

Interesting

frank canopy
#

and the global error set gets mapped onto a 16-bit int internally but the mapping isnt reliable

left orbit
#

anyerror is more of a convenience i'd say

fiery turtle
#

Can u store extra info in there?

left orbit
#

sadly not

frank canopy
#

if you return an error not in the explicit set you have then its a compile error

#

nope, its errors in the same way a status enum is

fiery turtle
#

Sadge

#

How do u work around that?

frank canopy
#

if you want extra info do it the C way and have a function to get extra info

#

which you store in a threadlocal global or something

fiery turtle
#

I see

#

Well that's fine I guess

frank canopy
#

you can get a stack trace for the error with a builtin though which is usually enough to debug things, or also catch errors and return more specific ones in intermediate stages

#

as long as you stay below 2^16 error names total its fine

fiery turtle
#

U can get an original backtrace of the error when itโ€™s propagated down?

frank canopy
#

yeah

fiery turtle
#

Damn

fiery turtle
frank canopy
#

any function that returns an error takes a hidden parameter of type *StackTrace and appends its current rip to the trace before calling an error-returning function or returning its own error

left orbit
#

65k errors ought to be enough for anybody

frank canopy
#

and then you can get that trace with @errorReturnTrace

left orbit
#

also defer and errdefer are beautiful

frank canopy
#

though the builtin returns an optional trace because that whole thing gets elided if you run optimized modes with error tracing turned off

#

gods yeah defer and errdefer rule

left orbit
#

errdefer is defer which runs if the function returns an error

frank canopy
#

block not function

fiery turtle
#

Really nice yeah

frank canopy
#

defer statements run in reverse order when the block theyre in is exited by any means

left orbit
#

zig has been successfully shilled

frank canopy
#

lol

frank canopy
# fiery turtle What about errdefer

same thing but only if the block returns by returning an error. useful for stuff that allocates something and then initializes and returns it - if the init code errors you can free the partially-initialized object with errdefer

fiery turtle
frank canopy
#

my favorite use for defer is for locks and for frees - put the free with the alloc or the unlock with the lock in the source and guarantee itll still go in the right order and everything

left orbit
#

yeah it's amazing

frank canopy
#

i think what actually convinced me to try zig was still the bit-packed structs though tbh

#

i think C has those now too but idk

frank canopy
#

yeah

left orbit
#

also arbitrarily sized integers

fiery turtle
#

Yeah C has that but in broken ways

left orbit
#

u5 is a thing

frank canopy
#

zig technically has every signed and unsigned int size from 0 bits to 65536 bits (idk why that big) and inside a packed struct any of those things take up exactly that many bits

#

instead of rounding up to bytes

fiery turtle
#

Damn

#

Built-in big int?

frank canopy
#

also inside a packed struct a bool becomes 1 bit

fiery turtle
left orbit
#

zig is probably a big fucking benchmark and test case for llvm lmao

frank canopy
#

idk if it actually works for big int, i remember some crashing issues for ints bigger than whatever your biggest register can support

#

and yeah lol zig runs on llvm atm

frank canopy
#

outside a packed struct, a u5 is a u8 but in safe modes it gets its overflow checks for 5 bits of size. inside a packed struct u5 is a 5-bit-wide bitfield

#

packed structs are backed by integers to and you can cast both ways there

#

basically means my page table entry struct looks like this and just works

left orbit
#

you really should give zig a go, not even for osdev :)

fiery turtle
#

Very cool

frank canopy
#

packed unions are untagged unions of packed things, and in this case Pfi and PtePfiPad are int types determined by comptime from the physical addr width and page size

left orbit
#

but a new osdev project that has a chance of getting off would be cool

frank canopy
#

if you do decide to do zig osdev i have fully working uacpi integration in zig already you can steal lmao

left orbit
#

i might try to make a hyper-template too

#

never looked at it but it might be fun

frank canopy
#

i still might grab limine-zig someday if i decide to switch off of bootelf

fiery turtle
#

Lol thanks, ill definitely be taking a look

left orbit
#

i dont really keep it up to date because i dont do much osdev, especially in zig

fiery turtle
#

How stable is the compiler btw

#

Do u run into bugs often

left orbit
#

it is pretty stable nowadays

#

it used to be terrible but its good

fiery turtle
#

Nice

left orbit
#

like zig 0.9 or 0.10 was bad

#

but 0.13 and 0.14 are very stable from my experience

fiery turtle
#

Good to hear

frank canopy
#

yeah

#

im running nightlies and have had nearly zero issues with zig itself

#

plenty of issues with my kernel being bad but thats separate lol

fiery turtle
#

Lol

kind mantle
#

Do you know what time it is?

#

It's (BadgerOS) uACPI time!

slim panther
#

bro is looking for a dtb on x86

kind mantle
#

Well that's kinda what happens in the early stages of adding AMD64 support to a RISC-V kernel.

#

Anyway, I'll make sure to run the uACPI benchmark thingy as well ;)

left orbit
#

no proper hyper bindings but cimport did well :^)

#

even the ULTRA_NEXT_ATTRIBUTE macro was translated which is pretty cool

north holly
#

trying to bait infy into using zig, I see

left orbit
#

if i was i would make proper hyper bindings

#

(i will at some point tomorrow)

#

(yes i want to see ultra-zig meme)

left orbit
north holly
#

I mean lgtm

fiery turtle
fiery turtle
fiery turtle
fiery turtle
#

Ideally it should be higher half exclusive I guess

torpid root
gentle peak
#

what a coincidence, i currently happen to be working on implementing realloc efficiently

#

it's not going to be that much faster than just normal kalloc+kfree, because of some of the general constraints of my allocator

#

(each heap page needs to have the same power-of-two size for each object, so shrinking/expanding an object beyond its current power-of-two size requires kalloc+memcpy+kfree)

#

but for ranges that end up using vmalloc_large, it should have a good impact

gentle peak
#

@fiery turtle just by making dynamic arrays use realloc, proxima's score went from 5.1M to 5.6M

fiery turtle
gentle peak
#

yeah

fiery turtle
#

damn

#

it also grows only by one element each time, i wonder if making this constant configurable could improve perf

gentle peak
#

oh definitely

#

if a dynamic array doubles its capacity when growing instead of just adding space for one element, its insert performance is amortized to O(1) iirc

fiery turtle
#

hmm

vagrant hull
gentle peak
fiery turtle
#

makes sense

fiery turtle
gentle peak
fiery turtle
#

nice, I guess an optional realloc is useful to have

gentle peak
vagrant hull
fiery turtle
vagrant hull
#

i did not use it but i was at the receiving end of many reports when the limine-zig-template was part of the limine organisation

#

which is the main reason why i transferred it to czapek

fiery turtle
#

ah

loud ice
#

it used to be that the language is cool but the compiler is buggy

#

and now they have a working compiler and a shitty language

left orbit
#

basically

rustic compass
#

In rust you get that automatically when implementing the allocator trait

left orbit
gentle peak
rustic compass
#

Nope mandatory is only alloc and free

left orbit
fiery turtle
#

@gentle peak btw for those measurements, did you look into the hit/miss rate of how many allocations were able to get resized, and where they came from etc?

rustic compass
gentle peak
#

for the former i assume not that many because all of them were getting routed to kalloc which has very strict requirements for actually resizing vs copying+freeing

fiery turtle
#

interesting

left orbit
# left orbit basically

also, most complaints about limine-zig not working were because of the big changes to the build api at the time, the rest were probably me not updating the thing lol

gentle peak
fiery turtle
#

lmao

gentle peak
#

actually maybe that's because this is with both realloc and dynamic array doubling

#

i wonder what it'd be like if it expanded by one at a time

fiery turtle
#

yeah the x2 growth probably allocates way too much

#

so u get way less allocations and hence the perf improves

gentle peak
#

not just that

#

2x growth guarantees that the new allocation won't fit in the same power-of-two bucket

fiery turtle
#

and that yeah

gentle peak
#

so krealloc can never resize the allocation

#

ok disabled the 2x growth
vmrealloc: 1823 calls, 271 with orig == NULL (routed to vmalloc), 1552 routed to krealloc
krealloc: 1552 calls, 980 successfully resized, 572 kalloc+memcpy+kfree

fiery turtle
#

that makes more sense

#

pretty good rate

gentle peak
#

yeah

#

on the other hand

#

i just tested with only dynamic array doubling and not realloc

#

it's still 5.9M

fiery turtle
#

lmao

gentle peak
#

dynamic array doubling + realloc was also 5.9M, and just realloc was 5.6M

fiery turtle
#

well realloc is basically a no-op for x2 growth as we've found out

gentle peak
#

my implementation for realloc, at least

#

but yeah

fiery turtle
#

id imagine for most implemetations, at least slab-like allocators

gentle peak
#

anyway this should be a pretty good universal performance improvement ```patch
diff --git a/include/uacpi/internal/dynamic_array.h b/include/uacpi/internal/dynamic_array.h
index 8135d7e..a68c1d6 100644
--- a/include/uacpi/internal/dynamic_array.h
+++ b/include/uacpi/internal/dynamic_array.h
@@ -65,8 +65,8 @@
void *new_buf;

type_size = sizeof(*arr->dynamic_storage); \

  •            bytes = arr->dynamic_capacity * type_size;                   \
    
  •            bytes += type_size;                                          \
    
  •            bytes = arr->dynamic_capacity * type_size * 2;               \
    
  •            if (bytes == 0) bytes = type_size * 8;                       \
                                                                            \
               new_buf = uacpi_kernel_alloc(bytes);                         \
               if (!new_buf)                                                \
    
fiery turtle
#

might need per-instance tuning, some of those are pretty huge structs

#

especially call_stack

#

or call_frame sorry

gentle peak
#

which source file is that in?

#

oh yeah 1840 bytes per element

fiery turtle
#

DYNAMIC_ARRAY_WITH_INLINE_STORAGE(call_frame_array, struct call_frame, 4)

#

this one

fiery turtle
gentle peak
#

maybe add a parameter to the dynamic array macro that specifies the initial capacity?

fiery turtle
#

i was also thinking of caching execution_context and reusing them for further eval's, since that thing is 2 pages almost

gentle peak
#

or even a parameter that enables/disables the doubling growth

fiery turtle
fiery turtle
#

or like that takes in a growth "functor"

gentle peak
fiery turtle
#

yup

gentle peak
#

i wonder if the call frame dynamic array ever even starts using dynamic storage

fiery turtle
#

depends how deep qemu's AML nests

#

probably never

#

i fine tuned these to have inline storage that should cover hopefully at least 80% of real life aml

#

so first 4 function calls are free

#

(nested that is)

gentle peak
#

yeah i overlooked that

#

then the initial capacity for the dynamic storage should probably not be 8 lmao

fiery turtle
#

maybe the size of inline storage

gentle peak
#

oh yeah that'd effectively continue the doubling

fiery turtle
#

basically yeah

#

and from there it could be any other algo

#

maybe += initial_capacity / 2

gentle peak
#

iirc the O(1) amortization applies as long as the new capacity is a factor of the previous one

loud ice
#

do you not grow arrays by 2x?

#

wtf

fiery turtle
#

i cant just blindly 2x

loud ice
#

also you should move uacpi_shareable_unref_and_delete_if_last, uacpi_shareable_unref and uacpi_shareable_ref into a header

loud ice
#

thats the only way to get O(1) performance in fact

loud ice
#

i think

fiery turtle
#

for some of them i can and should probably yeah, for huge strucuts i definitely dont want that, especially since exceeding inline capacity is rather rare there

loud ice
#

it produces hilariously bad codegen

flat badge
#

the factor doesn't matter

flat badge
#

whether it's 2 or 1.000001

loud ice
#

ofc

fiery turtle
loud ice
flat badge
#

(ofc 0.000001 would be stupid)

loud ice
#

maybe i should try getting lto working

fiery turtle
#

well its in a C file

flat badge
#

but something like 3/2 is reasonable

#

if you don't want to 2x every time

fiery turtle
#

i was thinking half of base inline storage size each time

#

but could be a more sophisticated formula

gentle peak
#

never! this does not result in a trap

loud ice
#

you need it to be a factor of the previous size

gentle peak
#

oh discord cleared the message i was replying to

#

anyway the call frame array never gets into dynamic storage

loud ice
fiery turtle
fiery turtle
gentle peak
#

also if i make the initial dynamic capacity the inline capacity the score becomes 5.7-5.8M instead of 5.9M

fiery turtle
#

isn't that 2x as well

#

i mean the numbers shouldnt change from 2x unless it grows even further?

gentle peak
#

yeah

#

but the 5.9M is when the initial dynamic capacity is a constant 8

#

for a lot of things, that's effectively multiple doublings at once

fiery turtle
#

ah

#

thats probably the item array id guess

#

although it has a base cap of 8

#

idk actually

flat badge
#

should definitely use a factor of the current size

gentle peak
#

with initial_dynamic_cap == inline_cap it's still O(1) amortized but a worse O(1)

loud ice
#

it has a worse constant

gentle peak
#

yeah

loud ice
fiery turtle
#

its interesting because u hardcoded 8, which happens to be the inline_cap of most used arrays

gentle peak
#

oh 8 just happens to be my go-to for initial cap of dynamic arrays

#

completely arbitrary

loud ice
#

8 or 16 is a pretty good choice i think

fiery turtle
#

no like, i dont get where we lost 200k

#

if its the same constant

#

all interpreter arrays are base 8, call frame (which is never resized as we've found out is 4)

gentle peak
#

when i say 5.9M btw it's more like 5.85-5.95M

#

i might've just gotten a bad run with inline_cap

fiery turtle
#

probably

gentle peak
#

yeah i just got one with 5.88M

#

and one with 5.90M

#

so not a huge difference

fiery turtle
#

what if u grow by prev_size / 2?

loud ice
#

wait

#

no it is

gentle peak
#

it's a factor

loud ice
#

its just growing by 1.5 times

gentle peak
#

it's just a factor below 1

loud ice
#

thats fine

gentle peak
#

or well yeah

#

one sec

fiery turtle
#

below 1 would be shrinking lol

loud ice
#

yes lol

fiery turtle
#

tbh the += 1 there was probably left from a very long time ago when i was debugging it lmao

#

and then never reverted to x2

gentle peak
#

still 5.8-5.9M but the mean seems to be closer to 5.83M

fiery turtle
#

thats not too bad considering its way less memory used

gentle peak
#
                bytes = arr->dynamic_capacity * type_size;                   \
                bytes += arr->dynamic_capacity / 2 * type_size;              \
                if (bytes == 0) bytes = type_size * inline_cap;              \
``` this is what i'm using for that btw
loud ice
#

i think you'd also benefit a lot from SSO tbh

#

not sure if its feasible for AML?

gentle peak
#

it's also with -O3 and LTO

fiery turtle
loud ice
#

most common allocations for the benchmark thing

fiery turtle
#

what are the hex numbers

loud ice
#

the top 4

#

assign, control method, package, buffer

#

the small 0x5 byte allocs are probably ssoable?

gentle peak
fiery turtle
#

assign is basically object copying

loud ice
fiery turtle
gentle peak
#

ahh

loud ice
#

the number 1 spot is when src->type is 2 or 3

fiery turtle
#

string & buffer

loud ice
#

and when behavior != UACPI_ASSIGN_BEHAVIOR_SHALLOW_COPY

fiery turtle
#

fair

#

i wonder how many of those are small enough buffers

loud ice
#

this is by size

#

so, 769 allocs of 5 byte buffers

#

lol

#

you can fit that in sso no problem

fiery turtle
#

ah, probably named references

#

AML name + null term

loud ice
#

ah

#

you can't abuse copyobject to change a string inplace right?

fiery turtle
#

yeah SSO could really help here

fiery turtle
#

like python basically

loud ice
#

like, ```
X = "asd"
Y = "def"
Z = X
CopyObject(X, Y) // doesn't set Z to "def"

#

right?

gentle peak
fiery turtle
gentle peak
#

or other 32 bit platforms for that matter, though i don't think any of them other than i386 use acpi

loud ice
#

wait

#

so you can't overwrite a string by reference?

fiery turtle
#

u can only change the characters, but not resize it

loud ice
#

ah

fiery turtle
#

so memcpy basically

#

or memcpy_zerout rather as uacpi calls it lol

#

if the thing being assigned is bigger, the rest of it is zeroed

fiery turtle
#

there are smart ways to get 6-7 bytes of storage out of ptr + size

#

iirc

loud ice
#

you can even get more

fiery turtle
#

on 32 bit

loud ice
#

because aml names (which are the common case anyway) are super common

#

so you can constrain to an alphabet of \_ and A-Z

#

and 0-9

#

that's 38 symbols

fiery turtle
#

no like, obviously object names are stored as inline data, i dont heap allocate them, these are probably package fields or something, which are just normal string objects, but they store the aml name to look it up later

loud ice
#

assuming lengths are less than 2^31, you can fit 12 whole characters

fiery turtle
#

if u add like an AML_NAME bit or something?

loud ice
#

you can handle fairly long ones

#

yeah something like that

fiery turtle
#

perhaps yeah

loud ice
#

apple did this kind of meme in objc :^)

fiery turtle
#

lol

#

yeah thats definitely an optimization you could do

#

would shave a lot of those allocs

loud ice
#

yeah

fiery turtle
#

i wonder how far that'd push the numbers lol

#

also if i cache execution contexts and have a small pool of them

#

although the benchmark is the first invocation of the interpreter so doenst matter

#

they're always allocated at the beginning of execute_control_method

#

and are 7k bytes lol

loud ice
#

how do you compile all the test stuff?

loud ice
#

the important thing is avoiding tons of small allocations

fiery turtle
#

cd tests/runner && mkdir build && cd build && cmake .. && make

loud ice
#

ah

fiery turtle
#

or ./run_tests.py

loud ice
#

btw you know that cmake .. -G Ninja && ninja can make builds go faster for free?

fiery turtle
#

yeye, my build times are shit because they're done over 9P anyway

loud ice
#

ah lol

fiery turtle
#

since im using wsl

#

io is ridiculously slow

#

well i could do it on the ext partition but whatever

#

but uacpi is small enough its not noticable

loud ice
#

fair enough

fiery turtle
gentle peak
#

nah dw

fiery turtle
#

lol sure, thanks for testing and stuff anyway

#

and pitust for allocation stats

gentle peak
#

i remember this question being asked but i don't remember the answer, for uacpi_kernel_wait_for_event if the timeout is 0 should it be non-blocking just like with uacpi_kernel_acquire_mutex? because right now i only implement that for mutexes

fiery turtle
#

yeah it should be, since you're not the first to ask that I should probably add a comment

#

since it's only used by AML it probably won't notice if u block it for a tiny bit, but yeah it shouldnt be

loud ice
#

when do you even check for UACPI_STRING_KIND_PATH actually

#

ah nvm

gentle peak
#

yeah right now it'd try to sleep for 0 tsc ticks, aka it'd be timed out immediately after blocking if the initial try was unsuccessful, but still

fiery turtle
#

out of my 500 blobs there isnt a single invocation of Wait with anything less than 0x05

#

in case u were wondering as well:

โฏ grep -rni 'Wait (' -l | wc -l
114
#

about 20% use Event

gentle peak
#

huh that's more than i thought it'd be

fiery turtle
#

from what i've seen its used on wake, aml waits for some sort of event from firmware

#

maybe some initialization to finish

gentle peak
#

that'd make sense ig

fiery turtle
#

but there could be other use cases as well, you never know with these people

#

every blob is strange and unique in its own way

gentle peak
#

yeah... unique... While ((GP50 || (GP51 || (GP52 || (GP53 || (GP54 || ( GP55 || (GP56 || (GP57 || (GP60 || (GP61 || (GP62 || (GP63 || (GP66 || (GP67 || (GP70 || (GP71 || (GP93 || (GP94 || ( GPAP || (GPBP || (GPCP || (GPDP || (GPEP || (GPFP || (GPGP || (GPHP || (FCDP || (FTVP || (FQSP || (GP96 || (GP97 || ( GPD0 || (GPD1 || (GPD2 || (GPD3 || (GPD4 || (BPFE || (TPBP || (ECDS || (B1ST || B2ST)))))))))))))))))))))))))))))))))))))))))

fiery turtle
#

lmao

loud ice
#

@fiery turtle do_make_empty_object seems to leak memory?

#

you set buf->text to a pointer that points to 1 byte of memory

#

without setting the size

#

which is invalid

fiery turtle
#

Check the corresponding free

#

But anyway its a hack that im not sure is needed, I might take a look at it at some point

#

Im sure there are no leaks because I run with asan on at all times

fiery turtle
loud ice
#

ah

#

cursed

#

why?

fiery turtle
#

I dont remember, probably not needed now

#

I think it was because the Mid operator is the only legal way to produce an empty buffer and I didnt want to add special handling for null buffers everywhere

#

But I dont think I actually rely on that anywhere

loud ice
#

also seems like handle_concatenate leaks memory?

#

if arg0 is UACPI_OBJECT_STRING and arg1 is UACPI_OBJECT_BUFFER

#

you allocate an on-stack buffer then never free it

#

(im trying to hack up sso into uacpi as an experiment)

#

ah wait nvm

#

i didnt see the free

fiery turtle
#

ye

fiery turtle
fiery turtle
#

on my experimental branch for now but will merge along with some api changes later

fiery turtle
#

it will always grow by 0

gentle peak
#

yeah

#

was intended as testing code, not to be super reliable

fiery turtle
#

ye, ill fix it

#

was just making sure

#
if (arr->dynamic_capacity == 0) {                            
    bytes = type_size * inline_cap;                          
} else {                                                     
    bytes = (arr->dynamic_capacity / 2) * type_size;         
    if (bytes == 0)                                          
        bytes += type_size;                                  
                                                             
    bytes += arr->dynamic_capacity * type_size;              
}                                                            

I think this should work

gentle peak
#

looks right yeah

loud ice
#

okay its now compiling

#

so good news: compiles

#

bad news: fails a bunch of tests

fiery turtle
#

how did u implement sso so fast

#

lmao

#

how many tests we talking

#

btw --large-tests meme

loud ice
#

tbh its probably all of them

fiery turtle
#

and dont forget to test 32 bits as well, there's a switch in ./run_tests

loud ice
fiery turtle
#

its not aml methods

loud ice
#

i see i see

#

also the 0xBF/0xBE thing is sketch

calm latch
fiery turtle
#

lol yeah

fiery turtle
calm latch
fiery turtle
#

embedded doesnt have acpi

calm latch
#

Still

#

Raspberry Pi

#

And UEFI galaxybrain

fiery turtle
#

thats aarch64 no

#

?

calm latch
#

Yes

#

Idk

fiery turtle
#

it might not even support 32 bits at EL1 or wahtever

calm latch
#

No, it runs 32 bit kernels

fiery turtle
#

ah ok

fiery turtle
calm latch
#

Like an official raspbian up to Raspberry Pi 4 was 32 bit

loud ice
#

also i figured it out

calm latch
#

Even though raspberry pi 3 was 64 bit

loud ice
#

i probably forgot to zero out a buffer

calm latch
#

And newer revisions of raspberry pi 2

fiery turtle
#

you're not sure what your SSO buffer size is? LULW

calm latch
#

ACPI has a lot of strings which are 5 characters ยฟ

fiery turtle
#

yeah

#

tbh im not entirely sure where they're coming from

gentle peak
#

truly 5 chars or 4 chars+null?

#

because from what i've seen of acpi dumps it's mostly 4c+0

calm latch
#

Like method names

fiery turtle
#

well in the byte stream its litrally 4 ascii chars

#

there are no zeroes anywhere

gentle peak
#

as it should be

#

zero-terminated strings are terrible imo

fiery turtle
#

yeah

#

it has a StringOp which is zero terminated tho

#

and it doesnt tell u the length

#

so u have to strlen it

calm latch
#

They save memory though

fiery turtle
#

yeah no aml encoding is pretty good

gentle peak
#

if you're that desperate for mem they're fine yeah

#

but having the length speeds up a lot of string ops

calm latch
fiery turtle
#

aml has a ByteOp + <byte> to encode bytes, but Zero, Ones or One are separate op codes which are exactly 1 byte long

calm latch
gentle peak
#

a lot of string ops are O(1) if you have the length already

calm latch
#

The're so common they must be optimized very well by the compilers and whatnot

gentle peak
#

strlen can be optimized a lot with simd and such but it's still O(n) by nature

fiery turtle
#

there's a reason people use string_view etc

mortal yoke
#

also stuff like strcmp could have early return if the length of both strings are known

fiery turtle
#

yeah

gentle peak
#

using slices instead of zero-terminated strings also makes syscall param validation easier, not that it wasn't easy to begin with

fiery turtle
#

strlen_from_user meme

calm latch
#

My syscalls only take slices

gentle peak
#

hence the "not that it wasn't easy to begin with"

#

yeah same

#

or well they did in my previous rewrite and they will when i implement them in this one

fiery turtle
#

honestly syscalls should always take slices

calm latch
#

You can just strlen in userspace if you need it that much

calm latch
#

(I kinda don't like C)

fiery turtle
#

ill have to take raw strings because im going for full linux compat tho (in my kernel)

gentle peak
#

like binary compat?

fiery turtle
#

yeah

gentle peak
#

damn

calm latch
#

Can you not do that in vdso?

fiery turtle
#

i hate userspace and porting shit

#

id rather have full compat

calm latch
#

Like have native API not take them

fiery turtle
#

also this allows me to reuse linux stuff for validation

calm latch
#

And then give a shim for syscalls

fiery turtle
#

syzkaller, fio, etc

gentle peak
fiery turtle
#

and programs that work on linux in one way i can instantly spot a mismatch e.g. in strace

fiery turtle
calm latch
#

Programs that do that are stupid (?)

fiery turtle
#

i just want cp ./bash ./myimage

calm latch
#

What if Linux adds a new syscall

fiery turtle
#

programs wont randomly start using it

calm latch
#

glibc or something might

mortal yoke
#

and thankfully the amount of raw syscalls programs do is not that much

fiery turtle
#

it does that based on the kernel version or some other property

#

that i can just not expose

calm latch
fiery turtle
#

just return-ENOSYS and glibc will fuck off

calm latch
#

Idk, personally I just find making Linux clones kinda uninspiring

fiery turtle
#

a posix clone is somehow more inspiring? LULW

calm latch
#

Posix is just a bunch of functions

fiery turtle
#

im mostly doing it to learn about linux internals while also focusing on drivers (the thing im interested in)

#

so i spend as little time as possible on userspace

calm latch
#

I implement all of them in userspace

fiery turtle
#

well u still have a posix server

calm latch
#

I have a process server, a vfs server and pipes server

fiery turtle
#

i just dont care about uniqueness, im just doing my thing

#

i want 3d accel with my drivers etc

calm latch
fiery turtle
#

not interested in innovating userspace

#

if i can run e.g. wine + some cool windows game fully 3d accelerated on my kernel that would be an achievement for me

#

at least on an older igpu, like 2015 or soemthing

#

although there isnt that much of a difference between generations

calm latch
#

Is new Arc memes very different from their older iGPUs?

fiery turtle
#

nah

#

although linux is using a new driver for it

#

they got rid of backward compat and made a new driver that uses only new things

calm latch
#

There was a lot of drama with Windows drivers when the first gen launched

fiery turtle
#

its the exact same igpu, just with more command streamer engines lmao

mortal yoke
#

one nice thing about them might be that as they are dedicated things you can probably pass through them to qemu I'd imagine unlike some other newer igpus

calm latch
#

iGPUs support GPU virtualization

#

I couldn't get it to work though

calm latch
#

Since that's what I had

fiery turtle
#

for development u should just run linux headless and pass through to qemu entirely

#

just ssh into it instead

calm latch
#

No but in theory you should full on be able to pass the GPU to Windows

#

While linux is not left headless

fiery turtle
#

u can via a virtual gpu

#

in practice that barely works

mortal yoke
#

I couldn't get that to work either, the south bridge registers always returned zeros on my alder lake igpu

calm latch
gentle peak
fiery turtle
#

motherboard skill issue

calm latch
#

But it's only on server GPUs on nvidia and amd afaik

calm latch
#

2.5 slot GPU

#

PCIe connector in second slot

fiery turtle
#

i have a 4060ti so no such problems LULW

mortal yoke
#

I could put a second gpu with a pcie riser cable troll though I think it would have to partially be outside the case

calm latch
fiery turtle
calm latch
#

I don't think this would make a difference

mortal yoke
calm latch
#

There's also Thunderbolt/USB 4 memes

fiery turtle
#

i mean there's a reason u put your gpu to the pcie slot closer to the cpu

calm latch
#

And on nower motherboards it's the slot which is wired to PCIe 4/5

fiery turtle
#

ah maybe idk

calm latch
#

Because you only get 20-28 on consumer CPUs

#

And GPU uses 16

fiery turtle
#

fun fact, igpus are mandated by the spec to be located at 0000:00:02:00

calm latch
#

It's for that forum person who refuses to use ACPI

gentle peak
#

you wouldn't even need ACPI to detect it in places other than that

calm latch
#

Windows 98 compat?

gentle peak
#

just brute force detect all possible devices on every addressable bus

fiery turtle
#

^

#

brute force every segment meme

calm latch
#

I don't have experience in computer industry so I don't know if that's true, but I would imagine there must be some embedded shit which uses some cursed OS to control machine tools and that stuff would have it hardcoded

gentle peak
#

doesn't that kinda stuff use 386 and 486 CPUs

fiery turtle
#

igpus are pretty tightly intergrated with acpi as well, they usually have a separate SSDT dedicated for them, a custom opregion, and various notification things

#

if you're lucky there is even a method to do modesetting via acpi

calm latch
#

The ASUS laptop which I've dumped yesterday was turning screen on and off with the keyboard buttons in pmOS

calm latch
#

With no GPU driver

median crest
#

Really?

calm latch
#

And spamming a bunch of ACPI events

fiery turtle
#

yeah

#

and brightness as well etc

calm latch
#

So could have that been done by ACPI?

fiery turtle
#

yeah, by the corresponding query handler

calm latch
fiery turtle
#

uDMA?

#

lol ask marvin idk

median crest
calm latch
#

I mean

#

Ultra kernel?

fiery turtle
#

we'll leave that to the rust kernel crate

#

@north holly i just realized

north holly
#

Ye

fiery turtle
#

maybe you're expected to call this after resume from suspend

#

your blob has this method

north holly
#

Hmm

fiery turtle
#

this might restore graphical output

north holly
fiery turtle
#

_DOS

north holly
#

Which blob

fiery turtle
#

the laptop one

north holly
#

I'll try that

fiery turtle
#

there's also _DOD

#

your laptop has all of that implemented

north holly
#

I assume it is under the GFX0 object?

fiery turtle
#

yeah

north holly
#

in an ssdt

fiery turtle
#

Name (_ADR, 0x00020000)

#

this is your iGPU

north holly
#

cool thanks

#

will be trying it

fiery turtle
#

SSDT1 has tons of stuff for graphics-related things

#

probably some combination of those methods can restore the screen

#

just read the entire spec chapter on that, its pretty small

#

so u need to detect which screen u want to activate, then activate it ig

#

idk

calm latch
#

It also has 6000 series AMD iGPU

#

Which has datasheet

fiery turtle
calm latch
#

Btw, I don't think it has Windows keys

fiery turtle
#

your laptop has 2

โฏ grep _DOS *.dsl
dsdt.dsl:                    Method (_DOS, 1, NotSerialized)  // _DOS: Disable Output Switching
dsdt.dsl:                Method (_DOS, 1, NotSerialized)  // _DOS: Disable Output Switching
calm latch
#

So you could probably add it to the database (?)

#

Or I could do it myself

calm latch
fiery turtle
#

if you could PR it that would be great

fiery turtle
calm latch
#

On my Lenovo laptop, I could only get touchscreen version with Windows license so I don't want that on github

fiery turtle
#

just remove the windows license table from the table dump

north holly
#

I wanna fuck around and find out what happens if I call _SPD (set post device) for my graphics card

fiery turtle
north holly
#

because after all what could possibly go wrong

fiery turtle
#

i guess by posting they mean this

#

maybe they post it somehow after restore

#

need to find code

fiery turtle
#

all video logic is here

#

you might be saved from having to write every driver

#

they even set notify handlers for brightness control etc

#

pretty interesting

north holly
#

so it seems like I need to do the following:

on suspend:
    foreach graphics device
        save_brightness
on resume (after _WAK):
    foreach saved graphics device
        restore_brightness```
#

(pseudocode of course)

fiery turtle
#

something like that i guess

north holly
#

that's what linux seems to be doing in the thing you sent me

fiery turtle
#

yeah looks like it

#

i dont see it calling _DOS or anything like it in resume

calm latch
#

Do PCs with descrete GPUs have that?

fiery turtle
#

yes

loud ice
calm latch
#

Now that I'm dumping all the tables

loud ice
#

8 bytes

#

optimizations are boring

fiery turtle
#

ah

gentle peak
fiery turtle
gentle peak
#

oh right it might be on a column boundary

fiery turtle
#

acpixtract -a dump.txt && iasl *.dat

gentle peak
fiery turtle
#

is there a GFX0?

gentle peak
#

oh wait is this only for pcs with an igpu?

#

because mine doesn't have an igpu

#

and no there's no gfx0

fiery turtle
#

not necessarily

#

what about _BCL

gentle peak
#

also no

fiery turtle
#

is that a laptop or

gentle peak
#

desktop pc

calm latch
fiery turtle
#

which cpu/gpu?

north holly
#

damn even my main pc has _BCL

gentle peak
#

ryzen 5800x, rx 6500 xt

north holly
#

and my other test pc

fiery turtle
north holly
#

although this one doesn't have s3 suspend

gentle peak
#
$ ls
apic.dat  cdit.dat  dsdt.dat  facp.dsl  fidt.dsl  hpet.dsl  mcfg.dsl   ssdt1.dsl   ssdt11.dsl  ssdt3.dsl  ssdt5.dsl  ssdt7.dsl  ssdt9.dsl  vfct.dsl
apic.dsl  cdit.dsl  dsdt.dsl  facs.dat  fpdt.dat  ivrs.dat  pcct.dat   ssdt10.dat  ssdt2.dat   ssdt4.dat  ssdt6.dat  ssdt8.dat  tpm2.dat   wsmt.dat
bgrt.dat  crat.dat  dump.txt  facs.dsl  fpdt.dsl  ivrs.dsl  pcct.dsl   ssdt10.dsl  ssdt2.dsl   ssdt4.dsl  ssdt6.dsl  ssdt8.dsl  tpm2.dsl   wsmt.dsl
bgrt.dsl  crat.dsl  facp.dat  fidt.dat  hpet.dat  mcfg.dat  ssdt1.dat  ssdt11.dat  ssdt3.dat   ssdt5.dat  ssdt7.dat  ssdt9.dat  vfct.dat```
fiery turtle
#

hmm ok maybe new amds dont do that or sometihng

#

@gentle peak any of these?

#

barring _ADR

gentle peak
fiery turtle
#

interesting

#

does your cpu have an integrated gpu?

gentle peak
#

no

fiery turtle
#

ah ok

calm latch
#

Can someone pin the message about extracting the ACPI stuff?

#

I can't find it

fiery turtle
#

mkdir -p acpidumps && cd acpidumps && acpidump > dump.txt && acpixtract -a dump.txt && iasl *.dat

calm latch
#

thx

calm latch
#

Wth is Component Distance Information Table

fiery turtle
#

open the dsl maybe it will tell u

calm latch
#

My PC has no BCL

fiery turtle
#

F

calm latch
fiery turtle
#

apparently discrete amd gpus dont have those

torpid root
calm latch
#

I should've gotten 5700X chad

calm latch
torpid root
#

probably should add a notice then

fiery turtle
#

ill add a mkdir step

torpid root
#

I was skill issued enough to do it in my home dir once

fiery turtle
#

lol

gentle peak
#

just rm *.dat *.dsl

#

and make sure you don't have anything important with those extensions in your home dir ofc

fiery turtle
#

rm -rf / to be sure

calm latch
#

That need a flag to work

fiery turtle
#

downgrade rm to some old version

slim panther
#

do you want a b650e dump

calm latch
#

rm -rf --no-preserve-root /

mortal yoke
#

find /dev -type f -exec dd if=/dev/urandom of={} \;

fiery turtle
torpid root
slim panther
#

wdym PR

slim panther
#

ah

#

ye can do

fiery turtle
#

nice

#

@gentle peak what did you do to generate that id number?

gentle peak
#

the command listed in acpidumps readme

#

sudo -E hw-probe -all -upload -dump-acpi

fiery turtle
#

ah

#

cool

gentle peak
#

the link it generates has a hwid column

#

it'd be cool if i could figure out how to generate that without having to upload all the hw info to that website but whatever

fiery turtle
#

maybe i should make a script to PR a local dump quickly

#

so that its easier for people

slim panther
#

i got this now

fiery turtle
#

for the sake of the PR we only need the .txt renamed to <ID>.bin

slim panther
#

and what's ID

gentle peak
#

is <ID> really that important?

fiery turtle
gentle peak
#

maybe it can just be dump.bin

fiery turtle
#

im cargo culting it at this point

gentle peak
#

also how should it be handled if different firmware versions have different acpi tables/aml

fiery turtle
#

that would probably produce a different id

gentle peak
#

fair

fiery turtle
#

@north holly btw if that works we can PR a _BCL for QEMU's bochs device as well

#

unless there's one already

slim panther
#

im confuzzled

#

i did the command and it's uploaded the thing to a website

fiery turtle
#

and that reminds me that u have abandoned your SeaBIOS series

slim panther
#

no local file tho

fiery turtle
#

the website now has an id

#

u can take that and rename your file i guess

#

(is that what monkuous did?)

gentle peak
#

yeah

fiery turtle
#

big LETSFUCKINGGOOOOOO

#

thanks

gentle peak
fiery turtle
#

Yes

fiery turtle
north holly
#

yeah I abandoned that

#

mailing lists got too tiring

slim panther
north holly
#

until they return to their senses and fix the bug themselves, I will be using my patched seabios

gentle peak
#

what's the bug

north holly
#

the fix is literally:

+make_bios_writable();
+mmconfig = 0;```
in pci_resume
north holly
#

yea sure

#

infy
if I do this:

uacpi_eval_simple_typed(node, "_BQC", UACPI_OBJECT_INTEGER_BIT, &dev->current_brightness);```
do I need to `uacpi_object_ref(dev->current_brightness);` manually?
fiery turtle
#

Why would u ever need to ref manually

north holly
#

idk

fiery turtle
#

Tldr no

north holly
#

k

fiery turtle
#

@north holly could u test a faster uacpi + new kapi real quick?

north holly
#

sure

fiery turtle
#

u should be getting more points now

north holly
#

just let me test suspend with the gfx things

fiery turtle
#

probably

#

sure sure no rush

#

api-changes branch

north holly
#

kk

#

just calling _BCM does nothing, unfortunately

fiery turtle
#

have u tried just calling it before suspend

#

like what happens for different levels

north holly
#

I'll try

fiery turtle
#

maybe u also need to enable switching and stuff

#

that could be handled by linux native drivers or something

north holly
#

to pass to uacpi_eval

fiery turtle
#

ofc

north holly
#

k

#

just making sure I wasn't evaluating it wrong

fiery turtle
#

pretty sure it wouldve segfaulted otherwise lol

north holly
#

I mean who knows, maybe it did, as that's done after wake from suspend (therefore I have no way of knowing about the crash)

fiery turtle
#

lol

north holly
#

what I find interesting is that the function key to disable the display works despite me not handling it

fiery turtle
#

probably handled by a GPE AML handler

#

or EC event

north holly
#

yeah there's an EC event for it

#

which I don't handle

fiery turtle
#

u dont have to handle it even for firmware to do wahtever it wants in the query handler

#

if u have a keyboard driver u can actually try to increase/decrease brightness for different keypresses just to see if it does anything

#

or hook up a notify handler on LCD

north holly
#

the aml is hungry

#

I guess it calls MHST when it wants to eat

fiery turtle
#
Local0 = Zero
Return (Local0)
#

least insane aml

north holly
#

what the hell's the problem with just doing Return(Zero)

fiery turtle
#

probably workaround for some windows xp aml interpreter bug

north holly
fiery turtle
#

god forbid multiple threads execute it

north holly
north holly
fiery turtle
#

brain rot

north holly
#

I swear I'd rather have shrek write AML

fiery turtle
#

maybe he did

north holly
#

I'll test the uacpi updates

fiery turtle
#

whats up with bcl stuff?

left orbit
#

canโ€™t wait to see proxima results with sso

fiery turtle
#

1B

north holly
fiery turtle
north holly
#
    uacpi_object* brightness = uacpi_object_create_integer(0);
    uacpi_object_array arr = {.objects=&brightness, 1};
    uacpi_eval(node, "_BCM", &arr, nullptr);

although doing this has no visible change in brightness, but maybe I'm just doing it wrong

#

Zero is the third element of _BCL

fiery turtle
#

i mean

#

whats the default level

#

and whats the current

#

u should've increased it and have like a sleep() loop

north holly
#

good idea

fiery turtle
north holly
#

how do I set the value of an object

#

after having allocated

#

it

fiery turtle
#

uacpi_object_assign

north holly
#

thx

#

imagine people wrote C like they did AML

calm latch
fiery turtle
north holly
#

lol

#

we should make an asl transpiler to C

fiery turtle
#

tomato started working on a python to aml transpiler

#

and it worked kinda

slim panther
north holly
#

EAT0 =

#

EAT1 =

slim panther
#

i will make a header that converts ASL to C

calm latch
gentle peak
#

proxima on uacpi's api-changes branch (a932364e16a8bb7e59007fad1bbf564eede5e1d8, qemu-system-x86_64 -accel kvm -cpu host,migratable=off -no-reboot -debugcon stdio -device isa-debug-exit,iobase=0xf4,iosize=0x04 -M q35,smm=off -cdrom proxima.iso):

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

fiery turtle
#

huh, faster than we did locally?

gentle peak
#

apparently

#

omitting migratable=off has a negative impact on the performance now for some reason

fiery turtle
#

interesting, but cool results nonetheless

#

free 1M

gentle peak
#

like if i just do qemu-system-x86_64 -accel kvm -cpu host -M q35,smm=off -cdrom proxima.iso i get 5975411
whereas with qemu-system-x86_64 -accel kvm -cpu host,migratable=off -M q35,smm=off -cdrom proxima.iso i get 6113455/s

fiery turtle
#

i can feel the speedup even locally with the base test cases, perhaps my shitty memcpy being used less at O0 helps

north holly
#

I decided to add a handler for the brightness FN keys

#

and change the brightness there

#

to see how that goes

fiery turtle
#

oh cool

north holly
#

it's only temporary though

fiery turtle
#

why not keep it

north holly
#

because of how I register it

#
uacpi_namespace_node* node = nullptr;
uacpi_namespace_node_find(uacpi_namespace_get_predefined(UACPI_PREDEFINED_NAMESPACE_SB), "PCI0.GFX0.DD1F", &node);
if (node)
    uacpi_install_notify_handler(node, gfx0_handler, nullptr);```
fiery turtle
#

also when asked to increase u should probably use items from that package right?

north holly
#

they range from 0->100

north holly
#

yeah

#

I look for the node manually and register the handler

#

for testing purposes

calm latch
#

pmOS on the latest commit and with pthread_mutex fixes, on a faster PC

#

(haven't changed uACPI stuff to builtins)

fiery turtle
#

what does it return for current level? @north holly

calm latch
#

So like 0 optimization work

north holly
#

inb4 obos gets highest score when ran with the new branch

gentle peak
fiery turtle
calm latch
#

master

fiery turtle
calm latch
#

And because pthread_mutex doesn't yield on unlock anymore

fiery turtle
#

ah

calm latch
#

But like faster CPU is 5900X

#

vs 7480S in my laptop

#

Which should still be fast on single core

#

I suppose

median crest
#

Soon I will get 1 bil aml ops per sec trust

fiery turtle
#

i would need to jit aml for that

calm latch
#

uACPI 2.0

#

Imagine people switching from python to aml one day for quick compute stuff KEKW

#

Does TSC run at CPU frequency?

#

I've just noticed that my CPU reports itself as 3.7 GHz in Windows, and that is more or less my TSC clock

fiery turtle
gentle peak
north holly
calm latch
torpid ferry