starting threading, no more threads, other questions...
Posted: Tue Sep 16, 2008 2:38 pm
Hello OSDev-ers!
OK, I've been without internet forever, so my OS has been progressing slowly with whatever I can do. I'm really desperate to know exactly what you guys think, I want to know the best way to do some things. I will start by telling you how far I am. I've made my boot sector and boot loader; It loads the kernel from a dynamic elf, so it knows its symbols, to 0xC0000000, using paging. My kernel has heap management, text video, and other small things. I've started to make sure all of the system calls and everything are thread safe. I can switch contexts; so far, each process has only one context, but I'm planning on making it so that each process has at least one thread. So I will start on my questions, they are kind of messy; These are the questions which I have been waiting to be answered and could not answer myself, I'm desperate! So here's what comes off of the top of my head:
1. Scheduling - Right now, the loader jumps to the kernel, so there is only one thread. The scheduler starts running after one process is running, and at least one process must be running. If there are no more threads, there is no context to switch to. And what if I don't want to start any threads before I run the scheduler? What if all threads are waiting for I/O? I can't think of anything else other than having a dummy low-priority thread or something. Any better ideas?
2. Timing - What kind of timing would you suggest for shceduling? Now, I have a big problem in Bochs with a high PIT frequency, so I don't know if there is a frequency that I should shoot for... is 15ms good enough for a timeslice? What about performance applications? How is this good enough, how does it work well on Windows?
3. Process space - I am not totally sure if my address space arrangement is the best way to do it, if you have any better ideas, or have seen better ways of organizing it, please tell me:
(This gives 2.5GB to the process. Do you think I should limit it to 2GB for safety, i.e. if someone uses a signed pointer?)
-- PROCESS SPACE
0x00000000-0x9FFFFFFF Unused by system, available for process
0xA0000000-0xAFFFFFFF Dynamic libraries
0xB0000000-0xBFFFFFFF thread stacks, IPC shared memory, disk buffers, etc.
-- KERNEL SPACE
0xC0000000-0xCFFFFFFF Kernel image and physical memory map
0xD0000000-0xDFFFFFFF Kernel heap
0xE0000000-0xEFFFFFFF Reserved for drivers
0xF0000000-0xFFFFFFFF Default kernel stack, various mappings (video memory, etc.), page tables
ALSO - The current method I came up with to synchronize the kernel space between processes is this:
When a process is created, copy the kernel PDEs into the process' PDT.
If another process adds a PDE to the kernel, it is not yet mapped into existing processes,
but if another process tries to access that PDE, it gets refreshed by the page fault handler.
PDEs are not allowed to be UNMAPPED, because it would not be unmapped in the other processes --
PDEs in other processes (in kernel space above 0xCxx...) only get updated when ADDING PDEs, not when removing them.
Is this the best way to do this? I have though about using Global pages but had decided not to for processor compatability... but I don't really think that should be an issue.
4. C library - If I implement newlib, I give a system call like sbrk() that malloc will use. Will this limit the way that a process allocates memory, I mean, will all libraries have to use malloc to allocate memory? If not, for example, a different allocator uses sbrk, then the two heaps are really using the same memory area for the heap, which is not good (_end - brk).
5. Dynamic unloading... I have basically up until now thought that I should probably not suppory dynamic unloading of drivers and libraries. Do any operating systems do this? It would probably be difficult to do right... Should I be thinking about supporting this? If I were, what would you suggest, buddy blocks?
ANYWAY I really feel like I need some input and that I may not be doing well. I'm sorry for the long post, and of any of the questions seeming stupid (or like it's not a question). I really appreciate your input and help. -Josh
OK, I've been without internet forever, so my OS has been progressing slowly with whatever I can do. I'm really desperate to know exactly what you guys think, I want to know the best way to do some things. I will start by telling you how far I am. I've made my boot sector and boot loader; It loads the kernel from a dynamic elf, so it knows its symbols, to 0xC0000000, using paging. My kernel has heap management, text video, and other small things. I've started to make sure all of the system calls and everything are thread safe. I can switch contexts; so far, each process has only one context, but I'm planning on making it so that each process has at least one thread. So I will start on my questions, they are kind of messy; These are the questions which I have been waiting to be answered and could not answer myself, I'm desperate! So here's what comes off of the top of my head:
1. Scheduling - Right now, the loader jumps to the kernel, so there is only one thread. The scheduler starts running after one process is running, and at least one process must be running. If there are no more threads, there is no context to switch to. And what if I don't want to start any threads before I run the scheduler? What if all threads are waiting for I/O? I can't think of anything else other than having a dummy low-priority thread or something. Any better ideas?
2. Timing - What kind of timing would you suggest for shceduling? Now, I have a big problem in Bochs with a high PIT frequency, so I don't know if there is a frequency that I should shoot for... is 15ms good enough for a timeslice? What about performance applications? How is this good enough, how does it work well on Windows?
3. Process space - I am not totally sure if my address space arrangement is the best way to do it, if you have any better ideas, or have seen better ways of organizing it, please tell me:
(This gives 2.5GB to the process. Do you think I should limit it to 2GB for safety, i.e. if someone uses a signed pointer?)
-- PROCESS SPACE
0x00000000-0x9FFFFFFF Unused by system, available for process
0xA0000000-0xAFFFFFFF Dynamic libraries
0xB0000000-0xBFFFFFFF thread stacks, IPC shared memory, disk buffers, etc.
-- KERNEL SPACE
0xC0000000-0xCFFFFFFF Kernel image and physical memory map
0xD0000000-0xDFFFFFFF Kernel heap
0xE0000000-0xEFFFFFFF Reserved for drivers
0xF0000000-0xFFFFFFFF Default kernel stack, various mappings (video memory, etc.), page tables
ALSO - The current method I came up with to synchronize the kernel space between processes is this:
When a process is created, copy the kernel PDEs into the process' PDT.
If another process adds a PDE to the kernel, it is not yet mapped into existing processes,
but if another process tries to access that PDE, it gets refreshed by the page fault handler.
PDEs are not allowed to be UNMAPPED, because it would not be unmapped in the other processes --
PDEs in other processes (in kernel space above 0xCxx...) only get updated when ADDING PDEs, not when removing them.
Is this the best way to do this? I have though about using Global pages but had decided not to for processor compatability... but I don't really think that should be an issue.
4. C library - If I implement newlib, I give a system call like sbrk() that malloc will use. Will this limit the way that a process allocates memory, I mean, will all libraries have to use malloc to allocate memory? If not, for example, a different allocator uses sbrk, then the two heaps are really using the same memory area for the heap, which is not good (_end - brk).
5. Dynamic unloading... I have basically up until now thought that I should probably not suppory dynamic unloading of drivers and libraries. Do any operating systems do this? It would probably be difficult to do right... Should I be thinking about supporting this? If I were, what would you suggest, buddy blocks?
ANYWAY I really feel like I need some input and that I may not be doing well. I'm sorry for the long post, and of any of the questions seeming stupid (or like it's not a question). I really appreciate your input and help. -Josh