#Ultra
1 messages · Page 14 of 1
the announcement doesnt (currently, im too lazy to try and look at edit history) make any mention of requiring things here to be 0% AI, just not full vibecoding
I have 0% AI generated code apart from tests too
I'd say the no-ai distinction is a bit useless, and it'd be pointless to move the thread and lose history
idk
i have a firm no-ai policy even in issues/docs/descriptions so moving there is right for my project
Why
ai shit is harder to read. it adds a lot of fluff that frankly makes it harder to get to the point of things, and it cannot be trusted to correctly interpret intention
it feels like that category is kinda invalidating all of my work
could always just do a complete rewrite and not use ai moving forward if its a big thing for you
It took me 4 years to write what I have, complete rewrite would be insane at this point
That's not feasible for large projects
it's 70k LoC I think
You can always write most of it, then refine it with the help of AI
and a lot of planning and descisions and things I've been slowly iterating upon
if the existence of a no-ai category is invalidating you rather than seeming like a place to stick the weirdo hardliners like me then uh maybe examine that feeling ig
I'm not a native English speaker and it sure helps with writing technical documentation
my experience of AI is that it can often turn out things where there don't have to be too many subtleties and considerations, but unfortunately kernels don't have much of that
im also extremely anti-ai-in-all-forms-no-exceptions
why?
Like sure, there are things I don't quite like, but I don't know if I would have energy to rewrite my OS
do you not have places in your code that you felt like you could do better?
Yeah, in a kernel there is too much context that is needed for it to be useful
and if you try to get them to do anything where there are these considerations, you end up with them adding more and more flags and states and you end up with a combinatorial explosion
wdym, like all of them
its a plagiarism machine that takes as much effort to edit into something actually useful as it wouldve been to just do shit myself in the first place
But like I wasn't really telling AI to write code for me
it's the worst for kernels but i was quite shocked at how badly they did on other tasks too
(except for a couple of places in 2023 I think, when the AI was all the hype, which I'm rewriting/not really using anyway because it's an unmaintainable mess)
just today i had heard that claude 4.7 is a genius so i asked him how he would add auto-restart to the service manager i am writing for keyronex and the proposal was horrible
I'm not sure, I've never tried giving it complex tasks, it's always been for writing tests or docs
like i ported the ultra log ring to zig for my project, and in the process learned how it works (up to the limits of my understanding of atomic order), and was able to bang that out fully by hand in less than an afternoon
the thing for me is (apart from my own personal anti-ai bias), if i cant trust something (whether ai or a human assistant or whatever) to write the code right i cant trust it to understand it well enough to write docs or tests
There's a difference between writing complex code and reading it
And even then, it's not like you can't just review and edit lol
it was a mess and maybe it would have worked but i couldn't understand it, i have a single state variable to drive the service lifecycle and it proposed 4 new variables which all have subtle effects and turned my state machine with clearly defined inputs like "PID exited" or "Stop requested" into a monstrosity
that again would take me a lot longer than just doing it
I doubt that
I haven't been using AI for documentation because I don't really have documentation 
Also, I think AI models kinda get confused by microkernels?
maybe but docs are also meant to capture intent and ideas imo not just the raw what the code does. i can look at some weird linux code and understand what its doing and maybe ai could quickly whip up docs about what its doing, but if thats true than why do the docs need to exist for what its doing, the docs are for WHY and THAT is what ai cant be trusted to figure out imo
this exactly reflects my last experience where i asked claude to make some improvements to my TCP stack. he wanted to introduce all kinds of new code paths while i deliberately had stayed to the course set by the BSD stack, where you have a single output function and output is programmatically determined based on the current states. just obnoxious work, i think AI seems to be allergic to that style of programming
Because id rather skim through a large documentation comment rather than try to understand the details and intricacies of implementation
on the other hand they are alright for documenting and testing for the most part
doc comments take like 30 fuckin seconds to write itll take longer for an ai to fuckin load it up and process it than for me to write them, i was talking the bigger deal docs
Oh, I write doc comments myself
If that's what people mean by documentation, then I try to comment my stuff
it wasnt what i meant lol but ig thats part of the confusion here is that wasnt clear lol
I mean I let copilot autocomplete it, if that's more or less I'm writing anyway
everyone saw docs and thought something different
I wanted to write a high level overview of what I have, eventually
Because the code comments are not a good documentation in my eyes, I guess
they dont take 30 seconds to write lol
by doc comments I mean large top-level comments of like > 30 lines
With a microkernel, which makes it a collection of programs
can easily take 30 minutes to write properly
ok so 5-10 minutes but itd still take me longer to edit something down
0% ai is the other thread
this one is ai assisted
idk for me specifically it helps, I am not a native english speaker and I would rather have something be slightly ai generated that was written in a better manner and faster than something all written by myself that takes longer to do and is less well written
then leave your thread in this forum and its fine
my stance is "no stance" basically
as much as im anti-ai for my own stuff i wont really begrudge anyone else as long as its not in the place where bsky is rn where its fully 100% vibe-coded and breaking every 5 seconds because of it lmao
(in which case i just wont use it and still wont care)
yall do your own things lmao its fine
I think the thing that doesn't help is that I kinda dislike AI, but have tainted my stuff with it
yeah thats your own issue to unpack
I wouldn't say I like AI, but I do find it useful in some cases
I have been using it as a studying method (generating quizzes etc) and it works really well
I thought u were from Canada
I did but I didn't pay attention lmfao
So you're from french Canada?
quebec yeah
Makes sense
I literally have the least english name possible which is a bit of a shame
its hard to pronounce
Why do u care so much lol
x86 and PA-RISC are the only two architectures that select HAVE_UNSTABLE_SCHED_CLOCK 
it adds code that works around jittery sched clock
aka unstable tsc on x86
Is it because of tsc offset firmware mess?
then why use tsc in the first place?
let me explain
if no invariant tsc I fallback to hpet
me too, I use hpet/pmtmr
yeah if no hpet then pm timer
I decided not to support PIT in any form
with kvmclock you would read the kvm struct anyway
linux has the following clock types:
struct clocksource, an abstraction over a counter (this can potentially be very expensive to read but it provides precise timestamps, client code usesktime_get()to access the best clocksourcesched_clock(), this is designed to be a very fast reentrant and nmi safe clock used on very hot paths, linux uses TSC even if its not constant for this purpose, since the scheduler just needs to know the amount of ticks that have elapsed on this specific CPU and doesnt care much if it drifts a bitstruct clock_event_device, an abstraction over an event generating clock, e.g. deadline lapic etcjiffies, just a global variable but generic code makes sure to increment it with ticks, this is the fastest but most coarse clock source, used as fallback etcwall_clock, a thing that returnsstruct timespec64, actual irl time
I have recently renamed my TimeCounter to ClockSource actually
slowly turning into linux 
i kinda hate the name clocksource
its way too broad
ill probably call it a counter
a counter is way more broad lol
so TimeCounter was a better name maybe 
clocksource sounds like something that gives u a wall clock
yeah maybe
timecounter is a BSD name
i want to maybe have a similar prefix/suffix for event and counter clock types
I renamed it because I liked clock.zig better than time.zig
clock sounds like it should return a timespec
a monotonic counter is definitely not a clock
ok maybe I should revert the commit 
based
I think you're right that clock is a weird name
yeah
at least according to this definition
kvm has a separate msr that returns an actual wall clock
its u32 sec, u32 nsec
like what? Also what about vmware
vmware has even more
and hyperv has even more
most of arch specific stuff like that will be entirely offloaded
actually idk if I want to rely on cool features more
because then it's not as portable
idk
no
by overriding arch callbacks
but then you get super fast tlb shootdown or IPI or something on kvm but not on other platforms
arch.tlb_flush = vmware_tlb_flush
and by default its just arch.tlb_flush = native_tlb_flush
that is slow though
what is?
ur joking right 
yes its phenomenal overhead
but yeah in reality since linux has a static_call mechanism and they didnt bother using it for this
I don't really need that tho since my tlb shootdown wont be synchronous
that means it doesnt matter
arch.tlb_flush_begin
what would that do
start async work
the cool part is like, the vcpu you're trying flush the tlb of might be preempted on the host, so u can just skip flushing stuff on it
and kvm allows you to detect that
I dont think I need architectural support at all for async shootdowns
only a way to invalidate a page
and when will it flush then
on vcpu resume
u cmpxchg a flag that tells the kvm to do it
also pvspinlocks are insanely cool
you can force kick vcpus to schedule them over yourself on the host etc
u can tell kvm that you're try to acquire a spinlock currently held by a preempted vcpu so it will schedule it
ah yeah I saw that in qspinlock code
ye
and hyperv is gigantic https://elixir.bootlin.com/linux/v7.0/source/arch/x86/hyperv
in terms of features
tlb flushing is just a hypercall
There's also XEN ofc
which offloads even more
but thats a bare metal hypervisor
and pvclock was invented by XEN
Meanwhile my kernel has virtual functions spammed all over it
fuck i could really use kconfig integration now
I imagine this is partly because windows wants to run under hyperv itself if possible nowadays
so they can do secure vs nonsecure kernel memes
static_call is for spectre mitigation
not for perf
isn't it?
yup
yeah
Static calls use code patching to hard-code function pointers into
direct branch instructions. They give the flexibility of function
pointers, but with improved performance. This is especially important
for cases where retpolines would otherwise be used, as retpolines can
significantly impact performance.
yep
well it is to recover perf lost to retpolines
it literally says so in the cover letter that added them
it was originally as a less-shit-perf replacement for retpolines, but now can get used for other stuff because its also just better perf sometimes
the secure/nonsecure kernel memes are actually really cool tbh, maybe once my kernel is fully working for normal shit i can look into making that sort of thing (esp since aarch64 has hardware support for that too)
All other usecases are bonus, but it would certainly be interesting to
investigate the impact of using these APIs for tracing: that too is a
feature enabled everywhere but utilized only by a small fraction of Linux
users - so literally every single cycle or instruction saved or hot-path
shortened is a major win.
static calls are still slower than the alternatives mechanism that linux has
alternatives are for patching instructions, not call targets
can't you patch the whole call?
apparently on some archs static calls compile to two calls
because these archs cannot patch call isns
the one use of alternatives ive actually seen looking at their code is that the mmio read is changed by it to use load-acquire on some stupid early apple hardware lol
so they patch a trampoline instead
like the original reason was to patch hot repolined stuff, but these days im pretty sure most uses that are arch specific are for avoiding indirection on hot paths
btw where did u get that info from
apparently only x86 and ppc have STATIC_CALL_INLINE
discussion in the original ml thread
slower for other arches or?
since static calls still need to prepare the calling conv
while patching out stuff entirely doesn't
not sure what u mean by that
for example, for tracing it is preferable to have no call at all (only nops)
if it's off
oh ok
(and also no mov rdi, #first_arg etc)
but the most common use case is just replacing the call target
so even if u did alternatives its just the offset u patch
$ grep -r 'select HAVE_STATIC_CALL'
arch/Kconfig: Where an architecture does not select HAVE_STATIC_CALL_INLINE, any
arch/powerpc/Kconfig: select HAVE_STATIC_CALL if PPC32
arch/powerpc/Kconfig: select HAVE_STATIC_CALL_INLINE if PPC32
arch/x86/Kconfig: select HAVE_STATIC_CALL
arch/x86/Kconfig: select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL
why cant u patch these on arm btw
you can probably but ARM doesn't have retpolines either
but also, on ARM the call isns immediates are smaller
according to Kconfig, arm does not have special support for static calls and it just compiles them to function pointers
perhaps
yeah this was added in 7.0
also HAVE_STATIC_CALL is the variant with trampolines
Unlike on x86, there is no pressing need on arm64 to avoid indirect
calls at all cost, but hiding it from the compiler as is done here does
have some benefits:
- the literal is located in .text, which gives us the same robustness
advantage that code patching does;- no performance hit on CFI enabled Clang builds that decorate compiler
emitted indirect calls with branch target validity checks.
this is the rationale for adding it
no runtime tricks and is perfectly predictable
What are these two points even trying to say
Especially the first one
yeah this is better than an indirect call
especially on hot paths
I noticed this when I was benchmarking a triangle rasterization function
yeah
How come, cpus can predict indirect calls also lol
the cpu is better at predicting a branch even if that branch is in a hot loop than doing an indirect call
Cpus have branch target buffers for predicting this stuff
they are fairly small and even then there are other costs
Anyway u have to profile to know for sure
yes
doing any optimization w/o profiling is a bad idea
but it's true that check + branch is usually better than indirect branch
Bro called vtables a runtime trick 
patching code is a runtime trick
Don't think there's a single kernel on here that supports code patching
we were talking about linux
It wouldn't work on Linux since it would have many more branches than just x2 and x apics
Due to pv support etc
Also conditionally enabled with kernel configs
static call trampoline code patching is actually something im considering trying to implement specifically for the apic/x2apic split even though thats basically my only use case
ultra kconfig when
Really want one
Yeah
Im thinking alternatives for now, they're super useful
So alternatives?
Not sure how alternatives work
for the apic use case this is really overkill
Patch code based on cpuid
But I'd just let the prekernel patch either isn sequences or call targets
Although alternatives support runtime patching
runtime patching seems like a bad idea
or @ornate jasper we could make one in zig that parses a zon file, but i kinda dont wanna write all the code to handle terminals portably 
Modules are the primary use case
well, module load time != runtime, right?
Im not sure we need a saner thing, kconfig is already pretty sane
x2apic for me is a compilation feature flag in addition to the requirement for hardware support so the loader cant know whether to enable x2apic and thus the selection of which impl is fully runtime
yes but I wanna NIH
Ig
I think KConfig is also like insane to parse
Why not just vtables for this?
Yes
Ill just use a python library
there is python kconfiglib
Yeah that
because its two functions so runtime if seems better. idk how a runtime if to switch two fixed function calls compares to vtables perf wise tho
the loader can just check the kernel for supported features
what I do is I try running kconfig-nconf first, or else I fallback to a python script using kconfiglib
that's what Managarm does
or just pass the kernel config to the loader
yeah but then i need to come up with a way to communicate that lol
Its not just two, the way you send ipis differes a lot, also EOI and other stuff
we use ELF notes
ah no you cant without recompiling
Yeah elf notes seems perfect for config detection
if i figure out how to actually write elf notes ill def do something like that for my feature tags
you should add kconfig too
because i hate external deps
yeah that part is fine its the utility to manage them that i dont want to bring in, and then id need to write my own parser for them in zig too, and that just increasingly sounds like more work than i want to do
ok then that wouldnt be a problem
And kconfig itself is configured via a frontend like python or anything, there's tons of them
yeah but that frontend is an external dep which rubs me the wrong way lol
esp if its python
i hate python more than anything else in software lmao
Yeah the frontend is external, but it can be of users choice
idk
i also prefer to keep build option selection tightly integrated with the build process itself
Oh well
I think later down the line you inevitably have to reinvent something similar
just enable everything unconditionally 
yeah if i need more config options in future ill consider it
and use load time patching to remove the stuff that you don't need
Thats the way of serenity
The 30 meg kernel
that sounds more like a serenity skill issue
A lot of it is c++ template bloat also
jesus what
Yeah lol
Managarm is also C++ but nowhere near 30M
Well its a microkernel lol
i actually dont know how big my kernel is
maybe ill check that today
i know its more than a 16-bit number of sectors because thats why i swapped off of bootelf to limine (before eventually from limine to my own bootloader)
or maybe it was 16 bit bytes i dont remember
wtf even with releasesmall mine is 1.2mb
esp if you use zig's formatting that aint bad
tf you mean hello world it has cool fireworks
the one downside to zig string formatting is it template explodes
formatting also uses a lot of stack
I think
the NVIDIA driver just takes 90M 💀
for storage yeah but i meant for the template explosion from different format strings
but this is with debugging symbols
idk but like I was running formatting in some functions for debugging and the stack would overflow
i had that more with debug symbols than formatting
it's 16M without and that's the largest driver
actually maybe it was unrelated and it didnt overflow
it was probably because of my pmm sharing pages bug
but it appeared less often when making stacks bigger
if its in debugging code and youre using zig's dwarf unwind that may be part of it
I don't
that stuff uses a ton of stack and ive not been able to pin down why
then idk
this
mhm
Mine is 2.3M with debug stuff and unwind tables (which I need to get rid off tbh, but my kernel init is hardcoded to my linker's layout atm)
Anything without KDE is a hello world 
did managarm get kde in the end?
mine is like 1 mib :^)
doesn't say much as it barely does anything though
(most of it is .text iirc)

needs gzip bro
trust
(releasesafe with full debug info)
lets try a stripped releasesmall build
stripped releasesmall (does still have eh frame just not full dwarf)
is that 3mb?
A little bit more than that
that's pretty big
yeah im a bit surprised
wonder how much of that is log template explosion
but also cant be assed to actually check
we are very, very close
kde in managarm before gta 6 is real
there's probably no major stuff left, just bug fixing
we get to the point where plasma/kwin start and run but for some reason output doesn't work yet
Clanker suggested some solutions for uploading .config into cmake, lets see if it works
macro(load_kconfig config_file)
if (NOT EXISTS "${config_file}")
message(FATAL_ERROR "Invalid config file path: ${config_file}")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${config_file}")
file(STRINGS "${config_file}" config_lines)
foreach(line IN LISTS config_lines)
# 1. Match 'n' (Unset Booleans/Tristates)
if(line MATCHES "^# (CONFIG_[A-Za-z0-9_]+) is not set")
set(${CMAKE_MATCH_1} OFF)
# 2. Match 'y' (Boolean/Tristate True)
elseif(line MATCHES "^(CONFIG_[A-Za-z0-9_]+)=y$")
set(${CMAKE_MATCH_1} ON)
# 3. Match 'm' (Tristate Module)
# CMake doesn't have a native tristate, so we use the string "m"
elseif(line MATCHES "^(CONFIG_[A-Za-z0-9_]+)=m$")
set(${CMAKE_MATCH_1} "m")
# 4. Match Strings
# We strip the quotes for CMake, but set a hidden _IS_STRING
# variable so we know to put the quotes back for the C compiler!
elseif(line MATCHES "^(CONFIG_[A-Za-z0-9_]+)=\"(.*)\"$")
set(${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
set(${CMAKE_MATCH_1}_IS_STRING TRUE)
# 5. Match Numbers / Hex / Anything else
elseif(line MATCHES "^(CONFIG_[A-Za-z0-9_]+)=(.*)$")
set(${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
endif()
endforeach()
endmacro()
unironically works great
and sanitization is handled transparently by olddefconfig
thats insanely convenient
clanker is truly great at scripting
and this is stuff i hate working on so its a W for me
straight to openslopware :^)
lol
nah the actual kernel will be almost 0 ai
clanker is not yet at the level where i would let it touch any c code thats not like something that has been solved a billion times before
some parts of my build system is also llm generated/translated
like write a strstr impl etc
yeah fair
most of mine is handwritten also
since it predates llms
being useful
lol
neat ig
Ultra bootloader is in there as an alternative to limine
mint added it
you can steal my bash script if u want
why do u need a bash script?
oh yeah i have my python wrapper for initial configuration like that Ill just add a warning there probably
I like kconfig-nconf more
than the python -m menuconfig one
i get that one if i just do menuconfig
$ which menuconfig
/home/infy/.local/bin/menuconfig
all these tools are from kconfiglib i guess
but olddefconfig is truly the goat
what is that
ah
infy@DESKTOP-IGT40G0:/mnt/d/Ultra$ cat .config
CONFIG_MODULES=m
CONFIG_ARCH_X86=y
# CONFIG_ARCH_ARM is not set
# CONFIG_ARCH_RISCV is not set
CONFIG_STUFF=m
# CONFIG_X86_STUF is not set
infy@DESKTOP-IGT40G0:/mnt/d/Ultra$ olddefconfig
.config:1: warning: 'm' is not a valid value for the bool symbol MODULES (defined at Kconfig:3). Assignment ignored.
Loaded configuration '.config'
Configuration saved to '.config'
infy@DESKTOP-IGT40G0:/mnt/d/Ultra$ cat .config
CONFIG_MODULES=y
CONFIG_ARCH_X86=y
# CONFIG_ARCH_ARM is not set
# CONFIG_ARCH_RISCV is not set
CONFIG_STUFF=m
# CONFIG_X86_STUF is not set
it also converts =n into is not set, so its always the same to parse
basically this thing is amazing
yeah so u cant insert bullshit values or incorrect values or mess up dependencies etc
if u manually edit it
it's a weird name tho lol
it is indeed
do you have static_call in ultra btw?
what's that
Rewrites a function pointer call into a normal call or something like that iirc
wat
To remove overhead
you mean inlining?
that sounds awful
no lol
if im doing something like that ill do alternatives first
it rewrites a call address into another address
it does that for hot paths that would otherwise have to be turned into a retpoline
which is slow af
its a vulnerability workaround
on those cpus u cant use function pointers at all
(without it being a vulnerability)
In CMake, if you pass multiple separate strings to set(), it creates a list.
When CMake converts a list back into a single string (like when you write it to a file), it automatically joins the list elements with semicolons (;).
Look closely at how you defined the variable:
set(
CONFIG_HDR
"/*\n" # Element 1
"* Auto-generated kernel configuration header\n" # Element 2
"* Do not edit manually!\n" # Element 3
"*/\n\n" # Element 4
)
Because they are separate strings, CMake treats this as an array of 4 items. When it writes them out, it glues them together: Element 1 + ; + Element 2 + ; etc., resulting in those unwanted semicolons.
How to fix it
There are two ways to fix this.
Method 1: Use a single quoted string
Wrap the entire block of text in a single pair of double quotes, rather than four separate strings:
set(CONFIG_HDR
"/*\n* Auto-generated kernel configuration header\n* Do not edit manually!\n*/\n\n"
)
Method 2: Use CMake's "Bracket Syntax" (Recommended)
If you have CMake 3.0 or newer, there is a much cleaner way to write multi-line strings without needing \n or quotes. You use [=[ and ]=].
This tells CMake "Treat everything in here as one exact string, preserving all newlines."
set(CONFIG_HDR [=[
/*
* Auto-generated kernel configuration header
* Do not edit manually!
*/
]=])
This makes writing C-style templates inside CMake much easier to read, and it completely avoids the semicolon/list problem!
cmake is a fucking joke lol
but on the bright side kconfig integration works way better than expected
automatically notices changes + regenerates config.h + detects variable changes and lazily rebuilds only stuff thats actually needed

cmake is great for like. most things. this is the one where it isn't lol
somehow they absolutely fucked up multiline strings
yeah
zig did em good yeah
for cmake big strings like that I always preferred template files where possible but idk offhand how well that integrates with variables
but also I've not touched cmake in like 8 years now
yeah, or ill just write a series of appends
oof
yeah turns out you shouldnt let it glob recurse itself
would you be down to work on a kconfig thing in zig with me
using zon and ncurses
because parsing kconfig is actually ass
maybe sometime yeah
so it'd use its own syntax based on zon
oh if own syntax im def in
(also could easily output zon too as an option, that can then be @imported by zig later)
is there good zig binds for ncurses?
id just use the raw C honestly
I'm aware there are zig libraries for TUIs but I'm scared to depend on zig stuff
mhm
exactly, it would output something like:
.{
.enable_logging = true,
.log_level = "info",
.output_dir = "./out",
.thread_count = 8,
.enable_tls = false,
}
which build.zig could import
cool
idk just a thought I had
yeah no i do like it
the only annoying part will be the TUI
yeah for sure
and probably managing dependencies
but that shouldnt be too hard (build a DAG)
zconfig it should be called
mhm
idk if I actually want to start work on this right now though
yeah me neither
but in the future that could be a really cool thing to work on
wouldnt take too long to get an MVP and we can get community backing easily I'm sure
my thing is rn my kernel doesnt need any non-bool options so my existing wacky config setup is fine
in fact we could get an MVP tonight if I vibecode it but I won't do that
so its a low priority for me
yeah but the idea would be to make generally available to the zig community
one use case i found instantly is CONFIG_OPTIMIZATION_LEVEL
not just for kernel stuff
yeah that too
range 0 3
compiler optimization is already built into build.zig as a thing to pass as an option
loading from a config could be nice ig yeah
rn im also using build cli flags for all my options anyway so the builtin option for build.zig for optimize level is fine
the idea is more for larger projects with large configurations
yeah no 100%, itd def be a useful thing for the future™
- make this popular
- tigerbeetle adopts it (VC funded zig startup)
- we get sponsored
- profit

just not a priority for me atm if noone else is also working on it
mhm
cant take more than like a week right 
I also thought about that
we can detect if ncurses is present during build
and if its not then it can be a console prompt
linux has that too
but it sucks obviously for large configs
oh is ncurses a dynamic library? that kinda sucks
?
I meant more like in the build script we check if we can find ncurses on the system
oh
and if we can't we fallback to a cli
ah ok
idk I'll try something and I'll ping you if I can come up with something good
👍
might not be tonight
are u gonna vibe code it
i have homework
yeah no worries
sounds like the perfect thing to vibe code
honestly kinda tempted to vibecode it
khitiara might not like that
if its vibe coded then im not going to be involved or use it personally
but anyway id need to modify most of it since AIs dont work well with zig
I'm not going to vibecode it but I might or might not use AI to avoid going through ncurses documentation, is that fine with you?
i dont really have time to invest learning how ncurses works
eh? idk how i feel about that. would be more willing to consume that but idk if id want to be involved then
this is part of why my instinct would be to use a zig library if theres a good one
or just like. maybe a better library than ncurses lmao
ncurses isnt bad
ncurses cant be that hard
but my problem like I said is mostly portability
ncurses works everywhere
and is present on most distros by default even
I don't wanna vibecode it because I would be ashamed to release something I vibecoded
I dont mind vibecoding useless stuff only I play with
tbh this json like stuff it can one shot
but yeah
depends how q&d u want it to be
zig has a parser built in
it's literally zig syntax
zig has a builtin parser for zon yeah
the zon stuff in std actually works as a (de)serialiser already
the only downside of using cmake stuff is its really damn slow, especially over wsl with its crappy p9 impl
fwiw when i said console prompts i wasnt talking about cli args i meant readline-type stuff
can always just use mingw or something, cmake does exist for windows
meson
yes me too
i could actually build it on windows using clang --target i guess
linux has that
but im too lazy
cool just wasnt sure if i was clear about it
where it goes through every config option individually and asks you
yeah this definitely is not gonna brick my pc :clueless:
nah im not installing it
they definitely have a billion regressions there
it already has a problem waking up from suspend every now and again
i have to do a literal power cycle
oof
suspend is an unsolved problem in computing
yeah
and they made it even more fragile with s2idle
to appease microsoft wanting to do stupid background updates
anyway im loving how this ended up
hell yeah
very happy with the end result and tbh i expected it to be way harder to integrate
yeah config headers are super nice
build.zig can generate headers too actually, theres a ConfigHeader step that can take a number of different input formats
i just want a bit more control i guess
since i have these variables in cmake anyway
cool
you using the cmakedefine config header stuff?
Nah it just regex parses the .config to transform that into in local cmake variables and also at the same time appends them into the config.h header
ah
(cmakedefine is a special syntax you can use to have cmake do config header processing using cmake variables)
yeah
i know you wouldnt like my parsing logic since the regex was developed by clanker 😭
F
honestly i dont see why someone would be against AI for something like that
yeah regex is hell on earth i can absolutely understand that case lmao
didnt humans keep inventing stuff so we have to do less boring work
i wouldnt do it but i can kinda understand using it for regex
regex is justifiable i guess
but everyone has their own line that they draw for that stuff
my line is different for things ill silently judge, things i wont use, and things i wont do lmao
like i wouldnt feel bad if i had vibecoded the entire parser in zig, but i would feel bad if i actually vibecoded something important in the kernel
tools/buildsystems/tests is where my line mostly is
my lines are that i wont use them for anything myself, but my i wont use something someone else made using it line is about where yours is for your own use
yeah ive not been very good at words today lmao
kinda funny we're three people all not talking in their native language
I think
unless khitiara you're english native idk
isnt khitiara from the us
idk
americans 
(i know german grammar almost completely but my ability to remember vocabulary is approximately null so i dont really speak it)
As an American, yeah your mostly right

yeah lmao
My English isn’t even good
I meant more like
knowing one language
I'll have you know I know one and know a little bit of another 
that one doesnt even know what rsource is
this is so much more cleaner than random cmake variables scattered everywhere
I just have a bunch of makefile targets...
L
Why does the build system not auto detect gcc vs clang?
How do you compile your kernel in the first place?
olddefconfig && mkdir build && cd build && cmake -DCONFIG_FILE=../.config && cmake --build .
but i have a python script for covenience that does image generation etc
if u select clang it just uses the host clang with --target
for gcc it builds one from source
And jinx kinda takes care of architectures in the first place
fair
i dont use any of that stuff
I did have to add this check into cmake because it really doesnt like changing the toolchain after configure
but i usually just let my build.py create separate directories so i can test different toolchains in parallel
My makefiles do that 
Also, I'm using my patched toolchain for both userspace and kernel, so I "can't" use host's toolchain anyway
Cool but not NIHed so less cool

you're using zig build, that's not NIH either 
at least the bootloader is NIHed 
so is Hyper
But the kconfig is NIHed
what does NIH even mean?
not invented here I think
ah ok
skrill tissue
lol

Finished improving my python script for Kconfig support
It's so convenient now
./build.py -> makes a build directory that's build-{toolchain}-{arch}, makes a default config inside the build directory, builds it
./build.py --arch aarch64 -> same thing but replaces defaults with CONFIG_AARCH64
./build.py --config .config -> creates a build-user-config, builds using it
./build.py {--menuconfig,--guiconfig} -> convenience helpers for editing the autogenerated config, also works with --config
not to mention it already had --make-image/--run/--debug/--ide-debug etc
wait wtf did i do
ah nvm
also my aarch64 bitrotted 😭
fuck, i had the vscode setting that auto trims whitespace off
i have to go through a shitload of commits and check all code now
try:
from kconfiglib import Kconfig
except ImportError:
print("Could not import kconfiglib, trying to install in-place...")
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--user", "kconfiglib"]
)
user_site_packages = site.getusersitepackages()
if user_site_packages not in sys.path:
sys.path.append(user_site_packages)
importlib.invalidate_caches()
from kconfiglib import Kconfig
Least cursed build script
it might be cursed but i like when my build stuff does dependency shit itself
vendor how?
like just put the kconfiglib there
hell nah
im not putting random code into my repo
it‘s a single file, that‘s just what I mean
its definitetly not a single file
A flexible Python 2/3 Kconfig implementation and library - ulfalizer/Kconfiglib
aside from all the menus
i need the menus also
otherwise how tf am i supposed to edit it lol
and if i have to install menus separately why would I vendor a 7k loc file
well that‘s true then
whats interesting is the pip package maintenance was overtaken by zephyr
because the guy that originally made the repo abandoned it
Canonical upstream for https://pypi.org/project/kconfiglib/ (replaces inactive https://github.com/ulfalizer/Kconfiglib) - zephyrproject-rtos/Kconfiglib
this is the current repo
thanks to zephyr otherwise idk what i would do
I took the kconfig stuff from zephyr too lol
whats your os
I‘m redoing a bunch of things and just started reading some os books again so not much to show currently
I had it setup on an old kernel and copied the build system for my new one
do u use make?
cmake
iirc it even was a bit of zephyrs cmake, i found the cmake integration on a github repository
oh ok
i had to do a shit ton of work to make sure it picked up changes to .config and all Kconfig files + sanitized it so that all options are set correctly etc
do you have some sort of fixdeps.c equivalent
what is that?
as in the linux tool
yeah but what does it do
yes
I found it interesting
No, but I saw some talk about kconfig here and wanted to look into something like that
ah ok
i wanted to optimize it by just using cmake definitions for most common options
though IDK how feasible it is with cmake
nah it has a diff purpose
some options are basically never changed but needed by a lot of code
e.g. the current arch, or the current arch bitness
or endianness
but yeah let me know if u figure out how to do that fixdep thing
i did that but it just kinda nicely fell into place with kconfig so i left it there
this allows me to include the respective kconfig of the arch subdir etc
pretty covenient
true
fixdep would probably require digging into cmake internals
I'll have to look into cmake first, like if you can change and remove a dependency for certain files
to figure out how it does that depepndency stuff
yup
kconfiglib includes a function similar to the linux kconfig
something something sync directory
what does that do?
like this functionality
* kconfig populates a tree in include/config/ with an empty file
* for each config symbol and when the configuration is updated
* the files representing changed config options are touched
* which then let make pick up the changes and the files that use
* the config symbols are rebuilt.
so i think the major challenge is getting the cmake side working
interesting
yeah that definitely sounds doable
so do u vendor kconfiglib or do u expect the user to install it
vendor
damn
i pasted that whole library in lol
why not?
I'd want to ensure it doesn't break or depend on the network further, though I mean it's possibly cleaner
hmm, but don't u have other network dependency like the compiler sources etc?
that's not really part of my kernel build process
You can always require deps but still have your build fully offline
sure
Installing network stuff in the build script is a bit stupid tho I agree
i just did it like zephyr :p
well
No write your own
does it submodule or copy paste?

interesting
kconfiglib doesn't really change much anways
yes but mine is like 2.5k
kconfiglib is like so much comment
for now
nvm that lol
unironically it's very difficult to parse since options can recursively depend on other options for their values and ranges etc
you probably have to make a multi-pass option resolver
and run it in a loop as long as you make progress
kconfig syntax is whatever linux parser accepts 
zonfig with a shitton of { ftw
let me know when it supports recursive options 
What is that
config FOO_4
bool
config FOO_8
bool
config FOO
int
default 4 if FOO_4
default 8 if FOO_8
config BAR
int
range 0 FOO
config X
def_bool y
select FOO_4
U can do stuff like that
BAR depends on FOO for its value, which is selected only later by X (which may depend on other options for its values)
idk if thats useful
heres an example
literally all properties of an option are dynamic
you can't remove a dependency via cmake (as far as I found out)... however I can remove and could also inject dependencies with https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html#prop_tgt:<LANG>_COMPILER_LAUNCHER from a small python script
I'll have to look into how linux exactly modifies the dep files
also this would only work for makefiles/ninja
this would allow to wrap the compiler in a script that changes options and stuff right?
yes
Contribute to lretq/dep-file-cmake development by creating an account on GitHub.
I atleast removed the generated config header dep already
now would just need to scan the file for CONFIG_* stuff, I think that's how linux does it
damn
yeah i think it scans not only the file but also all of the headers that it includes
yeah that makes sense of course
and the headers it gets from the dep file that the compiler produced
wait right, the compiler generates the file list for you
yeah, so this whole thing only starts working after build 1
before build 1 this wouldn't even make sense
as the config.h would've just been generated the first time
ye
@edgy remnant i decided to follow your advice but with a submodule instead of direct copy paste
i think thats cleaner
File "/mnt/d/Ultra/scripts/kconfiglib/guiconfig.py", line 263, in _detect_system_dark_mode
if sys.platform == "win32":
^^^
NameError: name 'sys' is not defined. Did you forget to import 'sys'?
wait do they even test their code
they use sys without importing it
I used the sync_deps from kconfiglib as a template as ninja NEEDS the files to be there:
https://github.com/lretq/dep-file-cmake/blob/main/scripts/kconfig/kconfig.py#L293-L330
and then I just scan all files from the dep file and modify:
https://github.com/lretq/dep-file-cmake/blob/main/fixdep.py
I just added a new argument to the zephyr kconfig.py and call my sync_deps from there:
https://github.com/lretq/dep-file-cmake/blob/main/cmake/kconfig.cmake#L203
and I reuse that cmake var and pass it to the fixdep.py script as first arg
wait so how do u intercept/overwrite cmake dep files?
via fixdep.py
set_target_properties(program PROPERTIES C_COMPILER_LAUNCHER
"python3;${CMAKE_SOURCE_DIR}/fixdep.py;${KCONFIG_SYNC_DIR}")
and this one
It works only for make and ninja as this LAUNCHER thing is only supported for those two, but I only use ninja anyways
interesting
the script removes the config.h from the dep list and adds for every CONFIG_* symbol the stamp file to the dep list
it parses the call the CC and if it finds an argument -MF it takes the next arg as <dep file>, if it doesn't find anything I just do nothing
makes sense
for whatever reason if i call menuconfig not via subprocess but via menuconfig.menuconfig() it starts in some half corrupted state
if args.menuconfig or args.guiconfig:
os.environ["KCONFIG_CONFIG"] = args.config
module = mc if args.menuconfig else gc
kconfig = root_kconfig()
with enter_work_dir(pg.project_root()):
module.menuconfig(kconfig)
sys.exit(0)
like what does it want from me
it parses the options but they're not modifyable
lol what
yeah lmao
ill just keep using subprocess lmao
and ill have to send a pr to fix their crappy guiconfig
which repo do u use
u use that repo as well right?
https://github.com/ulfalizer/kconfiglib this one?
that one is abandoned
Canonical upstream for https://pypi.org/project/kconfiglib/ (replaces inactive https://github.com/ulfalizer/Kconfiglib) - zephyrproject-rtos/Kconfiglib
ah
u use the old one?
ah nvm someone already made that fix but they arent reviewing it https://github.com/zephyrproject-rtos/Kconfiglib/pull/41
i use what zephyr uses lmao
why do they have two copies of the same repo??
zephyr doesnt seem to check the changes they do, the old repo does it correctly?
what huh
this repo is part of the zephyr project
but for some reason the actual kernel has some copy pasted code
instead of submoduling this one
yes
weird setup idk
anyways I checked and my guiconfig still is the version that supports python2
i have the version from 2019
they do pull in commits tho https://github.com/zephyrproject-rtos/zephyr/commit/745e0b28bd85668d66a5bedc2839de797adfca04
TK under Windows/Linux did not have a native support for dark mode.
Signed-off-by: Yves Wang [email protected]
but they didnt pull in the commit that dropped python2 support
btw that was a python funny
menuconfig.py does from Kconfiglib import ..., that was importing Kconfiglib from pip instead of kconfiglib.py, which was causing isinstance checks to fail
from .Kconfiglib fixed it lol
ah wow
this seems to be the more general fix:
import scripts.kconfiglib.kconfiglib as kc
# Make sure the rest of "import kconfiglib" always references this
sys.modules["kconfiglib"] = kc
also something I noticed with my dep file solution is that a missing kconfig symbol makes it so that the file is recompiled every time lol
was wondering why it didn't work but I never added that option to Kconfig
well I used it from actual code
I guess I could warn when I encounter non-existant kconfig variables or something like that
not if I do something like
#if CONFIG_OPTION
#endif
right right
its definitely possible to check that it exists yeah
although from python it might be slow af
ig this could be helpful to catch typos
to run for every source file
it's a single os.exists
as I create a stamp file for every option anyway
is it a flat hirerachy?
it turns _ into /
wdym
iirc the reasoning from linux was that some filesystems dont like thousands of small files
like whats the conversion path from CONFIG_FOO to its location on the fs?
so for a symbol FOO_BAR, in the generated directory would be a file foo/bar
yes
linux has flat include/config these days
well I based myself on the 2019 kconfiglib code idk
though it's not that big of a difference
as in I can easily just change the paths
yeah it seems zephyr's one still does that
i'll just do that rq, this seems easier to understand
seems like only this function would have to be patched https://github.com/zephyrproject-rtos/Kconfiglib/blob/b8535af53f0650a69e52db4bf8585c09d55852e7/kconfiglib.py#L6479
yes
I extracted the sync_deps stuff and did it seperatly from the kconfiglib.py so that integrating is easier and doesn't require a patched lib
ill probably just fork it
and fix the sys import + patch to allow configuring deps layout
where did u extract it to? Don't u have the full code locally anyway
u could just import the function from kconfiglib
yes, just the script that calls into kconfig (the one called from cmake)
like u do from kconfliglib import sync_deps right?
I might want to be able to update kconfiglib or smth idk, seemed better to me
no I added a check to sync_deps
cmake+ninja requires that the file actually exists
linux did some sort of makefile wildcard thing that would not require a rebuild if the dep stamp file is not there
as would be the case if the option is =n
so u copied basically the entire sync_deps code into the script that patches cmake deps?
yes