int main (int argc, char **argv) { parse_args (argc, argv); parse_file (inst_defn_file, 'd'); parse_file (inst_trace_file, 't'); create_arch(); while (instr_proc < instr_count) { cycles++; issue (); execute (); write_back(); } finish (); return 0; }
int main(int argc, char const *argv[]) { if(argc != 2){ printf("Useage: %s inputfile.txt\n",argv[0]); exit(-1); } input_file =fopen(argv[1],"r"); output_file =fopen("simulation.txt","w"); import(input_file); ini_context(); int i; for(i=1;i<32;i++){ clone(); fetch_decode(i); issue(); alu1(); alu2(); memory(); wb(); cout_state(i,output_file); } return 0; }
RcppExport SEXP cfamounts(SEXP params){ SEXP rl=R_NilValue; char* exceptionMesg=NULL; try{ RcppParams rparam(params); QuantLib::Date maturity(dateFromR(rparam.getDateValue("Maturity"))); QuantLib::Date settle(dateFromR(rparam.getDateValue("Settle"))); QuantLib::Date issue(dateFromR(rparam.getDateValue("IssueDate"))); double rate = rparam.getDoubleValue("CouponRate"); std::vector<double> rateVec(1, rate); double faceAmount = rparam.getDoubleValue("Face"); double period = rparam.getDoubleValue("Period"); double basis = rparam.getDoubleValue("Basis"); DayCounter dayCounter = getDayCounter(basis); Frequency freq = getFrequency(period); Period p(freq); double EMR = rparam.getDoubleValue("EMR"); Calendar calendar=UnitedStates(UnitedStates::GovernmentBond); Schedule sch(settle, maturity, p, calendar, Unadjusted, Unadjusted, DateGeneration::Backward, (EMR == 1)? true : false); FixedRateBond bond(1, faceAmount, sch, rateVec, dayCounter, Following, 100, issue); //cashflow int numCol = 2; std::vector<std::string> colNames(numCol); colNames[0] = "Date"; colNames[1] = "Amount"; RcppFrame frame(colNames); Leg bondCashFlow = bond.cashflows(); for (unsigned int i = 0; i< bondCashFlow.size(); i++){ std::vector<ColDatum> row(numCol); Date d = bondCashFlow[i]->date(); row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); row[1].setDoubleValue(bondCashFlow[i]->amount()); frame.addRow(row); } RcppResultSet rs; rs.add("cashFlow", frame); rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
bool GPUSMProcessor::advance_clock(FlodID fid) { if (!active) { // time to remove from the running queue TaskHandler::removeFromRunning(cpu_id); return false; } fetch(fid); if (!busy) return false; clockTicks.inc(); setWallClock(); if (unlikely(throttlingRatio>1)) { throttling_cntr++; uint32_t skip = ceil(throttlingRatio/getTurboRatioGPU()); if (throttling_cntr < skip) { return true; } throttling_cntr = 1; } // ID Stage (insert to instQueue) if (spaceInInstQueue >= FetchWidth) { //MSG("\nFor CPU %d:",getId()); IBucket *bucket = pipeQ.pipeLine.nextItem(); if( bucket ) { I(!bucket->empty()); spaceInInstQueue -= bucket->size(); pipeQ.instQueue.push(bucket); }else{ noFetch2.inc(); } }else{ noFetch.inc(); } // RENAME Stage if ( !pipeQ.instQueue.empty() ) { // FIXME: Clear the per PE counter spaceInInstQueue += issue(pipeQ); }else if (ROB.empty() && rROB.empty()) { //I(0); // Still busy if we have some in-flight requests busy = pipeQ.pipeLine.hasOutstandingItems(); return true; } retire(); return true; }
void Tomasulo::issue() { logger->debug(TAG, "**ISSUE BEGIN**"); if (!halted && !stallIssue) { bool advancePC = true; UWord rawInstruction = memory->readUWord(pc); InstructionPtr instruction = instructionFactory->decode(rawInstruction); assert(instruction); logger->debug(TAG) << "Decoded " << *instruction; // check for a halt if (instruction->getName() == InstructionName::TRAP && instruction->getImmediate() == 0) { halted = true; logger->info(TAG, "Halting when issued instructions are completed"); advancePC = false; } else { auto fu = functionalUnits[instruction->getType()]; advancePC = fu->issue(instruction, clockCounter); } if (advancePC) { if (instruction->getType() == FunctionalUnitType::Branch) { stallIssue = true; } else { pc += 4; } } else { logger->debug(TAG, "PC was not incremented"); } } else { logger->debug(TAG, "Issue stalled"); } logger->debug(TAG, "**ISSUE END**"); }
int main(int argc, char *argv[]) { state_t *state; int data_count; int commit_ret, dispatch_ret; int num_insn, i; int commit_status, areBuffersFull = 0; parse_args(argc, argv); state = state_create(&data_count, bin_file, fu_file, wbpi, wbpf); if (state == NULL) { fclose(bin_file); fclose(fu_file); return -1; } fclose(bin_file); fclose(fu_file); /* main sim loop */ for (i = 0, num_insn = 0; TRUE; i++) { printf("\n\n*** CYCLE %d\n", i); print_state(state, data_count); commit_status = commit(state); if(commit_status != 0) num_insn++; if(commit_status == -1) break; writeback(state); execute(state); memory_disambiguation(state); issue(state); if (!(state->fetch_lock)) { areBuffersFull = dispatch(state); if(areBuffersFull != -1) fetch(state); } } printf("SIMULATION COMPLETE!\n"); printf("COMMITTED %d INSTRUCTIONS IN %d CYCLES\n", num_insn, i); printf("CPI: %.2f\n", (float)i / (float)num_insn); return 0; }
void Tomasulo::doWork() { if (!instructionsQueue.empty()) { vector<string> currentInst = instructionsQueue.front(); if (issue(currentInst)) { instructionsQueue.pop(); } } for (int i = 0; i < addsub_rs; i++) { if (addsubRS[i].state == addsub_delay) { addsubRS[i].busy = false; //Here to trace instruction finished! } addsubRS[i].state += 1; } pc++; }
void Processor::advanceClock() { #ifdef TS_STALL if (isStall()) return; #endif clockTicks++; // GMSG(!ROB.empty(),"robTop %d Ul %d Us %d Ub %d",ROB.getIdFromTop(0) // ,unresolvedLoad, unresolvedStore, unresolvedBranch); // Fetch Stage if (IFID.hasWork() ) { IBucket *bucket = pipeQ.pipeLine.newItem(); if( bucket ) { IFID.fetch(bucket); } } // ID Stage (insert to instQueue) if (spaceInInstQueue >= FetchWidth) { IBucket *bucket = pipeQ.pipeLine.nextItem(); if( bucket ) { I(!bucket->empty()); // I(bucket->top()->getInst()->getAddr()); spaceInInstQueue -= bucket->size(); pipeQ.instQueue.push(bucket); }else{ noFetch2.inc(); } }else{ noFetch.inc(); } // RENAME Stage if ( !pipeQ.instQueue.empty() ) { spaceInInstQueue += issue(pipeQ); // spaceInInstQueue += issue(pipeQ); } retire(); }
int main() { int i, j, k, loc, ch1, ch2; char tch; load_books(); load_user(); for(;;) { printf("\n1 - creeate new account\n2 - login\n3 - exit\nenter ur choice\n"); fflush(stdin); scanf("%d", &ch1); switch(ch1) { case 1: create(); break; case 2: loc = login(); if(loc == -1) break; else { printf("\n1 - issue book\n2 - deposit book\n3 - update information\n4 - exit\nenter ur choice: "); scanf("%d",&ch2); fflush(stdin); for(;;) switch(ch2) { case 1: issue(loc); break; case 2: deposit(loc); break; case 3:update(loc); break; case 4: break; default: printf("error in choice....retry\n"); } } break; case 3: exit(0); default: printf("\nerror in choice....retry\n"); } } write_books(); }
void Tomasulo::run(Address entryPoint) { pc = entryPoint; logger->debug(TAG) << "Executing from address " << util::hex<Address> << entryPoint << "\n"; while (!halted || !functionalUnitsIdle()) { ++clockCounter; logger->info(TAG) << "****CLOCK CYCLE " << clockCounter << " BEGIN****"; advanceInstructions(); issue(); execute(); write(); dumpState(); logger->info(TAG) << "****CLOCK CYCLE " << clockCounter << " END****\n"; } }
TEST(GithubFormatter, Print) { { std::ifstream issueFile("test/issue.json"); std::vector<char> issue((std::istreambuf_iterator<char>(issueFile)), std::istreambuf_iterator<char>()); std::string issuePrinted; ASSERT_EQ(GithubWebhookFormatter::FormatResult::OK, GithubWebhookFormatter::FormatWebhookMessage("issues", issue, issuePrinted)); std::cout << issuePrinted << std::endl; } { std::ifstream releaseFile("test/release.json"); std::vector<char> release((std::istreambuf_iterator<char>(releaseFile)), std::istreambuf_iterator<char>()); std::string releasePrinted; ASSERT_EQ(GithubWebhookFormatter::FormatResult::OK, GithubWebhookFormatter::FormatWebhookMessage("release", release, releasePrinted)); std::cout << releasePrinted << std::endl; } }
void AcceptedLedgerTx::buildJson () { mJson = Json::objectValue; mJson[jss::transaction] = mTxn->getJson (0); if (mMeta) { mJson[jss::meta] = mMeta->getJson (0); mJson[jss::raw_meta] = strHex (mRawMeta); } mJson[jss::result] = transHuman (mResult); if (!mAffected.empty ()) { Json::Value& affected = (mJson[jss::affected] = Json::arrayValue); for (auto const& ra : mAffected) { affected.append (ra.humanAccountID ()); } } if (mTxn->getTxnType () == ttOFFER_CREATE) { auto const account (mTxn->getSourceAccount ().getAccountID ()); auto const amount (mTxn->getFieldAmount (sfTakerGets)); // If the offer create is not self funded then add the owner balance if (account != amount.issue ().account) { LedgerEntrySet les (mLedger, tapNONE, true); auto const ownerFunds (funds( les, account, amount, fhIGNORE_FREEZE)); mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText (); } } }
int main(int argc, char** argv) { DataStoreNodeTemplate tlb_stat("tlb_stat"); { tlb_stat.summable = 1; tlb_stat.addint("hits"); tlb_stat.addint("misses"); } DataStoreNodeTemplate PerContextOutOfOrderCoreStats("PerContextOutOfOrderCoreStats"); { DataStoreNodeTemplate& fetch = PerContextOutOfOrderCoreStats("fetch"); { DataStoreNodeTemplate& stop = fetch("stop"); { stop.summable = 1; stop.addint("stalled"); stop.addint("icache_miss"); stop.addint("fetchq_full"); stop.addint("issueq_quota_full"); stop.addint("bogus_rip"); stop.addint("microcode_assist"); stop.addint("branch_taken"); stop.addint("full_width"); stop.addint("icache_stalled"); stop.addint("invalid_blocks"); } fetch.histogram("opclass", 29, opclass_names); fetch.histogram("width", OutOfOrderModel::FETCH_WIDTH+1, 0, OutOfOrderModel::FETCH_WIDTH, 1); fetch.addint("blocks"); fetch.addint("uops"); fetch.addint("user_insns"); } DataStoreNodeTemplate& frontend = PerContextOutOfOrderCoreStats("frontend"); { DataStoreNodeTemplate& status = frontend("status"); { status.summable = 1; status.addint("complete"); status.addint("fetchq_empty"); status.addint("rob_full"); status.addint("physregs_full"); status.addint("ldq_full"); status.addint("stq_full"); } frontend.histogram("width", OutOfOrderModel::FRONTEND_WIDTH+1, 0, OutOfOrderModel::FRONTEND_WIDTH, 1); DataStoreNodeTemplate& renamed = frontend("renamed"); { renamed.addint("none"); renamed.addint("reg"); renamed.addint("flags"); renamed.addint("reg_and_flags"); } DataStoreNodeTemplate& alloc = frontend("alloc"); { alloc.addint("reg"); alloc.addint("ldreg"); alloc.addint("sfr"); alloc.addint("br"); } frontend.histogram("consumer_count", 256, 0, 255, 1); } DataStoreNodeTemplate& dispatch = PerContextOutOfOrderCoreStats("dispatch"); { dispatch.histogram("cluster", OutOfOrderModel::MAX_CLUSTERS, OutOfOrderModel::cluster_names); DataStoreNodeTemplate& redispatch = dispatch("redispatch"); { redispatch.addint("trigger_uops"); redispatch.addint("deadlock_flushes"); redispatch.addint("deadlock_uops_flushed"); redispatch.histogram("dependent_uops", OutOfOrderModel::ROB_SIZE+1, 0, OutOfOrderModel::ROB_SIZE, 1); } } DataStoreNodeTemplate& issue = PerContextOutOfOrderCoreStats("issue"); { issue.addint("uops"); issue.addfloat("uipc"); DataStoreNodeTemplate& result = issue("result"); { result.summable = 1; result.addint("no_fu"); result.addint("replay"); result.addint("misspeculated"); result.addint("refetch"); result.addint("branch_mispredict"); result.addint("exception"); result.addint("complete"); } issue.histogram("opclass", 29, opclass_names); } DataStoreNodeTemplate& writeback = PerContextOutOfOrderCoreStats("writeback"); { writeback.histogram("writebacks", OutOfOrderModel::PHYS_REG_FILE_COUNT, OutOfOrderModel::phys_reg_file_names); } DataStoreNodeTemplate& commit = PerContextOutOfOrderCoreStats("commit"); { commit.addint("uops"); commit.addint("insns"); commit.addfloat("uipc"); commit.addfloat("ipc"); DataStoreNodeTemplate& result = commit("result"); { result.summable = 1; result.addint("none"); result.addint("ok"); result.addint("exception"); result.addint("skipblock"); result.addint("barrier"); result.addint("smc"); result.addint("memlocked"); result.addint("stop"); result.addint("dcache_stall"); } DataStoreNodeTemplate& fail = commit("fail"); { fail.summable = 1; fail.addint("free_list"); fail.addint("frontend_list"); fail.addint("ready_to_dispatch_list"); fail.addint("dispatched_list"); fail.addint("ready_to_issue_list"); fail.addint("ready_to_store_list"); fail.addint("ready_to_load_list"); fail.addint("issued_list"); fail.addint("completed_list"); fail.addint("ready_to_writeback_list"); fail.addint("cache_miss_list"); fail.addint("tlb_miss_list"); fail.addint("memory_fence_list"); fail.addint("ready_to_commit_queue"); } DataStoreNodeTemplate& setflags = commit("setflags"); { setflags.summable = 1; setflags.addint("yes"); setflags.addint("no"); } commit.histogram("opclass", 29, opclass_names); } DataStoreNodeTemplate& branchpred = PerContextOutOfOrderCoreStats("branchpred"); { branchpred.addint("predictions"); branchpred.addint("updates"); branchpred.histogram("cond", 2, branchpred_outcome_names); branchpred.histogram("indir", 2, branchpred_outcome_names); branchpred.histogram("ret", 2, branchpred_outcome_names); branchpred.histogram("summary", 2, branchpred_outcome_names); DataStoreNodeTemplate& ras = branchpred("ras"); { ras.summable = 1; ras.addint("pushes"); ras.addint("overflows"); ras.addint("pops"); ras.addint("underflows"); ras.addint("annuls"); } } DataStoreNodeTemplate& dcache = PerContextOutOfOrderCoreStats("dcache"); { DataStoreNodeTemplate& load = dcache("load"); { DataStoreNodeTemplate& issue = load("issue"); { issue.summable = 1; issue.addint("complete"); issue.addint("miss"); issue.addint("exception"); issue.addint("ordering"); issue.addint("unaligned"); DataStoreNodeTemplate& replay = issue("replay"); { replay.summable = 1; replay.addint("sfr_addr_and_data_not_ready"); replay.addint("sfr_addr_not_ready"); replay.addint("sfr_data_not_ready"); replay.addint("missbuf_full"); replay.addint("interlocked"); replay.addint("interlock_overflow"); replay.addint("fence"); replay.addint("bank_conflict"); replay.addint("dcache_stall"); } } DataStoreNodeTemplate& forward = load("forward"); { forward.summable = 1; forward.addint("cache"); forward.addint("sfr"); forward.addint("sfr_and_cache"); } DataStoreNodeTemplate& dependency = load("dependency"); { dependency.summable = 1; dependency.addint("independent"); dependency.addint("predicted_alias_unresolved"); dependency.addint("stq_address_match"); dependency.addint("stq_address_not_ready"); dependency.addint("fence"); dependency.addint("mmio"); } DataStoreNodeTemplate& type = load("type"); { type.summable = 1; type.addint("aligned"); type.addint("unaligned"); type.addint("internal"); } load.histogram("size", 4, sizeshift_names); load.histogram("datatype", DATATYPE_COUNT, datatype_names); } DataStoreNodeTemplate& store = dcache("store"); { DataStoreNodeTemplate& issue = store("issue"); { issue.summable = 1; issue.addint("complete"); issue.addint("exception"); issue.addint("ordering"); issue.addint("unaligned"); DataStoreNodeTemplate& replay = issue("replay"); { replay.summable = 1; replay.addint("sfr_addr_and_data_not_ready"); replay.addint("sfr_addr_not_ready"); replay.addint("sfr_data_not_ready"); replay.addint("sfr_addr_and_data_and_data_to_store_not_ready"); replay.addint("sfr_addr_and_data_to_store_not_ready"); replay.addint("sfr_data_and_data_to_store_not_ready"); replay.addint("interlocked"); replay.addint("fence"); replay.addint("parallel_aliasing"); replay.addint("bank_conflict"); } } DataStoreNodeTemplate& forward = store("forward"); { forward.summable = 1; forward.addint("zero"); forward.addint("sfr"); } DataStoreNodeTemplate& type = store("type"); { type.summable = 1; type.addint("aligned"); type.addint("unaligned"); type.addint("internal"); } store.histogram("size", 4, sizeshift_names); store.histogram("datatype", DATATYPE_COUNT, datatype_names); } DataStoreNodeTemplate& fence = dcache("fence"); { fence.summable = 1; fence.addint("lfence"); fence.addint("sfence"); fence.addint("mfence"); } dcache.add("dtlb", tlb_stat); dcache.add("itlb", tlb_stat); dcache.histogram("dtlb_latency", 1001, 0, 200, 1); dcache.histogram("itlb_latency", 1001, 0, 200, 1); } PerContextOutOfOrderCoreStats.addint("interrupt_requests"); PerContextOutOfOrderCoreStats.addint("cpu_exit_requests"); PerContextOutOfOrderCoreStats.addint("cycles_in_pause"); } DataStoreNodeTemplate OutOfOrderCoreStats("OutOfOrderCoreStats"); { OutOfOrderCoreStats.addint("cycles"); DataStoreNodeTemplate& dispatch = OutOfOrderCoreStats("dispatch"); { DataStoreNodeTemplate& source = dispatch("source"); { source.summable = 1; source.histogram("integer", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("fp", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("st", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("br", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); } dispatch.histogram("width", OutOfOrderModel::DISPATCH_WIDTH+1, 0, OutOfOrderModel::DISPATCH_WIDTH, 1); } DataStoreNodeTemplate& issue = OutOfOrderCoreStats("issue"); { DataStoreNodeTemplate& source = issue("source"); { source.summable = 1; source.histogram("integer", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("fp", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("st", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); source.histogram("br", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names); } DataStoreNodeTemplate& width = issue("width"); { width.histogram("all", OutOfOrderModel::MAX_ISSUE_WIDTH+1, 0, OutOfOrderModel::MAX_ISSUE_WIDTH, 1); } } DataStoreNodeTemplate& writeback = OutOfOrderCoreStats("writeback"); { DataStoreNodeTemplate& width = writeback("width"); { width.histogram("all", OutOfOrderModel::MAX_ISSUE_WIDTH+1, 0, OutOfOrderModel::MAX_ISSUE_WIDTH, 1); } } DataStoreNodeTemplate& commit = OutOfOrderCoreStats("commit"); { DataStoreNodeTemplate& freereg = commit("freereg"); { freereg.summable = 1; freereg.addint("pending"); freereg.addint("free"); } commit.addint("free_regs_recycled"); commit.histogram("width", OutOfOrderModel::COMMIT_WIDTH+1, 0, OutOfOrderModel::COMMIT_WIDTH, 1); } DataStoreNodeTemplate& branchpred = OutOfOrderCoreStats("branchpred"); { branchpred.addint("predictions"); branchpred.addint("updates"); branchpred.histogram("cond", 2, branchpred_outcome_names); branchpred.histogram("indir", 2, branchpred_outcome_names); branchpred.histogram("ret", 2, branchpred_outcome_names); branchpred.histogram("summary", 2, branchpred_outcome_names); DataStoreNodeTemplate& ras = branchpred("ras"); { ras.summable = 1; ras.addint("pushes"); ras.addint("overflows"); ras.addint("pops"); ras.addint("underflows"); ras.addint("annuls"); } } OutOfOrderCoreStats.add("total", PerContextOutOfOrderCoreStats); OutOfOrderCoreStats.add("vcpu0", PerContextOutOfOrderCoreStats); OutOfOrderCoreStats.add("vcpu1", PerContextOutOfOrderCoreStats); OutOfOrderCoreStats.add("vcpu2", PerContextOutOfOrderCoreStats); OutOfOrderCoreStats.add("vcpu3", PerContextOutOfOrderCoreStats); DataStoreNodeTemplate& simulator = OutOfOrderCoreStats("simulator"); { simulator.addfloat("total_time"); DataStoreNodeTemplate& cputime = simulator("cputime"); { cputime.summable = 1; cputime.addfloat("fetch"); cputime.addfloat("decode"); cputime.addfloat("rename"); cputime.addfloat("frontend"); cputime.addfloat("dispatch"); cputime.addfloat("issue"); cputime.addfloat("issueload"); cputime.addfloat("issuestore"); cputime.addfloat("complete"); cputime.addfloat("transfer"); cputime.addfloat("writeback"); cputime.addfloat("commit"); } } } DataStoreNodeTemplate PerContextDataCacheStats("PerContextDataCacheStats"); { DataStoreNodeTemplate& load = PerContextDataCacheStats("load"); { DataStoreNodeTemplate& hit = load("hit"); { hit.summable = 1; hit.addint("L1"); hit.addint("L2"); hit.addint("L3"); hit.addint("mem"); } DataStoreNodeTemplate& dtlb = load("dtlb"); { dtlb.summable = 1; dtlb.addint("hits"); dtlb.addint("misses"); } DataStoreNodeTemplate& tlbwalk = load("tlbwalk"); { tlbwalk.summable = 1; tlbwalk.addint("L1_dcache_hit"); tlbwalk.addint("L1_dcache_miss"); tlbwalk.addint("no_lfrq_mb"); } } DataStoreNodeTemplate& fetch = PerContextDataCacheStats("fetch"); { DataStoreNodeTemplate& hit = fetch("hit"); { hit.summable = 1; hit.addint("L1"); hit.addint("L2"); hit.addint("L3"); hit.addint("mem"); } DataStoreNodeTemplate& itlb = fetch("itlb"); { itlb.summable = 1; itlb.addint("hits"); itlb.addint("misses"); } DataStoreNodeTemplate& tlbwalk = fetch("tlbwalk"); { tlbwalk.summable = 1; tlbwalk.addint("L1_dcache_hit"); tlbwalk.addint("L1_dcache_miss"); tlbwalk.addint("no_lfrq_mb"); } } DataStoreNodeTemplate& store = PerContextDataCacheStats("store"); { store.addint("prefetches"); } } DataStoreNodeTemplate DataCacheStats("DataCacheStats"); { DataStoreNodeTemplate& load = DataCacheStats("load"); { DataStoreNodeTemplate& transfer = load("transfer"); { transfer.summable = 1; transfer.addint("L2_to_L1_full"); transfer.addint("L2_to_L1_partial"); transfer.addint("L2_L1I_full"); } } DataStoreNodeTemplate& missbuf = DataCacheStats("missbuf"); { missbuf.addint("inserts"); DataStoreNodeTemplate& deliver = missbuf("deliver"); { deliver.summable = 1; deliver.addint("mem_to_L3"); deliver.addint("L3_to_L2"); deliver.addint("L2_to_L1D"); deliver.addint("L2_to_L1I"); } } DataStoreNodeTemplate& prefetch = DataCacheStats("prefetch"); { prefetch.summable = 1; prefetch.addint("in_L1"); prefetch.addint("in_L2"); prefetch.addint("required"); } DataStoreNodeTemplate& lfrq = DataCacheStats("lfrq"); { lfrq.addint("inserts"); lfrq.addint("wakeups"); lfrq.addint("annuls"); lfrq.addint("resets"); lfrq.addint("total_latency"); lfrq.addfloat("average_latency"); lfrq.histogram("width", CacheSubsystem::MAX_WAKEUPS_PER_CYCLE+1, 0, CacheSubsystem::MAX_WAKEUPS_PER_CYCLE+1, 1); } DataCacheStats.add("total", PerContextDataCacheStats); DataCacheStats.add("vcpu0", PerContextDataCacheStats); DataCacheStats.add("vcpu1", PerContextDataCacheStats); DataCacheStats.add("vcpu2", PerContextDataCacheStats); DataCacheStats.add("vcpu3", PerContextDataCacheStats); } DataStoreNodeTemplate stall_sub("stall_sub"); { stall_sub.summable = 1; stall_sub.addint("dependency"); stall_sub.addint("cache_port"); stall_sub.addint("buffer_full"); } DataStoreNodeTemplate CacheStats("CacheStats"); { DataStoreNodeTemplate& cpurequest = CacheStats("cpurequest"); { DataStoreNodeTemplate& count = cpurequest("count"); { count.summable = 1; DataStoreNodeTemplate& hit = count("hit"); { DataStoreNodeTemplate& read = hit("read"); { read.summable = 1; DataStoreNodeTemplate& hit = read("hit"); { hit.summable = 1; hit.addint("hit"); hit.addint("forward"); } } DataStoreNodeTemplate& write = hit("write"); { write.summable = 1; DataStoreNodeTemplate& hit = write("hit"); { hit.summable = 1; hit.addint("hit"); hit.addint("forward"); } } } DataStoreNodeTemplate& miss = count("miss"); { miss.summable = 1; miss.addint("read"); miss.addint("write"); } } DataStoreNodeTemplate& stall = cpurequest("stall"); { stall.summable = 1; stall.add("read", stall_sub); stall.add("write", stall_sub); } cpurequest.addint("redirects"); } DataStoreNodeTemplate& snooprequest = CacheStats("snooprequest"); { snooprequest.summable = 1; snooprequest.addint("hit"); snooprequest.addint("miss"); } CacheStats.addint("annul"); CacheStats.addint("queueFull"); DataStoreNodeTemplate& latency = CacheStats("latency"); { latency.summable = 1; latency.addint("IF"); latency.addint("load"); latency.addint("store"); } DataStoreNodeTemplate& lat_count = CacheStats("lat_count"); { lat_count.summable = 1; lat_count.addint("IF"); lat_count.addint("load"); lat_count.addint("store"); } DataStoreNodeTemplate& mesi_stats = CacheStats("mesi_stats"); { DataStoreNodeTemplate& hit_state = mesi_stats("hit_state"); { hit_state.summable = 1; hit_state.histogram("snoop", 5, 0, 4, 1); hit_state.histogram("cpu", 5, 0, 4, 1); } mesi_stats.histogram("state_transition", 17, 0, 16, 1); } } DataStoreNodeTemplate PerCoreCacheStats("PerCoreCacheStats"); { PerCoreCacheStats.add("CPUController", CacheStats); PerCoreCacheStats.add("L1I", CacheStats); PerCoreCacheStats.add("L1D", CacheStats); PerCoreCacheStats.add("L2", CacheStats); PerCoreCacheStats.add("L3", CacheStats); } DataStoreNodeTemplate BusStats("BusStats"); { DataStoreNodeTemplate& broadcasts = BusStats("broadcasts"); { broadcasts.summable = 1; broadcasts.addint("read"); broadcasts.addint("write"); broadcasts.addint("update"); } DataStoreNodeTemplate& broadcast_cycles = BusStats("broadcast_cycles"); { broadcast_cycles.summable = 1; broadcast_cycles.addint("read"); broadcast_cycles.addint("write"); broadcast_cycles.addint("update"); } BusStats.addint("addr_bus_cycles"); BusStats.addint("data_bus_cycles"); } DataStoreNodeTemplate EventsInMode("EventsInMode"); { EventsInMode.summable = 1; EventsInMode.addint("user64"); EventsInMode.addint("user32"); EventsInMode.addint("kernel64"); EventsInMode.addint("kernel32"); EventsInMode.addint("legacy16"); EventsInMode.addint("userlib"); EventsInMode.addint("microcode"); EventsInMode.addint("idle"); } DataStoreNodeTemplate PerCoreEvents("PerCoreEvents"); { PerCoreEvents.add("cycles_in_mode", EventsInMode); PerCoreEvents.add("insns_in_mode", EventsInMode); PerCoreEvents.add("uops_in_mode", EventsInMode); } DataStoreNodeTemplate PTLsimStats("PTLsimStats"); { PTLsimStats.addint("snapshot_uuid"); PTLsimStats.addstring("snapshot_name", 64); DataStoreNodeTemplate& summary = PTLsimStats("summary"); { summary.addint("cycles"); summary.addint("insns"); summary.addint("uops"); summary.addint("basicblocks"); } DataStoreNodeTemplate& simulator = PTLsimStats("simulator"); { DataStoreNodeTemplate& version = simulator("version"); { version.addstring("build_timestamp", 32); version.addint("svn_revision"); version.addstring("svn_timestamp", 32); version.addstring("build_hostname", 64); version.addstring("build_compiler", 16); } DataStoreNodeTemplate& run = simulator("run"); { run.addint("timestamp"); run.addstring("hostname", 64); run.addstring("kernel_version", 32); run.addstring("hypervisor_version", 32); run.addint("native_cpuid"); run.addint("native_hz"); } DataStoreNodeTemplate& config = simulator("config"); { config.addstring("config", 256); } DataStoreNodeTemplate& performance = simulator("performance"); { DataStoreNodeTemplate& rate = performance("rate"); { rate.addfloat("cycles_per_sec"); rate.addfloat("issues_per_sec"); rate.addfloat("user_commits_per_sec"); } } } DataStoreNodeTemplate& decoder = PTLsimStats("decoder"); { DataStoreNodeTemplate& throughput = decoder("throughput"); { throughput.addint("basic_blocks"); throughput.addint("x86_insns"); throughput.addint("uops"); throughput.addint("bytes"); } decoder.histogram("x86_decode_type", DECODE_TYPE_COUNT, decode_type_names); DataStoreNodeTemplate& bb_decode_type = decoder("bb_decode_type"); { bb_decode_type.summable = 1; bb_decode_type.addint("all_insns_fast"); bb_decode_type.addint("some_complex_insns"); } DataStoreNodeTemplate& page_crossings = decoder("page_crossings"); { page_crossings.summable = 1; page_crossings.addint("within_page"); page_crossings.addint("crosses_page"); } DataStoreNodeTemplate& bbcache = decoder("bbcache"); { bbcache.addint("count"); bbcache.addint("inserts"); bbcache.histogram("invalidates", INVALIDATE_REASON_COUNT, invalidate_reason_names); } DataStoreNodeTemplate& pagecache = decoder("pagecache"); { pagecache.addint("count"); pagecache.addint("inserts"); pagecache.histogram("invalidates", INVALIDATE_REASON_COUNT, invalidate_reason_names); } decoder.addint("reclaim_rounds"); } PTLsimStats.add("ooocore_total", OutOfOrderCoreStats); PTLsimStats.add("ooocore_context_total", PerContextOutOfOrderCoreStats); PTLsimStats.addint("elapse_seconds"); DataStoreNodeTemplate& ooocore = PTLsimStats("ooocore"); { ooocore.add("total", OutOfOrderCoreStats); ooocore.add("c0", OutOfOrderCoreStats); ooocore.add("c1", OutOfOrderCoreStats); ooocore.add("c2", OutOfOrderCoreStats); ooocore.add("c3", OutOfOrderCoreStats); ooocore.add("c4", OutOfOrderCoreStats); ooocore.add("c5", OutOfOrderCoreStats); ooocore.add("c6", OutOfOrderCoreStats); ooocore.add("c7", OutOfOrderCoreStats); } DataStoreNodeTemplate& dcache = PTLsimStats("dcache"); { dcache.add("total", DataCacheStats); dcache.add("c0", DataCacheStats); dcache.add("c1", DataCacheStats); dcache.add("c2", DataCacheStats); dcache.add("c3", DataCacheStats); dcache.add("c4", DataCacheStats); dcache.add("c5", DataCacheStats); dcache.add("c6", DataCacheStats); dcache.add("c7", DataCacheStats); } DataStoreNodeTemplate& external = PTLsimStats("external"); { external.histogram("assists", ASSIST_COUNT, assist_names); external.histogram("l_assists", L_ASSIST_COUNT, light_assist_names); external.histogram("traps", 256, x86_exception_names); external.add("total", PerCoreEvents); external.add("c0", PerCoreEvents); external.add("c1", PerCoreEvents); external.add("c2", PerCoreEvents); external.add("c3", PerCoreEvents); external.add("c4", PerCoreEvents); external.add("c5", PerCoreEvents); external.add("c6", PerCoreEvents); external.add("c7", PerCoreEvents); } DataStoreNodeTemplate& memory = PTLsimStats("memory"); { memory.add("total", PerCoreCacheStats); memory.add("c0", PerCoreCacheStats); memory.add("c1", PerCoreCacheStats); memory.add("c2", PerCoreCacheStats); memory.add("c3", PerCoreCacheStats); memory.add("c4", PerCoreCacheStats); memory.add("c5", PerCoreCacheStats); memory.add("c6", PerCoreCacheStats); memory.add("c7", PerCoreCacheStats); memory.add("bus", BusStats); memory.histogram("dcache_latency", 200, 0, 199, 1); memory.histogram("icache_latency", 200, 0, 199, 1); } } ofstream os(argv[1], std::ios::binary |std::ios::out); PTLsimStats.write(os); os.close(); }
int main() { char wait; printf("press key to issue requests (with some bad ones): "); wait = getchar(); issue('P', 3, 4); issue('A', 3, 4); issue('L', 3, 4); issue('L', 3, 4); issue('L', 3, 4); issue('A', 6, 4); issue('A', 2, 0); issue('A', -7, 4); issue('A', 2, -1); printf("press key to call start_shuttle(): "); wait = getchar(); start(); int i=0; char type = 'X'; int init; int dest; printf("press key to issue 100 random requests: "); wait = getchar(); for(i; i<100; i++) { int r = (rand() % (3))+1; if(r == 1) type = 'C'; else if(r == 2) type = 'A'; else if(r == 3) type = 'L'; init = (rand() % 5)+1; dest = (rand() % 5)+1; issue(type, init, dest); } printf("press key to call stop_shuttle(): "); wait = getchar(); stop(); printf("press key to call issue another request: "); wait = getchar(); issue('A', 1, 1); printf("press key to call start_shuttle(): "); wait = getchar(); start(); printf("press key to call stop_shuttle(): "); wait = getchar(); stop(); return 0; }
ter createoffer::doapply() { if (m_journal.debug) m_journal.debug << "offercreate> " << mtxn.getjson (0); std::uint32_t const utxflags = mtxn.getflags (); bool const bpassive (utxflags & tfpassive); bool const bimmediateorcancel (utxflags & tfimmediateorcancel); bool const bfillorkill (utxflags & tffillorkill); bool const bsell (utxflags & tfsell); stamount satakerpays = mtxn.getfieldamount (sftakerpays); stamount satakergets = mtxn.getfieldamount (sftakergets); if (!islegalnet (satakerpays) || !islegalnet (satakergets)) return tembad_amount; auto const& upaysissuerid = satakerpays.getissuer (); auto const& upayscurrency = satakerpays.getcurrency (); auto const& ugetsissuerid = satakergets.getissuer (); auto const& ugetscurrency = satakergets.getcurrency (); bool const bhaveexpiration (mtxn.isfieldpresent (sfexpiration)); bool const bhavecancel (mtxn.isfieldpresent (sfoffersequence)); std::uint32_t const uexpiration = mtxn.getfieldu32 (sfexpiration); std::uint32_t const ucancelsequence = mtxn.getfieldu32 (sfoffersequence); // fixme understand why we use sequencenext instead of current transaction // sequence to determine the transaction. why is the offer seuqnce // number insufficient? std::uint32_t const uaccountsequencenext = mtxnaccount->getfieldu32 (sfsequence); std::uint32_t const usequence = mtxn.getsequence (); const uint256 uledgerindex = getofferindex (mtxnaccountid, usequence); if (m_journal.debug) { m_journal.debug << "creating offer node: " << to_string (uledgerindex) << " usequence=" << usequence; if (bimmediateorcancel) m_journal.debug << "transaction: ioc set."; if (bfillorkill) m_journal.debug << "transaction: fok set."; } // this is the original rate of this offer, and is the rate at which it will // be placed, even if crossing offers change the amounts. std::uint64_t const urate = getrate (satakergets, satakerpays); ter terresult (tessuccess); // this is the ledger view that we work against. transactions are applied // as we go on processing transactions. core::ledgerview& view (mengine->view ()); // this is a checkpoint with just the fees paid. if something goes wrong // with this transaction, we roll back to this ledger. core::ledgerview view_checkpoint (view); view.bumpseq (); // begin ledger variance. sle::pointer slecreator = mengine->entrycache ( ltaccount_root, getaccountrootindex (mtxnaccountid)); // additional checking for currency asset. // buy asset if (assetcurrency() == upayscurrency) { if (assetcurrency() == ugetscurrency || // asset for asset bsell) // tfsell set while buying asset return temdisabled; if (satakerpays < stamount(satakerpays.issue(), getconfig().asset_tx_min) || !satakerpays.ismathematicalinteger()) return tembad_offer; if (upaysissuerid == mtxnaccountid || ugetsissuerid == mtxnaccountid) { m_journal.trace << "creating asset offer is not allowed for issuer"; return temdisabled; } } // sell asset if (assetcurrency() == ugetscurrency) { if (!bsell) // tfsell not set while selling asset return temdisabled; if (satakergets < stamount(satakergets.issue(), getconfig().asset_tx_min) || !satakergets.ismathematicalinteger()) return tembad_offer; } if (utxflags & tfoffercreatemask) { if (m_journal.debug) m_journal.debug << "malformed transaction: invalid flags set."; terresult = teminvalid_flag; } else if (bimmediateorcancel && bfillorkill) { if (m_journal.debug) m_journal.debug << "malformed transaction: both ioc and fok set."; terresult = teminvalid_flag; } else if (bhaveexpiration && !uexpiration) { m_journal.warning << "malformed offer: bad expiration"; terresult = tembad_expiration; } else if (satakerpays.isnative () && satakergets.isnative ()) { m_journal.warning << "malformed offer: xrp for xrp"; terresult = tembad_offer; } else if (satakerpays <= zero || satakergets <= zero) { m_journal.warning << "malformed offer: bad amount"; terresult = tembad_offer; } else if (upayscurrency == ugetscurrency && upaysissuerid == ugetsissuerid) { m_journal.warning << "malformed offer: redundant offer"; terresult = temredundant; } // we don't allow a non-native currency to use the currency code vrp. else if (badcurrency() == upayscurrency || badcurrency() == ugetscurrency) { m_journal.warning << "malformed offer: bad currency."; terresult = tembad_currency; } else if (satakerpays.isnative () != isnative(upaysissuerid) || satakergets.isnative () != isnative(ugetsissuerid)) { m_journal.warning << "malformed offer: bad issuer"; terresult = tembad_issuer; } else if (view.isglobalfrozen (upaysissuerid) || view.isglobalfrozen (ugetsissuerid)) { m_journal.warning << "offer involves frozen asset"; terresult = tecfrozen; } else if (view.accountfunds ( mtxnaccountid, satakergets, fhzero_if_frozen) <= zero) { m_journal.warning << "delay: offers must be at least partially funded."; terresult = tecunfunded_offer; } // this can probably be simplified to make sure that you cancel sequences // before the transaction sequence number. else if (bhavecancel && (!ucancelsequence || uaccountsequencenext - 1 <= ucancelsequence)) { if (m_journal.debug) m_journal.debug << "uaccountsequencenext=" << uaccountsequencenext << " uoffersequence=" << ucancelsequence; terresult = tembad_sequence; } if (terresult != tessuccess) { if (m_journal.debug) m_journal.debug << "final terresult=" << transtoken (terresult); return terresult; } // process a cancellation request that's passed along with an offer. if ((terresult == tessuccess) && bhavecancel) { uint256 const ucancelindex ( getofferindex (mtxnaccountid, ucancelsequence)); sle::pointer slecancel = mengine->entrycache (ltoffer, ucancelindex); // it's not an error to not find the offer to cancel: it might have // been consumed or removed as we are processing. if (slecancel) { m_journal.warning << "cancelling order with sequence " << ucancelsequence; terresult = view.offerdelete (slecancel); } } // expiration is defined in terms of the close time of the parent ledger, // because we definitively know the time that it closed but we do not // know the closing time of the ledger that is under construction. if (bhaveexpiration && (mengine->getledger ()->getparentclosetimenc () >= uexpiration)) { return tessuccess; } // make sure that we are authorized to hold what the taker will pay us. if (terresult == tessuccess && !satakerpays.isnative ()) terresult = checkacceptasset (issue (upayscurrency, upaysissuerid)); bool crossed = false; bool const bopenledger (mparams & tapopen_ledger); if (terresult == tessuccess) { // we reverse gets and pays because during offer crossing we are taking. core::amounts const taker_amount (satakergets, satakerpays); // the amount of the offer that we will need to place, after we finish // offer crossing processing. it may be equal to the original amount, // empty (fully crossed), or something in-between. core::amounts place_offer; std::tie(terresult, place_offer) = crossoffers (view, taker_amount); if (terresult == tecfailed_processing && bopenledger) terresult = telfailed_processing; if (terresult == tessuccess) { // we now need to reduce the offer by the cross flow. we reverse // in and out here, since during crossing we were takers. assert (satakerpays.getcurrency () == place_offer.out.getcurrency ()); assert (satakerpays.getissuer () == place_offer.out.getissuer ()); assert (satakergets.getcurrency () == place_offer.in.getcurrency ()); assert (satakergets.getissuer () == place_offer.in.getissuer ()); if (taker_amount != place_offer) crossed = true; if (m_journal.debug) { m_journal.debug << "offer crossing: " << transtoken (terresult); if (terresult == tessuccess) { m_journal.debug << " takerpays: " << satakerpays.getfulltext () << " -> " << place_offer.out.getfulltext (); m_journal.debug << " takergets: " << satakergets.getfulltext () << " -> " << place_offer.in.getfulltext (); } } satakerpays = place_offer.out; satakergets = place_offer.in; } } if (terresult != tessuccess) { m_journal.debug << "final terresult=" << transtoken (terresult); return terresult; } if (m_journal.debug) { m_journal.debug << "takeoffers: satakerpays=" <<satakerpays.getfulltext (); m_journal.debug << "takeoffers: satakergets=" << satakergets.getfulltext (); m_journal.debug << "takeoffers: mtxnaccountid=" << to_string (mtxnaccountid); m_journal.debug << "takeoffers: funds=" << view.accountfunds ( mtxnaccountid, satakergets, fhzero_if_frozen).getfulltext (); } if (satakerpays < zero || satakergets < zero) { // earlier, we verified that the amounts, as specified in the offer, // were not negative. that they are now suggests that something went // very wrong with offer crossing. m_journal.fatal << (crossed ? "partially consumed" : "full") << " offer has negative component:" << " pays=" << satakerpays.getfulltext () << " gets=" << satakergets.getfulltext (); assert (satakerpays >= zero); assert (satakergets >= zero); return tefinternal; } if (bfillorkill && (satakerpays != zero || satakergets != zero)) { // fill or kill and have leftovers. view.swapwith (view_checkpoint); // restore with just fees paid. return tessuccess; } // what the reserve would be if this offer was placed. auto const accountreserve (mengine->getledger ()->getreserve ( slecreator->getfieldu32 (sfownercount) + 1)); if (satakerpays == zero || // wants nothing more. satakergets == zero || // offering nothing more. bimmediateorcancel) // do not persist. { // complete as is. } else if (mpriorbalance.getnvalue () < accountreserve) { // if we are here, the signing account had an insufficient reserve // *prior* to our processing. we use the prior balance to simplify // client writing and make the user experience better. if (bopenledger) // ledger is not final, can vote no. { // hope for more reserve to come in or more offers to consume. if we // specified a local error this transaction will not be retried, so // specify a tec to distribute the transaction and allow it to be // retried. in particular, it may have been successful to a // degree (partially filled) and if it hasn't, it might succeed. terresult = tecinsuf_reserve_offer; } else if (!crossed) { // ledger is final, insufficent reserve to create offer, processed // nothing. terresult = tecinsuf_reserve_offer; } else { // ledger is final, insufficent reserve to create offer, processed // something. // consider the offer unfunded. treat as tessuccess. } } else { assert (satakerpays > zero); assert (satakergets > zero); // we need to place the remainder of the offer into its order book. if (m_journal.debug) m_journal.debug << "offer not fully consumed:" << " satakerpays=" << satakerpays.getfulltext () << " satakergets=" << satakergets.getfulltext (); std::uint64_t uownernode; std::uint64_t ubooknode; uint256 udirectory; // add offer to owner's directory. terresult = view.diradd (uownernode, getownerdirindex (mtxnaccountid), uledgerindex, std::bind ( &ledger::ownerdirdescriber, std::placeholders::_1, std::placeholders::_2, mtxnaccountid)); if (tessuccess == terresult) { // update owner count. view.incrementownercount (slecreator); uint256 const ubookbase (getbookbase ( {{upayscurrency, upaysissuerid}, {ugetscurrency, ugetsissuerid}})); if (m_journal.debug) m_journal.debug << "adding to book: " << to_string (ubookbase) << " : " << satakerpays.gethumancurrency () << "/" << to_string (satakerpays.getissuer ()) << " -> " << satakergets.gethumancurrency () << "/" << to_string (satakergets.getissuer ()); // we use the original rate to place the offer. udirectory = getqualityindex (ubookbase, urate); // add offer to order book. terresult = view.diradd (ubooknode, udirectory, uledgerindex, std::bind ( &ledger::qualitydirdescriber, std::placeholders::_1, std::placeholders::_2, satakerpays.getcurrency (), upaysissuerid, satakergets.getcurrency (), ugetsissuerid, urate)); } if (tessuccess == terresult) { if (m_journal.debug) { m_journal.debug << "sfaccount=" << to_string (mtxnaccountid); m_journal.debug << "upaysissuerid=" << to_string (upaysissuerid); m_journal.debug << "ugetsissuerid=" << to_string (ugetsissuerid); m_journal.debug << "satakerpays.isnative()=" << satakerpays.isnative (); m_journal.debug << "satakergets.isnative()=" << satakergets.isnative (); m_journal.debug << "upayscurrency=" << satakerpays.gethumancurrency (); m_journal.debug << "ugetscurrency=" << satakergets.gethumancurrency (); } sle::pointer sleoffer (mengine->entrycreate (ltoffer, uledgerindex)); sleoffer->setfieldaccount (sfaccount, mtxnaccountid); sleoffer->setfieldu32 (sfsequence, usequence); sleoffer->setfieldh256 (sfbookdirectory, udirectory); sleoffer->setfieldamount (sftakerpays, satakerpays); sleoffer->setfieldamount (sftakergets, satakergets); sleoffer->setfieldu64 (sfownernode, uownernode); sleoffer->setfieldu64 (sfbooknode, ubooknode); if (uexpiration) sleoffer->setfieldu32 (sfexpiration, uexpiration); if (bpassive) sleoffer->setflag (lsfpassive); if (bsell) sleoffer->setflag (lsfsell); if (m_journal.debug) m_journal.debug << "final terresult=" << transtoken (terresult) << " sleoffer=" << sleoffer->getjson (0); } } if (terresult != tessuccess) { m_journal.debug << "final terresult=" << transtoken (terresult); } return terresult; }
TER PathCursor::deliverNodeForward ( AccountID const& uInAccountID, // --> Input owner's account. STAmount const& saInReq, // --> Amount to deliver. STAmount& saInAct, // <-- Amount delivered, this invocation. STAmount& saInFees) const // <-- Fees charged, this invocation. { TER resultCode = tesSUCCESS; // Don't deliver more than wanted. // Zeroed in reverse pass. node().directory.restart(multiQuality_); saInAct.clear (saInReq); saInFees.clear (saInReq); int loopCount = 0; // XXX Perhaps make sure do not exceed node().saRevDeliver as another way to // stop? while (resultCode == tesSUCCESS && saInAct + saInFees < saInReq) { // Did not spend all inbound deliver funds. if (++loopCount > CALC_NODE_DELIVER_MAX_LOOPS) { WriteLog (lsWARNING, RippleCalc) << "deliverNodeForward: max loops cndf"; return telFAILED_PROCESSING; } // Determine values for pass to adjust saInAct, saInFees, and // node().saFwdDeliver. advanceNode (saInAct, false); // If needed, advance to next funded offer. if (resultCode != tesSUCCESS) { } else if (!node().offerIndex_) { WriteLog (lsWARNING, RippleCalc) << "deliverNodeForward: INTERNAL ERROR: Ran out of offers."; return telFAILED_PROCESSING; } else if (resultCode == tesSUCCESS) { // Doesn't charge input. Input funds are in limbo. // There's no fee if we're transferring XRP, if the sender is the // issuer, or if the receiver is the issuer. bool noFee = isXRP (previousNode().issue_) || uInAccountID == previousNode().issue_.account || node().offerOwnerAccount_ == previousNode().issue_.account; const STAmount saInFeeRate = noFee ? saOne : previousNode().transferRate_; // Transfer rate of issuer. // First calculate assuming no output fees: saInPassAct, // saInPassFees, saOutPassAct. // Offer maximum out - limited by funds with out fees. auto saOutFunded = std::min ( node().saOfferFunds, node().saTakerGets); // Offer maximum out - limit by most to deliver. auto saOutPassFunded = std::min ( saOutFunded, node().saRevDeliver - node().saFwdDeliver); // Offer maximum in - Limited by by payout. auto saInFunded = mulRound ( saOutPassFunded, node().saOfrRate, node().saTakerPays.issue (), true); // Offer maximum in with fees. auto saInTotal = mulRound (saInFunded, saInFeeRate, saInFunded.issue (), true); auto saInRemaining = saInReq - saInAct - saInFees; if (saInRemaining < zero) saInRemaining.clear(); // In limited by remaining. auto saInSum = std::min (saInTotal, saInRemaining); // In without fees. auto saInPassAct = std::min ( node().saTakerPays, divRound ( saInSum, saInFeeRate, saInSum.issue (), true)); // Out limited by in remaining. auto outPass = divRound ( saInPassAct, node().saOfrRate, node().saTakerGets.issue (), true); STAmount saOutPassMax = std::min (saOutPassFunded, outPass); STAmount saInPassFeesMax = saInSum - saInPassAct; // Will be determined by next node(). STAmount saOutPassAct; // Will be determined by adjusted saInPassAct. STAmount saInPassFees; WriteLog (lsTRACE, RippleCalc) << "deliverNodeForward:" << " nodeIndex_=" << nodeIndex_ << " saOutFunded=" << saOutFunded << " saOutPassFunded=" << saOutPassFunded << " node().saOfferFunds=" << node().saOfferFunds << " node().saTakerGets=" << node().saTakerGets << " saInReq=" << saInReq << " saInAct=" << saInAct << " saInFees=" << saInFees << " saInFunded=" << saInFunded << " saInTotal=" << saInTotal << " saInSum=" << saInSum << " saInPassAct=" << saInPassAct << " saOutPassMax=" << saOutPassMax; // FIXME: We remove an offer if WE didn't want anything out of it? if (!node().saTakerPays || saInSum <= zero) { WriteLog (lsDEBUG, RippleCalc) << "deliverNodeForward: Microscopic offer unfunded."; // After math offer is effectively unfunded. pathState_.unfundedOffers().push_back (node().offerIndex_); node().bEntryAdvance = true; continue; } if (!saInFunded) { // Previous check should catch this. WriteLog (lsWARNING, RippleCalc) << "deliverNodeForward: UNREACHABLE REACHED"; // After math offer is effectively unfunded. pathState_.unfundedOffers().push_back (node().offerIndex_); node().bEntryAdvance = true; continue; } if (!isXRP(nextNode().account_)) { // ? --> OFFER --> account // Input fees: vary based upon the consumed offer's owner. // Output fees: none as XRP or the destination account is the // issuer. saOutPassAct = saOutPassMax; saInPassFees = saInPassFeesMax; WriteLog (lsTRACE, RippleCalc) << "deliverNodeForward: ? --> OFFER --> account:" << " offerOwnerAccount_=" << node().offerOwnerAccount_ << " nextNode().account_=" << nextNode().account_ << " saOutPassAct=" << saOutPassAct << " saOutFunded=" << saOutFunded; // Output: Debit offer owner, send XRP or non-XPR to next // account. resultCode = ledger().accountSend ( node().offerOwnerAccount_, nextNode().account_, saOutPassAct); if (resultCode != tesSUCCESS) break; } else { // ? --> OFFER --> offer // // Offer to offer means current order book's output currency and // issuer match next order book's input current and issuer. // // Output fees: possible if issuer has fees and is not on either // side. STAmount saOutPassFees; // Output fees vary as the next nodes offer owners may vary. // Therefore, immediately push through output for current offer. resultCode = increment().deliverNodeForward ( node().offerOwnerAccount_, // --> Current holder. saOutPassMax, // --> Amount available. saOutPassAct, // <-- Amount delivered. saOutPassFees); // <-- Fees charged. if (resultCode != tesSUCCESS) break; if (saOutPassAct == saOutPassMax) { // No fees and entire output amount. saInPassFees = saInPassFeesMax; } else { // Fraction of output amount. // Output fees are paid by offer owner and not passed to // previous. assert (saOutPassAct < saOutPassMax); auto inPassAct = mulRound ( saOutPassAct, node().saOfrRate, saInReq.issue (), true); saInPassAct = std::min (node().saTakerPays, inPassAct); auto inPassFees = mulRound ( saInPassAct, saInFeeRate, saInPassAct.issue (), true); saInPassFees = std::min (saInPassFeesMax, inPassFees); } // Do outbound debiting. // Send to issuer/limbo total amount including fees (issuer gets // fees). auto const& id = isXRP(node().issue_) ? xrpAccount() : node().issue_.account; auto outPassTotal = saOutPassAct + saOutPassFees; ledger().accountSend ( node().offerOwnerAccount_, id, outPassTotal); WriteLog (lsTRACE, RippleCalc) << "deliverNodeForward: ? --> OFFER --> offer:" << " saOutPassAct=" << saOutPassAct << " saOutPassFees=" << saOutPassFees; } WriteLog (lsTRACE, RippleCalc) << "deliverNodeForward: " << " nodeIndex_=" << nodeIndex_ << " node().saTakerGets=" << node().saTakerGets << " node().saTakerPays=" << node().saTakerPays << " saInPassAct=" << saInPassAct << " saInPassFees=" << saInPassFees << " saOutPassAct=" << saOutPassAct << " saOutFunded=" << saOutFunded; // Funds were spent. node().bFundsDirty = true; // Do inbound crediting. // // Credit offer owner from in issuer/limbo (input transfer fees left // with owner). Don't attempt to have someone credit themselves, it // is redundant. if (isXRP (previousNode().issue_.currency) || uInAccountID != node().offerOwnerAccount_) { auto id = !isXRP(previousNode().issue_.currency) ? uInAccountID : xrpAccount(); resultCode = ledger().accountSend ( id, node().offerOwnerAccount_, saInPassAct); if (resultCode != tesSUCCESS) break; } // Adjust offer. // // Fees are considered paid from a seperate budget and are not named // in the offer. STAmount saTakerGetsNew = node().saTakerGets - saOutPassAct; STAmount saTakerPaysNew = node().saTakerPays - saInPassAct; if (saTakerPaysNew < zero || saTakerGetsNew < zero) { WriteLog (lsWARNING, RippleCalc) << "deliverNodeForward: NEGATIVE:" << " saTakerPaysNew=" << saTakerPaysNew << " saTakerGetsNew=" << saTakerGetsNew; resultCode = telFAILED_PROCESSING; break; } node().sleOffer->setFieldAmount (sfTakerGets, saTakerGetsNew); node().sleOffer->setFieldAmount (sfTakerPays, saTakerPaysNew); ledger().entryModify (node().sleOffer); if (saOutPassAct == saOutFunded || saTakerGetsNew == zero) { // Offer became unfunded. WriteLog (lsDEBUG, RippleCalc) << "deliverNodeForward: unfunded:" << " saOutPassAct=" << saOutPassAct << " saOutFunded=" << saOutFunded; pathState_.unfundedOffers().push_back (node().offerIndex_); node().bEntryAdvance = true; } else { CondLog (saOutPassAct >= saOutFunded, lsWARNING, RippleCalc) << "deliverNodeForward: TOO MUCH:" << " saOutPassAct=" << saOutPassAct << " saOutFunded=" << saOutFunded; assert (saOutPassAct < saOutFunded); } saInAct += saInPassAct; saInFees += saInPassFees; // Adjust amount available to next node(). node().saFwdDeliver = std::min (node().saRevDeliver, node().saFwdDeliver + saOutPassAct); } } WriteLog (lsTRACE, RippleCalc) << "deliverNodeForward<" << " nodeIndex_=" << nodeIndex_ << " saInAct=" << saInAct << " saInFees=" << saInFees; return resultCode; }
int fetch_decode(int bk_cycle){ //printf("in fetch_decode\n"); executed_ins = NULL; int free_slot; int fetch_count=0; free_slot= 4- cpre_issue->count; int i; struct decoded_ins *new_ins; for(i=0;i<2;i++){ if(free_slot ==0){ return fetch_count; } if(waiting_ins !=NULL){ //pending branch ins execute_branch(waiting_ins); return fetch_count; } new_ins = cr_decoded_ins(mem[adr2sub(pc)]); int opcode; opcode = get_opcode(new_ins->binary); //handle special instructions switch (opcode){ case 27:{ //NOP pc +=4; executed_ins = new_ins; fetch_count++; return fetch_count; } case 16:{ //JUMP pc = new_ins->imd26 * 4; executed_ins = new_ins; fetch_count++; return fetch_count; } case 17:{ //JR pc = reg[new_ins->rs]; executed_ins = new_ins; fetch_count++; return fetch_count; } case 21:{ //BREAK executed_ins = new_ins; issue(); alu1(); alu2(); memory(); wb(); cout_state(bk_cycle,output_file); ///this cycle I decided manually exit(0); } case 18: case 19: case 20:{ if(execute_branch(new_ins)){ //if succeed, return fetch_count++; return fetch_count; }else{ //if failed, put in waiting_ins, return waiting_ins= new_ins; fetch_count++; return fetch_count; } } }//end of special case switch enq_preissue(new_ins); fetch_count++; free_slot--; pc+=4; }//end of for loop return fetch_count; }
void Updates::buildQuery() { Query = QString("/update-new.php?uuid=%1&version=%2").arg(ConfigurationManager::instance()->uuid().toString()).arg(Core::version()); if (Application::instance()->configuration()->deprecatedApi()->readBoolEntry("General", "SendSysInfo"), true) { QString platform("&system="); #if defined(Q_OS_LINUX) platform.append("Linux-"); QFile issue("/etc/issue"); if (issue.open(QIODevice::ReadOnly | QIODevice::Text)) { QString tmp = issue.readLine(); tmp.truncate(tmp.indexOf(" ")); platform.append(tmp); issue.close(); } else platform.append("Unknown"); #elif defined(Q_OS_FREEBSD) platform.append("FreeBSD"); #elif defined(Q_OS_NETBSD) platform.append("NetBSD"); #elif defined(Q_OS_OPENBSD) platform.append("OpenBSD"); #elif defined(Q_OS_SOLARIS) platform.append("Solaris"); #elif defined(Q_OS_MAC) switch (QSysInfo::MacintoshVersion) { case QSysInfo::MV_PANTHER: platform.append("MacOSX-Panther"); break; case QSysInfo::MV_TIGER: platform.append("MacOSX-Tiger"); break; case QSysInfo::MV_LEOPARD: platform.append("MacOSX-Leopard"); break; case QSysInfo::MV_SNOWLEOPARD: platform.append("MacOSX-SnowLeopard"); break; default: platform.append("MacOSX-Unknown"); break; } #elif defined(Q_OS_WIN) switch (QSysInfo::WindowsVersion) { case QSysInfo::WV_95: platform.append("Windows95"); break; case QSysInfo::WV_98: platform.append("Windows98"); break; case QSysInfo::WV_Me: platform.append("WindowsME"); break; case QSysInfo::WV_NT: platform.append("WindowsNT"); break; case QSysInfo::WV_2000: platform.append("Windows2000"); break; case QSysInfo::WV_XP: platform.append("WindowsXP"); break; case QSysInfo::WV_2003: platform.append("Windows2003"); break; case QSysInfo::WV_VISTA: platform.append("WindowsVista"); break; case QSysInfo::WV_WINDOWS7: platform.append("Windows7"); break; default: platform.append("Windows-Unknown"); break; } #elif defined(Q_OS_HAIKU) platform.append("Haiku OS"); #else platform.append("Unknown"); #endif Query.append(platform); } }
bool ANFparser::parse(Scene * scene,const char* filename){ this->scene = scene; try{ TiXmlDocument * doc = new TiXmlDocument(filename); //First things first, reading the XML/ANF file if (!doc->LoadFile()){ issue("Could not load file '%"+str(filename)+"'. Error='" + str(doc->ErrorDesc()) + "'.", ERROR); } //Must exist anf root block TiXmlElement* anfRoot = doc->FirstChildElement("anf"); if (!anfRoot){ issue("Main block 'anf' block not found!",ERROR); } //Lets process the global variables TiXmlElement* anfGlobals = anfRoot->FirstChildElement("globals"); if(!anfGlobals){ issue("Block 'globals' not found!",WARNING); }else{ parseGlobals(anfGlobals); } //Lets process the cameras TiXmlElement* anfCameras = anfRoot->FirstChildElement("cameras"); if(!anfCameras){ issue("Block 'cameras' not found!",ERROR); }else{ std::string firstCameraId = str(anfCameras->Attribute("initial")); if(firstCameraId == "" ){ issue("Cameras block must declare the first camera.. ", WARNING); } parseCameras(anfCameras,firstCameraId); } //Lets process the lights TiXmlElement* anfLights = anfRoot->FirstChildElement("lights"); if(!anfLights){ issue("Block 'lights' not found!",WARNING); }else{ parseLights(anfLights); } //If textures extist, we process it TiXmlElement* anfTextures = anfRoot->FirstChildElement("textures"); map<std::string,Texture *> textures; if(!anfTextures){ issue("Block 'textures' not found!",WARNING); }else{ parseTextures(anfTextures,textures); } //If appearances block exist, we call its parser TiXmlElement* anfAppearances = anfRoot->FirstChildElement("appearances"); map<std::string,Appearance *> appearances; if(!anfAppearances){ issue("Block 'appearances' not found!",WARNING); }else{ parseAppearances(anfAppearances,appearances,textures); } //If animations extist, we process it TiXmlElement* anfAnimations = anfRoot->FirstChildElement("animations"); map<std::string,Animation *> animations; if(!anfAnimations){ issue("Block 'animations' not found!",WARNING); }else{ parseAnimations(anfAnimations,animations); } //If graph block exist, we call its parser TiXmlElement* anfGraph = anfRoot->FirstChildElement("graph"); if(!anfGraph){ issue("Block 'graph' not found!",ERROR); }else{ this->scene->setRoot(parseGraph(anfGraph,appearances,animations)); } return true; }catch(...){ return false; } }