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

1 messages · Page 18 of 1

north holly
#

oh shit

#

obos is broken on amd

calm latch
#

I am at home now

north holly
#

try it anyway

calm latch
#

Where I have 4 more AMD machines

north holly
calm latch
#

From different gens

slim panther
north holly
#

yes

calm latch
#

Though I can't find the charger for one of the lapptops sadmeme

north holly
#

but only intel

slim panther
#

i have only amd

#

i got 3 machines

north holly
#

oh funny thing

#

obos stopped booting on my pc without an EC

#

it hangs after trying to init an EC

fiery turtle
#

ah no thats unrelated

calm latch
north holly
#

there's an EC object actually

calm latch
#

Try pmOS ultrameme

north holly
#

but it's bogus

fiery turtle
#

actually nvm it was fine lol

north holly
#

it has no _CRS

#

therefore it doesn't exist

calm latch
#

My EC driver doesn't use that

#

Afaik

#

iirc

fiery turtle
#

it cant not use that

#

it does current_resources() right?

#

thats _CRS

median crest
#

Least batshit insane firmeare

north holly
#

at all

north holly
median crest
north holly
#

it's not really a loadable driver

#

or one that I would make loadable

#

or discoverable through conventional methods

fiery turtle
north holly
#

and so does my other computer's blob

#

has EC object

#

but no _CRS under it

fiery turtle
#

could be in other SSDTs under the scope

north holly
#

y tho

#

sounds retarted as fuck

#

wait

#

nvm

fiery turtle
#

just filled by the bios dynamically

north holly
#

I remember on my PC it said no EC

#

so

#

just another case of firmware dev

median crest
north holly
#

well, it intertwines with uacpi init quite a bit

#

afaik you rather initialize it before namespace load or after namespace init, depending on how you discover the EC

#

before namespace load is when you have an ECDT

#

and after namespace init is when you don't have an ECDT

fiery turtle
#

yeah

north holly
#

if you truly wanted to, you could add a config option to your kernel

#

to compile it out

jaunty fox
#

how has my track record been

fiery turtle
#

1 for 1 I think?

jaunty fox
#

i think i've only reported one or two problems with u.ACPI and both genuine

fiery turtle
#

yeah

jaunty fox
#

it sounds like a lot of kernels' allocators are stretched to breaking point by uACPI and that provokes false reports

fiery turtle
#

and locking primitives lately meme

median crest
#

Astral survived both teste

#

Tests

north holly
#

not me

#

if you had a penny for each time obos crashed because of uacpi in my 4th rewrite, you would be a billionaire

slim panther
#

just use rust

#

it cannot crash

#

impossible

north holly
#

I hate rust

slim panther
#

why

vale isle
north holly
vale isle
#

i disagree

slim panther
#

wow :(

vale isle
#

i use rust because i like how it smells

slim panther
#

it's just a tool

vale isle
#

not because it's safe

slim panther
#

i use rust because i don't have to think about the code i write

north holly
#

I use C because I like how it smells

slim panther
#

the compiler is my slave

vale isle
#

tbh everyone should learn rust just to understand how to write safe code

#

then just use whatever smells the best

slim panther
#

everyone should be open to learn new things

#

i tried zig and hated it

#

i tried rust and love it

heady pewter
#

D

slim panther
#

:D

vale isle
jaunty fox
heady pewter
#

Yeah

jaunty fox
#

you could do the same in Java or Haskell or ML

north holly
#

just use kasan and ubsan smh

vale isle
slim panther
vale isle
#

whenever i write other languages i still think in rust

north holly
#

idk how corrupting memory in my kernel is the compiler's problem tho

vale isle
jaunty fox
#

i don't intend to come across arrogant in the slightest with this statement, but i have found obsessing over scalability and good locking in keyronex a tonic that has quite changed how i see memory and safety

vale isle
#

sure experience in that will affect how you see this

#

that's not arrogant

#

it's not arrogant to be more experienced

jaunty fox
#

the problems of memory reclamation in single-threaded or crudely multithreaded code now seem completely trifling

flat badge
#

acutally, having RCU at your disposal sometimes makes lifetimes easier, not harder IMHO

flat badge
#

because a lot of times you can just say "i know that objects of this type are never going away while I work with them"

jaunty fox
#

the first taste of it was the vm_page struct

#

since those always exist that makes life so much easier

#

and now just being able to make anything that exists not go away over some period of time - or even to make anything that exists, if the memory backing it ends up reused, be reused as the same type - that is powerful too (and that way is less overhead since it fits so naturally with a slab allocator anyway - just make the slab be deferred free)

rustic compass
#

@fiery turtle what is that? what type does it have exactly?

typedef struct uacpi_namespace_node uacpi_namespace_node;
#

i dont know what rust equivalent i should choose

fiery turtle
#

opaque

rustic compass
#

i mean is it mutated?

fiery turtle
#

thats a tough question

#

not via public api

rustic compass
#

is uacpi_namespace_node itself mutated or only to what it points?

#

forgive me rustc

fiery turtle
#

The latter

rustic compass
#

then opaque should be safe enough

#

is it reference counted?

fiery turtle
#

Only internally

#

Aka the user never gets access to temporary nodes

rustic compass
#

so its safe to copy around?

fiery turtle
#

U cant copy it, its an opaque type

#

Its only ever returned as a pointer

rustic compass
#

is the same true for uacpi_object?

fiery turtle
#

Yes

rustic compass
#

i see that it exposes reference counting, does that mean its allowed to be copied?

fiery turtle
#

what do u mean by copied

#

again its a pointer

#

u can copy the pointer yes

#

stuff like uacpi_eval returns a uacpi_object* that is owned by the caller

#

the caller can unref it to delete or ref if it wants to share it

#

same goes for uacpi_object_create_*

rustic compass
#

i mean that i would allow the opaque type wrapper of uacpi_object to be cloneable which would increase the ref count

#

basicly Object.clone() would increase the ref count

fiery turtle
#

u mean cloning a pointer object?

#

or would that object wrap the pointer

rustic compass
#

this is a struct which contains a uacpi_object pointer which is invisible for the user
the user would get object and is free to clone/copy it, the Object implementation would update the refcount acordingly

pub struct Object(pub(crate) *mut uacpi_sys::uacpi_object);
fiery turtle
#

sorry no idea what that means LULW

#

like a struct that contains a pointer or what

rustic compass
#

i pressed enter before i was finished writing

fiery turtle
#

ah ok

#

yeah

#

in that sense u can copy it

rustic compass
#

as namespace_node doesnt expose refcounting there would only be one instance per pointer

#

its probably a good idea that i explain the wrapper to you once im finished so that you can catch stuff that i implemented wrong

fiery turtle
#

yeah

rustic compass
#

is it correct that these two are identical?

UACPI_OBJECT_BUFFER_INDEX = 21,
UACPI_OBJECT_MAX_TYPE_VALUE = UACPI_OBJECT_BUFFER_INDEX
fiery turtle
#

the last one u probably dont even need to propagate to rust

#

not very useful

rustic compass
#

yea rust also doesnt like it if two fields in an enum have the same value

#

if its not needed i will ignore it else i would give it a different value and translate it

fiery turtle
#

ye

rustic compass
#

so needed or not?

fiery turtle
#

not needed

#

only way how its used

rustic compass
#

i bet 10 second after uacpi-rs is published someone will complain meme

fiery turtle
#

about what?

rustic compass
#

that i dropped that enum value

#

max_type_value

fiery turtle
#

its a common C construct needed only for C

vale isle
#

if you do that there's no way anyone would complain but i don't know what that is used for

vale isle
#

because that's what it really is

#

like const UACPI_OBJECT_MAX_TYPE_VALUE: Foo = Foo::ObjectBufferIndex or something like that

#

if it's needed that is, if it's not needed just expose it in the -sys crate as a constant which is what stuff like bindgen should do automatically

rustic compass
#

using a enum in rust groups the values nicely together

left orbit
#

uacpi on linux when pepepray

#

i can't wait to see how linux scores

#

@fiery turtle would you be able to send a patch or your linux work?

#

unless you actually plan on finishing it

#

otherwise i wanted to look at it myself, but it looks painful to say the least

fiery turtle
#

sure i can send it

#

why painful?

left orbit
#

idk, maybe i'm just unfamiliar with how it's supposed to actually work

#

but the acpi_* functions are ujsed in a lot of places

fiery turtle
#

i wasnt planning on actually integrating uacpi

#

that would take years

#

of literal time

left orbit
#

oh lol

fiery turtle
#

just implement kernel api and initialize it

#

alongside acpica

#

just to see the numbers

#

but yeah there's like a thousand different files using acpica API if u want to fully replace it with uacpi

left orbit
#

yeah, i do wonder how painful would it be meme

#

it would be kinda based tho

#

mainline running with uacpi instead of acpica

fiery turtle
#

probably a year of work

#

if i had to estimate

left orbit
#

yeah... more than i am willing to put in lol

fiery turtle
#

maybe less if u can make a smart script or something

left orbit
#

by about a year

fiery turtle
#

because a lot of apis are translatable 1 for 1

#

some are more complex but not all

#

but for getting the score i was going to just implement kernel api then call uacpi_initialize; uacpi_namespace_load

#

that would be enough

left orbit
#

if i had to guess the "easiest" way to replace acpica would be to remove all the implementation and basically implement it with uacpi instead

fiery turtle
#

u can mostly blindly copy acpica acpi_os_* implementation for that

left orbit
#

but yeah just running using linux kernmel as testbench is good too!

#

i think i can do without patches in that case, unless you think that will greatly reduce the amount of work i have to do

fiery turtle
#

maybe once its integrated into reactos and is successful + stable for a while that could be an idea to entertain

left orbit
#

but it's not like i know linux at all so i'll be staring at the code for a while anyway

fiery turtle
#

i mean full replacement

left orbit
#

i wonder if that would actually be upstreamable

#

just imagine

#

booting your favorite linux distro™️

#

dmesg | grep -i uacpi

#

is uacpi compatible with acpica in terms of aml behavior?

#

i wonder if linux relies on the way acpica works, that sounds silly

fiery turtle
#
--- a/Makefile
+++ b/Makefile
@@ -570,6 +570,7 @@ LINUXINCLUDE    := \
                -I$(objtree)/arch/$(SRCARCH)/include/generated \
                -I$(srctree)/include \
                -I$(objtree)/include \
+               -I$(srctree)/drivers/acpi/uACPI/include \
                $(USERINCLUDE)

 KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 40208a0f5dfb..379f6131bd41 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -31,6 +31,8 @@ acpi-$(CONFIG_ACPI_SYSTEM_POWER_STATES_SUPPORT) += sleep.o
 acpi-y                         += device_sysfs.o device_pm.o
 acpi-$(CONFIG_ACPI_SLEEP)      += proc.o

+obj-y += uACPI/
+

Makefile in uACPI/

ccflags-y           += -DUACPI_OVERRIDE_LIBC
ccflags-y           += -DUACPI_OVERRIDE_TYPES

obj-y += glue.o source/

Makefile in uACPI/source/

ccflags-y           += -DUACPI_OVERRIDE_LIBC
ccflags-y           += -DUACPI_OVERRIDE_TYPES

obj-y += \
        default_handlers.o \
        event.o \
        interpreter.o \
        io.o \
        mutex.o \
        namespace.o \
        notify.o \
        opcodes.o \
        opregion.o \
        osi.o \
        registers.o \
        resources.o \
        shareable.o \
        sleep.o \
        stdlib.o \
        tables.o \
        types.o \
        uacpi.o \
        utilities.o
fiery turtle
#

uacpi would work just fine

fiery turtle
fiery turtle
#

include/uacpi_types.h:

#pragma once

#include <linux/kernel.h>

#include <uacpi/helpers.h>

typedef uint8_t uacpi_u8;
typedef uint16_t uacpi_u16;
typedef uint32_t uacpi_u32;
typedef uint64_t uacpi_u64;

typedef int8_t uacpi_i8;
typedef int16_t uacpi_i16;
typedef int32_t uacpi_i32;
typedef int64_t uacpi_i64;

#define UACPI_TRUE true
#define UACPI_FALSE false
typedef bool uacpi_bool;

#define UACPI_NULL NULL

typedef uintptr_t uacpi_uintptr;
typedef uacpi_uintptr uacpi_virt_addr;
typedef size_t uacpi_size;

typedef va_list uacpi_va_list;
#define uacpi_va_start va_start
#define uacpi_va_end va_end
#define uacpi_va_arg va_arg

typedef char uacpi_char;

#define uacpi_offsetof offsetof

/*
 * We use unsignd long long for 64-bit number formatting because 64-bit types
 * don't have a standard way to format them. The inttypes.h header is not
 * freestanding therefore it's not practical to force the user to define the
 * corresponding PRI macros. Moreover, unsignd long long  is required to be
 * at least 64-bits as per C99.
 */
UACPI_BUILD_BUG_ON_WITH_MSG(
    sizeof(unsigned long long) < 8,
    "unsigned long long must be at least 64 bits large as per C99"
);
#define UACPI_PRIu64 "llu"
#define UACPI_PRIx64 "llx"
#define UACPI_PRIX64 "llX"
#define UACPI_FMT64(val) ((unsigned long long)(val))
#

this is basically all I have

#

for uacpi_libc.h you'll wnat to just make sure everything is using the linux's super fast versions

left orbit
#

i'll see how far i can get

#

for now i'm just compiling it with those changes and see where it errors out

fiery turtle
#

drivers/acpi/osl.c has basically everything in terms of kernel_api.h

left orbit
#

no glue yet ofc

#

ooo thanks

fiery turtle
#

you just have to copy paste carefully

#

everything that starts with acpi_os_* is uacpi_kernel_ basically

#

well they have custom ones that arent actually referenced by acpica but whatever

left orbit
#

also one quick question

#

why did you add the -D flags in both makefiles?

#

is there any reason behind this or just copy paste mistake?

fiery turtle
#

apparently if u add it to one its not propagated to the other

#

im not sure why

left orbit
#

oh wow that sucks

#

thanks

fiery turtle
#

maybe it was a skill issue but i had to add to both

left orbit
#

is uacpi event == acpica semaphore

#

ah fuck it what can go wrong meme

fiery turtle
#

yeah it is

left orbit
#

epic

#

i need to somehow implement mutexes

#

i wonder if i can just do

fiery turtle
#

binary semaphore == mutex, semaphore == event

left orbit
#

spinlock -> mutex -> semaphore

fiery turtle
#

hm?

#

like in your os?

left orbit
#

no like in linux

#

acpi_os implements lock in terms of semaphore

#

and a mutex can be imlemented using a semaphore too

fiery turtle
#

linux has a mutex primitive lol just use that

left orbit
#

oh?

#

hmm

fiery turtle
#

static DEFINE_MUTEX(acpi_ioremap_lock);

left orbit
#

yeah i have no idea what im doing, ill take a look

fiery turtle
#

example

left orbit
#

oh wow nice

#

i have never done linux kernel dev

fiery turtle
#

same, i just know it has every locking primitive on the planet

left orbit
#

so like i actually dont know what im doing

fiery turtle
left orbit
#

but i hope i can make it through

fiery turtle
#

i didnt find a mutex acquire with timeout api

#

there was a patch series in 2020

#

maybe u should use semaphores instead then lmao

left orbit
#

oops

#

yeah i will

#

mutex api is weird

fiery turtle
#

this basically already is a mutex

#

because they have ifs everywhere checking that unit count is always 1

#
    if (!sem || (units < 1))
        return AE_BAD_PARAMETER;

    if (units > 1)
        return AE_SUPPORT;
#

as long as initial_units is 1 this is a mutex

left orbit
#

can i use pthread apis in the kernel ☠️

#
uacpi_thread_id uacpi_kernel_get_thread_id(void)
{
    return (uacpi_thread_id)pthread_self();
}```
#

i was planning for that to be my get_thread_id

#

but i am afraid that might not work ugh

calm latch
#

That's what I do

left orbit
#

yeah but ur not linux

left orbit
#

what the heck is a current

#

is that really a thing?

fiery turtle
#

current task

#

yeah

#

wait lemme see

left orbit
#

damn lol thats crazy

fiery turtle
#

acpica has that kernel api as well

left orbit
fiery turtle
#
static inline acpi_thread_id acpi_os_get_thread_id(void)
{
    return (acpi_thread_id) (unsigned long)current;
}
left orbit
#

☠️

fiery turtle
#

yup

left orbit
#

even copilot knows

hollow elm
#

those who know

left orbit
#

does timeout = 0 work the same for events as it does for mutexes?

slim panther
#

cursed

left orbit
#

the kernel api docs dont explain that

fiery turtle
#

yeah

#

same thing

left orbit
#

cool ty

fiery turtle
#

0 => try_acquire

left orbit
#

yeah, question still stands

#

i guess i can read the acpica os deps

fiery turtle
#

they already do

left orbit
#

well i was asking because uacpi kernel api returns the flags

#

and there's raw_spin_lock and raw_spin_lock_irqsave

#

i was wondering which ones i should use ;D

fiery turtle
#

for whatever reason i think acpica spinlocks dont??

#

u want lock_irqsave

left orbit
#

makes sense

#

now the "worst" kernel apis are left uacpi_kernel_handle_firmware_request uacpi_kernel_install_interrupt_handler uacpi_kernel_uninstall_interrupt_handler uacpi_kernel_schedule_work uacpi_kernel_wait_for_work_completion

#

i wonder if i should try running without those

#

i mean i don't think they are needed during namespace load

gentle peak
#

i think of those only install_interrupt_handler is ran by uacpi_namespace_load on qemu/kvm

#

and i think it'll still work without it

fiery turtle
#

very interesting

left orbit
#

also, where should i call uacpi_initialize? :^)

#

or where did you call it

gentle peak
#

i'd do so wherever acpi_subsystem_initialize is currently being called

fiery turtle
#

here

fiery turtle
#

acpica has exact same api, u could just steal osl.c for it

#

with workqueues and stuff

left orbit
#

effort

gentle peak
#

meanwhile i'm just trying to figure out how to get linux to compile with -march=x86-64-v2 to get rid of the popcount libgcc reference

left orbit
#

and probably not needed meme

fiery turtle
gentle peak
#

trying to yeah

left orbit
#

like before bus_register would be good?

fiery turtle
#

like literally anywhere in that function at the bottom

#

this is right after acpica init

left orbit
#

ok ill do it after the bus_register then

fiery turtle
#

cool

left orbit
#

hopefully it wont breka nything

gentle peak
#

this is what i'm doing for init (bus.c)

#

figured i'd make acpica init fail since idk if they'd try to double init hardware

fiery turtle
#

on qemu shouldnt matter

#

(probably)

#

i dont think QEMU's aml has global state that would interfere, but im not 100% confident

gentle peak
#

probably not but better safe than sorry

fiery turtle
#

yeah

gentle peak
#

wonder how long linux compile would take with LTO

fiery turtle
#

depends how many modules u have as -y

gentle peak
#

defconfig

fiery turtle
#

quite a lot probably lol

#

inb4 linux scores less than your kernel

gentle peak
#

idk if linux parallelizes init but if it does hydrogen will probably outperform it since on there uacpi has the whole vcpu to itself

#

during init at least

fiery turtle
#

nah, this is fairly early init as part of subsystem initcalls

#

i think its single threaded

left orbit
#

ld: vmlinux.o: in function uacpi_popcount': (.text+0x5de955): undefined reference to __popcountdi2'

gentle peak
#

yeah i just edited one of the makefiles to pass -march=x86-64-v2

fiery turtle
#

i should really get rid of that __builtin_popcount

gentle peak
#

yeahh

fiery turtle
#

its needed only for the aml countbits i think

gentle peak
#

proxima isn't affected by it since it uses clang for compilation but still

fiery turtle
#

clang ships its own implementation for it?

left orbit
gentle peak
#

i think clang just doesn't use a builtin

left orbit
#

it linked! 🎉

gentle peak
#

if popcount isn't available for the target it does it inline

fiery turtle
#

qemu-system-x86_64 -kernel vmlinuz should work i think?

gentle peak
#

the command i'm using for testing is make -j12 && qemu-system-x86_64 -accel kvm -cpu host -kernel arch/x86/boot/bzImage -serial stdio -append "earlyprintk=ttyS0 console=ttyS0" -display none

fiery turtle
#

nice

#

@left orbit u did the libc overrides and stuff right?

#

to make sure it uses the linux stuff

left orbit
#

nope lol but i just want ot make it works first

#

i forgot

fiery turtle
#

that would probably really bump the perf

left orbit
#

i dont see any uacpi logs

#

how did i fuck it up

fiery turtle
#

lol

left orbit
#

ill try to bug_on(false) in print

#

👍

fiery turtle
#

u mean bug_on(true)?

gentle peak
#

where is it getting this oom from, i'm logging all uacpi_kernel_alloc calls

fiery turtle
#

mutex or spinlock

gentle peak
#

ohh

fiery turtle
#

or event

gentle peak
#

right

left orbit
#

it never gets to my prints

#

rip

fiery turtle
#

lmaoo

#

u did bug_on(true) right?

left orbit
#

yeah

fiery turtle
#

because false means not a bug

left orbit
#

ill call uacpi_init at the start of acpi_bus_init

fiery turtle
#

or just do WARN_ON(1)

left orbit
#

it didnt get called

fiery turtle
#

how did u even manage to fuck that part up 💀

left orbit
#

[ 0.426670] RSDP 0x00000000000F52B0 00000000 v00 (BOCHS )
[ 0.428618] ioremap error for 0x7fe2000-0x7fe3000, requested 0x2, got 0x0
[ 0.429566] ACPI: Unable to initialize uACPI

#

yoooo

fiery turtle
#

nice

#

what was it?

left orbit
#

oh i am retarded

#
result = bus_register(&acpi_bus_type);
if (!result)
    return 0;```
#

i put it

#

after the return 0

fiery turtle
#

lmao

left orbit
#

well no shit it never got called

#

time to figure out why my kernel api is fucked

fiery turtle
#

maybe we should fork linux and make a branch with uacpi integration since thats pretty interesting

#

could start slowly carving away at acpica calls

left orbit
#

that would be cool as fuck

fiery turtle
#

yes LETSFUCKINGGOOOOOO

left orbit
#

got somewhere

#

1.7m

fiery turtle
#

thats with my shitty libc right?

left orbit
#

i'd assume so, yes

fiery turtle
#

nice

hollow elm
#

oddly precise 1705000/s

fiery turtle
#

exactly 1ms i geuss

#

or is the timer resolution just garbage

left orbit
#

i copied that from acpica

#
uacpi_u64 uacpi_kernel_get_nanoseconds_since_boot(void)
{
    return (get_jiffies_64() - INITIAL_JIFFIES) * (ACPI_NSEC_PER_SEC / HZ);
}```
fiery turtle
#

looks correct

#

how did u manage to invoke an invalid opcode error in spinlock_free LULW

slim panther
#

i just realized the fn is called "since boot"

left orbit
#

because my BUG_ON was inverted lmao

slim panther
#

is it fine to just pass any timer

left orbit
#

i did BUG_ON(!locked) in spinlock_free

fiery turtle
left orbit
#
[    0.436317] RSDP 0x00000000000F52C0 00000000 v00 (BOCHS )
[    0.438221] RSDT 0x0000000007FE22FC 00000038 v01 (BOCHS  BXPC    )
[    0.440229] DSDT 0x0000000007FE0040 000020B4 v01 (BOCHS  BXPC    )
[    0.441216] FACP 0x0000000007FE20F4 000000F4 v03 (BOCHS  BXPC    )
[    0.444218] APIC 0x0000000007FE21E8 00000078 v03 (BOCHS  BXPC    )
[    0.446232] HPET 0x0000000007FE2260 00000038 v01 (BOCHS  BXPC    )
[    0.448240] MCFG 0x0000000007FE2298 0000003C v01 (BOCHS  BXPC    )
[    0.450249] WAET 0x0000000007FE22D4 00000028 v01 (BOCHS  BXPC    )
[    0.452570] FACS 0x0000000007FE0000 00000040
[    0.455686] successfully loaded 1 AML blob, 1705 ops in 2ms (avg 852500/s)
[    0.456373] unable to install SCI interrupt handler: unimplemented
[    0.457216] event initialization failed: unimplemented
[    0.461014] ACPI: Unable to load uACPI namespace```
#

damn, it's slower with linux ones

fiery turtle
#

huh what lol

left orbit
#
#pragma once

#include <asm/string.h>

#define uacpi_memcpy memcpy
#define uacpi_memset memset
#define uacpi_memcmp memcmp
#define uacpi_strcmp strcmp
#define uacpi_memmove memmove
#define uacpi_strlen strlen
#define uacpi_snprintf snprintf
#define uacpi_vsnprintf vsnprintf
#

i did that

#

basically

fiery turtle
#

wtf

#

how is that possible LULW

#

my impl is literally crap

left orbit
#

great question

fiery turtle
#

or that timer is bogus

#

but looks correct to me idk

left orbit
#

ok yeah that timer is shit

#

[ 0.454548] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 1705000000000/s)

#

fastest uacpi implementation

fiery turtle
#

what did u change?

left orbit
#

nothing

#

i just reran it

slim panther
left orbit
#

¯_(ツ)_/¯

fiery turtle
#

ah yeah its crap

#

i guess

left orbit
#

[ 0.458990] successfully loaded 1 AML blob, 1705 ops in 2ms (avg 852500/s)
[ 0.450287] successfully loaded 1 AML blob, 1705 ops in 3ms (avg 568333/s)
[ 0.452721] successfully loaded 1 AML blob, 1705 ops in 1ms (avg 1705000/s)

#

three consecutive runs

#

makes no sense for there to be so much variation

fiery turtle
#

yeah not to mention its slow as shit

left orbit
#

i mean

#

honestly i didnt expect it to be particularly fast

winter orbit
fiery turtle
#

i kinda did because their mem* stuff is very fast

left orbit
#

i dont think the speed of linux comes from it being really well optimized and shit

#

maybe it matters more in a hobby os? idk

slim panther
fiery turtle
#

if u look at the leaderboard thats like menix speed lol

calm latch
fiery turtle
#

maybe monkuous will have better results

left orbit
#

linux is the fastest out there

fiery turtle
#

with that magic touch

slim panther
#

maybe menix slab is the same as the linux impl

fiery turtle
left orbit
#

ikik

#

i can tell lmao

fiery turtle
#

lmao

gentle peak
#

and so is get_jiffies_64

fiery turtle
#

ohh

#

like the fact that overriding libc made no difference does sound sketchy

gentle peak
#

i know the kernel has a time reference at time of init already because printk is printing time

fiery turtle
#

yeah

left orbit
#

ill try ktime_get

#

oh

#

well ill try anyway meme

gentle peak
#

yknow what i'm just gonna return __builtin_ia32_rdtsc()

fiery turtle
#

lool

left orbit
#

same shit

fiery turtle
#

are u sure 1 tick == 1 ns?

left orbit
#

as inaccurate as get_jiffies_64

gentle peak
fiery turtle
#

ohh

#

i wonder if kvm clock is still not initialized at this point

gentle peak
#

that might be it

fiery turtle
#

hmm

gentle peak
#

although i wonder what magical time api printk is using then

#

anyway: [ 0.070157] uacpi: 3: successfully loaded 1 AML blob, 1705 ops in 1ms (avg 1512953/s)

fiery turtle
#

thats with libc overrides right

gentle peak
#

yeah

fiery turtle
#

L

gentle peak
#
#pragma once

#define memcmp __builtin_memcmp
#define memcpy __builtin_memcpy
#define memmove __builtin_memmove
#define memset __builtin_memset

#define strcmp __builtin_strcmp
#define strlen __builtin_strlen
#define strnlen __builtin_strnlen
fiery turtle
#

menix > linux

left orbit
#

kvm clock is initialized at that point

#

[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[ 0.000002] kvm-clock: using sched offset of 435683178 cycles
[ 0.001871] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns

fiery turtle
gentle peak
#

wasn't sure whether the linux versions were fully conforming

fiery turtle
#

they are i think

#

with some extensions

#

is it possible that override libc is not propagated everywhere?

left orbit
#

it is

fiery turtle
#

like the define

#

beacuse i had issues with that

left orbit
#

adding the c flag in the makefile should be enough

fiery turtle
#

should be

fiery turtle
gentle peak
#

oh wait i didn't prefix the things with uacpi_

fiery turtle
#

lol

gentle peak
#

brain not working full speed today

fiery turtle
#

1.5 with naive memcpy is fair

gentle peak
#

[ 0.067545] uacpi: 3: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 3104283/s)

#

that seems more reasonable

fiery turtle
#

indeed

gentle peak
#

i also wonder whether telling qemu to override the tsc frequency degrades speed

fiery turtle
#

right behind managarm

gentle peak
#

so i am going to get the real tsc freq from proxima and hardcode that instead

left orbit
#

damn that rdtsc is nice

gentle peak
#

3792.961870 MHz

fiery turtle
#

do u also build with LTO?

gentle peak
#

not yet

#

i do with proxima

fiery turtle
#

ah

#

that might give it the final bump LULW

gentle peak
#

probably but i figured i wouldn't wait >1h for it to compile before making sure the kernel api works

fiery turtle
#

fair fair

gentle peak
#

actually i might try and figure out how much i need to enable starting from tinyconfig to get the output

fiery turtle
#

what is that?

gentle peak
#

tinyconfig is a preset that's just the minimum to get a working kernel

fiery turtle
#

ohh

#

i wonder if a lot of other allocations including acpica are fragmenting the heap causing degraded perf

left orbit
#

pretty sure linux does lto with default config

#

when i did BUG_ON in print i got a lot of noreturn warnings

gentle peak
#

so i doubt it

fiery turtle
#

maybe other subsystems as well ig

gentle peak
#

with hardcoded tsc frequency so that qemu can just pass through rdtsc to the host cpu:
[ 0.065107] uacpi: 3: successfully loaded 1 AML blob, 1705 ops in 0ms (avg 3120527/s)

#

didn't make a huge difference

fiery turtle
#

yeah i guess its cheap then

gentle peak
#

makes sense considering there were a grand total of 2 calls

fiery turtle
#

lol

gentle peak
#

tinyconfig time

fiery turtle
gentle peak
#

and linking didn't take >1h

#

...huh

#

with tinyconfig there's a significant performance regression

#

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

#

wonder what that's caused by

fiery turtle
#

btw you might also be building with unconditional memory zeroing and stuff

#

or sanitizers

gentle peak
#

maybe

fiery turtle
#

a lot of stuff that could be on by default

#

i know ubsan and unconditional zeroing is enabled for ubuntus

gentle peak
#

i really have no idea where to look in menuconfig for those things

fiery turtle
#

ubsan is just CONFIG_UBSAN_*

#

zeroing is somewhere in the security section

gentle peak
#

ah this is enabled by default with tinyconfig

fiery turtle
#

dont remember the exact option

#

ah the crappy slab

left orbit
#

just use the arch config

#

its pretty good minus the terrible amount of drivers you have to build

gentle peak
left orbit
#

but u can turn those off

#

wtf

gentle peak
fiery turtle
#

uacpi is not allocator bound proved meme

gentle peak
#

ok so that's not it

#

stack vars were zero-inited by default i imagine that had an impact

#

but none of the other zero-init stuff was enabled

fiery turtle
#
config INIT_ON_ALLOC_DEFAULT_ON
    bool "Enable heap memory zeroing on allocation by default"
    depends on !KMSAN
    help
      This has the effect of setting "init_on_alloc=1" on the kernel
      command line. This can be disabled with "init_on_alloc=0".
      When "init_on_alloc" is enabled, all page allocator and slab
      allocator memory will be zeroed when allocated, eliminating
      many kinds of "uninitialized heap memory" flaws, especially
      heap content exposures. The performance impact varies by
      workload, but most cases see <1% impact. Some synthetic
      workloads have measured as high as 7%.
#

this one maybe

gentle peak
#

yeah that one's disabled

gentle peak
fiery turtle
#

makes sense

left orbit
#

im compiling with -O3 -march=native -pipe with clang thinlto

gentle peak
#

i really have no idea what the rest could be since the only kernel api functions i had to implement are incredibly basic

left orbit
#

lets see how bad it is

gentle peak
#

oh god does linux even work with -O3?

fiery turtle
#

does linux even support O3

#

i dont think so

left orbit
#

@gentle peak can i have the command line you're using to do rdtsc?

#

we're about to fdind out meme

gentle peak
#

-cpu host,tsc-frequency=1000000000

left orbit
#

god my pc is dying

fiery turtle
#

linux doesnt work with anything other than O2

left orbit
#

thanks'

median crest
fiery turtle
#

welllll

#

if u look at the leaderboard...

gentle peak
#

yknow what i'm just gonna remove stuff from defconfig instead of adding to tinyconfig

fiery turtle
#

fair

slim panther
median crest
left orbit
#

any bets on how long it'll take to link with lld? :^)

#

thinlto

#

idk waht that means but

#

it definitely is doing something

#

judging by it hogging up an entire code for whatever it's doing

#

mining crypto or whatever

gentle peak
#

oh god the final stage of lto is single threaded?

left orbit
#

i think so lmao

fiery turtle
left orbit
#

it went full blast for like 20 seconds and now its stuck on a single thread

#

IT DID IT

gentle peak
left orbit
#

link takes about 2 mintues meme

#
[    0.360596] RSDP 0x00000000000F52C0 00000000 v00 (BOCHS )
[    0.362528] RSDT 0x0000000007FE22FC 00000038 v01 (BOCHS  BXPC    )
[    0.364499] DSDT 0x0000000007FE0040 000020B4 v01 (BOCHS  BXPC    )
[    0.365495] FACP 0x0000000007FE20F4 000000F4 v03 (BOCHS  BXPC    )
[    0.369574] APIC 0x0000000007FE21E8 00000078 v03 (BOCHS  BXPC    )
[    0.370500] HPET 0x0000000007FE2260 00000038 v01 (BOCHS  BXPC    )
[    0.372585] MCFG 0x0000000007FE2298 0000003C v01 (BOCHS  BXPC    )
[    0.374644] WAET 0x0000000007FE22D4 00000028 v01 (BOCHS  BXPC    )
[    0.375497] FACS 0x0000000007FE0000 00000040
[    0.378258] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 2857324/s)
[    0.380480] unable to install SCI interrupt handler: unimplemented
[    0.380496] event initialization failed: unimplemented
[    0.383523] ACPI: Unable to load uACPI namespace```
#

meh that's shit

gentle peak
#

really not sure

fiery turtle
left orbit
#

also , it works with -O3? :^)

gentle peak
#

i didn't pay attention to perf for a while because i use tcg while developing

#

and like 20 commits and a few uacpi updates later i checked again

#

don't know what exactly caused the regression

left orbit
#

if anybody wants to give the image a go

#

qemu-system-x86_64 -M q35 -kernel arch/x86/boot/bzImage -enable-kvm -serial stdio -append "earlyprintk=ttyS0 console=ttyS0" -cpu host,tsc-frequency=1000000000

fiery turtle
fiery turtle
gentle peak
# left orbit

i'll test later but how do you get the kernel to compile with lto and -o3?

#

wanna test with my kernel api impl

left orbit
#

make LLVM=1 KCFLAGS="-O3 -march=native -pipe" -j26

fiery turtle
# left orbit if anybody wants to give the image a go
qemu-system-x86_64: warning: TSC frequency mismatch between VM (1000000 kHz) and host (3600010 kHz), and TSC scaling unavailable
qemu-system-x86_64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Operation not supported
left orbit
#

also make LLVM=1 menuconfig

#

then go into general architectue blah blah blah

#

and enable lto

#

i dont think it can do lto with gcc, there were no options in menuconfig without LLVM=1

#

so you'll have to recompile with llvm

fiery turtle
#

WSL2 loses again i guess

left orbit
#

oh, im on wsl2

fiery turtle
#

hmm then idk lol

left orbit
median crest
#

Its some cpu specific bullshit

gentle peak
#

i'm gonna use -j20 even though i only have 16 lcpus wish me luck

fiery turtle
#

im on i9 9900K

median crest
#

Hyperv likes some cpus and dislikes others

left orbit
#

i do -j26 and i have 24 threads

#

should i try linux zen config?

#

or arch maybe

gentle peak
#

oh great this isn't valid on clang

left orbit
#

-fno-builtin?

gentle peak
#

-fno-builtin just means that it doesn't translate x() to __builtin_x()

left orbit
#

oh i see

gentle peak
#

that linked really quickly wtf is it even using lto

#

it's now 3.5M/s vs 3.2M/s so maybe?

#

well whatever

#

i'll test your image

fiery turtle
#

seems fair

#

btw does the score change if u change -smp?

gentle peak
# left orbit

this image is only 600k-800k on my machine somehow

fiery turtle
#

magic mokuous touch is real

#

it boosts your points by 3mil at least

gentle peak
#

-smp 4 is still in the 3.4-3.6M/s range

fiery turtle
#

i guess doesnt matter

north holly
fiery turtle
#

would be fun to do isolcpus=1,2,3,4 and then pin qemu vcpus there

#

see how perf changes with exclusive vcpu pinning

gentle peak
#

i wonder...

left orbit
#

oh god turning lto off is a full rebuild?

#

wtf

fiery turtle
fiery turtle
slim panther
# left orbit

[ 0.114300] successfully loaded 1 AML blob, 1705 ops in 2ms (avg 783966/s)

#

lol

slim panther
gentle peak
# fiery turtle but then again you didnt measure proxima that way and got 5m anyway

oh no i wasn't wondering about that, what i was wondering about is that proxima's perf actually slightly degrades when i'm using -accel kvm -cpu host,migratable=off because it can then get the tsc frequency from cpuid, skip calibration and get to uacpi init so quickly that linux hasn't increased the cpu freq of whatever it's running on or whatever

slim panther
#

-smp 1 yields 1.8mil on menix, but -smp 2 yields 700k

gentle peak
#

whereas if i just use normal -accel kvm -cpu host it calibrates for 500ms during which, from linux's perspective, qemu's utilizing 100% cpu

north holly
#

which tbf without smp enabled are a lot faster than what they were before

gentle peak
#

i was wondering whether something similar could be applied to linux here

slim panther
#

okay this is weird

#

[ 0.116306] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 2601524/s)

#

rerun

fiery turtle
#

are u on a laptop?

gentle peak
#

nah, ryzen 5800x

fiery turtle
#

i mean marvin

gentle peak
#

oh

slim panther
#

7700X desktop

fiery turtle
#

because laptops do this scaling thing

#

maybe desktops too lmao idk

slim panther
#

it's only on the first ever boot up

gentle peak
#

let's see

slim panther
#

[ 0.115882] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 2621600/s)

#

yea seems stable

#

2.6m

fiery turtle
#

secret uacpi benchmarking tricks they dont tell u about

slim panther
fiery turtle
#

cpu warming up before the benchmark

gentle peak
#

okay i'm pretty sure this is getting optimized away even though the asm is volatile

#

either that or my threshold is wrong

fiery turtle
#

::: "memory"?

gentle peak
#

multiplying the threshold by 10 first because there's no way i'm missing a 5s delay

#

yeah ok i just wasn't noticing it

#

didn't have a noticeable effect on uacpi perf though, damn

fiery turtle
#

damn

gentle peak
#

for reference: proxima when doing tsc calibration (aka 500ms of 100% cpu usage) gets 4.8-4.9M/s. when not doing tsc calibration, it gets 3.7-3.8M/s

fiery turtle
#

very curious

#

i wonder if other projects are affected by this LULW

left orbit
#

@gentle peak do you do irq handlers?

gentle peak
#

in proxima yeah

left orbit
#

i was curious about your linux api

gentle peak
fiery turtle
#

your malloc is so fucking simple lol

#

i guess struct page helps

gentle peak
#

it's simple, and it's enough for my purposes

fiery turtle
#

yeah

#

i wonder how it scales tho

#

im definitely stealing this when i get back to actual osdev

gentle peak
#

like, smp scaling? probably similar to any other allocator that doesn't have magazines

fiery turtle
#

or even threads, since it doesnt have lockless fast paths etc

gentle peak
#

true but it doesn't do much work while holding a lock

fiery turtle
#

yeah

gentle peak
#

iirc lockless stuff tends to be slower on single-cpu machines

fiery turtle
#

why does it need a mutex there, wouldnt a spinlock be enough?

median crest
gentle peak
#

so if it doesn't need a spinlock it gets a mutex

fiery turtle
#

hmm

#

wouldnt a spinlock that doesnt disable irqs be faster

gentle peak
#

same speed actually

fiery turtle
#

or are we talking uncontended cases

median crest
#

same speed yeah

#

its all a CAS at the end

gentle peak
#

spinlock without disabling irqs is 1 CAS, mutex is 1 CAS

#

if it's contended any kind of spinlock is usually slower especially on single cpu machines

fiery turtle
#

i guess spinlock would be even slower

#

because it cant reschedule when it waits

gentle peak
#

yeah

fiery turtle
#

whereas for mutexes it would just block the thread

gentle peak
#

a spinlock that does sched_yield instead of cpu_relax would be somewhere in the middle i believe

#

but still worse than a normal mutex

fiery turtle
#

makes sense

#

yeah im definitely stealing a lot of fundamentals from your os

gentle peak
#

no problem, that's why it's MIT licensed

fiery turtle
#

it's mit too which is nice

#

yeah

median crest
#

and why I am gonna use something else soon enough

fiery turtle
#

any plans to make it numa aware?

gentle peak
#

not really

left orbit
#
[    0.926961] RSDP 0x00000000000F52C0 00000000 v00 (BOCHS )
[    0.927269] RSDT 0x0000000007FE22FC 00000038 v01 (BOCHS  BXPC    )
[    0.928269] DSDT 0x0000000007FE0040 000020B4 v01 (BOCHS  BXPC    )
[    0.929272] FACP 0x0000000007FE20F4 000000F4 v03 (BOCHS  BXPC    )
[    0.930273] APIC 0x0000000007FE21E8 00000078 v03 (BOCHS  BXPC    )
[    0.931267] HPET 0x0000000007FE2260 00000038 v01 (BOCHS  BXPC    )
[    0.932269] MCFG 0x0000000007FE2298 0000003C v01 (BOCHS  BXPC    )
[    0.933266] WAET 0x0000000007FE22D4 00000028 v01 (BOCHS  BXPC    )
[    0.934288] FACS 0x0000000007FE0000 00000040
[    0.936003] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 2834533/s)```
gentle peak
#

at least not in this rewrite

left orbit
#

final score, i am not going to try anymore

fiery turtle
#

close enough

#

got the image?

left orbit
#

me?

fiery turtle
#

yeah

left orbit
gentle peak
left orbit
#

it does the funny rdtsc warmup

fiery turtle
#

maybe it would be faster on monkuous' cpu

left orbit
#

idk if it actually makes any difference

gentle peak
left orbit
fiery turtle
gentle peak
#

nothing concrete, probably just "indistinguishable from standard linux except NIH"

fiery turtle
#

which probably takes a bit of your points

gentle peak
#

oh no not abi

fiery turtle
#

ah

left orbit
#

yeah true, i was thinking about properly implementing a bounds check but i gave up because i was like "meh"

#

ill change that real quick and see if it makes a difference

gentle peak
#

the kernel won't even have a true stable abi

#

my plan is to make a vdso-like thing be the only stable way to do syscalls

fiery turtle
north holly
#

ntdll.dll

gentle peak
#

yeah

left orbit
fiery turtle
#

ntdll is not exactly a vdso

gentle peak
fiery turtle
#

oh

north holly
left orbit
#

it does this weird thing where its either hhdm or actual mapping

#

and i didnt know how to properly do unmap for that lol

#

its probably easy but yeah idk

fiery turtle
#

lol

#

its probably always hhdm

left orbit
#

nope it does get to the ioremap

fiery turtle
#

@gentle peak can you dump your api impl as well?

gentle peak
fiery turtle
left orbit
#

3271792/s with proper iomap :D

left orbit
fiery turtle
#

ah

fiery turtle
left orbit
#
static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr)
{
    unsigned long pfn;

    pfn = pg_off >> PAGE_SHIFT;
    if (should_use_kmap(pfn))
        kunmap(pfn_to_page(pfn));
    else
        iounmap(vaddr);
}```
#

their unmap can do that

#

because it takes a pg_off

#

whatever that means

gentle peak
#

i think i indirectly use that exact method

#

since my uacpi_kernel_{map,unmap} just call acpi_os_*

fiery turtle
#

loool

gentle peak
#

not the most familiar with linux's kernel internals and i figured that that'd be the easiest way to make sure it worked

fiery turtle
#

lmao

#

probably true

left orbit
#

what the hell did u pass to unmap as the physical address

#

u dont even get one from uacpi

gentle peak
#

the function you sent is an internal one for the osl layer

fiery turtle
gentle peak
#

the actual function - acpi_os_unmap_memory - takes a pointer

#

that's the one i call

gentle peak
#

and i assume it eventually calls acpi_unmap

left orbit
#

ah they just keep a list of mappings

fiery turtle
#

they have a cache yeah

gentle peak
fiery turtle
#

I can update the score later if you'd like meme it’s still at 4.6

left orbit
#

back to 2.8-2.9M wtf

#

i did nothing 😭

gentle peak
#

too small of a difference to make me really care about it, and the giving empty pages back to pmm thing is desirable behavior, so i won't be permanently removing it, but nice to know where it came from

fiery turtle
#

Do you think it’s possible to squeeze out more?

gentle peak
north holly
fiery turtle
gentle peak
#

ah ok

gentle peak
#

2s let me get a real sample

north holly
#

I'm allowed to do --no-smp right

#

to the kernel

fiery turtle
#

The rules are all API must be implemented fairly, q35 + kvm

#

Everything else is up to u

dusky glade
#

after i get this bug fixed i might make uacpi run in a thread trl

#

kentry thread anyway

#

i have no way of communicating with other threads atm

north holly
dusky glade
north holly
#

block threads for specific periods of time

fiery turtle
#

Kid named Morse

north holly
#

btw

fiery turtle
#

Noted

north holly
#

although I still don't beat anyone yet

#

I will at least be far from being beaten by nyaux

north holly
fiery turtle
#

Inb4 nyaux fixes skill issues and gets 10M

north holly
fiery turtle
left orbit
#

but im not too sure about how correct it is

fiery turtle
#

Nice, we should really make a fork

left orbit
#

but not like it matters

fiery turtle
#

To at least store it for testing

left orbit
#

that would definitely be cool

north holly
#

is it finally happening

fiery turtle
#

Ill make one

north holly
#

is linux getting uacpi support

fiery turtle
#

Kinda

fiery turtle
left orbit
#

i can make a patch one sec

gentle peak
fiery turtle
left orbit
#

oh i don't have a submodule meme

left orbit
#

i just downloaded a tarball of uacpi and extracted it

fiery turtle
#

Bruh

#

That works ig KEKW

left orbit
#

lemme nuke test cases tho

#

and everything that isnt source or a header lol

gentle peak
# fiery turtle Crazy numbers

with my current unpushed code i get 5,063,043/s but i feel like that's a bit cheating since the heap shrinking is commented out

#

(aka stuff <PAGE_SIZE doesn't get returned to pmm)

fiery turtle
#

Sort of I guess, since u dont wanna be leaking pages

fiery turtle
gentle peak
#

no, <

fiery turtle
#

Oh

gentle peak
#

PAGE_SIZE gets handled by a different allocator, that one still gives back memory

left orbit
#

@fiery turtle is a patch okay?

fiery turtle
#

I see

fiery turtle
left orbit
#

lots of uacpi :^)

fiery turtle
#

Lol

gentle peak
gentle peak
#

wanted to make sure everything could handle PAGE_SHIFT not matching what the architecture expects so i just picked something at random

left orbit
#

for "our" usecase it's probably okay to add a submodule in the root of the repo and symlink source + include into drivers/acpi/uacpi

fiery turtle
#

Ah good idea

gentle peak
#

i can set it to 12 rq and see how it affects benchmarks

#

page fault.

fiery turtle
#

Lol

left orbit
#

that gets rid of the "makefile in submodule" problem

fiery turtle
#

Yea

left orbit
#

at the expense of "fuck windows users" but not like ur compiling linux on windows anyway

fiery turtle
#

U cant even clone it on windows

left orbit
#

actually?

#

lmao

fiery turtle
#

Yeah

#

Same name different case

#

Doesnt work on windows

left orbit
#

good

#

anyway if you do fork linux i can do the dirty work of submodule + adapting this patch for that i guess

left orbit
#

shouldn't be that bad but yeah

#

ultraos org maybe?

#

makes sense

fiery turtle
#

Sure ill do that first thing tomorrow

left orbit
#

ultraos/linux-uacpi or something

#

sounds good

fiery turtle
gentle peak
# gentle peak page fault.

figured it out:

  • KERNEL_STACK_SIZE is still 16k, so the kernel stack of the init task was allocated with vmalloc_large instead of kalloc as it was when PAGE_SIZE was 16k
  • the size given to vmfree when freeing said stack was the size of my task_t struct instead of that of the stack itself, so it was freed with kfree instead of vmfree_large
left orbit
#

i will do that yes

fiery turtle
gentle peak
#

this worked before because kfree unlike vmfree doesn't take size as param

#

anyway has no bearing on uacpi benchmark thankfully

fiery turtle
#

So you've uncovered a bug?

gentle peak
#

yeah

#

well a page fault is a bug regardless

#

but still

fiery turtle
#

I should adapt a dumb page size idea as well

#

For my stuff

#

Like Linux does with jiffies

#

Setting initial to random values

gentle peak
#

uacpi benchmarks

  • PAGE_SIZE 4k: 4 560 359
  • PAGE_SIZE 16k: 4 794 861
#

not too significant of an impact

fiery turtle
#

Probably because u get buckets for smaller allocations instead of going into the pmm?

gentle peak
#

going into the pmm is pretty fast actually, but for >PAGE_SIZE i don't just go into the pmm, i go off of the hhdm entirely so i need to allocate a virtual address and map it

fiery turtle
#

Ah

#

Vmalloc basically?

gentle peak
#

yeah

fiery turtle
#

Makes sense

#

Do u prefault those

#

I guess u do

gentle peak
#

demand paging isn't used for kernel memory so doesn't really apply

#

but yeah it's the equivalent of prefaulting

left orbit
#

ok epic back to where we were but now with a submodule
[ 0.376604] successfully loaded 1 AML blob, 1705 ops in 0ms (avg 2818167/s)

fiery turtle
#

Very nice

fiery turtle
gentle peak
#

nt yeah but hydrogen doesn't and won't

fiery turtle
#

Fair lol

gentle peak
#

the idea is that if you're calling into vmalloc_large a lot you're probably doing something wrong anyway

fiery turtle
#

Why _large?

gentle peak
#

it's only used for >PAGE_SIZE

fiery turtle
#

Is there a small equivalent

gentle peak
#

there's normal vmalloc which decides whether to use kalloc or vmalloc_large based on the size given

fiery turtle
#

Ohh

#

Smart

gentle peak
#

basically:

  • you use kalloc when you need power-of-two alignment or easy mapping to paddr
  • you use vmalloc anywhere else
fiery turtle
#

How does vfree know where to go

gentle peak
#

it's a sized free

fiery turtle
#

Or well struct page I guess

fiery turtle
gentle peak
#

nah struct page is only used for kfree since with vmfree the pointer might not be in hhdm

fiery turtle
#

U can vfree less than u malloced?

gentle peak
#

no the size still has to match

left orbit
#
hacker@raptor:~/sources/linux$ git pull origin master --depth=1
remote: Enumerating objects: 39, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 20 (delta 19), reused 6 (delta 6), pack-reused 0
Unpacking objects: 100% (20/20), 2.76 KiB | 201.00 KiB/s, done.
From https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
 * branch                master     -> FETCH_HEAD
fatal: mmap failed, check sys.vm.max_map_count and/or RLIMIT_DATA: Cannot allocate memory```
#

holy 🔥

gentle peak
#

i just figured that for a lot of purposes the size is known at compile time even for free

fiery turtle
#

Why require that?

gentle peak
#

so making it a sized free allows for LTO to optimize vmfree into a direct call to kfree

gentle peak
#

i haven't actually measured what impact uacpi's sized frees option has on perf

#

since my uacpi glue code emulates a non-sized free

fiery turtle
#

Its probably worse because uacpi has to calculate it in some cases

#

Even strlen sometimes

gentle peak
#

oh wow

fiery turtle
#

Yeah

#

Most are hardcoded tho

gentle peak
#

i might add another allocator that delegates to vmalloc/vmfree but doesn't have a sized free in case things like that pop up elsewhere in the kernel

#

won't do it until i need it but still

fiery turtle
#

Fair

gentle peak
#

probably not worth it