/** * Creates a new process structure. This will have one thread created for it, * but with no information populated. */ scheduler_pcb_t *scheduler_new_process(void) { unsigned int frame = find_free_frame(); set_frame(frame); frame *= 0x1000; frame += TCB_START; // allocate the memory for this structure uintptr_t phys = vm_allocate_phys(); platform_pm_map(platform_pm_get_kernel_table(), frame, phys, VM_FLAGS_KERNEL); // allocate the process struct here scheduler_pcb_t *pcb = (scheduler_pcb_t *) frame; pcb->process_id = scheduler_new_pid(); // allocate a TCB scheduler_tcb_t *tcb = scheduler_new_tcb(pcb); // initialise process struct pcb->thread = tcb; // initialise thread struct return pcb; }
/** * Creates a new thread structure. If @process is not NULL, the thread is added * to the linked list of threads for the given process. */ scheduler_tcb_t *scheduler_new_tcb(scheduler_pcb_t *process) { unsigned int frame = find_free_frame(); set_frame(frame); frame *= 0x1000; frame += TCB_START; // allocate the memory for this structure uintptr_t phys = vm_allocate_phys(); platform_pm_map(platform_pm_get_kernel_table(), frame, phys, VM_FLAGS_KERNEL); // allocate a thread struct scheduler_tcb_t *tcb = (scheduler_tcb_t *) frame; tcb->thread_id = scheduler_new_tid(); // add it to the linked list of threads if(process) { scheduler_tcb_t *thread = process->thread; while(thread) { // next thread NULL? if(!thread->next) { thread->next = tcb; break; } // check the next thread thread = thread->next; } } return tcb; }
void allocate_page(void) { int framenumb; vmem->adm.pf_count++; framenumb = find_free_frame(); // wenn alle Frames schon besetzt -> löschen ein frame if (framenumb == VOID_IDX) { framenumb = find_remove_frame(); } vmem->adm.next_alloc_idx = framenumb; update_pt(framenumb); // "Pagefault" note event.alloc_frame=vmem->adm.next_alloc_idx; event.g_count=vmem->adm.g_count; event.pf_count=vmem->adm.pf_count; event.req_pageno=vmem->adm.req_pageno; logger(event); }