Bugfix for ALUInstr

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1743 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
unzner
2012-10-13 22:02:09 +00:00
parent c9f1a5dbb8
commit 111cf2dc97
4 changed files with 37 additions and 10 deletions

View File

@ -92,14 +92,14 @@ bool BochsALUInstructions::isALUInstruction(bxInstruction_c const *src) {
return false; return false;
} }
void BochsALUInstructions::randomEquivalent(bxInstruction_c &result, int BochsALUInstructions::randomEquivalent(bxInstruction_c &result,
std::string &details) const { std::string &details) const {
// find a random member of the same equivalence class // find a random member of the same equivalence class
X86AluClass equClassID = lastInstr.aluClass; X86AluClass equClassID = lastInstr.aluClass;
if (equClassID == ALU_UNDEF) { if (equClassID == ALU_UNDEF) {
// something went wrong - just return the original instruction // something went wrong - just return the original instruction
result = lastOrigInstr; result = lastOrigInstr;
return; return 10;
} }
InstrList const &destList = equivalenceClasses.at(equClassID); InstrList const &destList = equivalenceClasses.at(equClassID);
@ -108,7 +108,7 @@ void BochsALUInstructions::randomEquivalent(bxInstruction_c &result,
do { do {
int index = rand() % destList.size(); int index = rand() % destList.size();
dest = destList[index]; dest = destList[index];
} while (memcmp(&dest, &lastInstr, sizeof(BochsALUInstr)) == 0); } while (dest == lastInstr);
// alternative chosen -- now store the necessary details // alternative chosen -- now store the necessary details
std::ostringstream oss; std::ostringstream oss;
@ -136,6 +136,13 @@ void BochsALUInstructions::randomEquivalent(bxInstruction_c &result,
if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) { if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) {
result.setRm(dest.opcodeRegisterOffset); result.setRm(dest.opcodeRegisterOffset);
} }
if (memcmp(&result, &lastOrigInstr, sizeof(bxInstruction_c)) == 0) {
fprintf(stderr,"randomEquivalent failed\n");
scanf("%*s");
}
return 0;
} }
#ifdef DEBUG #ifdef DEBUG

View File

@ -76,6 +76,24 @@ struct BochsALUInstr {
* the count of registers * the count of registers
*/ */
static const unsigned REG_COUNT = 8; static const unsigned REG_COUNT = 8;
/**
* returns true if obj equals this object
* the Bochs opcode is generated dynamically and thus not relevant for comparison
*/
bool operator==(BochsALUInstr const &obj) const
{
return opcode == obj.opcode &&
reg == obj.reg &&
opcodeRegisterOffset == obj.opcodeRegisterOffset &&
aluClass == obj.aluClass;
}
/**
* returns false if obj equals this object
* \see operator==
*/
bool operator!=(BochsALUInstr const &obj) const {
return !(*this == obj);
}
}; };
@ -325,7 +343,7 @@ public:
* @param result the resulting bxInstruction_c object as described above * @param result the resulting bxInstruction_c object as described above
* @param details after completion contains details about \c result * @param details after completion contains details about \c result
*/ */
void randomEquivalent(bxInstruction_c &result, std::string &details) const; int randomEquivalent(bxInstruction_c &result, std::string &details) const;
protected: protected:
/** /**
* Convert a bxInstruction_c object into its matching BochsALUInstr object. * Convert a bxInstruction_c object into its matching BochsALUInstr object.

View File

@ -162,10 +162,10 @@ void L4SysExperiment::injectInstruction(bxInstruction_c *oldInstr, bxInstruction
memcpy(oldInstr, &backupInstr, sizeof(bxInstruction_c)); memcpy(oldInstr, &backupInstr, sizeof(bxInstruction_c));
} }
unsigned L4SysExperiment::calculateTimeout() { unsigned L4SysExperiment::calculateTimeout(unsigned instr_left) {
// the timeout in seconds, plus one backup second (avoids rounding overhead) // the timeout in seconds, plus one backup second (avoids rounding overhead)
// [instr] / [instr / s] = [s] // [instr] / [instr / s] = [s]
unsigned seconds = L4SYS_NUMINSTR / L4SYS_BOCHS_IPS + 1; unsigned seconds = instr_left / L4SYS_BOCHS_IPS + 1;
// 1.1 (+10 percent) * 1000 ms/s * [s] // 1.1 (+10 percent) * 1000 ms/s * [s]
return 1100 * seconds; return 1100 * seconds;
} }
@ -600,7 +600,7 @@ bool L4SysExperiment::run() {
// now exchange it with a random equivalent // now exchange it with a random equivalent
bxInstruction_c newInstr; bxInstruction_c newInstr;
string details; string details;
aluInstrObject.randomEquivalent(newInstr, details); int result = aluInstrObject.randomEquivalent(newInstr, details);
if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) { if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) {
// something went wrong - exit experiment // something went wrong - exit experiment
param.msg.set_resulttype(param.msg.UNKNOWN); param.msg.set_resulttype(param.msg.UNKNOWN);
@ -627,10 +627,12 @@ bool L4SysExperiment::run() {
// aftermath // aftermath
BPSingleListener ev_done(L4SYS_FUNC_EXIT, L4SYS_ADDRESS_SPACE); BPSingleListener ev_done(L4SYS_FUNC_EXIT, L4SYS_ADDRESS_SPACE);
simulator.addListener(&ev_done); simulator.addListener(&ev_done);
unsigned instr_left = L4SYS_NUMINSTR - instr_offset;
BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE); BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE);
ev_incomplete.setCounter(static_cast<unsigned>(L4SYS_NUMINSTR * 1.1)); ev_incomplete.setCounter(
static_cast<unsigned>(instr_left * 1.1));
simulator.addListener(&ev_incomplete); simulator.addListener(&ev_incomplete);
TimerListener ev_timeout(calculateTimeout()); TimerListener ev_timeout(calculateTimeout(instr_left));
simulator.addListener(&ev_timeout); simulator.addListener(&ev_timeout);
//do not discard output recorded so far //do not discard output recorded so far

View File

@ -73,7 +73,7 @@ private:
/** /**
* Calculate the timeout of the current workload in milliseconds. * Calculate the timeout of the current workload in milliseconds.
*/ */
unsigned calculateTimeout(); unsigned calculateTimeout(unsigned instr_left);
}; };
#endif // __L4SYS_EXPERIMENT_HPP__ #endif // __L4SYS_EXPERIMENT_HPP__