bool DiskPageCache::verify ( BigFile *f ) {
	long vfd = f->getVfd();
	// ensure validity
	if ( vfd < 0 ) return true;
	// this vfd may have already been nuked by call to unlink!
	if ( ! m_memOff [ vfd ] ) return true;
	// debug msg
	//log("VERIFYING PAGECACHE vfd=%li fn=%s",vfd,f->getFilename());
	// read into here
	char buf [ 32 * 1024 ];//GB_PAGE_SIZE ]; //m_pageSize ];
	// ensure threads disabled
	bool on = ! g_threads.areThreadsDisabled();
	if ( on ) g_threads.disableThreads();
	// disable ourselves
	disableCache();
	// add valid offsets used by vfd into m_availMemOff
	for ( long i = 0 ; i < m_maxPagesInFile [ vfd ] ; i++ ) {
		long off = m_memOff [ vfd ] [ i ];
		if ( off < 0 ) continue;
		//char *p = getMemPtrFromOff ( off );
		oldshort size = 0;
		readFromCache(&size, off, OFF_SIZE, sizeof(oldshort));
		//oldshort size = *(oldshort *)(p+OFF_SIZE);
		oldshort skip = 0;
		readFromCache(&skip, off, OFF_SKIP, sizeof(oldshort));
		if ( size > 32 * 1024 ){
			char *xx=NULL; *xx=0; }
		//oldshort skip = *(oldshort *)(p+OFF_SKIP);
		FileState fstate;
		if ( ! f->read ( buf           ,
				 size          ,
				 ((long long)i * (long long)m_pageSize) + 
				                 (long long)skip ,
				 &fstate       ,
				 NULL          ,  // state
				 NULL          ,  // callback
				 0             )){// niceness
			// core if it did not complete
			char *xx = NULL; *xx = 0; }
		// compare to what we have in mem
		log("checking page # %li size=%li skip=%li", i, size, skip);
		char buf2[32 * 1024];
		readFromCache( buf2, off, HEADERSIZE + skip, size );
		if ( memcmp ( buf, buf2, size ) != 0 ){
			char *xx = NULL; *xx = 0; }
		//if ( memcmp ( buf , p + HEADERSIZE + skip, size ) != 0 ) {
		//char *xx = NULL; *xx = 0; }
	}
	if ( on ) g_threads.enableThreads();
	enableCache();
	// debug msg
	log("DONE VERIFYING PAGECACHE");
	return true;
}
示例#2
0
int main() {
	/* Initialize hardware */
	// Turn off interrupt
	asm("msr 	CPSR_c, #0xd3");

	// Tune up the system
	enableCache();
	// speedUpCpu();

	// Setup UART2
	setUARTLineControl(UART2_BASE, 3, FALSE, FALSE, FALSE, FALSE, FALSE, 115200);
	setUARTControl(UART2_BASE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);

	// Setup UART1
	setUARTLineControl(UART1_BASE, 3, FALSE, TRUE, FALSE, FALSE, FALSE, 2400);
	setUARTControl(UART1_BASE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE);

	// Setup timer
	setTimerLoadValue(TIMER1_BASE, TIMER_TICK_SIZE);
	setTimerControl(TIMER1_BASE, TRUE, TRUE, TRUE);
	setTimerControl(TIMER3_BASE, TRUE, FALSE, FALSE);

	// Enable interrupt
	enableVicInterrupt(VIC1_BASE, VIC_TIMER1_MASK);
	enableVicInterrupt(VIC2_BASE, VIC_UART2_MASK);
	enableVicInterrupt(VIC2_BASE, VIC_UART1_MASK);

	/* Initialize ReadyQueue and Task related data structures */
	KernelGlobal global;
	ReadyQueue	ready_queue;
	Heap		task_heap;
	HeapNode	*task_heap_data[TASK_PRIORITY_MAX];
	HeapNode	task_heap_nodes[TASK_PRIORITY_MAX];
	FreeList	free_list;
	Task		task_array[TASK_MAX];
	TaskList	task_list[TASK_PRIORITY_MAX];
	BlockedList	receive_blocked_lists[TASK_MAX];
	BlockedList	event_blocked_lists[EVENT_MAX];
	MsgBuffer	msg_array[TASK_MAX];
	char		stacks[TASK_MAX * TASK_STACK_SIZE];

	taskArrayInitial(task_array, stacks);
	freeListInitial(&free_list, task_array);
	heapInitial(&task_heap, task_heap_data, TASK_PRIORITY_MAX);
	readyQueueInitial(&ready_queue, &task_heap, task_heap_nodes, task_list);
	blockedListsInitial(receive_blocked_lists, TASK_MAX);
	blockedListsInitial(event_blocked_lists, EVENT_MAX);
	msgArrayInitial(msg_array);

	/* Setup global kernel entry */
	int *swi_entry = (int *) SWI_ENTRY_POINT;
	*swi_entry = (int) (TEXT_REG_BASE + swiEntry);
	int *irq_entry = (int *) IRQ_ENTRY_POINT;
	*irq_entry = (int) (TEXT_REG_BASE + irqEntry);

	/* Setup kernel global variable structure */
	global.ready_queue = &ready_queue;
	global.free_list = &free_list;
	global.receive_blocked_lists = receive_blocked_lists;
	global.event_blocked_lists = event_blocked_lists;
	global.msg_array = msg_array;
	global.task_array = task_array;

	kernelGlobalInitial(&global);

	/* Create first task with highest priority */
	Task *first_task = createTask(&free_list, 0, umain);
	insertTask(&ready_queue, first_task);

	/* Main syscall handling loop */
	while(1){
		// If no more task to run, break
		if(!scheduleNextTask(&ready_queue)) break;

		UserTrapframe* user_sp = (UserTrapframe *)ready_queue.curtask->current_sp;
		DEBUG(DB_TASK, "| TASK:\tEXITING SP: 0x%x SPSR: 0x%x ResumePoint: 0x%x\n", user_sp, user_sp->spsr, user_sp->resume_point);
		STAT_TASK_BEGIN(&global);

		// Exit kernel to let user program to execute
		kernelExit(ready_queue.curtask->current_sp);

		asm("mov r1, %0"
		    :
		    :"r"(&global)
		    :"r0", "r2", "r3"
		    );
		asm("bl	handlerRedirection(PLT)");
	}

	// printStat(&global);

	/* Turm off timer */
	setTimerControl(TIMER1_BASE, FALSE, FALSE, FALSE);
	setTimerControl(TIMER3_BASE, FALSE, FALSE, FALSE);

	return 0;
}