Thread kernel stacks are now reused
This commit is contained in:
parent
5fabb01a8b
commit
3367cdc9bf
@ -291,7 +291,7 @@ void isr_handler(registers_t* r) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,13 +310,17 @@ void isr_register_handler(int n,isr_t handler) {
|
|||||||
* \param r The saved state of the CPU
|
* \param r The saved state of the CPU
|
||||||
*/
|
*/
|
||||||
void irq_handler(registers_t* r) {
|
void irq_handler(registers_t* r) {
|
||||||
/* After every interrupt we need to send an EOI to the PICs
|
/* After every interrupt we need to send an EOI to the PICs
|
||||||
* or they will not send another interrupt again */
|
* or they will not send another interrupt again */
|
||||||
if (r->int_no >= 40) port_byte_out(0xA0,0x20); /* slave */
|
if (r->int_no >= 40) port_byte_out(0xA0,0x20); /* slave */
|
||||||
port_byte_out(0x20,0x20); /* master */
|
port_byte_out(0x20,0x20); /* master */
|
||||||
/* Handle the interrupt in a more modular way */
|
/* Handle the interrupt in a more modular way */
|
||||||
if (irq_handlers[r->int_no-32] != NULL) {
|
if (irq_handlers[r->int_no-32] != NULL) {
|
||||||
isr_t handler = irq_handlers[r->int_no-32];
|
isr_t handler = irq_handlers[r->int_no-32];
|
||||||
handler(r);
|
if((uint32_t)handler<32768) {
|
||||||
|
kernel_rpc_call((pid_t)handler,"irq_handler",NULL,NULL);
|
||||||
|
} else {
|
||||||
|
handler(r);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,8 @@ static pg_struct_entry kstack_page_tables[218*1024] __attribute__((aligned(4096)
|
|||||||
static pg_struct_entry kmalloc_page_tables[4*1024] __attribute__((aligned(4096))); //!< Page tables for the kmalloc heap
|
static pg_struct_entry kmalloc_page_tables[4*1024] __attribute__((aligned(4096))); //!< Page tables for the kmalloc heap
|
||||||
static pg_struct_entry* pagdirmap=(pg_struct_entry*)0xFFFFF000; //!< Pointer to the page directory entries in the recursive mapping
|
static pg_struct_entry* pagdirmap=(pg_struct_entry*)0xFFFFF000; //!< Pointer to the page directory entries in the recursive mapping
|
||||||
static pg_struct_entry* page_table_map=(pg_struct_entry*)0xFFC00000; //!< Pointer to the page table entries in the recursive mapping
|
static pg_struct_entry* page_table_map=(pg_struct_entry*)0xFFC00000; //!< Pointer to the page table entries in the recursive mapping
|
||||||
/**
|
|
||||||
* Checks whether a page is present
|
char is_page_present(size_t page) {
|
||||||
* \param page The page number to check
|
|
||||||
* \return Whether the page is present
|
|
||||||
*/
|
|
||||||
static char is_page_present(size_t page) {
|
|
||||||
int table=page>>10;
|
int table=page>>10;
|
||||||
page=page&0x3FF;
|
page=page&0x3FF;
|
||||||
if (!pagdirmap[table].pres) {
|
if (!pagdirmap[table].pres) {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "../tasking_helpers.h"
|
#include "../tasking_helpers.h"
|
||||||
#include "../../pmem.h"
|
#include "../../pmem.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
static void** kstacks=(void*)0xC8000000; //!< Pointer to all the thread kernel stacks
|
static void** kstacks=(void*)0xC8000000; //!< Pointer to all the thread kernel stacks
|
||||||
static char kstack_bmap[(218*1024)/8]={0}; //!< Bitmap of what kernel stacks have been allocated
|
static char kstack_bmap[(218*1024)/8]={0}; //!< Bitmap of what kernel stacks have been allocated
|
||||||
@ -49,7 +50,9 @@ static int new_kstack() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mark_kstack_allocated(num);
|
mark_kstack_allocated(num);
|
||||||
map_pages(((char*)kstacks+num*0x1000),pmem_alloc(1),1,1,1);
|
if (!is_page_present(((uint32_t)((char*)kstacks+num*0x1000))>>12)) {
|
||||||
|
map_pages(((char*)kstacks+num*0x1000),pmem_alloc(1),1,1,1);
|
||||||
|
}
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,3 +79,12 @@ void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip)
|
|||||||
kstacks[top_idx-1]=(void*)eip;
|
kstacks[top_idx-1]=(void*)eip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_kstack(void* stack_ptr) {
|
||||||
|
uint32_t stack=(uint32_t)stack_ptr;
|
||||||
|
stack-=0xC8000000;
|
||||||
|
stack=stack>>12;
|
||||||
|
size_t byte=stack/8;
|
||||||
|
size_t bit=stack%8;
|
||||||
|
kstack_bmap[byte]=kstack_bmap[byte]&(~(1<<bit));
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef PAGING_H
|
#ifndef PAGING_H
|
||||||
#define PAGING_H
|
#define PAGING_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a block of code in a different address space
|
* Run a block of code in a different address space
|
||||||
@ -87,4 +88,11 @@ void* find_free_pages(int num_pages);
|
|||||||
*/
|
*/
|
||||||
void* get_address_space();
|
void* get_address_space();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a page is present
|
||||||
|
* \param page The page number to check
|
||||||
|
* \return Whether the page is present
|
||||||
|
*/
|
||||||
|
char is_page_present(size_t page);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,4 +34,10 @@ void wait_for_unblocked_thread_asm();
|
|||||||
*/
|
*/
|
||||||
void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip);
|
void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees a kernel stack so it can be used again
|
||||||
|
* \param stack_ptr The kernel stack to free
|
||||||
|
*/
|
||||||
|
void free_kstack(void* stack_ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,6 +274,9 @@ void tasking_block(thread_state newstate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
current_thread->process->num_threads_blocked++;
|
current_thread->process->num_threads_blocked++;
|
||||||
|
if (current_thread->process->num_threads_blocked==current_thread->process->num_threads) {
|
||||||
|
unmark_proc_scheduled(current_thread->process->pid);
|
||||||
|
}
|
||||||
tasking_yield();
|
tasking_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +335,7 @@ void tasking_exit(int code) {
|
|||||||
ready_to_run_tail=ready_to_run_tail->prev_ready_to_run;
|
ready_to_run_tail=ready_to_run_tail->prev_ready_to_run;
|
||||||
if (ready_to_run_tail==NULL) {
|
if (ready_to_run_tail==NULL) {
|
||||||
ready_to_run_head=NULL;
|
ready_to_run_head=NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ready_to_run_head&&ready_to_run_head->next_ready_to_run) {
|
if (ready_to_run_head&&ready_to_run_head->next_ready_to_run) {
|
||||||
@ -348,7 +351,10 @@ void tasking_exit(int code) {
|
|||||||
}
|
}
|
||||||
unmark_proc_scheduled(current_thread->process->pid);
|
unmark_proc_scheduled(current_thread->process->pid);
|
||||||
for (Thread* thread=current_thread->process->first_thread;thread!=NULL;thread=thread->next_thread_in_process) {
|
for (Thread* thread=current_thread->process->first_thread;thread!=NULL;thread=thread->next_thread_in_process) {
|
||||||
thread->state=THREAD_EXITED;
|
if (thread->state!=THREAD_EXITED) {
|
||||||
|
thread->state=THREAD_EXITED;
|
||||||
|
free_kstack(thread->kernel_esp_top);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
current_thread->process->num_threads_blocked=current_thread->process->num_threads;
|
current_thread->process->num_threads_blocked=current_thread->process->num_threads;
|
||||||
num_procs--;
|
num_procs--;
|
||||||
@ -383,6 +389,7 @@ void* tasking_get_rpc_ret_buf() {
|
|||||||
|
|
||||||
void tasking_thread_exit() {
|
void tasking_thread_exit() {
|
||||||
tasking_block(THREAD_EXITED);
|
tasking_block(THREAD_EXITED);
|
||||||
|
free_kstack(current_thread->kernel_esp_top);
|
||||||
}
|
}
|
||||||
|
|
||||||
char tasking_check_proc_exists(pid_t pid) {
|
char tasking_check_proc_exists(pid_t pid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user