#Nyaux

1 messages ยท Page 45 of 1

thorny glen
#

You must allow lower priority threads to run while you wait for the mutex or you can deadlock

#

You can do adaptive spinning where if the owner is running on another processor you spin wait for a little bit for the mutex to be released

#

And if not then you block

flat nymph
#

yeah, but spinlocks should ideally also have mechanisms to prevent that if that kind of thing can happen

thorny glen
#

Yes, it's called "threads don't own spinlocks, cpus do"

#

Generally you block preemption (if not disable interrupts entirely) while waiting for a spinlock or holding one

finite summit
#

^

flat nymph
#

in kernel

surreal path
#

meow

thorny glen
#

Spinlocks are double bad in userspace

flat nymph
#

but they are still useful as a simple synchronization mechanism

thorny glen
#

For guarding stuff you cannot guard with a blocking mutex yeah

#

Like the scheduler itself

#

Or locks that have to be taken by ISRs

#

Otherwise they r bad

flat nymph
#

but for small things, spinlocks could probably still be faster

#

you yield if you can't take it and there's less cost than blocking/unblocking threads

thorny glen
#

And when not contended you can make it just as fast as grabbing a spinlock

silver yarrow
#

I dont understand the diff between blocking and yielding

flat nymph
#

blocking is not letting task run untill someone explicitly unblocks it

silver yarrow
#

so like a waitlist

flat nymph
#

I guess

#

yielding is just asking scheduler to run a different thread

silver yarrow
#

yeah

#

aight

surreal path
#

meowmeowmeow

flat nymph
#

I found the right term

#

It's sleeping mutex

surreal path
#

say meow with me everyone!

#

meow

flat nymph
#

woof

surreal path
#

๐Ÿ˜ก

flat nymph
flat nymph
#

(I'm a bit biased because my pthread_mutex_unlock() can fail with ENOMEM trl)

surreal path
#

meowmeow

#

oh my god

#

im feeling the effects of 8gb of ram

plush hearth
#

I remember the pain I went through with only 8GB of RAM on my laptop

flat nymph
#

what is does meowing mean?

flat nymph
flat nymph
plush hearth
flat nymph
#

15 years?

#

Maybe more

plush hearth
#

At that time, I would have been an infant or maybe not even born yet

flat nymph
#

It was still very little for the time

#

Below Windows Vista requirements?

flat nymph
silver yarrow
#

vscode only uses like 500mb for me

#

actually that was one electron process

#

so that might be a lie

desert haven
#

laughs in 14M used by vim

finite summit
#

electron moment

silver yarrow
#

real

#

500mb is nothing tho

finite summit
#

I use Kate

silver yarrow
#

I used to use neovim, and others

finite summit
#

(if you don't know what that is, it's the KDE fancy text editor)

silver yarrow
#

vscode has just worked for me

flat nymph
#

If you have ram for electron

surreal path
#

shut up and let me watch squid game

#

๐Ÿ˜ก

#

/j

flat nymph
#

(tbh I also just use vscode and haven't bothered setting up anything else)

plush hearth
#

I use vscode since I can't be bothered setting clion up for this project (frostyos, not what this thread is for) or trying to setup neovim

flat nymph
#

(only good thing about them)

silver yarrow
#

skill issue on my part

broken depot
surreal path
#

okay guys

#

when i reach the end of squid game thread blocking ๐Ÿ˜Ž

#

in nyaux soon

#

while watching squid game i was thinking of how my threadblocking function would look like

#
void ThreadBlock(struct thread_t *towhichqueue); // will block the current thread (remove it from the run queue, throw it into the parameter queue and scheduler yield)
void ThreadReady(struct thread_t *thread); // will ready whatever thread it got in its parameter
#

i think this is a good way of doign that

#

also my alt key

thorny glen
#

i see a problem

surreal path
#

is broken

surreal path
thorny glen
#

ill let you find it

#

good experience

surreal path
#

u should tell me

thorny glen
#

the comment

#

"block the current thread (remove it from the run queue"

#

if its the current thread then surely its already running

#

and not on the run queue

surreal path
#

oh

#

ill explain this

#

in my scheduler design i have 2 pointers

#

current thread and run queue

#

run queue keeps a list of ready threads and whatever the current thread selects it changes its state to running

#

it stays in the run queue however

#

thats how my scheduler works

#

so actually the comment is correct will

thorny glen
#

thats slightly odd

surreal path
#

i guess so

#

but i believe obos does the same

#

if im not wrong

thorny glen
#

obos is the paragon of design

surreal path
#

real

thorny glen
#

i think the main issue with doing that is, one you dont get the natural like fifo properties of popping threads from the head of a queue and then pushing them to the tail later

#

two it makes fine grained locking a bit harder

surreal path
#

to be fair

#

anyways ima watch squid game

#

๐Ÿ˜Ž

#

or well

#

continue to watch the episode

thorny glen
finite summit
finite summit
surreal path
#

oh ok

thorny glen
finite summit
#

lol

finite summit
# surreal path oh ok

what obos does is has a function to take a thread of the runqueue it is on ("block" it), and a function to put it back on a runqueue

#

then a layer of abstraction above that in the form of struct waitable_header, which allows for threads to wait on objects, and for threads to be signalled by other threads, if they have that object

#

if that makes sense

flat nymph
surreal path
#

last episode everyone

thorn bramble
surreal path
#

wow

#

that was the ending

#

crazy

#

that was actually so ass

#

anyways

#

thread blocking time

#

and mutexes for nyaux

surreal path
#

tf

#

crazy things happening in ze scheduler lol

#

these functions should work wtf

#

sorry just realized

#

im stupid

#

no nvm

surreal path
#

cause im struggling hard trying to get the queueing to work

#

its just easier :)

rigid fable
surreal path
#

hey

rigid fable
surreal path
#

time to learn more

#

nvm ill js do a single circular linked list

#

no point in having a double linked list

#

nvm

#

fine

#

ill do a double circular linked list

rigid fable
surreal path
#

idfk

rigid fable
#

then why you leraning this

surreal path
#

just let me code for a bit pls

#

im trying to fucking fix this code

rigid fable
#

you got new pc or laptop ???

surreal path
#

new

#

no

#

its my old laptop

rigid fable
#

yay you fixed it

surreal path
#

no i didnt fix it

#

bro

rigid fable
surreal path
#

WHY CANT I GET CIRCULAR DOUBLELY LINKED LISTS RIGHT

#

UGH

#

whatever forget about it

#

no nvm

#

ill make a userspace program later

#

to get circular doublely linked lists right

#

for now im going to just take a break cause im rlly frustrated

plush hearth
#

what do you need a circular linked list for?

surreal path
#

its just

#

better

#

ig

steady flume
#

meow :3

errant mantle
#

Its so nice to use

haughty kite
#

or the bsd ones?

haughty kite
spice yarrow
#

Yeah, but the Linux one is gpl, that's what I was talking about

haughty kite
#

yes

broken depot
#

I have an MIT one if you want very permissive

surreal path
#

my bad been having a bad sleep schedule

#

slept til like

#

10pm

#

๐Ÿ’€

#

just woke up

#

@kind root @finite summit whats yall opinion on this ass sleep schedule

#

i need to fix it

#

i dont know how

surreal path
#

i just need to write a userspace program, test it a bunch, put it into the kernel

#

like a good programmer would

#

even in userspace im screwing this up

#

๐Ÿ’€

#

okokok i got it

#

time to impl this into kernel space

#

figured it out using cool double pointer

#

seems like it works

#

why is bro stuck now

#

got it working :)

#

works with smp too

#

thread blocking time ig

surreal path
#

or no

#

well i have the functions anyway

#

its time to impl a kernel mutex thing

flat nymph
#

I wonder if you can pass some sort of callback to the unblocking thread Thonk

surreal path
#

no thanks

#

too complicated

flat nymph
#

why

surreal path
#

more work

flat nymph
#

2 instructions

finite summit
#

The hell would you do that

flat nymph
#

so when the thread is dying or something it can do work in the context of new thread

finite summit
flat nymph
#

so like to free stack or something

surreal path
#

dw they still there

kind root
surreal path
surreal path
#

damn feel like shit again

finite summit
#

Not shit

cinder plinth
#

They're short tho

#

I'd have done a single big video

tender gorge
surreal path
surreal path
surreal path
#

my bad chat

#

wasnt in the mood today either

#

hopefully tmrw will be better

tender gorge
#

is okie, you do not have to apologise for not doing anything

#

huuuuugggg

hollow goblet
#

no you must get back to work

#

jkjk

surreal path
#

chat i just got a gf

#

anyways lets get back to work

coral dove
#

walking W

#

Os dev gets girlfriend? never seen before

surreal path
#

lol

#

todo list for today:

impl blocking threads and kmutex
see how i can impl schedule work and wait for work completion
then we are done

#

is the bool acquired used for checking if it was acquired?

flat nymph
#

yes

#

idk if it's the best impl

#

(like it's not)

#

*i'm probably not the best person to be asking things about concurrency

#

but it should work

surreal path
#

who can i ask about concurrency

flat nymph
#

idk

surreal path
molten grotto
#

what do you want to ask

surreal path
#

for a kernel mutex

molten grotto
#

I don't think

flat nymph
#

it's ok but probably there are better implementations, which you probably don't really need

#

I've never written a futex so I might get it wrong

#

if you listen to me*

surreal path
flat nymph
#

that's probably masters in computer engineering level of knowledge lol

molten grotto
surreal path
molten grotto
#

semaphore

surreal path
#

a semaphore?

#

wha

molten grotto
#

a thing that you can signal and wait until someone signals it

flat nymph
#

mutex is theoretically just a binary semaphore

surreal path
molten grotto
#

actually yeah, idk why did I do my mutex like this on top of the semaphore KEKW

flat nymph
#

having semaphores allows you to implement other forms of concurrency I think

surreal path
#

well ima go impl my kmutex

#

and yeye

#

also

#

anyone got a better vscode theme

#

i really hate the one i have now

flat nymph
#

white theme trl

surreal path
flat nymph
#

So I think you lock the lock, do compare exchange on the address given by the user, if it succeeds you block the thread

surreal path
#

what

#

why are there 2 locks

#

compare exchange on what address

#

im confused

molten grotto
#

the bool

surreal path
#

so theres 2 locks

#

why

molten grotto
#

one is to protect the waiter list

surreal path
#

oh

#

fair

#

and the bool acquired is the actual thing

flat nymph
#

Wait, we're talking about kernel

surreal path
#

yea

flat nymph
#

not futex

surreal path
#

yea

flat nymph
#

ignore what I said

#

half-ignore

#

You take the mutex::lock, check if lock is acquired. If it isn't, you set it to true. If it is, you block the thread and push it to the list of waiters. Unblock the lock

#

You've said you've implemented circular lists, right?

surreal path
#

yea

flat nymph
#

No

surreal path
#

oh

flat nymph
#

Only mutex::lock

#

You can remove the lock and do it with atomics

#

But that's more complicated

surreal path
#

only mutex::lock??

#

im not followiung

flat nymph
#

Yes

#
void take_lock(struct mutex *him) {
    spinlock_lock(&him->lock);
    if (!ackquired) {
        acquired = true;
        spinlock_unlock(&him->lock);
    } else {
        // Push yourself to list of blocked threads
        spinlock_unlock(&him->lock);
        // Switch to some other thread
    }
    // Lock is taken
}```
#

Something like that

surreal path
#

ohhh i see

#

quite simple

flat nymph
#

Yeah

surreal path
#

also why are u naming the variable him

#

why are u stealing my code style

#

๐Ÿ˜ก

flat nymph
#

it's funny

surreal path
#

fair

thorn bramble
surreal path
#

shes very pretty :3

#

i love her

thorn bramble
#

bold thing to say as a 13 year old

surreal path
#

i am 17

#

๐Ÿ’€

thorn bramble
#

fake news

surreal path
#

bru

#

โ˜ ๏ธ

flat nymph
#

let him have fun before the adult life hits trl

surreal path
#

my birthdays in 2 months actually

#

@flat nymph what about releasing the lock, what exactly do u do

#

wake up the blocked threads?

flat nymph
#

if the queue is empy, you unlock the bool

#

If it isn't unlock the thread of the front

coral dove
surreal path
#

what about the other blocked threads

flat nymph
#

Yes (?)

#

they stay in the queue

surreal path
#

why

flat nymph
#

What about them

#

Only one thread can take the mutex

surreal path
#

oh

flat nymph
#

or goto memes since it's c

surreal path
#

nah its good

#

also @flat nymph do u sched yield on releasing yet

flat nymph
#

what

#

no

surreal path
#

okay

#

thanks

flat nymph
#

it's up to you

surreal path
#

its fine

flat nymph
#

it could make sense

#

maybe it doesn't

surreal path
#

nahh its fineeeeeeeeeeeee

flat nymph
#

you sched_yield in locks in userspace

surreal path
#

for futex yea

flat nymph
#

no

#

doesn't matter...

#

forget about it

surreal path
#

kk

surreal path
#

its not working

#

guys so confusing frfr

finite summit
#

"reaper(): thread killed"

surreal path
#

yea thats normal

finite summit
#

it's killing random threads?

surreal path
#

no

#

idk where klocktest2 is hanging

#

im running three threads btw

finite summit
#

maybe your release function is broken?

surreal path
#

letsss check

#

hmmm

finite summit
#

mutex
looks inside
spinlock

surreal path
#

threadready doesnt yield

finite summit
surreal path
finite summit
#

have you tried: gdb

surreal path
#

will try

#

later

#

im so hungry

finite summit
#

bruh

surreal path
#

it hurts my stomach

finite summit
#

oh

surreal path
#

and i need to wait til

#

1:10am

#

to eat

#

my time

finite summit
#

kbye

surreal path
finite summit
#

sure

#

also why do you not ref count threads

surreal path
#

i do

finite summit
#

instead of doing the cursed reaper thing

#

then what is the reaper

thorn bramble
#

klocktest(): I have the lock

#

useful log

surreal path
#

checks if ref count is 0

#

if it is free ze thread

finite summit
#

that's not how reference counting works

surreal path
#

what

thorn bramble
#

and thats not how reaping threads work

finite summit
#
if (!(--obj->refcount))
  free(obj);```
surreal path
#

i do refcount_inc on create_kthread()
and refcount_dec on exit_thread()

finite summit
#

ok

surreal path
#

whats wrong with that

finite summit
#

then in refcount_dec

finite summit
#

not in thread x

finite summit
surreal path
#

ill show what i do in refcount_inc and refcount_dec

finite summit
#

wrong.

#
struct thread
{
    //shit
    atomic_size_t refcount;
};
void ref_thread(struct thread* obj)
{
  obj->refcount++;
}
void unref_thread(struct thread* obj)
{
  if (!(--obj->refcount))
    free(obj);
}```
surreal path
#

so im supposed to free the thread in the unref thread thing?

#

atomic_size_t

#

i dont have that

#

like huhh

finite summit
#

it's in atomic.h

#

stdatomic.h

#

if you're in C11 or higher, iirc

surreal path
#

#include <stdatomic.h>

#

doesnt exist

#

file not found

wicked loom
#

right so

#

stdatomic.h is not a freestanding header before C23 i don't think

finite summit
#

idk worked for me

#

I'm using C17 I think

wicked loom
#

in any case the bsd0 freestanding headers that the template pulls by default does not have it

finite summit
#

either way, you can do _Atomic(size_t)

wicked loom
#

do this ^

#

stdatomic is a useless wrapper anyways that does this

surreal path
#

and where can i import _Atomic

finite summit
#

nowhere

#

it is predefined

#

it's a keyword

wicked loom
#

it's a keyword

surreal path
#

okay thanks

#

so no more reaper thread ig

#

it looked cool thooo

kind root
#

your free() can queue the thread for reaping

surreal path
#

oh

#

thanks

finite summit
#

infy stop giving him bad ideas

surreal path
kind root
#

thread reaper thread is a good idea

finite summit
#

unless you mean free just schedules a DPC to actually free the thread at a lower priority

surreal path
finite summit
#

I disagree

#

imo, memory is ideally released as soon as possible, unless you cannot because your IRQL/IPL/whatever is too high

surreal path
#

in my opinion

#

i want to eat you

#

im way too hungry bro

finite summit
#

eat

surreal path
#

cant til 1:10am

finite summit
finite summit
surreal path
#

no its just my ed

finite summit
#

ed?

surreal path
#

eating disorder

kind root
#

and you're stealing that time without an upper bound

finite summit
#

then in that case, that kinda just falls into "unless you cannot because IRQL is too high"

#

then you can schedule a DPC to free everything

surreal path
#

anyways i dont think i can think anymore without food, so ima watch something til i can eat

#

then we can get back to work

#

im even struggling to type lol

finite summit
surreal path
#

i eat 10:10am so

#

8 hours behind is 1:10am

#

or

#

2:10am

#

but because im feeling extra hungry today im allowing myself to eat 1:10am

cinder plinth
#

this is in a thread context

finite summit
#

I mean you'd probably be at dispatch level

cinder plinth
#

threads can get preempted

#

so

#

whats the issue

finite summit
#

my exit_thread raises IRQL to dispatch

cinder plinth
#

your skill issue does not apply to general cases

finite summit
#

Once you remove a thread from a runqueue, it won't get run until it's back on a runqueue.
exit_thread removes the current thread from the runqueue

#

that's why I run mine at dispatch

cinder plinth
#

yes you can take a lock

#

for like

#

removing the thread from the list?

#

that's the only point where you'd have high irql that I can think of

#

and thats like

#

a few operations

finite summit
#

good point

cinder plinth
#

so I don't see what your point is

#

or why that would affect having a reaper thread

#

because a reaper thread would basically mean taking another lock (reaper queue) for a short time to add the thread to that list

#

instead of freeing everything directly in exit() which would incur latency

#

if anything you may want freeing to be a high irql operation

#

so doing it there would just add more latency

flat nymph
#

Why have a reaper thread though if you can just push zombie to ready queue?

cinder plinth
#

you mean doing the freeing when the scheduler encounters a zombie thread?

flat nymph
#

yes (?)

cinder plinth
#

same issue

#

you want your thread picking code to be as quick as possible

surreal path
#

im starting to feel really sick

#

like dizzy

#

is this a bad sign

#

i checked my weight and im starting to lose a ton of weight again

#

just 2 hours chat

#

gotta stay strong

cinder plinth
surreal path
#

eating disorder

cinder plinth
#

that does not answer my question

surreal path
#

thoughts of being fat

#

if i eat

#

and they are VERY strong thoughts

cinder plinth
#

ok so you complain about feeling dizzy but you dont eat on purpose?

#

have you seen a doctor

surreal path
#

yes

#

they know my issues and they did get me once to eat 2k cals, but now im doing something they dont like anymore

#

which is eating 1k

#

anyways id prefer we keep on topic to nyaux

#

i will debug the blocking threads issue shortly

#

as oberrow said it might be the release function

cinder plinth
surreal path
#

my bad chat kinda overslept

#

now its working?

#

ok now its not working

#

okay

#

something very bad

#

it only works not under gdb?

#

oh nvm its random

#

ok it seems that whenever a thread has the lock the other thread dies

#

not fun

#

idk whats going on and it being rlly random makes it difficult

#

help

rigid fable
#

we lost you

elder shoal
#

Real osdevs would never be in a relationship, its a distraction from osdev

edgy pilot
rigid fable
surreal path
#

yea

#

my bad chat

#

was sleeping then had to talk with my gf and play with her a bit

#

anyways i think the kprintfs are causing the random behavior

#

i have an idea

#

okay i see

rigid fable
#

๐Ÿฆ†๐Ÿ˜”

#

๐Ÿฆ†๐Ÿ˜ญ

flat nymph
#

Why did you comment schedd?

#

You need to reschedule

surreal path
#

my bad

#

but

#

doesnt help

flat nymph
#

And when you unblock you need to check that the thread has been saved

#

Because SMP

flat nymph
#

Wait a second

surreal path
#

kk

flat nymph
#

What does your threadblock do?

#

It's sus

surreal path
flat nymph
surreal path
#

what they do

flat nymph
#

You need to be scheduling the next thread

#

And

#

What I was typing

#
CPU 1                    CPU 2
ThreadBlock(stuff);
                         ThreadReady();
schedd(NULL):
surreal path
#

im not saving the context

flat nymph
#

Then what are you doing

surreal path
#

nvm i am

#

but

#

i have different cpu queues

#

so cpu 1 and cpu 2 dont even share the same thread

flat nymph
#

still

#

CPU 1 and CPU 2 can share mutex

surreal path
#

im protecting the blocked thread queue with a spinlock

flat nymph
#

But if threads get pushed to ready back on the CPU they were blocked on then it should be fine

surreal path
#
void acquire_kmutex(struct KMutex* mutex)
{    spinlock_lock(&mutex->protectionlock);
    // kprintf("acquire_kmutex(): lock is %d\n", mutex->lock);
    if (!mutex->lock) {
        mutex->lock = true;
        spinlock_unlock(&mutex->protectionlock);
        return;
    } else {
        ThreadBlock(mutex->blockedthreadsqueue);
        spinlock_unlock(&mutex->protectionlock);
        schedd(NULL);
    }
}
void release_kmutex(struct KMutex* mutex)
{
    spinlock_lock(&mutex->protectionlock);
    if (mutex->blockedthreadsqueue == NULL) {
        mutex->lock = false;
        spinlock_unlock(&mutex->protectionlock);
        return;
    } else {
        struct thread_t *thread = pop_from_list(&mutex->blockedthreadsqueue);
        ThreadReady(thread);
        spinlock_unlock(&mutex->protectionlock);
    }
}
#

2 of my kmutex functions

#

still dont understand why klocktest2 isnt getting unblocked

#

gdb not telling me anything

flat nymph
#

mutex->blockedthreadsqueue == NULL

#

Is never NULL with circular lists

#

Or they are not circular

surreal path
#

it can be null

flat nymph
#

Also, what is your ThreadReady

surreal path
#

above

flat nymph
surreal path
#

wanna die chat

flat nymph
flat nymph
surreal path
#

that shouldnt happen

#

at all

flat nymph
#

Think about it

surreal path
#

im protecting it with a spinlock tho

#

no 2 cpus will have the spinlock

#

so it SHOULD be fine

flat nymph
surreal path
flat nymph
#

idk how to explain it to you

surreal path
#

bru

flat nymph
#

@finite summit am I insane

finite summit
#

*yes

flat nymph
#

there are gradations of insanity

flat nymph
cinder plinth
#

why are you mixing PascalCase with snake_case btw

flat nymph
surreal path
cinder plinth
#

you just reschedule

rigid fable
#

@surreal path is it true what you leave osdev because you have a gf and you will no more say hello to me ๐Ÿฆ†๐Ÿ˜”

surreal path
cinder plinth
#

reschedule when blocking the thread

surreal path
#

but i do

cinder plinth
#

so it's removed from the runqueue

surreal path
#

@cinder plinth

cinder plinth
#

idk your codebase enough

surreal path
#

bru

#

not only am i fucked

#

but im fucked

rigid fable
flat nymph
#

There are various solutions

#

Like mark your thread as ready inside the switch_to whatever it's called function

surreal path
#

also even if i solve this

#

i still have this issue where klocktest2 never executers

#

executes*

#

gonna cry chat

rigid fable
surreal path
#

@flat nymph

#

even this solution

surreal path
#

my bad with that

surreal path
flat nymph
#

idk how to help you

#

ask me in a week

surreal path
#

bru

flat nymph
#

I have difficult ass exams in 2 days nooo

#

analog electronics basically

surreal path
rigid fable
#

poor nyaux... First ECDT now this

surreal path
#

yea i need help from someone

#

codes on github

#

just gotta hope someone will take a look

#

cause im out of ideas

#

and i just wanna work on my vfs atp

#

mr @finite summit has bash already

#

and what does nyaux have

#

nothing lmao

kind root
#

how are u literally always out of ideas

#

every bug

surreal path
#

thats why lmao

flat nymph
#

You're missing a degree in computer science trl

surreal path
#

bru

molten grotto
#

degree in computer science is literally useless

surreal path
#

our lord and savior

cinder plinth
molten grotto
#

well for getting a job maybe but like otherwise

flat nymph
#

it depends

surreal path
rigid fable
surreal path
#

but thats stupid

rigid fable
surreal path
molten grotto
surreal path
#

understandable

flat nymph
surreal path
#

maybe later when u feel better?

rigid fable
#

you don't understand this

molten grotto
#

yeah I wouldn't copy paste anything from nyaux

surreal path
surreal path
rigid fable
#

it will be fun if someone copypaste from nyaux

molten grotto
#

what even is the problem

#

I haven't followed

surreal path
#

i.e. klocktest2 is not executing anything anymore after acquire

#

after getting blocked

#

even tho all the code makes sense

#

no klocktest2 i have the lock

#

shit

flat nymph
#

i'm saying he has a race condition

surreal path
#

with a hacky method

flat nymph
#

(though idk if it's what's manifesting in bug)

surreal path
#

cause i solved it and bug isnt solved

cinder plinth
#

lol

surreal path
cinder plinth
#

blocked threads don't run

surreal path
#

when its unblocked

#

lmao

surreal path
cinder plinth
#

did you add it back to the list

surreal path
#

yes

#

ofc

flat nymph
surreal path
#
void ThreadReady(struct thread_t *thread) {
    struct per_cpu_data* cpu = arch_get_per_cpu_data();
    thread->state = READYING;

    push_into_list(&cpu->run_queue, thread);
}

...
push_into_list(&cpu->run_queue, cpu->cur_thread);
        cpu->cur_thread = pop_from_list(&cpu->run_queue);
        if (cpu->cur_thread->state == READYING) {
            cpu->cur_thread->state = READY;
            push_into_list(&cpu->run_queue, cpu->cur_thread);
            cpu->cur_thread = pop_from_list(&cpu->run_queue);
        cpu->cur_thread->state = RUNNING;
            return old;
        }
...

bit hacky but it should

flat nymph
#

you need to be waiting

surreal path
#

what

cinder plinth
#

you need to be waiting.

surreal path
#

bru

rigid fable
#

you need to be waiting...

surreal path
#

bro

#

doesnt answer anything but ok

molten grotto
#

your ThreadBlock is broken

#

think about what its doing

surreal path
#

sets thread to readying?

#

oh wait

surreal path
#

wrong function

#

i push it into the queue

flat nymph
#

you set thread to reasy in schedd or wherever

molten grotto
#

you take the address of a parameter

surreal path
flat nymph
#

the function that switches the context

molten grotto
#

and pushing the thread to there is not going to last very long

#
void ThreadBlock(struct thread_t *whichqueue) {
    struct per_cpu_data* cpu = arch_get_per_cpu_data();
    cpu->cur_thread->state = BLOCKED;
    push_into_list(&whichqueue, cpu->cur_thread);
}
flat nymph
#

after you push the registers on stack and load different stack

flat nymph
#

when loading thread, you spin wait untill it's ready

flat nymph
#

like you can't switch to a thread that's running on other CPU

surreal path
#

they have different cpu queues

#

bru

flat nymph
#

So you either

  1. wait for it to not be running
  2. return it back to its CPU so it deals with it
surreal path
#

if its not on the cpus run queue

molten grotto
# surreal path wdym

well here you do push_into_list(&whichqueue, cpu->cur_thread); and whichqueue is NULL so you end up doing ```c
void ThreadBlock(struct thread_t whichqueue) {
struct per_cpu_data
cpu = arch_get_per_cpu_data();
cpu->cur_thread->state = BLOCKED;
// what push_into_list(&whichqueue, cpu->cur_thread); does:
whichqueue = cpu->cur_thread;
whichqueue->next = whichqueue;
whichqueue->back = whichqueue;
}

flat nymph
surreal path
#

not of the queue of a different cpu?

surreal path
#

im so confused lol

flat nymph
surreal path
#

bcs i didnt save the threads context?

#

on blocking?

flat nymph
#

I'm not talking about thread context

molten grotto
# surreal path yea and whats wrong with that?

well how do you access the queue after that? its not stored anywhere, its the same as ```c
void ThreadBlock(struct thread_t whichqueue) {
struct per_cpu_data
cpu = arch_get_per_cpu_data();
cpu->cur_thread->state = BLOCKED;
// what push_into_list(&whichqueue, cpu->cur_thread); does:
struct thread_t* dump = cpu->cur_thread;
dump->next = dump;
dump->back = dump;
}

flat nymph
#

Idk how to name it

#

You push saved registers and save the stack address

molten grotto
#

you need to make ThreadBlock take an address of the queue not the first thing in the queue

flat nymph
#

When switching to a different context

flat nymph
#

(which can be NULL for some reason)

surreal path
#

therefore only modifying the parameter

#

not the actual queue

molten grotto
#

or just make it a proper circular list

#

though well doing that with threads might not be the best thing ever as then you'd have to have a dummy thread entry inside kmutex for the start

surreal path
flat nymph
#

make lists store addresses of the list itself?

#

List head

#

Idk

#

That's what my circular lists do afair

#

So it's still just 2 pointers

surreal path
#

that solved it but it kills itself

flat nymph
#

Yes because your circular lists are broken

surreal path
#

how

molten grotto
flat nymph
#

Yeah

molten grotto
#

as you'd need a dummy thread at the start

flat nymph
#

He's missing some cursed macros

surreal path
surreal path
unkempt relic
#

they're not circular of course, that's something other people do

flat nymph
#

circular lists are just a bit easier

surreal path
cinder plinth
flat nymph
#

Stop copy-pasting code and write (or steal) yourself a proper circular list

cinder plinth
#

here are mine

#

๐Ÿ˜Ž

surreal path
#

@flat nymph im not copy pasting??????????????????????

surreal path
#

where did i copy paste

cinder plinth
surreal path
#

like wtf

#

i did not copy paste

kind root
cinder plinth
#

yea that is fair

#

but

#

you can just press the collapse button

flat nymph
#

(only a tiny bit cursed)

surreal path
#

@flat nymph where did i copy paste

kind root
#

u would press collapse 50 times

surreal path
#

i find that very insulting

kind root
#

if theres 50 functions

thorn bramble
#

thank god this exists

cinder plinth
#

mine is literally copy pasted from "introduction to algorithms"

molten grotto
surreal path
molten grotto
#

because I am too dumb to understand how it works lol

flat nymph
cinder plinth
#

not a bad idea

flat nymph
surreal path
cinder plinth
#

I implemented a hash array mapped trie which no one here has, so checkmate nerds ๐Ÿ˜Ž

unkempt relic
surreal path
#

it was my own impl

surreal path
cinder plinth
flat nymph
thorn bramble
#

go back to osdev

#

implement ze scheduler

#

or wahtev er ud oign

surreal path
#

i have ze scheduler im just fucking dying

#

and like

#

i feel extremely insulted

#

plus kinda upset? weirdly. idk i had a bad day today

thorn bramble
#

take out ur anger by fixing ur code

surreal path
#

not angry just

#

annoyed

cinder plinth
#

dont be so susceptible

thorn bramble
#

ur EMOTIONS then

#

tjis

kind root
#

no offense but literally every bug u encounter u instantly give up and ask other people to fix it

surreal path
#

bro what

#

..

#

i dont do that what

thorn bramble
#

i wouldn't agree with the 2nd statement but

#

the first definitely true

#

ur mental is so fragile when it comes to coding and bugs

cinder plinth
#

he's kinda right

surreal path
thorn bramble
#

btw not tryna shit on u or whatever, legitimate remark

#

i know i say a bunch of mean things but this isnt meant to be one of them

kind root
#

im saying that because i want nyaux to succeed as well

thorn bramble
#

but tbf i give up a lot too

#

i wanna succeed too but

#

it just aint working meme

kind root
#

u gotta know how to use gdb and printfs

surreal path
#

i do

kind root
#

instead of giving up

surreal path
#

didnt u see me trying to use gdb

#

that was the first thing i did

kind root
#

use it harder

surreal path
#

bro

kind root
#

yes

surreal path
#

i still tried to solve it myself

#

and plus i dont beg for help everytime

kind root
#

yes but why was qwinci able to debug it in like 5 mins

surreal path
#

because everyone on this server is smarter then me

#

and im a fucking idiot

kind root
#

thats not it

surreal path
#

that is tho?

#

im being serious

kind root
#

no its because qwinci actually learned to solve bugs by debugging his stuff

finite summit
#

Debugging is not something you are born with

surreal path
#

thats not what i meant

finite summit
#

Intelligence is dictated by your willingness to learn

molten grotto
#

yeah you just get better at it over time

surreal path
finite summit
#

I'll be back for motivational words soon

#

Gtg shower

surreal path
#

no cause like no 1 why did miskaov immdeitly assume i copy pasted code like wtf. no 2 yes i get it its stupid im always not figuring out the simpliest of things but again im still new to osdev and i still TRIED to debug my own stuff that still counts no 3 all of yall saying this is kinda making me feel even worse not better. i get yall are trying to give me cristism but i already had a really shitty day today and im actually starting to cry cause i feel like nothing i did even mattered and yall just did the code yourselves and i didnt do any effort or smt. im not saying yall are trying to say this but that what it feels like to me rn

#

i still worked hard on this project

#

doesnt matter if i dont have the debugging skills of qwinci or anyone, i still did try to printf i still did try to gdb and im still learning

#

plus as qwinci said

#

you get better at this over time

kind root
#

my point was exactly that

#

but u dont get better if qwinci solves your bugs

thorn bramble
surreal path
cinder plinth
#

you tried for 5 mins and gave up is the problem

kind root
#

what rustc said

surreal path
kind root
#

i saw u try but u barely did so

thorn bramble
#

osdev is just like "load gdt, set up page tables" but everything else is just regular programming but with weird constraints of no os

cinder plinth
cinder plinth
#

kernel programming is advanced concurrent programming

thorn bramble
#

yeah but still it's not specific to osdev

kind root
#

just do -smp 1 trl

thorn bramble
#

i might have phrased that wrong because i had a bit more background to it

#

but i guess this is similar to how people think "oh how do i do X with limine"

surreal path
surreal path
thorn bramble
#

and they dont realize that once the RIP is in their kernel limine does not do anything anymore and they are on their own

surreal path
#

i agree i didnt try that hard

kind root
#

this has been a consistent pattern

surreal path
#

remember the first bugs i encountered at the start?

#

remember how i reacted?

#

compare to how i react now

kind root
#

well maybe i just dont know the full picture

thorn bramble
#

i think the rust arc might have skewed the picture a bit lol

#

12 hours a day of ub and complaining

surreal path
#

bro

thorn bramble
#

am i wrong tho

#

๐Ÿ˜ญ

surreal path
#

not rlly

thorn bramble
#

but ur back to C and that's all that matters

flat nymph
surreal path
#

also i was crying earlier and now i feel like actually awful, i dont think im gonna work on anything anymore for today for my mental health. i dont wanna get more upset atm im on the verge of crying again lol

#

cant believe im crying over what strangers think of my code on the internet, man i really am pathetic lol

#

wish i wasnt like this im not going to lie

kind root
#

we didnt say anything about your code tho

#

just your approach to working with said code

surreal path
#

more about my behavior yes

flat nymph
#

Your code is fine

#

Idk if I sounded too strong

#

But I believe that it's a good idea to just write a single good list implementation (and other containers) with C macros and not spend your time debugging it

surreal path
#

i get what yall are trying to say to me anyway i just need to calm down and stop crying, i havent told yall this but i have an issue with being like really sensitive which sucks ass because i cry over the smallest things

surreal path
surreal path
#

i just went back to school today and shit wasnt nice

#

especially with the teachers shouting at me

kind root
#

yeah sorry if that sounded too rough

surreal path
#

its fine, i just need to lie down and not think about anything rn

flat nymph
kind root
flat nymph
#

I also learned to program when I was 18

#

Started learning*

surreal path
#

thanks

#

im gonna lie down

flat nymph
surreal path
#

i injoured my leg and arm today while coming back from the store

#

im in too much pain to do anything today

#

hopefully tmrw

edgy pilot
#

get well soon

#

injoured :p

finite summit
surreal path
#

thanks!

surreal path
#

still need to heal