Ejemplo n.º 1
0
void MtxTranspose3x3(matrix_t m)
{
  float tmp;
  SWAP_IDX(0,1);
  SWAP_IDX(0,2);
  SWAP_IDX(1,2);
}
Ejemplo n.º 2
0
void MtxTranspose(matrix_t m)
{
  float tmp;
  SWAP_IDX(0,1);
  SWAP_IDX(0,2);
  SWAP_IDX(0,3);
  SWAP_IDX(1,2);
  SWAP_IDX(1,3);
  SWAP_IDX(2,3);
}
static void swapin(int npages, struct addrspace* as) {
	// 1. check if coremap lock is already held, else acquire it

	if (swap_state == SWAP_STATE_NOSWAP) {
		panic("Attempting to swap in when no swap disk is found!\n");
	}
	lock_acquire(swap_lock);
	// 2. select a bunch of non kernel pages.
	unsigned int i;

	for (i = 0; i < page_count; i++) {
		int i_idx = SWAP_IDX(i + swap_prev_write_idx);
		if (cm_isEntryUsed(COREMAP(i_idx)) && cm_getEntryAddrspaceIdent(COREMAP(i_idx)) != NULL) {
			struct page* pg = NULL;
			if (cm_getEntryAddrspaceIdent(COREMAP(i_idx)) == as) {
				pg = findPageFromCoreMap(COREMAP(i_idx), i_idx);
				int spl = splhigh();
				int tlbpos = tlb_probe(pg->pt_virtbase * PAGE_SIZE, 0);
				splx(spl);
				if (tlbpos >= 0) {
					//kprintf("tlb hit at %x %d\n",pg->pt_pagebase, tlbpos);
					continue;
				}
			}
			int j = 0;
			int flag = 1;
			for (j = 0; j < npages; j++) {
				int j_idx = SWAP_IDX(i + j + swap_prev_write_idx);
				if (j_idx >= (int)page_count) {
					kprintf("page count greater than i+j\n");
					flag = 0;
					break;
				}
				if (cm_isEntryUsed(
						COREMAP(j_idx)) && cm_getEntryAddrspaceIdent(COREMAP(j_idx)) == NULL) {
					kprintf("page used by kernel\n");
					flag = 0;
					break;
				}
			}
			if (flag == 1) {
				for (j = 0; j < npages; j++) {
					int j_idx = SWAP_IDX(i + j + swap_prev_write_idx);
					if (cm_isEntryUsed(COREMAP(j_idx)) && cm_getEntryAddrspaceIdent(COREMAP(j_idx)) != NULL) {
						swaponepagein(j_idx, as);
						cm_setEntryUseState(COREMAP(j_idx), false);
						cm_setEntryDirtyState(COREMAP(j_idx), false);
						// let the address space identifier be NULL initially
						cm_setEntryAddrspaceIdent(COREMAP(j_idx), NULL);
						coremap_pages_free++;
						swap_prev_write_idx = j_idx + 1;
						/*if(pg != NULL) {
							kprintf("swapped in page was = %x\n", pg->pt_virtbase);
						} else {
							kprintf("page was nill\n");
						}*/
					} else {
						kprintf("How did this get approved?\n");
					}
				}
				//spinlock_acquire(&coremap_lock);
				lock_release(swap_lock);
				return;
			}
		}
	}
	panic("Out of pages to swap out!\n");
	//spinlock_acquire(&coremap_lock);
	lock_release(swap_lock);

	// 2.5 Maintain a index of last page that was swapped in so that you swap in the one after that

	// 5. free lock if you had acquired it in this method
}