int main(int argc, const char **argv) { if (argc < 3) { usage(std::cerr); return EXIT_FAILURE; } const char *image_flnm = argv[2]; bool log = false; bool log_dumpregs = false; if (argv[1][0] >= '1') log = true; if (argv[1][0] >= '2') log_dumpregs = true; std::fstream image(image_flnm, std::ios_base::binary | std::ios_base::in); if (image.fail()) { std::cerr << "Could not open image file " << image_flnm << std::endl; return EXIT_FAILURE; } EndianMemory mem(new VirtualMemory, LittleEndian); std::auto_ptr<ExecutableLoader> elfloader(new ELFLoader); std::auto_ptr<ExecutableLoader> peloader(new PELoader); addr_t entry_point; if (!elfloader->load(image, &mem, entry_point) && !peloader->load(image, &mem, entry_point)) { std::cerr << "Image in " << image_flnm << "is neither ELF nor PE format, or contains some error." << std::endl; return EXIT_FAILURE; } CPU cpu(mem, log, log_dumpregs, argc - 2, argv + 2); std::cout << "Loaded image, starting execution" << std::endl; Time time_start = Time::now(); cpu.run(entry_point); Time time_end = Time::now(); Time duration = time_end - time_start; std::cout << "Execution ended." << std::endl; std::cout << "Executed " << cpu.pc_counter() << " instructions." << std::endl; std::cout.setf(std::ios_base::fixed); std::cout.precision(2); std::cout << "Execution took " << duration << " (" << ((double)cpu.pc_counter())/((double)duration.time()) << " \"MHz\")" << std::endl; return EXIT_SUCCESS; }
/* Can be used to select a 'good' default gws size */ size_t autotune_get_task_max_size(int multiplier, int keys_per_core_cpu, int keys_per_core_gpu, cl_kernel crypt_kernel) { size_t max_available; max_available = get_max_compute_units(gpu_id); if (cpu(device_info[gpu_id])) return max_available * keys_per_core_cpu; else if (gpu_intel(device_info[gpu_id])) return 0; else return max_available * multiplier * keys_per_core_gpu * get_kernel_max_lws(gpu_id, crypt_kernel); }
// Acquire the lock. // Loops (spins) until the lock is acquired. // (Because contention is handled by spinning, must not // go to sleep holding any locks.) void acquire(struct spinlock *lock) { if(holding(lock)) panic("acquire"); if(cpus[cpu()].nlock == 0) cli(); cpus[cpu()].nlock++; while(cmpxchg(0, 1, &lock->locked) == 1) ; // Serialize instructions: now that lock is acquired, make sure // we wait for all pending writes from other processors. cpuid(0, 0, 0, 0, 0); // memory barrier (see Ch 7, IA-32 manual vol 3) // Record info about lock acquisition for debugging. // The +10 is only so that we can tell the difference // between forgetting to initialize lock->cpu // and holding a lock on cpu 0. lock->cpu = cpu() + 10; getcallerpcs(&lock, lock->pcs); }
/* * Execute a single step */ void do_step(void) { BYTE *p; cpu_state = SINGLE_STEP; cpu_error = NONE; cpu(); if (cpu_error == OPHALT) handel_break(); cpu_err_msg(); print_head(); print_reg(); p = PC; disass(&p, p - ram); }
static void reset(struct db_main *db) { if (!db) { //Initialize openCL tuning (library) for this format. self->methods.crypt_all = crypt_all_benchmark; opencl_init_auto_setup(SEED, ROUNDS_DEFAULT/8, split_events, warn, 2, self, create_clobj, release_clobj, sizeof(pwsafe_pass), 0); //Auto tune execution from shared/included code. autotune_run(self, ROUNDS_DEFAULT, 0, (cpu(device_info[gpu_id]) ? 500000000ULL : 1000000000ULL)); self->methods.crypt_all = crypt_all; } }
void bc2s_256_feature<A>::update(const I& in, const cpu&) { dim3 dimblock = ::cuimg::dimblock(cpu(), sizeof(V) + sizeof(i_uchar1), in.domain()); cv::Mat opencv_s1(s1_); cv::Mat opencv_s2(s2_); cv::GaussianBlur(cv::Mat(in), opencv_s1, cv::Size(3, 3), 1, 1, cv::BORDER_REPLICATE); fill_border_clamp(s1_); cv::GaussianBlur(cv::Mat(s1_), opencv_s2, cv::Size(5, 5), 1.8, 1.8, cv::BORDER_REPLICATE); fill_border_clamp(s2_); // local_jet_static_<0, 0, 2, 2>::run(in, s1_, tmp_, 0, dimblock); // local_jet_static_<0, 0, 3, 3>::run(in, s2_, tmp_, 0, dimblock); //local_jet_static_<0, 0, 1, 1>::run(s1_, s2_, tmp_, 0, dimblock); }
static void reset(struct db_main *db) { if (!db) { //Initialize openCL tuning (library) for this format. opencl_init_auto_setup(SEED, HASH_LOOPS, split_events, warn, 2, self, create_clobj, release_clobj, sizeof(state_t), 0); //Auto tune execution from shared/included code. self->methods.crypt_all = crypt_all_benchmark; autotune_run(self, ITERATIONS, 0, (cpu(device_info[gpu_id]) ? 1000000000 : 10000000000ULL)); self->methods.crypt_all = crypt_all; } }
int main( int argc, char** argv ) { int done=0; SDL_Surface *screen2; SDL_Event event; SDL_Joystick *joy; if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO) <0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); exit(1); } joy=0; if(SDL_NumJoysticks()>0) joy=SDL_JoystickOpen(0); screen2 = SDL_SetVideoMode(64*8, 32*8, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( screen2 == NULL ) { printf("Unable to set 480x272 video: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); init( argc, argv ); cpu_int(); while(done == 0) { //for(x=0;x<5000;x++) //some arbitrary number of loops cpu( keys, screen2, &event ); //call cpu to execute instructions, etc if (dtime>0)dtime-=1; if (s_time>0)s_time-=1; } return 0; }
void sig_handler_common_skas(int sig, void *sc_ptr) { struct sigcontext *sc = sc_ptr; struct uml_pt_regs *r; void (*handler)(int, struct uml_pt_regs *); int save_user, save_errno = errno; /* * This is done because to allow SIGSEGV to be delivered inside a SEGV * handler. This can happen in copy_user, and if SEGV is disabled, * the process will die. * XXX Figure out why this is better than SA_NODEFER */ if (sig == SIGSEGV) { change_sig(SIGSEGV, 1); /* * For segfaults, we want the data from the * sigcontext. In this case, we don't want to mangle * the process registers, so use a static set of * registers. For other signals, the process * registers are OK. */ r = &ksig_regs[cpu()]; copy_sc(r, sc_ptr); } else r = TASK_REGS(get_current()); save_user = r->is_user; r->is_user = 0; if ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) || (sig == SIGILL) || (sig == SIGTRAP)) GET_FAULTINFO_FROM_SC(r->faultinfo, sc); change_sig(SIGUSR1, 1); handler = sig_info[sig]; /* unblock SIGVTALRM, SIGIO if sig isn't IRQ signal */ if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM)) unblock_signals(); handler(sig, r); errno = save_errno; r->is_user = save_user; }
// Release the lock. void release(struct spinlock *lock) { if(!holding(lock)) panic("release"); lock->pcs[0] = 0; lock->cpu = 0xffffffff; // Serialize instructions: before unlocking the lock, make sure // to flush any pending memory writes from this processor. cpuid(0, 0, 0, 0, 0); // memory barrier (see Ch 7, IA-32 manual vol 3) lock->locked = 0; if(--cpus[cpu()].nlock == 0) sti(); }
/* * Run the CPU emulation endless */ static void do_go(char *s) { while (isspace((int)*s)) s++; if (isxdigit((int)*s)) PC = ram + exatoi(s); cont: cpu_state = CONTIN_RUN; cpu_error = NONE; cpu(); if (cpu_error == OPHALT) if (handel_break()) if (!cpu_error) goto cont; cpu_err_msg(); print_head(); print_reg(); }
void AdcTest(){ uint8_t program[] = { //0x05, //junk byte since PC is incremented before reading instruction 0x69, 0x16, // LDA #$16 0x6D ,0x00 ,0x00 //LDA $00 }; auto tma =std::unique_ptr<TestMemoryAccesor>(new TestMemoryAccesor()); for(int i = 0; i<sizeof(program); i++){ tma->SetMemory(i,program[i]); } CPU cpu(std::move(tma)); cpu.Step(); // A = 22 cpu.Step(); // A = 22 + *(0) = 22 + 0x69 = 22 + 105 = 127 }
void SolidHwTest::testDeviceExistence() { QCOMPARE(Solid::Device("/org/kde/solid/fakehw/acpi_LID0").isValid(), true); QCOMPARE(Solid::Device("/org/kde/solid/fakehw/volume_label_SOLIDMAN_BEGINS").isValid(), true); // Note the extra space QCOMPARE(Solid::Device("/org/kde/solid/fakehw/computer ").isValid(), false); QCOMPARE(Solid::Device("#'({(à]").isValid(), false); QCOMPARE(Solid::Device(QString()).isValid(), false); // Now try to see if isValid() changes on plug/unplug events Solid::Device cpu("/org/kde/solid/fakehw/acpi_CPU0"); QVERIFY(cpu.isValid()); fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0"); QVERIFY(!cpu.isValid()); fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0"); QVERIFY(cpu.isValid()); }
void panic(char *s) { int i; uint pcs[10]; __asm __volatile("cli"); use_console_lock = 0; cprintf("cpu%d: panic: ", cpu()); cprintf(s); cprintf("\n"); getcallerpcs(&s, pcs); for(i=0; i<10; i++) cprintf(" %p", pcs[i]); panicked = 1; // freeze other CPU for(;;) ; }
void compiler_smoothstep(void) { const int n = 32; float src1[n], src2[n], src3[n]; // Setup kernel and buffers OCL_CREATE_KERNEL("compiler_smoothstep"); OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL); OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL); OCL_CREATE_BUFFER(buf[2], 0, n * sizeof(float), NULL); OCL_CREATE_BUFFER(buf[3], 0, n * sizeof(float), NULL); OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]); OCL_SET_ARG(2, sizeof(cl_mem), &buf[2]); OCL_SET_ARG(3, sizeof(cl_mem), &buf[3]); globals[0] = n; locals[0] = 16; OCL_MAP_BUFFER(0); OCL_MAP_BUFFER(1); OCL_MAP_BUFFER(2); for (int i = 0; i < n; ++i) { float a = 0.1f * (rand() & 15) - 0.75f; float b = a + 0.1f * (rand() & 15) + 0.1f; float c = 0.1f * (rand() & 15) - 0.75f; src1[i] = ((float*)buf_data[0])[i] = a; src2[i] = ((float*)buf_data[1])[i] = b; src3[i] = ((float*)buf_data[2])[i] = c; } OCL_UNMAP_BUFFER(0); OCL_UNMAP_BUFFER(1); OCL_UNMAP_BUFFER(2); OCL_NDRANGE(1); OCL_MAP_BUFFER(3); for (int i = 0; i < n; ++i) { float a = ((float*)buf_data[3])[i]; float b = cpu(src1[i], src2[i], src3[i]); OCL_ASSERT(fabsf(a - b) < 1e-4f); } OCL_UNMAP_BUFFER(3); }
CPU* Macho::get_cpu(std::ifstream &file) { CPU *cpu(NULL); RP_MACH_HEADER<x86Version> header32; std::cout << "Loading Mach-O information.." << std::endl; /* Remember where the caller was in the file */ std::streampos off = file.tellg(); file.seekg(0, std::ios::beg); file.read((char*)&header32, sizeof(RP_MACH_HEADER<x86Version>)); switch(header32.cputype) { case CPU_TYPE_x86_64: { cpu = new (std::nothrow) Ia64(); init_properly_macho_layout<x64Version>(); break; } case CPU_TYPE_I386: { cpu = new (std::nothrow) Ia32(); init_properly_macho_layout<x86Version>(); break; } default: RAISE_EXCEPTION("Cannot determine which architecture is used in this Mach-O file"); } file.seekg(off); if(cpu == NULL) RAISE_EXCEPTION("Cannot allocate cpu"); /* Now we can fill the structure */ m_MachoLayout->fill_structures(file); return cpu; }
void SolidHwTest::testDeviceInterfaces() { Solid::Device cpu("/org/kde/solid/fakehw/acpi_CPU0"); Solid::DeviceInterface *iface = cpu.asDeviceInterface(Solid::DeviceInterface::Processor); Solid::DeviceInterface *processor = cpu.as<Solid::Processor>(); QVERIFY(cpu.isDeviceInterface(Solid::DeviceInterface::Processor)); QVERIFY(iface!=0); QCOMPARE(iface, processor); Solid::Device cpu2("/org/kde/solid/fakehw/acpi_CPU0"); QCOMPARE(cpu.as<Solid::Processor>(), cpu2.as<Solid::Processor>()); QCOMPARE(cpu.as<Solid::GenericInterface>(), cpu2.as<Solid::GenericInterface>()); QPointer<Solid::Processor> p = cpu.as<Solid::Processor>(); QVERIFY(p!=0); fakeManager->unplug("/org/kde/solid/fakehw/acpi_CPU0"); QVERIFY(p==0); fakeManager->plug("/org/kde/solid/fakehw/acpi_CPU0"); QPointer<Solid::StorageVolume> v; QPointer<Solid::StorageVolume> v2; { Solid::Device partition("/org/kde/solid/fakehw/volume_uuid_f00ba7"); v = partition.as<Solid::StorageVolume>(); QVERIFY(v!=0); { Solid::Device partition2("/org/kde/solid/fakehw/volume_uuid_f00ba7"); v2 = partition2.as<Solid::StorageVolume>(); QVERIFY(v2!=0); QVERIFY(v==v2); } QVERIFY(v!=0); QVERIFY(v2!=0); } QVERIFY(v!=0); QVERIFY(v2!=0); fakeManager->unplug("/org/kde/solid/fakehw/volume_uuid_f00ba7"); QVERIFY(v==0); QVERIFY(v2==0); fakeManager->plug("/org/kde/solid/fakehw/volume_uuid_f00ba7"); }
// Acquire the lock. // Loops (spins) until the lock is acquired. // Holding a lock for a long time may cause // other CPUs to waste time spinning to acquire it. void acquire(struct spinlock *lock) { pushcli(); if(holding(lock)) panic("acquire"); // The xchg is atomic. // It also serializes, so that reads after acquire are not // reordered before it. while(xchg(&lock->locked, 1) == 1) ; // Record info about lock acquisition for debugging. // The +10 is only so that we can tell the difference // between forgetting to initialize lock->cpu // and holding a lock on cpu 0. lock->cpu = cpu() + 10; getcallerpcs(&lock, lock->pcs); }
TEST(reduce, DISABLED_reduce_func) { viennacl::ocl::current_context().cache_path("c:/tmp/"); static viennacl::context g_context = viennacl::ocl::current_context(); static bool init = false; viennacl::ocl::context* ctx = g_context.opencl_pcontext(); ctx->build_options("-cl-std=CL2.0 -D CL_VERSION_2_0"); std::cout << "Device " << ctx->current_device().name() << std::endl; { int size = 160000; viennacl::vector<double> test(size, g_context); std::vector<double> cpu(size); for (int i = 0; i < cpu.size(); ++i) cpu[i] = 1; viennacl::copy(cpu, test); double res = viennacl::ml::opencl::reduce(test); ASSERT_EQ(res, cpu.size()); } }
/** * Bootstrap processor starts running C code here. */ int main(void) { /** * ld会生成如下几个变量用来标识程序的段 * * _etext(etext) 正文段结束后第一个地址 * _edata(edata) 数据段结束后第一个地址 * _end(end) bss段结束后第一个地址 */ extern char edata[], end[]; // clear BSS memset(edata, 0, end - edata); // collect info about this machine mp_init(); lapic_init(mp_bcpu()); cprintf("\ncpu%d: starting myos\n\n", cpu()); cprintf("Welcome to myos !\n"); pinit(); // process table binit(); // buffer cache pic_init(); // interrupt controller ioapic_init(); // another interrupt controller kinit(); // physical memory allocator tvinit(); // trap vectors fileinit(); // file table iinit(); // inode cache console_init(); // I/O devices & their interrupts ide_init(); // disk if(!ismp) timer_init(); // uniprocessor timer userinit(); // first user process bootothers(); // start other processors // Finish setting up this processor in mpmain. mpmain(); }
int main(void) { srand(time(NULL)); currPID = 0; sysStackPC = 0; /*io1Count = -1; io2Count = -1;*/ timerCount = TIMER_QUANTUM; newProcesses = fifoQueueConstructor(); readyProcesses = fifoQueueConstructor(); terminatedProcesses = fifoQueueConstructor(); device1 = IODeviceConstructor(); device2 = IODeviceConstructor(); printf("Sean Markus\r\nWing-Sea Poon\r\nAbigail Smith\r\nTabi Stein\r\n\r\n"); //An initial process to start with currProcess = PCBConstructor(); if(currProcess != NULL) // Remember to call the destructor when finished using newProc { PCBSetID(currProcess, currPID); PCBSetPriority(currProcess, rand() % PRIORITY_LEVELS); PCBSetState(currProcess, running); //fifoQueueEnqueue(newProcesses, currProcess); printf("Process created: PID: %d at %lu\r\n", PCBGetID(currProcess), PCBGetCreation(currProcess)); // printf("Process created: %s\r\n", PCBToString(currProcess)); cpu(); } //free all the things! fifoQueueDestructor(&newProcesses); fifoQueueDestructor(&readyProcesses); fifoQueueDestructor(&terminatedProcesses); IODeviceDestructor(device1); IODeviceDestructor(device2); printf("End of simulation\r\n"); return 0; }
int sc_main(int argc, char * argv[]) { try { //Instantiate Modules Memory mem("main_memory"); CPU cpu("cpu"); //Signals sc_buffer<Memory::Function> sigMemFunc; sc_buffer<Memory::RetCode> sigMemDone; sc_signal<int> sigMemAddr; sc_signal_rv<32> sigMemData; // The clock that will drive the CPU and Memory sc_clock clk; // Connecting module ports with signals mem.Port_Func(sigMemFunc); mem.Port_Addr(sigMemAddr); mem.Port_Data(sigMemData); mem.Port_Done(sigMemDone); cpu.Port_MemFunc(sigMemFunc); cpu.Port_MemAddr(sigMemAddr); cpu.Port_MemData(sigMemData); cpu.Port_MemDone(sigMemDone); mem.Port_CLK(clk); cpu.Port_CLK(clk); cout << "Installing trace signals. Output in ram_trace.vcd " << endl; sc_trace_file *wf = sc_create_vcd_trace_file("ram_trace"); sc_trace(wf, clk, "clock"); sc_trace(wf, sigMemFunc, "function"); sc_trace(wf, sigMemAddr, "sigMemAddr"); sc_trace(wf, sigMemData, "sigMemData"); cout << " Running (press CTRL + C to exit)... " << endl; // Start Simulation sc_start(); } catch (const std::exception & e) { cerr << e.what() << endl; } return 0; }
/** Thread context switchin. Called on every re-activation of a thread (switch_exec()). This method is public only because it is called from from assembly code in switch_cpu(). */ IMPLEMENT void Context::switchin_context(Context *from) { assert_kdb (this == current()); assert_kdb (state() & Thread_ready_mask); // Set kernel-esp in case we want to return to the user. // kmem::kernel_sp() returns a pointer to the kernel SP (in the // TSS) the CPU uses when next switching from user to kernel mode. // regs() + 1 returns a pointer to the end of our kernel stack. Cpu::cpus.cpu(cpu()).kernel_sp() = reinterpret_cast<Address>(regs() + 1); // switch to our page directory if necessary vcpu_aware_space()->switchin_context(from->vcpu_aware_space()); // load new segment selectors load_segments(); // update the global UTCB pointer to make the thread find its UTCB // using fs:[0] Mem_layout::user_utcb_ptr(current_cpu()) = utcb().usr(); }
static void init(struct fmt_main *self) { opencl_init("$JOHN/kernels/pwsafe_kernel.cl", gpu_id, NULL); init_kernel = clCreateKernel(program[gpu_id], KERNEL_INIT_NAME, &ret_code); HANDLE_CLERROR(ret_code, "Error while creating init kernel"); crypt_kernel = clCreateKernel(program[gpu_id], KERNEL_RUN_NAME, &ret_code); HANDLE_CLERROR(ret_code, "Error while creating crypt kernel"); finish_kernel = clCreateKernel(program[gpu_id], KERNEL_FINISH_NAME, &ret_code); HANDLE_CLERROR(ret_code, "Error while creating finish kernel"); //Initialize openCL tuning (library) for this format. self->methods.crypt_all = crypt_all_benchmark; opencl_init_auto_setup(SEED, ROUNDS_DEFAULT/8, split_events, warn, 2, self, create_clobj, release_clobj, sizeof(pwsafe_pass), 0); //Auto tune execution from shared/included code. autotune_run(self, ROUNDS_DEFAULT, 0, (cpu(device_info[gpu_id]) ? 500000000ULL : 1000000000ULL)); self->methods.crypt_all = crypt_all; }
void compiler_double_3(void) { const size_t n = 16; float cpu_src[n]; double cpu_dst[n]; // Setup kernel and buffers OCL_CREATE_KERNEL("compiler_double_3"); OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL); OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(double), NULL); OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]); globals[0] = n; locals[0] = 16; // Run random tests for (uint32_t pass = 0; pass < 1; ++pass) { OCL_MAP_BUFFER(0); for (int32_t i = 0; i < (int32_t) n; ++i) cpu_src[i] = ((float*)buf_data[0])[i] = .1f * (rand() & 15) - .75f; OCL_UNMAP_BUFFER(0); // Run the kernel on GPU OCL_NDRANGE(1); // Run on CPU for (int32_t i = 0; i < (int32_t) n; ++i) cpu(i, cpu_src, cpu_dst); // Compare OCL_MAP_BUFFER(1); for (int32_t i = 0; i < (int32_t) n; ++i) OCL_ASSERT(fabs(((double*)buf_data[1])[i] - cpu_dst[i]) < 1e-4); OCL_UNMAP_BUFFER(1); } }
void trap(struct trapframe *tf) { if(tf->trapno == T_SYSCALL){ if(cp->killed) exit(); cp->tf = tf; syscall(); if(cp->killed) exit(); return; } switch(tf->trapno){ case IRQ_OFFSET + IRQ_TIMER: if(cpu() == 0){ acquire(&tickslock); ticks++; wakeup(&ticks); release(&tickslock); } lapic_eoi(); break; case IRQ_OFFSET + IRQ_IDE: ide_intr(); lapic_eoi(); break; case IRQ_OFFSET + IRQ_KBD: kbd_intr(); lapic_eoi(); break; case IRQ_OFFSET + IRQ_SPURIOUS: cprintf("cpu%d: spurious interrupt at %x:%x\n", cpu(), tf->cs, tf->eip); lapic_eoi(); break; default: if(cp == 0 || (tf->cs&3) == 0){ // In kernel, it must be our mistake. cprintf("unexpected trap %d from cpu %d eip %x\n", tf->trapno, cpu(), tf->eip); panic("trap"); } // In user space, assume process misbehaved. cprintf("pid %d %s: trap %d err %d on cpu %d eip %x -- kill proc\n", cp->pid, cp->name, tf->trapno, tf->err, cpu(), tf->eip); cp->killed = 1; } // Force process exit if it has been killed and is in user space. // (If it is still executing in the kernel, let it keep running // until it gets to the regular system call return.) if(cp && cp->killed && (tf->cs&3) == DPL_USER) exit(); // Force process to give up CPU on clock tick. // If interrupts were on while locks held, would need to check nlock. if(cp && cp->state == RUNNING && tf->trapno == IRQ_OFFSET+IRQ_TIMER) yield(); }
void input(int turn, int computer) { int count = 0; while (1) { if (_kbhit()) { switch (_getch()) { case 0x4D://右 for (int i = 0; i < 3; i++) { if (move_field[i][0] == 2) { move_field[i][0] = 1; move_field[i][1] = 2; } else if (move_field[i][1] == 2) { move_field[i][1] = 1; move_field[i][2] = 2; } } break; case 0x4B://左 for (int i = 0; i < 3; i++) { if (move_field[i][2] == 2) { move_field[i][2] = 1; move_field[i][1] = 2; } else if (move_field[i][1] == 2) { move_field[i][1] = 1; move_field[i][0] = 2; } } break; case 0x48://上 for (int i = 0; i < 3; i++) { if (move_field[1][i] == 2) { move_field[1][i] = 1; move_field[0][i] = 2; } else if (move_field[2][i] == 2) { move_field[2][i] = 1; move_field[1][i] = 2; } } break; case 0x50://下 for (int i = 0; i < 3; i++) { if (move_field[0][i] == 2) { move_field[0][i] = 1; move_field[1][i] = 2; } else if (move_field[1][i] == 2) { move_field[1][i] = 1; move_field[2][i] = 2; } } break; case 0x0D://Enter for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (move_field[i][j] == 2) { if (display_field[i][j] == 1) { display_field[i][j] = turn; count++; if (computer == 2) { if (turn == 3)turn = 4; else if (turn == 4)turn = 3; } else if (computer == 1) { indicate(); if (judge(count) > 0) { system("cls"); break; } else { Sleep(2000); system("cls"); cpu(); count++; } } } else { indicate(); printf("\nその場所には置くことができません。\n"); Sleep(1000); system("cls"); } } } } } } else { indicate(); if (judge(count) > 0)break; else { Sleep(100); system("cls"); } } } }
void loadGaugeQuda(void *h_gauge, QudaGaugeParam *param) { checkGaugeParam(param); // Set the specific cpu parameters and create the cpu gauge field GaugeFieldParam gauge_param(h_gauge, *param); cpuGaugeField cpu(gauge_param); // switch the parameters for creating the mirror precise cuda gauge field gauge_param.create = QUDA_NULL_FIELD_CREATE; gauge_param.precision = param->cuda_prec; gauge_param.reconstruct = param->reconstruct; gauge_param.pad = param->ga_pad; gauge_param.order = (gauge_param.precision == QUDA_DOUBLE_PRECISION || gauge_param.reconstruct == QUDA_RECONSTRUCT_NO ) ? QUDA_FLOAT2_GAUGE_ORDER : QUDA_FLOAT4_GAUGE_ORDER; cudaGaugeField *precise = new cudaGaugeField(gauge_param); precise->loadCPUField(cpu, QUDA_CPU_FIELD_LOCATION); param->gaugeGiB += precise->GBytes(); // switch the parameters for creating the mirror sloppy cuda gauge field gauge_param.precision = param->cuda_prec_sloppy; gauge_param.order = (gauge_param.precision == QUDA_DOUBLE_PRECISION || gauge_param.reconstruct == QUDA_RECONSTRUCT_NO ) ? QUDA_FLOAT2_GAUGE_ORDER : QUDA_FLOAT4_GAUGE_ORDER; cudaGaugeField *sloppy = NULL; if (param->cuda_prec != param->cuda_prec_sloppy) { sloppy = new cudaGaugeField(gauge_param); sloppy->loadCPUField(cpu, QUDA_CPU_FIELD_LOCATION); param->gaugeGiB += sloppy->GBytes(); } else { sloppy = precise; } switch (param->type) { case QUDA_WILSON_LINKS: if (gaugePrecise) errorQuda("Precise gauge field already allocated"); gaugePrecise = precise; if (gaugeSloppy) errorQuda("Sloppy gauge field already allocated"); gaugeSloppy = sloppy; break; case QUDA_ASQTAD_FAT_LINKS: if (gaugeFatPrecise) errorQuda("Precise gauge fat field already allocated"); gaugeFatPrecise = precise; if (gaugeFatSloppy) errorQuda("Sloppy gauge fat field already allocated"); gaugeFatSloppy = sloppy; break; case QUDA_ASQTAD_LONG_LINKS: if (gaugeLongPrecise) errorQuda("Preise gauge long field already allocated"); gaugeLongPrecise = precise; if (gaugeLongSloppy) errorQuda("Sloppy gauge long field already allocated"); gaugeLongSloppy = sloppy; break; default: errorQuda("Invalid gauge type"); } endInvertQuda(); // need to delete any persistant dirac operators }
// Check whether this cpu is holding the lock. int holding(struct spinlock *lock) { return lock->locked && lock->cpu == cpu() + 10; }
// Per-CPU process scheduler. // Each CPU calls scheduler() after setting itself up. // Scheduler never returns. It loops, doing: // - choose a process to run // - swtch to start running that process // - eventually that process transfers control // via swtch back to the scheduler. void scheduler(void) { struct proc *p; struct cpu *c; int i; #ifdef STRACE st_init(); #endif c = &cpus[cpu()]; for(;;){ // Enable interrupts on this processor. sti(); acquire(&proc_table_lock); //hold lottery #ifdef LOTTERY if (tickets == 0) { release(&proc_table_lock); continue; } //cprintf("tickets: %d\n", tickets); int winner = rand() / (32767 / tickets + 1); int sum = 0; //cprintf("winner: %d\n", winner); #endif // Loop over process table looking for process to run. for(i = 0; i < NPROC; i++){ p = &proc[i]; if(p->state != RUNNABLE) continue; #ifdef LOTTERY sum += p->tickets; if (sum <= winner) continue; #endif // Switch to chosen process. It is the process's job // to release proc_table_lock and then reacquire it // before jumping back to us. c->curproc = p; setupsegs(p); setstate(p, RUNNING); #ifdef STRACE st_add(p); #endif swtch(&c->context, &p->context); // Process is done running for now. // It should have changed its p->state before coming back. c->curproc = 0; setupsegs(0); #ifdef LOTTERY break; #endif } release(&proc_table_lock); } }