Example #1
0
paddr_t swap_out(int flag){
	struct coremap *local_coremap = coremap_list;
	struct coremap *swap_coremap = NULL ;//coremap_list;
	uint32_t min = 4294967295;
	//struct tlbshootdown *tlbsd = (struct tlbshootdown*)kmalloc(sizeof(struct tlbshootdown)) ;
	struct tlbshootdown tlbsd ;
	while(local_coremap!=NULL){
		if(local_coremap->status == 0 && local_coremap->timestamp <= min /*&& local_coremap->swap == 0*/){
					min = local_coremap->timestamp;
					swap_coremap = local_coremap;
		}
		local_coremap = local_coremap->next;
	}
	if(swap_coremap == NULL){
		panic("Could not find page in other processes\n");
	}

		struct addrspace *temp = swap_coremap->as;
		struct page_table_entry *pt = temp->page_table;
		while(pt!=NULL){
			if(pt->pa == swap_coremap->pa && pt->state!=1)
				break;
			pt=pt->next;
		}
		off_t off = 0;
		if(pt == NULL)
			panic("swap_out : test panic \n");//off = write_to_swap(PADDR_TO_KVADDR(swap_coremap->pa),-1) ;
		else{
			//swap_coremap->swap = 1;
			//if(swap_coremap->as == curthread->t_addrspace){
				tlbsd.ts_vaddr = swap_coremap->va ;
				vm_tlbshootdown(&tlbsd) ;
			//}
			off = write_to_swap(PADDR_TO_KVADDR(swap_coremap->pa),pt->offset) ;
			pt->state = PAGE_ON_DISK;
			pt->offset = off;
		}

	bzero((void *)PADDR_TO_KVADDR(swap_coremap->pa),PAGE_SIZE);
	swap_coremap->timestamp = localtime;
	localtime++;
	swap_coremap->pages=1;
	if(flag){                               //We are swapping to allocate a kernel page.
		swap_coremap->status = 1;
		swap_coremap->as=NULL;
	}
	else{                                   //We are swapping to allocate user page
		swap_coremap->status = 0 ;
		swap_coremap->as=curthread->t_addrspace;
	}
	//swap_coremap->swap = 0;
	return swap_coremap->pa;
}
Example #2
0
void
interprocessor_interrupt(void)
{
	uint32_t bits;
	int i;

	spinlock_acquire(&curcpu->c_ipi_lock);
	bits = curcpu->c_ipi_pending;

	if (bits & (1U << IPI_PANIC)) {
		/* panic on another cpu - just stop dead */
		spinlock_release(&curcpu->c_ipi_lock);
		cpu_halt();
	}
	if (bits & (1U << IPI_OFFLINE)) {
		/* offline request */
		spinlock_release(&curcpu->c_ipi_lock);
		spinlock_acquire(&curcpu->c_runqueue_lock);
		if (!curcpu->c_isidle) {
			kprintf("cpu%d: offline: warning: not idle\n",
				curcpu->c_number);
		}
		spinlock_release(&curcpu->c_runqueue_lock);
		kprintf("cpu%d: offline.\n", curcpu->c_number);
		cpu_halt();
	}
	if (bits & (1U << IPI_UNIDLE)) {
		/*
		 * The cpu has already unidled itself to take the
		 * interrupt; don't need to do anything else.
		 */
	}
	if (bits & (1U << IPI_TLBSHOOTDOWN)) {
		if (curcpu->c_numshootdown == TLBSHOOTDOWN_ALL) {
			vm_tlbshootdown_all();
		}
		else {
			for (i=0; i<curcpu->c_numshootdown; i++) {
				vm_tlbshootdown(&curcpu->c_shootdown[i]);
			}
		}
		curcpu->c_numshootdown = 0;
	}

	curcpu->c_ipi_pending = 0;
	spinlock_release(&curcpu->c_ipi_lock);
}