Ready to answer your questions...

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
ababo
Member
Member
Posts: 27
Joined: Thu Jun 13, 2013 8:20 am
Location: Ukraine

Ready to answer your questions...

Post by ababo »

Resting between iterations of my toy kernel development I would like to help other guys by answering different questions (theory / practical implementation). It would be nice to start a big interesting discussion.

I would like to base this discussion on my little piece of code: https://github.com/ababo/toy.
It covers many useful techniques and principles of kernel development. You can build it in Linux (tested on recent versions of Ubuntu) by gcc/clang, and run using qemu/kvm.

So I'm ready to answer your questions about OS kernel development. Just try... :)
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Ready to answer your questions...

Post by bwat »

Quick question: why have you implemented mutexes and not semaphores? As I'm sure you know, semaphores don't require much more effort and you can implement mutexes in terms of semaphores very easily.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Ready to answer your questions...

Post by gravaera »

Wow

much code
very OS
so much doge
such abstract
10/10

Thank you based god T_T
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Ready to answer your questions...

Post by OSwhatever »

When did this forum become Jeopardy?
Gigasoft
Member
Member
Posts: 855
Joined: Sat Nov 21, 2009 5:11 pm

Re: Ready to answer your questions...

Post by Gigasoft »

What do you do right after resuming a thread that is waiting on a mutex?
Which line could this statement be moved to?
Which 16 byte structure is then allocated on the heap only to be freed a couple of lines later on?
User avatar
ababo
Member
Member
Posts: 27
Joined: Thu Jun 13, 2013 8:20 am
Location: Ukraine

Re: Ready to answer your questions...

Post by ababo »

Quick question: why have you implemented mutexes and not semaphores? As I'm sure you know, semaphores don't require much more effort and you can implement mutexes in terms of semaphores very easily.
Yes, I have mutexes, but you're right, it's easy just to add a counter to implement semaphores. I just wanted to make sure that I can build synchronization primitives on top of my scheduler interface (and started with mutex as the simplest and widely used one).
What do you do right after resuming a thread that is waiting on a mutex?
I have a list of paused threads, each thread is a structure holding a CPU context (and other stuff). This list is guarded by a spinlock. If a new thread tries to acquire mutex, it checks this list. If it isn't empty the thread adds itself to list and pauses (removes itself from scheduling queue). When some thread releases the mutex, it removes a next waiting thread from the mutex list and inserts it to the scheduler queue, so next quantums it will be scheduled. This is simplified explanation, there are many details I have thrown off.
Which 16 byte structure is then allocated on the heap only to be freed a couple of lines later on?
Didn't exactly understand your question, but if you emphasize inefficiency in memory allocation, I can respond that all allocations are done through memory pool (fixed sized chunks, yes it's still not implemented, just a temporary stub directly calling malloc/free), so this should be very efficient.
Post Reply