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

1 messages ยท Page 47 of 1

left orbit
#

everyone being?

calm latch
#

who's everyone?

torpid root
#

idk I have seen multiple oses in the past days

left orbit
#

im only aware of mr pmos

#

i am planning on doing la64 but

#

it's far from being anything serious

calm latch
#

the fact that uACPI initialized means that I have full userspace working

fiery turtle
#

Lol cool

slim panther
calm latch
#

(I mean I think everything pagefaults after that)

calm latch
left orbit
#

successfully loaded 1 AML blob, 840 ops in 0ms (avg 840000000000/s)

#

epic

fiery turtle
#

Update uacpi and it won't show time

left orbit
#

(update uacpi)

#

bruh

fiery turtle
#

I've added a check

#

Yeah

left orbit
#

why does everyone think faster than me

calm latch
#

i know about that, but it's not a priority

calm latch
calm latch
strong heath
#

now do it in real hardware

slim panther
#

trolled

#

i think i'm the only one that has actual hw?

left orbit
#

you have la64 hardware?

#

wtf

#

why lol

slim panther
#

work

left orbit
#

ah

slim panther
#

i also have ppc64le hw

left orbit
#

that is actually cool tbh

slim panther
#

i have a 3A6000 la64

left orbit
#

what do you even do at suse?

calm latch
slim panther
calm latch
#

Though does it have EDK?

slim panther
#

not sure

#

probably not

calm latch
#

I've seen a port on GitHub

#

But I think it was not accepted to mainline

#

Wait a second

#

PPC

#

Why did I think about MIPS

slim panther
#

let me check our system

strong heath
#

several kinds of drugs

#

to numb the pain of working at suse

left orbit
#

no but suse seems like a cool company to work at lol

#

thats why im curious

strong heath
#

its a cool company

slim panther
#

it's an IBM L922

#

power9

calm latch
#

What does it use to boot?

#

(like protocol)

slim panther
#

idk

left orbit
#

i mean it boots linux

#

so what do you think

slim panther
#

something something device trees

lofty dragon
#

loongarch64 is the coolest risc

#

they are actually on board with proper standards like UEFI and ACPI

#

there is actual hardware that works and is cheaper and powerful, unlike riscv

calm latch
#

Now somebody just needs to add SMP support to Limine

lofty dragon
#

and it is not boring unlike aarch64

#

yeah that is true

calm latch
#

Lack of documentation

#

(like for vector extensions)

lofty dragon
#

i mean it still has some documentation, it's not completely undocumented

left orbit
#

linux trl

lofty dragon
#

i bet if you look for stuff in Chinese you'll find way more

calm latch
#

And the documentation that's there is translated from Chinese, with errors

left orbit
#

no the chinese one is also TBD

left orbit
#

vector instructions and virtualization manuals are TBD in both chinese and english

#

and i guess from what mishakov says they are translated from chinese

calm latch
#

I've gotten vector extensions to work

left orbit
#

nice :^)

calm latch
#

(like the clang issued code does not crash)

#

It's a matter of saving and restoring registers from the kernel's point of view, so like not complicated

left orbit
#

ah makes sense

#

it was pretty readable to me tbh

#

i didnt notice many errors

calm latch
#

I've seen a bunch of them

#

But like it's fine, just not excellent I guess

left orbit
#

i guess i just didn't pay attention

calm latch
#

Because it was linking against libc with brainrot bug in it

#

I think its ACPI looks more interesting than that of RISC-V

left orbit
#

that's really cool

fiery turtle
#

I guess now the only arch where uacpi hasn't been confirmed to work is itanium

calm latch
#

MIPS?

fiery turtle
#

no acpi there

frank canopy
#

pushed an update to zuacpi to update to zig 0.14

fiery turtle
#

nice

jaunty fox
#

i'll probably buy a loongarch board if/when i come across one

calm latch
gentle peak
#

does looongarch have HPET? or is this something else

calm latch
#

It looks like an x86 hpet

hollow crescent
sterile egret
fiery turtle
tired temple
#

btw, doesn't anyone have MIPS Creator CI20? I won't ask to test anything on it, ๐Ÿ˜ I just remembered, I had this tiny cute purple SBC. Good memories. My lowest level coding experience. sigh. I could take it with myself, but we hoped we return.

hollow crescent
#

Honestly I'm not sure it's still around anymore ๐Ÿ˜”

#

Was probably destroyed in the war

tired temple
hollow crescent
#

hopefully your family is OK

tired temple
#

thank you. Are alive, already ok. As ok as it can be under almost everydays moped (drones) attacks and a bit rarer ballistic missiles attacks. Kyiv is targeted pretty often.

strong heath
#

Man that sucks, they will pay one day, if not in this life, the next one

vale isle
#

I speak Turkish and English, I technically studied German for 11 years but I can barely say Kartoffelsalad, I used to be intermediate in toki pona but forgot, I know enough polish to understand some basic song lyrics, I know a couple words of Zazaki - my heritage language

vale isle
#

I've at least encountered risc-v boards

#

loongarch is pretty much still a china-only thing IMO

#

I'd love to see that (being china only) changed ofc

at least in my mind risc-v comes before loongarch in the list of possible targets

#

I'd like to see them as equals one day

fiery turtle
#

@gentle peak in old hydrogen u have event callbacks that run from a timer irq right

#

one of them is a scheduler thing

#

that can call into do_yield

#

wouldnt that yield from current irq handler, so u dont run lapic_eoi or other event handlers?

gentle peak
#

which is done after eoi

fiery turtle
#

but next time u reschedule this task, would it then be basically on the enable_preempt(); line in the timer handler?

gentle peak
#

that's where the actual yield happens yea

fiery turtle
#

makes sense

#

is this how its normally done?

gentle peak
#

think so yeah

#

i didn't really look into how other kernels did it when i made it

#

i know this is basically equivalent to a two-level softipl thing

#

but i don't really know anything beyond that

fiery turtle
#

im gonna take a look at how keyronex does it

surreal current
#

we do it identically so it doesnt matter

fiery turtle
#

not because its worse or anything lol

#

just the lang

surreal current
#

u hate jackal?

fiery turtle
#

if you would explain how you do it id appreciate it

#

more mental effort to read for me personally

surreal current
#

its just a C reskin

fiery turtle
#

not because its a bad reskin

#

just not used to syntax

surreal current
#

there are interrupt priority levels (IPLs)

#

the lowest 3 are reserved for software interrupts

#

0 is everything enabled, 2 is preemption (among other things) masked off

#

ignore 1 thats out of scope

#

when a new thread should be scheduled in, a software interrupt is set pending at IPL 2

fiery turtle
#

by software interrupt u mean dpcs?

surreal current
#

next time IPL drops below 2, the pending bit is seen and the software interrupt handler is called which performs the actual reschedule

surreal current
#

i dont do preemption as a DPC because itd be bad to preempt in the middle of dispatching the DPC queue

#

i dispatch all the DPCs and then i check for preemption and switch to a new thread if necessary

fiery turtle
#

ok i see that keyronex basically sends an ipi to itself in the timer irq

#

which then runs the dispatch dpc thing

#

which then calls reschedule

surreal current
#

yeah we diverge there, he does it with a self-hardware-interrupt and uses cr8 to implement ipl, i do it completely in software

fiery turtle
#

isnt doing in hw kinda overkill just to do a context switch

surreal current
#

i think my way is better

fiery turtle
#

and slow

surreal current
#

thats my opinion

#

especially bc software raise and lower ipl you can make like 1 and 3 instructions respectively in the fast path

#

on x86

#

so its not like that much more than setting cr8. actually its much faster if youre running under a hypervisor

fiery turtle
surreal current
#

yeah KiLowerIpl

fiery turtle
#

basically, when do u check pending software irqs

#

oh ok

#

so basically u do the same thing as proxima

surreal current
#

it sets the new ipl and then checks if there are soft ints pending and if so it calls KiDispatchSoftwareInterrupts

#

otherwise branches around the call

fiery turtle
#

QuantumEnd is what triggers a preempt?

surreal current
#

it like does quantum end processing like priority boost decay (if necessary) and selecting the next thread yeah

#

but doesnt actually switch to it yet

#

its just one source of thread preemption among others so thats not rolled together

fiery turtle
#

when does it actually switch?

jaunty fox
#

what's this i hear about UltraOS returning

surreal current
fiery turtle
fiery turtle
jaunty fox
fiery turtle
#

mostly around scheduling i guess

surreal current
jaunty fox
#

i see you invited hyena as visiting lecturer

fiery turtle
surreal current
fiery turtle
#

lmao

#

i appreciate it tho

surreal current
#

ohhhh i introduced a bug

#

recently

#

and only just noticed

#

thx for making me stare at that

fiery turtle
# surreal current literally is in that function i linked

ah ok, so basically:

  1. Timer irq sets quantum end
  2. Does a RaiseIpl
  3. RaiseIpl checks pending software irqs
  4. If current thread's quantum is over, call into KiQuantumEnd, which picks the next thread to run
  5. That thread is switchd to at the end of RaiseIpl
fiery turtle
#

btw, dpcs are just a linked list of function pointers? what sort of dpcs are there usually, who queues them?

jaunty fox
#

and distinguishing raise/lower to/from software levels was a nice trick which i think should be no great difficulty to adapt to and enables those common cases to be written much more optimally

surreal current
# fiery turtle ah ok, so basically: 1. Timer irq sets quantum end 2. Does a RaiseIpl 3. RaiseIp...
  1. timer irq decrements current thread timeslice and if it reached zero ticks left, it sets curcpu->QuantumEnd=TRUE and sets a soft int at IPL 2
  2. return is about to occur from the outermost interrupt handler (they can nest if higher priority interrupts are taken). if there are now pending soft ints at the last IPL before the interrupt was taken, then the interrupt handler calls KiDispatchSoftwareInterrupts directly before returning. it turns out to be weird and fucked up to call KiRaiseIpl and KiLowerIpl for these things. if the last IPL before the interrupt was taken was too high to dispatch the new soft ints, they will be dispatched at the next KiLowerIpl to a lower IPL, and not at this moment
  3. interrupt handler for IPL 2 (aka KI_IPL_DPC) calls KiQuantumEnd which determines what thread should run next (if any); it gets set into curcpu->NextThread if so
  4. if curcpu->NextThread is set before returning from the IPL 2 handler, a switch directly into this new thread is conducted
hollow crescent
jaunty fox
fiery turtle
#

nah, nothing concrete like that atm, mostly in the deciding phase

jaunty fox
fiery turtle
#

point 2 is a bit too big brained

surreal current
#

note that NextThread is checked locklessly there (bc its safe to do so just to check for for transition from null->set) but actually setting it or using it is guarded by the per-processor ready queue spinlock

jaunty fox
#

excuse my cross-examination

fiery turtle
#

im definitely more interested in the hw side, so it wont be sophisticated algorithm-wise probably

#

just the bare minimum to not be embarassing

hollow crescent
surreal current
hollow crescent
#

but i need to build an idea of how things are structured first

fiery turtle
#

what does this mean

#

last IPL?

surreal current
#

ok so like if you were at IPL 0 when you took the interrupt, and the timer interrupt set the pending bit for IPL 2, then it will be dispatched before returning from the interrupt

hollow crescent
#

if there are any pending DPCs or quantum end, is what i understood it to be

surreal current
#

however if you were at IPL 2 when the interrupt was taken, this soft int will not be dispatched yet

#

because it is masked off by the IPL you are returning to from the interrupt

#

it will be dispatched next time the interrupted code lowers its IPL

fiery turtle
#

like its probably a simple idea but i cant parse it because of these terms i dont understand that well

#

i need an x86-ified explanation

surreal current
#

the current IPL masks off any interrupt with an associated IPL that is <= the current one

fiery turtle
#

right

hollow crescent
#

on x86_64 that can be directly represented with the cr8 register

fiery turtle
#

no like i understand cr8

#

i dont understand what problem this is solving or working around tho

surreal current
#

so basically if you were at IPL 2, masking off preemption, and then the timer interrupt was taken and decided to do a quantum end, you probably dont want to get preempted

#

so you dont get preempted, it just returns without dispatching that soft int

#

it gets dispatched when you lower IPL

#

however if you were at a lower IPL then you do want to get preempted asap

#

so in that case it is dispatched in the interrupt handler before returning

hollow crescent
hollow crescent
surreal current
#

in mintia2 its the second highest after the IPI which is the highest

fiery turtle
#

so higher than 2?

surreal current
#

yes

#

its like 30

#

ipi is 31

#

other device interrupts are in the 3-29 range

fiery turtle
#

so what you're saying is, you only dispatch context switches when you lower ipl to some small number?

surreal current
#

when i lower ipl to <2 yeah

#

since 2 and up is what masks off preemption

jaunty fox
# fiery turtle i need an x86-ified explanation

just define IPL = %cr8, raising a soft interrupt as sending yourself an IPI on a vector that's within that priority class, and every interrupt handler starts by raising %cr8 to the appropriate value for that priority class, and ends by lowering %cr8 to its previous value. that's the kind of concrete processor that the abstract processor that the IPL concept prescribes, and which an IPL mechanism emulates in software to a greater or lesser degree (and it's useful for efficiency to do more emulation than necessary)

fiery turtle
hollow crescent
#

A hardware interrupt can interrupt a few circumstances:

  • User mode / normal IPL kernel mode code
  • Code running in IPL 2 (DISPATCH_LEVEL) in NT
  • Another hardware interrupt at a lower level
surreal current
#

right before you return from the interrupt handler

jaunty fox
#

in short everything is conceptualised as interrupts existing in a hierarchy of priority classes, with the ability to raise IPL to a level such that some priority class of interrupts is blocked (this includes the level 2, that level which does DPC dispatch and does context switch if one is pending)

fiery turtle
#

before return u loweripl to previous, and if it was smaller then 2 than u context switch?

hollow crescent
#

Think about it like this. You basically "morph" the interrupt into a lower level interrupt

fiery turtle
#

otherwise u defer to the interrupted code?

surreal current
#

but i dont use KiLowerIpl to do it

hollow crescent
#

The timer interrupt essentially "becomes" the dispatch interrupt

#

Without bearing the cost of a return from interrupt and another hardware interrupt

fiery turtle
fiery turtle
surreal current
hollow crescent
surreal current
#

so i can just forego that entirely and pretend ipls that affect hardware interrupts dont exist in those routines

#

which makes them inappropriate for raising and lowering ipl in hardware interrupt handling

fiery turtle
hollow crescent
#

If you interrupted dispatch level then you have to return from that interrupt back into dispatch level

surreal current
#

dispatch level = ipl dpc = ipl 2 = irql 2

#

in case terminology is confusing u

hollow crescent
#

now i'm not sure if the timer interrupt or something else is supposed to determine if a quantum is over

fiery turtle
#

but u can only context switch if < 2?

surreal current
#

yes since >=2 masks it off

hollow crescent
#

in boron the timer interrupt does

fiery turtle
#

ok i think i understand

hollow crescent
#

when it detects that a quantum is over it sets a flag "PENDING_QUANTUM_END"

surreal current
fiery turtle
#

why does it need to interrupt self in this case, if loweripl checks for quantumend anyway?

surreal current
#

because it wont call KiDispatchSoftwareInterrupts (which calls the IPL 2 interrupt handler if necessary) unless that bit is set

#

this basically enables a fast path where you just go like

KiLowerIpl(new):
  curcpu->Ipl = new
  
  if curcpu->Pending >> new != 0:
    KiDispatchSoftwareInterrupts()
  
  return
#

where Pending is a bit set

hollow crescent
surreal current
#

if this looks racey bc interrupts can come in and fiddle with it and whatever while youre in KiLowerIpl, youre right. and i noticed that and would take time to disable interrupts for that routine and stuff. however one day i realized that all of the races are harmless and instantly self-correcting and that i dont need to do that

fiery turtle
#

hm ok makes sense

#

i see it calls it in Hal

surreal current
#

it do?

fiery turtle
surreal current
#

yeah thats explicitly coded in a few places, the actual KiLowerIpl implementation is this though (the fox32 version for somewhat increased readability for x86 ppl)

fiery turtle
#

i see u also have a similar function for Apcs

surreal current
#

the magic number 0xFFFFF000 is where i map the per-cpu structure on fox32 (where there is only ever one cpu)

#

dont ask why i did that i forgot

#

i think it micro optimizes some stuff

fiery turtle
#

btw what sort of dpcs does this run usually

surreal current
#

one of them is the ULE global work balancer

#

runs each second on the boot processor and moves threads from the most loaded processor to the least loaded processor until theres balance

fiery turtle
#

it's just a list of function pointers right?

surreal current
#

(or until it has moved a lot of threads and needs to take a breather bc its currently holding up literally all threads from executing on that core)

fiery turtle
#

DPCs

surreal current
#

essentially yes

fiery turtle
#

whats the difference vs apcs?

surreal current
#

DPCs are targeted to a processor and run with preemption disabled

#

APCs are targeted to a thread and are next executed when the thread is next scheduled in and is at < KI_IPL_APC (which is IPL 1)

#

they are preemptible

#

they can also access the userspace of the thread's process

#

and take faults on it

fiery turtle
#

hmm interesting

surreal current
#

so an APC is used to asynchronously write out the IO status block after an async IO request finishes for instance

fiery turtle
#

what apcs does mintia have

surreal current
#

new mintia has none yet, old mintia used them extensively for async IO completion and so will new mintia

#

basically targeting an APC at the originally requesting thread to cause some completion work to be done in its context

#

i actually implemented them early on in old mintia and then like a year later i hadnt found a use for them so i removed them

#

and then a year after that i implemented async io and was like "oh. thats what theyre for." and had to dig thru the repo history to resurrect them

fiery turtle
#

clean and abstracted away

hollow crescent
#

will, do you mind answering some of the questions in my boron thread

#

im again kinda lost. i have an inkling of an idea what to do but im not totally sure and would appreciate some feedback

fiery turtle
hollow crescent
#

DPCs run at dispatch level yes

surreal current
#

its the level the dispatch interrupt runs at

#

where dispatch is a VMSy way to say scheduling

#

aka preemption

#

so raising to that level masks off the dispatch interrupt ie masks off preemption

fiery turtle
#

so the scheduler doesnt preempt itself basically?

surreal current
#

yes

fiery turtle
#

ah

surreal current
#

my scheduler never disables interrupts (except at architecturally necessary moments where itd explode if it didnt)

fiery turtle
#

yeah it seems unnecessary if u have ipls

surreal current
#

architecturally necessary moments being like where youve only partially switched context and if an interrupt came in at that moment youd blow up for whatever reason dependent upon the architecture's interrupt dispatch details

#

unavoidable stuff like that

left orbit
surreal current
#

and i was trying not to completely overwhelm infy with information lol

#

infymation

fiery turtle
#

nah i know about lazy ipl

left orbit
#

mov gs:[0xNNN], new_ipl

#

how is that slow

surreal current
#

its not

#

its exactly as fast as my way

left orbit
#

ah

#

well you said slower so

surreal current
#

and then lowering is either the same or slower

fiery turtle
#

so u must save that info somewhere

calm latch
surreal current
#

and dispatch is definitely slower

left orbit
#

lower is slower, yeah

#

you always have to write cr8 when lowering

surreal current
#

its pretty simple

#

its just complicated to explain

left orbit
#

interrupt priority levels are a very nice thing

fiery turtle
#

nah its very simple once u understand

left orbit
#

i dont understand them fully yet but meme

calm latch
#

Not tied to priority levels

fiery turtle
#

for lazy ipls im not sure when ur supposed to run the hardware handler properly

#

maybe u queue it as dpc to run later or something

calm latch
#

(I mean in theory, I haven't implemented timer preemption yet)

surreal current
#

in mine its a branch

fiery turtle
#

in vms, writing cr8 is much more expensive

#

because it's a vmexit

#

on real hw, probably

calm latch
calm latch
#

because an exception is like 100 cycles?

calm latch
surreal current
#

so ive probably mostly removed whatever 0.1% loss from that branch from most of the hot paths

#

noncontended locks dont raise ipl for instance

#

also its a forward branch so in the absence of any history or hints its predicted taken (ie no softints pending, the common case) on most uarches :)

fiery turtle
#

jackal allows u to do FN (<typedef>)?

surreal current
#

nvm

fiery turtle
#

thats interesting

surreal current
#

i got that backward. forward branches are predicted NOT taken on most uarches. :(

#

backward branches are what are predicted taken bc they are Probably A Loop

#

which Probably Loops At Least Once

surreal current
#

and then it screams at you violently if you even name a parameter differently than the typedef

hybrid turtleBOT
surreal current
#

in the absence of hints the branch prediction is primed using the sign bit of the branch offset is the common trick i think

fiery turtle
surreal current
#

actually you have to do that

#

before you can assign a field of that type with a function pointer

slim panther
#

new bios dropped for my faulty mobo

#

we shall see if they touched the AML at all

fiery turtle
#

it should

lofty dragon
#

damn new microcode

dusky glade
slim panther
#

we will see in a few hrs

dusky glade
slim panther
#

@rustic compass @fiery turtle could i work on uacpi-rs?

fiery turtle
#

i dont have a say in this lol, but i dont mind

slim panther
#

well, you control the orga don't you?

fiery turtle
#

yes but uacpi-rs is shinribo's code

slim panther
#

ah

#

just pinged you so i could get write access

#

but yes, waiting for shin

rustic compass
#

which is basicly 99% of types.h

#

except handlers, i will figure out how to do them once i encounter them and see how they are used by uacpi

#

also as of now i copy all strings used by uacpi which are exported to the user into rust code so that i can guarantee that only the reference to the string is passed to the user instead of the entire string (maybe i can cast a reference to a c string to a &str then we can just use uacpi string stuff)

#

also sorry for taking so long nooo

#

i assume you want the table api for now so maybe we could just get barebones mode first

slim panther
#

yea

#

i don't really do anything with handlers yet

#

only hpet and mcfg and madt

rustic compass
#

i would say those standard table names which are also defined by uacpi should go into a enum

slim panther
#

how would that look like

rustic compass
#

you would call the table find method with a member of that enum as a parameter and internally it would use match to turn it into a string and call the string variant

#

pushed everything

#

barebones mode included

#

but no cfg! added to the functions yet

slim panther
#

k

fiery turtle
#

Do u want to be added to the org?

#

since you're gonna work on it

slim panther
#

im actually not aware of any other user of uacpi-rs atm (besides shinribos os)

rustic compass
#

also i didnt pass the use buildin mem functions so aparently that works out of the box with rust (core exports mem stuff with c abi)

#

me neither

fiery turtle
#

sent

slim panther
#

accepted

frank canopy
# slim panther i guess

the way i do it for zuacpi is to have a u32-backed enum and each member's value is the four-byte string treated as a u32

#

idk how youd do that in rust

#

but its very nice to use in my experience

kind mantle
#

But I think you probably mean this

match packed_name {
  0x54445352 => Thing::Rsdt,
  _ => Thing::Invalid,
}
rustic compass
#

more like

enum table {
  fadt
  hpet

}


match var {
  table::fadt => "FADT"
  table::hpet => "HPET"
...
}

fiery turtle
#

uacpi_table_find takes a struct with uacpi_object_name which can technically work on a u32 signature

frank canopy
#

i usually use find_by_signature

#

can just @bitCast the u32 back to a [4]u8

#

and it just works

#

make it inline and the compiler will do it eagerly too

slim panther
frank canopy
vocal geyser
#

when an interruption occurs, for example, from the power button, what will happen if cr3 is not a kernel ? (my scheduling changes cr3 for each task)

left orbit
#

it's an interrupt like any other interrupt

#

how you handle it is up to you

#

how do you handle other interrupts if your kernel isn't mapped lol

vocal geyser
left orbit
#

well then where's the problem?

vocal geyser
#

i mean suddenly uacpi will use some addresses which are not mapped

left orbit
#

then that's your problem

#

why aren't they mapped?

#

kernel stuff should probably always be mapped

#

or just defer that work instead of doing it in an isr

#

really up to you

#

but i don't see why uacpi should be concerned by that, literally nothing about handling interrupts is specific to uacpi

#

do what you need to do in the isr to either a) defer that work to a worker thread b) allow uacpi to run properly

urban galleon
slim panther
#

rust enums can only be converted into an integery not the other way around

#

because of the pattern matching rules

#

if you suddenly have an unhandled enum representation you'd fall through and get ub

slim panther
urban galleon
slim panther
#

enums in rust are not layers upon ints

urban galleon
#

Breakign news assembly is more flexible than rust

urban galleon
slim panther
#

ct?

slim panther
rustic compass
#

It would be sufficient to turn a enum into a int and define each enum element with the value corresponding to a table

#

Like defining it as a [c_char;4]

#

And then casting it into a u32

#

And put that into the enum

urban galleon
kind mantle
slim panther
#

not sure what you're trying to say

kind mantle
#

Whether enums are compile time. No. They're not macros but like any other value, expressions with them can be evaluated at compile time.

urban galleon
#

The language doesnโ€™t have to be safe

#

The code should be safe

#

โ„ข๏ธ

kind mantle
#

I used to think this way you know

#

I considered myself an expert C programmer and still do

#

And then I tried Rust and immediately fell in love with it

#

It's very nice not to have to worry about:

  • Heap corruption
  • Garbage pointers
  • Use after free
  • Double free
    And as a bonus, while not impossible, it's much less common to leak memory.
flat badge
#

Rust doesn't really help with memory leaks over C++ though

vale isle
#

it does in specific cases

flat badge
#

all the stuff that prevents memory leaks in Rust also exists in c++

#

like refcounting pointers, containers, box/unique_ptr

leaden fox
flat badge
#

not really

#

you can just call Box::leak etc

#

in safe code

leaden fox
#

yeah but that's on purpose

flat badge
#

just like calling raw new in C++

#

Rust protects against memory safety issues and that's very valuable, but it doesn't really improve memory leakage over C++

slim panther
#

rust doesn't solve logic issues meme

flat badge
#

i know. i'm not claiming that they are

slim panther
#

ah you edited your msg

leaden fox
urban galleon
#

Which is different to languages that provide abstraction like C++ which donโ€™t limit you and only allow you to make your code look nicer

kind mantle
#

But Rust isn't trying to replace C++

#

If it's "replacing" anything it'd be C

#

Personally I'm not a big fan of C++

urban galleon
#

I just mentioned C++ as something that doesnโ€™t do explicit safety and it works well

frank canopy
# rustic compass And put that into the enum

this is exactly what zuacpi does fwiw, though zig enums are always int-backed and can be defined as non-exhaustive or have an error for an unexpected value depending on what i want it to do

#

its just that zig also lets me safely convert that back into a 4-char-array-with-compile-time-length so i can pass it to uacpi

slim panther
#

taking shortcuts everywhere is bound to cause some footguns

jaunty fox
#

there is a place for safe rust but i think it's rather smaller than people imagine

urban galleon
loud ice
#

i dont understand the point of rust

#

safe rust is way harder to write than safe go

fiery turtle
urban galleon
#

real

jaunty fox
#

in particular the fearless concurrency and memory safety are not compatible with big shared state machines like kernels (yes, i know we try to localise the state per cpu or per thread or w/e, but we still have it)

fiery turtle
loud ice
fiery turtle
loud ice
#

am i?

#

god i hate rust

fiery turtle
#

Yes

slim panther
#

kinda

#

malding

jaunty fox
#

the simpler truth is that an efficient kernel needs Frightful Concurrency and Memory Chill

loud ice
#

the problem with rust is that i dont see where it makes sense

#

i dont think it makes sense in app stuff

#

because in that case you have plenty of GClangs to choose from

fiery turtle
#

I trust your opinion because u know it well

slim panther
#

gclangs are slow

loud ice
fiery turtle
#

Go is pretty fast

jaunty fox
loud ice
#

go is pretty shit lol

fiery turtle
#

And safe af

fiery turtle
loud ice
#

dotnet, HotSpot, JavaScriptCore, V8, LuaJIT...

loud ice
jaunty fox
#

in fact they tend to outperform all but the most sophisticated techniques of manual memory management or automated-but-simplistic

slim panther
#

dotnet is also very slow in comparison

loud ice
#

they are objectively really really bad

fiery turtle
#

The lang itself allows for better optimizations

loud ice
#

yeah

jaunty fox
#

what a good JIT can do is absolutely incredible

loud ice
#

go is not a very good gclang

#

and they still have great perf

jaunty fox
#

v8 can make even something like JS run like lightning

loud ice
loud ice
#

but yeah they all do an incredible job of making code run really fast

fiery turtle
#

and manhours

#

its crazy to think about

loud ice
#

it is

loud ice
slim panther
# loud ice really?

you can optimize a jit and gc all you want, but it's still bound by the language design. a lot of the dotnet abstractions are not zero cost

jaunty fox
hallow marten
#

what's cool is that JITs have inherently a better overview of program runtime so they can optimize accordingly

loud ice
fiery turtle
#

the cool thing about dot net is struct vs class etc

hallow marten
fiery turtle
#

allows for some extra optimizations

jaunty fox
#

HotSpot was written by the Animorphic Smalltalk team, and google later hired all of them to write V8. so it has a remarkable degree of overlap

urban galleon
#

I am a big fan of D

urban galleon
#

I think tsoding even made a video on it

jaunty fox
#

in fact even terminology as fundamental as the Oop (ordinary object pointer) can be found in common between Strongtalk, HotSpot, and V8

loud ice
#

but yeah the problem with rust is that it really doesnt make sense imo

fiery turtle
#

good because i kinda hate it lmfao

hallow marten
loud ice
#

GClangs are way better for apps stuff

kind mantle
loud ice
#

for high performance things yeah idk maybe?

hallow marten
#

I did not choose my name

#

it was given to me by the allfathers

fiery turtle
#

also the next ubuntu will ship with rust tools instead of gnu stuff right

slim panther
#

well who wouldn't want to write high performance apps

jaunty fox
#

and the Smi as well (SmallInteger, a smalltalk class of integers below (system word size) >> a few tag bits. V8 iirc rejects NaN boxing as an unwanted innovation and retains traditional Smi-tagging

fiery turtle
#

that will be fun

loud ice
#

actually i think they dont have unboxed pointers in general?

loud ice
#

without objectively hard to work with borrow checking issues

jaunty fox
slim panther
loud ice
fiery turtle
#

python better

torpid ferry
loud ice
torpid ferry
#

yeah but they're not very good at it compared to LLVM

slim panther
jaunty fox
#

david chisnall actually argues for a lot more use of high-level languages in the core userland of operating systems, he thinks a service manager/"init system" would actually be better off as a small C++ core and lua on top to provide more complex semantics. and he may have a point

loud ice
slim panther
#

i would argue yes

fiery turtle
torpid ferry
#

2-4x worse is not significantly worse for large apps where the ease of developement benefits justify it 10 fold

slim panther
#

oh yea sure

jaunty fox
loud ice
fiery turtle
#

ohh ok

torpid ferry
#

like, for mid-high performance userspace stuff like some web servers Go and Rust are head to head

slim panther
#

random article i found

loud ice
#

except that go is like 10 times easier to write code in

torpid ferry
slim panther
#

no

loud ice
#

memory is expected yeah

torpid ferry
#

oh i read only the beginning, the issue is that GC memory usage is really hard to measure

fiery turtle
#

^

slim panther
#

i don't really mind memory usage of dotnet et al

#

im more about the cpu usage

loud ice
fiery turtle
#

imo its less important than performance

jaunty fox
loud ice
#

so the benchmark is kinda not super useful

#

that could be like random quiescent work

fiery turtle
#

u can call into the gc after every statement to bring it down trl

torpid ferry
loud ice
#

go hits a better p99 in those benchmarks as well

torpid ferry
#

gcs can be faster than manual allocation too

loud ice
#

yeah

#

and gc semantics are easier to optimize around

slim panther
loud ice
jaunty fox
#

so i am very sympathetic to chisnall's position now, that writing a service manager in C or C++ or Rust is giving yourself a lot of pain and adding some risk in the case of the former two, for nothing. it simply doesn't cost much to maintain and operate on a graph of what's probably going to be at most a few hundred services

kind mantle
loud ice
#

C# and go use more memory because there is no memory pressure

#

so theres no point collecting and wasting cpu time

#

c# stays under 3%

torpid ferry
slim panther
#

unused memory = wasted memory

torpid ferry
#

like memory latency

hallow marten
#

which is cool

loud ice
slim panther
#

i keep seeing people mald over windows memory usage

kind mantle
loud ice
kind mantle
fiery turtle
#

microsofts fault for choosing the algo for displaying free memory in task manager

torpid ferry
slim panther
#

when openFont

#

hw accel for typeface rendering

kind mantle
#

And if you're editing documents a lot of it doesn't need to be re-rendered because it's just scrolled around

#

Be that literal scrolling or inserting lines

loud ice
#

but yeah the problem with rust is that its lacking good use cases:

  • for web server stuff, go is about as fast at runtime and way faster to write code in (async rust is a mess)
  • for kernel stuff, it kinda works? but it's not oom safe so you need lots of ugly hacks if you want to be a real kernel etc
  • for embedded, its cool ig? but how much of that is there
  • for tools, go works better too imo
fiery turtle
#

Why is it cool for embedded

slim panther
#

very much embedded actually

torpid ferry
#

like, look at redox futexes

loud ice
#

it has a nice ecosystem

#

embedded != osdev

slim panther
#

rustsbi, oreboot

loud ice
kind mantle
fiery turtle
#

You mean like toolchain support?

loud ice
#

i meant more the "microcontroller shit" kind of embedded

loud ice
fiery turtle
#

Oh

slim panther
#

rustsbi works on microcontrollers afaik

hallow marten
loud ice
slim panther
#

idk

slim panther
jaunty fox
loud ice
#

its not as great as C

#

but yeah no rust is cool there

jaunty fox
#

the embedded people are getting away with murder

kind mantle
fiery turtle
#

Maybe firmware devs should take note

loud ice
#

rust is hell to rev

hallow marten
#

river was fairly small

loud ice
#

at least with c you can pop their code into ida and see what kind of crap they did

slim panther
fiery turtle
fiery turtle
loud ice
#

but yeah the problem is like. you either are on a platform which is desktopy enough that a gclang is fine

slim panther
loud ice
#

or you are in embedded which isnt that big

kind mantle
loud ice
#

or you are anything where you need async

#

where rust is insane cbt

fiery turtle
kind mantle
slim panther
#

now my mobo never wakes up again once it hits s3

fiery turtle
loud ice
slim panther
loud ice
#

and rust is also like 90% about hype

fiery turtle
#

True

jaunty fox
slim panther
#

most crypto bros dont know shit about coding

kind mantle
loud ice
slim panther
#

lol

kind mantle
#

Because this is what I thought before I tried it

hallow marten
#

rust is very much overhyped

loud ice
#

yeah

hallow marten
#

it's a good language though

loud ice
#

its a cool langauge

hallow marten
#

I would rather see it with a GC

loud ice
#

wouldnt want to write an app in it

loud ice
jaunty fox
slim panther
#

am i stupid

loud ice
#

rust with gc instead of borrowck crap would be so good

hallow marten
#

the ocaml stuff is nice, the C/++ stuff is nice, the borrow checker sucks and is annoying to work with

slim panther
#

rust gives you the benefit of gclangs without requiring a gc. how is this a bad thing?

jaunty fox
#

the most of the job is probably knowing how to mix freertos and lwip and other things made by the talented ones

loud ice
#

lol

loud ice
#

it fails pretty miserably at it

slim panther
#

example?

#

i cant wrap my head around it

hallow marten
#

the benefit of gclangs is not having to care about it

#

in rust you very much do

loud ice
gentle peak
#

the main benefit of gclangs is that you don't have to worry about memory management

loud ice
jaunty fox
#

as someone i can't remember put it

gentle peak
#

in rust you do, you just experience the issues at compile time instead of runtime like with c

loud ice
#

the main point of a gclang is that there is 0 thinking required

jaunty fox
#

low level languages is when you have to think about things you don't need to care about

#

i badly butchered this quote but it went something like that

slim panther
#

when compile fails i just do what it says

jaunty fox
#

and the truth of the matter is most apps do not need to care about memory management

loud ice
kind mantle
loud ice
#

foo has a pointer back to bar

hallow marten
loud ice
#

the point is that this type is cyclic

jaunty fox
#

it's alan perlis

#

"8. A programming language is low level when its programs require attention to the irrelevant."

loud ice
#

like rust with GC and good async or goroutines would be very nice to have

hallow marten
#

The MLisms in it are cool

slim panther
#

i fucking hate having opinions
when i didnt like rust everyone was praising it
now i like it and everyone says how trash it is
???

gentle peak
loud ice
#

tbh

kind mantle
loud ice
#

you cannot construct <cycle>: Bar { items: vec![Foo { thingy: <cycle> }] }

#

the only way to do it requires a Cell

slim panther
#

just put an option around it smart

loud ice
kind mantle
#

IIRC the idiomatic way to do this was to use weak refcounting pointers

loud ice
#

is less ergonmic

rustic compass
loud ice
#

and is also STILL unconstructible without a refcell

loud ice
kind mantle
#

In Rust you sacrifice some of the memory-safe programs and in return you get a type system that guarantees* your code is memory-safe.

loud ice
#

also, rust unsafe semantics are insanely hard

fiery turtle
#

no proper oom handling in rust is truly hilarious

gentle peak
loud ice
loud ice
kind mantle
#

Well

#

Languages with garbage collection do not generally compile to machine code

loud ice
kind mantle
#

Not directly

loud ice
#

from JITs you have DotNet, HotSpot, JavaScriptCore, V8

kind mantle
#

They all have an intermediate representation

loud ice
#

from AOT you have NativeAOT, Go

#

GCC Java back when that was a thing

slim panther
#

nativeaot is actually pretty bad though

jaunty fox
loud ice
#

i dont have a lot of knowledge about that tbh

slim panther
#

i've used it when .net 8 came out

#

it uses clang to compile

loud ice
slim panther
#

startup is faster, but overall perf is lower than regular c#

loud ice
#

huh

slim panther
#

and you lose all runtime reflection

loud ice
#

unity's il2cpp has reflection

slim panther
#

yea but nativeaot is not il2cpp

loud ice
#

so its defo possible

gentle peak
loud ice
#

go has PGO for example

slim panther
#

you have some form of reflection, but only the things that are statically determinable

loud ice
#

yeah idk this is one somewhat shitty impl tho

#

what about literally all of the others?

slim panther
#

wdym

loud ice
#

oh theres also GraalVM

#

which is like nativeaot but for java

slim panther
#

cant comment on that as i haven't used it

loud ice
#

dart has AOT as well i think

loud ice
slim panther
#

when os in llvm ir

loud ice
#

but yeah static PGO kills most of the gains from JIT PGO i think

kind mantle
#

What about this though: Are there other "well-supported" languages with the same kind of traits system that Rust has? Another one I really like is how Rust deals with generics compared to C++. C++ templates are a good idea executed poorly and IMO Rust does that same thing better.

loud ice
#

it is a cool think in rust

slim panther
#

i like rust error handling

loud ice
#

but damn i would not want to do it in my lang lol

#

its insanely complex

kind mantle
loud ice
#

its also stolen straight from other languages

kind mantle
#

? operator my beloved

loud ice
#

but thats besides the point

frank canopy
#

oh god i looked away for 90 minutes and this place has gone nuts now

slim panther
#

yes

#

average rust flame war

loud ice
#

rusts error handling is cool

frank canopy
#

rusts error handling just reminds me of haskell tbh

#

that isnt a bad thing per se but it does

loud ice
#

traits are cool too, but they don't outweigh the pain of the borrow checker to me

flat badge
flat badge
#

every library has their own error types and converting between them is a pain

loud ice
#

i dont think theres a good way to solve it without a gclang though

#

speaking of which go has a single error type, which works everywhere!

#

but no try operator

jaunty fox
#

what i like about rust error handling is that they added a way to catch a panic! and now they've got exceptions

frank canopy
kind mantle
fiery turtle
jaunty fox
#

the fate of every programming language that boldly declares "We have something better than exceptions" is to eventually add them in, with some limitation or other

loud ice
#

(but for real)

frank canopy
#

i do like zig's error handling tbh. no exception type stuff there either but its a fairly early lang

loud ice
#

no idea how that plays with BEAM and JS though

frank canopy
#

you can "catch" a panic insofar as you can control what panic calls

loud ice
#

i dont like zig's lack of a good error type

#

because a status code is not enough

loud ice
#

also exceptions arent a good solution /j

frank canopy
loud ice
#

go's solution is way better than exceptions

jaunty fox
#

what becomes clear from the history of programming languages is that new ideas come up, they're a fad for a while, then they fade away, and old ideas that were despised for a few years have a habit of coming back

loud ice
#

and has kinda the same issue as rust

#

it doesnt compose particularly well

kind mantle
loud ice
#

i do think rust is here to stay though

fiery turtle
#

noooooo

loud ice
#

okay so now that we have complained at length about rust language

slim panther
#

okay i think i have formed a well-thought out opinion

i want a language that gives me the profile of c++ without looking like c++

loud ice
#

lets discuss rust libs

slim panther
#

liberals ๐Ÿ˜ก

loud ice
#

aka the ecosystem shitshow

flat badge
#

My hot take on Rust's viability is that most (but not all) situations in which people reach for Rust would better be solved by a GC lang

fiery turtle
#

very true

slim panther
#

same could be said about c++, no?

kind mantle
#

Also probably

slim panther
#

the second you need more than C, you're doomed anyways

loud ice
#

tbh

#

except maybe ada

slim panther
#

fair point actually

loud ice
#

because you may use ada for their theorem proving magic

flat badge
#

if you're writing a webserver that needs to process 500 requests / sec, you probably do not want to use Rust

slim panther
#

*need

jaunty fox
kind mantle
fiery turtle
#

imagine gc-based autopilot

#

or a c based autopilot

#

one hangs the other segfaults

loud ice
#

autopilot for what?

#

for a plane?

fiery turtle
#

like a boeing

#

yeah

loud ice
#

they can hang for quite a while without it being a problem tbh

#

so long as its not like a critical phase of flight

jaunty fox
#

we can say this: rust is unsuitable for any app which isn't extremely sensitive to performance to such an extent as it can't handle a tracing GC, because rust would require the programmer to invest completely unnecessary effort by virtue of using a too-low-level language;
rust is of limited suitability for complicated shared state monsters like a kernel, because those rely exactly on Frightful Concurrency and Memory Chill techniques for efficiency, and Fearless Concurrency/Memory Safety are pure poison here;
rust may be useful for those apps which don't fall into either category

kind mantle
# fiery turtle or a c based autopilot

AFAIK airplane software is written in C and they have (like embedded actually) strict requirements about acceptable programming and memory management patterns

jaunty fox
#

and most apps are in the first category

slim panther
#

do go and c# have something like typed enums and/or options

frank canopy
#

c# does not yet though i think theyre looking into discriminated unions now

#

which i assume is what you mean by typed enums

kind mantle
fiery turtle
#

go doesnt have anything like that

frank canopy
#

tagged, fat, or discriminated union

loud ice
#

go does not

#

sadly

frank canopy
#

terms used fairly interchangeably

slim panther
#

tagged union yea

kind mantle
#

More languages should do tagged,fat,discriminated,etc unions

slim panther
#

more languages should get rid of nullable shit

#

regardless of memory safety

kind mantle
#

100%

loud ice
#

yeah

#

on the other hand

#

sometimes it can be useful

kind mantle
#

Also why doesn't stuff like Java support having just a plain ol' struct in an array? why does it need to be full on class instances?

slim panther
#

when

frank canopy
slim panther
#

c# has structs

frank canopy
#

or didnt last i checked

#

c# does yeah

loud ice
kind mantle
#

Also java is way too verbose for my liking

frank canopy
#

c# structs are great. you can even set explicit field offsets on them

flat badge
#

yeah java's type system is very limited

slim panther
#

kinda ironic

kind mantle
#

AFAIK still doesn't the struct

frank canopy
#

yeah no

#

scala still relies on the jvm so cant add structs properly

kind mantle
#

But at least it's got better types than java

frank canopy
#

yup

loud ice
#

if anyone wants to hear more shit about rust: the lack of TLS and async in the standard library is kinda ludicrous

#

literally every other good language has it

fiery turtle
#

huh

#

they dont have tls?

loud ice
#

nope!

frank canopy
#

god c#'s async is so good. legit the biggest reason i use c# for general high level stuff still

fiery turtle
#

well global variables are a crime in rust anyway

kind mantle
#

My opinion on language to use:

  • Kernel -> C and maybe Rust
  • Command-line -> Python
  • GUI application -> It's a mess either way
  • Embedded -> C
loud ice
kind mantle
#

I guess there's also:

  • Website -> You're fucked
fiery turtle
#

for gui u really want inheritance

slim panther
#

website -> typescript

fiery turtle
#

which rust doesnt have

slim panther
loud ice
loud ice
#

what the actual fuck

fiery turtle
frank canopy
#

website is typescript or js5 preferrably with as few libraries as possible and plain handwritten html

loud ice
frank canopy
#

speaking as a hobbyist web dev lmao

fiery turtle
#

lol

frank canopy
#

over the years ive migrated to modern js over typescript but both i still like to use on occasion

hallow marten
#

I think the JS ecosystem is fucked but react is pretty cool

loud ice
#

why not typescript?

kind mantle
fiery turtle
#

btw for the typescript thing they chose go over c#

#

and that was microsoft themselves

#

soo

hallow marten
#

they had a reason

#

I forgot tho

frank canopy
slim panther
frank canopy
hallow marten
#

preact is pretty good for small stuff

fiery turtle
slim panther
kind mantle
#

Rust does support thread-local storage but no matter the programming language I don't really find myself ever using actual thread-local globals and just pass around a context instead.

fiery turtle
#

so thats a thing

frank canopy
#

tbh i cant remember the last time i needed a thread local outside of kernel dev, where language threadlocal support isnt applicable anyway

fiery turtle