/** * hwmp_route_info_get - Update routing info to originator and transmitter * * @sdata: local mesh subif * @mgmt: mesh management frame * @hwmp_ie: hwmp information element (PREP or PREQ) * @action: type of hwmp ie * * This function updates the path routing information to the originator and the * transmitter of a HWMP PREQ or PREP frame. * * Returns: metric to frame originator or 0 if the frame should not be further * processed * * Notes: this function is the only place (besides user-provided info) where * path routing information is updated. */ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt, const u8 *hwmp_ie, enum mpath_frame_type action) { struct ieee80211_local *local = sdata->local; struct mesh_path *mpath; struct sta_info *sta; bool fresh_info; const u8 *orig_addr, *ta; u32 orig_sn, orig_metric; unsigned long orig_lifetime, exp_time; u32 last_hop_metric, new_metric; bool process = true; rcu_read_lock(); sta = sta_info_get(sdata, mgmt->sa); if (!sta) { rcu_read_unlock(); return 0; } last_hop_metric = airtime_link_metric_get(local, sta); /* Update and check originator routing info */ fresh_info = true; switch (action) { case MPATH_PREQ: orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie); orig_sn = PREQ_IE_ORIG_SN(hwmp_ie); orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie); orig_metric = PREQ_IE_METRIC(hwmp_ie); break; case MPATH_PREP: /* Originator here refers to the MP that was the target in the * Path Request. We divert from the nomenclature in the draft * so that we can easily use a single function to gather path * information from both PREQ and PREP frames. */ orig_addr = PREP_IE_TARGET_ADDR(hwmp_ie); orig_sn = PREP_IE_TARGET_SN(hwmp_ie); orig_lifetime = PREP_IE_LIFETIME(hwmp_ie); orig_metric = PREP_IE_METRIC(hwmp_ie); break; default: rcu_read_unlock(); return 0; } new_metric = orig_metric + last_hop_metric; if (new_metric < orig_metric) new_metric = MAX_METRIC; exp_time = TU_TO_EXP_TIME(orig_lifetime); if (ether_addr_equal(orig_addr, sdata->vif.addr)) { /* This MP is the originator, we are not interested in this * frame, except for updating transmitter's path info. */ process = false; fresh_info = false; } else { mpath = mesh_path_lookup(sdata, orig_addr); if (mpath) { spin_lock_bh(&mpath->state_lock); if (mpath->flags & MESH_PATH_FIXED) fresh_info = false; else if ((mpath->flags & MESH_PATH_ACTIVE) && (mpath->flags & MESH_PATH_SN_VALID)) { if (SN_GT(mpath->sn, orig_sn) || (mpath->sn == orig_sn && new_metric >= mpath->metric)) { process = false; fresh_info = false; } } else if (!(mpath->flags & MESH_PATH_ACTIVE)) { bool have_sn, newer_sn, bounced; have_sn = mpath->flags & MESH_PATH_SN_VALID; newer_sn = have_sn && SN_GT(orig_sn, mpath->sn); bounced = have_sn && (SN_DELTA(orig_sn, mpath->sn) > MAX_SANE_SN_DELTA); if (!have_sn || newer_sn) { /* if SN is newer than what we had * then we can take it */; } else if (bounced) { /* if SN is way different than what * we had then assume the other side * rebooted or restarted */; } else { process = false; fresh_info = false; } } } else { mpath = mesh_path_add(sdata, orig_addr); if (IS_ERR(mpath)) { rcu_read_unlock(); return 0; } spin_lock_bh(&mpath->state_lock); } if (fresh_info) { mesh_path_assign_nexthop(mpath, sta); mpath->flags |= MESH_PATH_SN_VALID; mpath->metric = new_metric; mpath->sn = orig_sn; mpath->exp_time = time_after(mpath->exp_time, exp_time) ? mpath->exp_time : exp_time; mesh_path_activate(mpath); spin_unlock_bh(&mpath->state_lock); ewma_mesh_fail_avg_init(&sta->mesh->fail_avg); /* init it at a low value - 0 start is tricky */ ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1); mesh_path_tx_pending(mpath); /* draft says preq_id should be saved to, but there does * not seem to be any use for it, skipping by now */ } else spin_unlock_bh(&mpath->state_lock); } /* Update and check transmitter routing info */ ta = mgmt->sa; if (ether_addr_equal(orig_addr, ta)) fresh_info = false; else { fresh_info = true; mpath = mesh_path_lookup(sdata, ta); if (mpath) { spin_lock_bh(&mpath->state_lock); if ((mpath->flags & MESH_PATH_FIXED) || ((mpath->flags & MESH_PATH_ACTIVE) && (last_hop_metric > mpath->metric))) fresh_info = false; } else { mpath = mesh_path_add(sdata, ta); if (IS_ERR(mpath)) { rcu_read_unlock(); return 0; } spin_lock_bh(&mpath->state_lock); } if (fresh_info) { mesh_path_assign_nexthop(mpath, sta); mpath->metric = last_hop_metric; mpath->exp_time = time_after(mpath->exp_time, exp_time) ? mpath->exp_time : exp_time; mesh_path_activate(mpath); spin_unlock_bh(&mpath->state_lock); ewma_mesh_fail_avg_init(&sta->mesh->fail_avg); /* init it at a low value - 0 start is tricky */ ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1); mesh_path_tx_pending(mpath); } else spin_unlock_bh(&mpath->state_lock); } rcu_read_unlock(); return process ? new_metric : 0; }
bool LCovSource::writeScript(JSScript* script) { numFunctionsFound_++; outFN_.printf("FN:%d,", script->lineno()); if (!writeScriptName(outFN_, script)) return false; outFN_.put("\n", 1); uint64_t hits = 0; ScriptCounts* sc = nullptr; if (script->hasScriptCounts()) { sc = &script->getScriptCounts(); numFunctionsHit_++; const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(script->main())); outFNDA_.printf("FNDA:%" PRIu64 ",", counts->numExec()); if (!writeScriptName(outFNDA_, script)) return false; outFNDA_.put("\n", 1); // Set the hit count of the pre-main code to 1, if the function ever got // visited. hits = 1; } jsbytecode* snpc = script->code(); jssrcnote* sn = script->notes(); if (!SN_IS_TERMINATOR(sn)) snpc += SN_DELTA(sn); size_t lineno = script->lineno(); jsbytecode* end = script->codeEnd(); size_t branchId = 0; size_t tableswitchExitOffset = 0; for (jsbytecode* pc = script->code(); pc != end; pc = GetNextPc(pc)) { JSOp op = JSOp(*pc); bool jump = IsJumpOpcode(op) || op == JSOP_TABLESWITCH; bool fallsthrough = BytecodeFallsThrough(op) && op != JSOP_GOSUB; // If the current script & pc has a hit-count report, then update the // current number of hits. if (sc) { const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(pc)); if (counts) hits = counts->numExec(); } // If we have additional source notes, walk all the source notes of the // current pc. if (snpc <= pc) { size_t oldLine = lineno; while (!SN_IS_TERMINATOR(sn) && snpc <= pc) { SrcNoteType type = (SrcNoteType) SN_TYPE(sn); if (type == SRC_SETLINE) lineno = size_t(GetSrcNoteOffset(sn, 0)); else if (type == SRC_NEWLINE) lineno++; else if (type == SRC_TABLESWITCH) tableswitchExitOffset = GetSrcNoteOffset(sn, 0); sn = SN_NEXT(sn); snpc += SN_DELTA(sn); } if (oldLine != lineno && fallsthrough) { outDA_.printf("DA:%d,%" PRIu64 "\n", lineno, hits); // Count the number of lines instrumented & hit. numLinesInstrumented_++; if (hits) numLinesHit_++; } } // If the current instruction has thrown, then decrement the hit counts // with the number of throws. if (sc) { const PCCounts* counts = sc->maybeGetThrowCounts(script->pcToOffset(pc)); if (counts) hits -= counts->numExec(); } // If the current pc corresponds to a conditional jump instruction, then reports // branch hits. if (jump && fallsthrough) { jsbytecode* fallthroughTarget = GetNextPc(pc); uint64_t fallthroughHits = 0; if (sc) { const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(fallthroughTarget)); if (counts) fallthroughHits = counts->numExec(); } uint64_t taken = hits - fallthroughHits; outBRDA_.printf("BRDA:%d,%d,0,", lineno, branchId); if (taken) outBRDA_.printf("%d\n", taken); else outBRDA_.put("-\n", 2); outBRDA_.printf("BRDA:%d,%d,1,", lineno, branchId); if (fallthroughHits) outBRDA_.printf("%d\n", fallthroughHits); else outBRDA_.put("-\n", 2); // Count the number of branches, and the number of branches hit. numBranchesFound_ += 2; if (hits) numBranchesHit_ += !!taken + !!fallthroughHits; branchId++; } // If the current pc corresponds to a pre-computed switch case, then // reports branch hits for each case statement. if (jump && op == JSOP_TABLESWITCH) { MOZ_ASSERT(tableswitchExitOffset != 0); // Get the default and exit pc jsbytecode* exitpc = pc + tableswitchExitOffset; jsbytecode* defaultpc = pc + GET_JUMP_OFFSET(pc); MOZ_ASSERT(defaultpc > pc && defaultpc <= exitpc); // Get the low and high from the tableswitch int32_t low = GET_JUMP_OFFSET(pc + JUMP_OFFSET_LEN * 1); int32_t high = GET_JUMP_OFFSET(pc + JUMP_OFFSET_LEN * 2); MOZ_ASSERT(high - low + 1 >= 0); size_t numCases = high - low + 1; jsbytecode* jumpTable = pc + JUMP_OFFSET_LEN * 3; jsbytecode* firstcasepc = exitpc; for (size_t j = 0; j < numCases; j++) { jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j); if (testpc < firstcasepc) firstcasepc = testpc; } // Count the number of hits of the default branch, by subtracting // the number of hits of each cases. uint64_t defaultHits = hits; // Count the number of hits of the previous case entry. uint64_t fallsThroughHits = 0; // Record branches for each cases. size_t caseId = 0; for (size_t i = 0; i < numCases; i++) { jsbytecode* casepc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * i); // The case is not present, and jumps to the default pc if used. if (casepc == pc) continue; // PCs might not be in increasing order of case indexes. jsbytecode* lastcasepc = firstcasepc - 1; for (size_t j = 0; j < numCases; j++) { jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j); if (lastcasepc < testpc && (testpc < casepc || (j < i && testpc == casepc))) lastcasepc = testpc; } if (casepc != lastcasepc) { // Case (i + low) uint64_t caseHits = 0; if (sc) { const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(casepc)); if (counts) caseHits = counts->numExec(); // Remove fallthrough. fallsThroughHits = 0; if (casepc != firstcasepc) { jsbytecode* endpc = lastcasepc; while (GetNextPc(endpc) < casepc) endpc = GetNextPc(endpc); if (BytecodeFallsThrough(JSOp(*endpc))) fallsThroughHits = script->getHitCount(endpc); } caseHits -= fallsThroughHits; } outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId); if (caseHits) outBRDA_.printf("%d\n", caseHits); else outBRDA_.put("-\n", 2); numBranchesFound_++; numBranchesHit_ += !!caseHits; defaultHits -= caseHits; caseId++; } } // Compute the number of hits of the default branch, if it has its // own case clause. bool defaultHasOwnClause = true; if (defaultpc != exitpc) { defaultHits = 0; // Look for the last case entry before the default pc. jsbytecode* lastcasepc = firstcasepc - 1; for (size_t j = 0; j < numCases; j++) { jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j); if (lastcasepc < testpc && testpc <= defaultpc) lastcasepc = testpc; } if (lastcasepc == defaultpc) defaultHasOwnClause = false; // Look if the last case entry fallthrough to the default case, // in which case we have to remove the number of fallthrough // hits out of the default case hits. if (sc && lastcasepc != pc) { jsbytecode* endpc = lastcasepc; while (GetNextPc(endpc) < defaultpc) endpc = GetNextPc(endpc); if (BytecodeFallsThrough(JSOp(*endpc))) fallsThroughHits = script->getHitCount(endpc); } if (sc) { const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(defaultpc)); if (counts) defaultHits = counts->numExec(); } defaultHits -= fallsThroughHits; } if (defaultHasOwnClause) { outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId); if (defaultHits) outBRDA_.printf("%d\n", defaultHits); else outBRDA_.put("-\n", 2); numBranchesFound_++; numBranchesHit_ += !!defaultHits; } // Increment the branch identifier, and go to the next instruction. branchId++; tableswitchExitOffset = 0; } } // Report any new OOM. if (outFN_.hadOutOfMemory() || outFNDA_.hadOutOfMemory() || outBRDA_.hadOutOfMemory() || outDA_.hadOutOfMemory()) { return false; } // If this script is the top-level script, then record it such that we can // assume that the code coverage report is complete, as this script has // references on all inner scripts. if (script->isTopLevel()) hasTopLevelScript_ = true; return true; }