Skip to content

Commit

Permalink
Moves the calculation of due_insn_count from the VM into the JIT epil…
Browse files Browse the repository at this point in the history
…ogue.
  • Loading branch information
Lichtso committed Sep 30, 2023
1 parent 9b1d33f commit 0097061
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ impl JitProgram {
_config: &Config,
vm: &mut EbpfVm<C>,
registers: [u64; 12],
) -> i64 {
) {
unsafe {
let mut instruction_meter =
(vm.previous_instruction_meter as i64).wrapping_add(registers[11] as i64);
std::arch::asm!(
// RBP and RBX must be saved and restored manually in the current version of rustc and llvm.
"push rbx",
Expand All @@ -118,19 +116,17 @@ impl JitProgram {
"mov rbp, [r11 + 0x50]",
"mov r11, [r11 + 0x58]",
"call r10",
"mov rax, rbx",
"pop rbp",
"pop rbx",
host_stack_pointer = in(reg) &mut vm.host_stack_pointer,
inlateout("rax") instruction_meter,
inlateout("rdi") (vm as *mut _ as *mut u64).offset(get_runtime_environment_key() as isize) => _,
inlateout("rax") (vm.previous_instruction_meter as i64).wrapping_add(registers[11] as i64) => _,
inlateout("r10") self.pc_section[registers[11] as usize] => _,
inlateout("r11") &registers => _,
lateout("rsi") _, lateout("rdx") _, lateout("rcx") _, lateout("r8") _,
lateout("r9") _, lateout("r12") _, lateout("r13") _, lateout("r14") _, lateout("r15") _,
// lateout("rbp") _, lateout("rbx") _,
);
instruction_meter
}
}

Expand Down Expand Up @@ -1315,6 +1311,10 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
if self.config.enable_instruction_meter {
self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x81, 5, REGISTER_INSTRUCTION_METER, 1, None)); // REGISTER_INSTRUCTION_METER -= 1;
self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x29, REGISTER_SCRATCH, REGISTER_INSTRUCTION_METER, 0, None)); // REGISTER_INSTRUCTION_METER -= pc;
// *DueInsnCount = *PreviousInstructionMeter - REGISTER_INSTRUCTION_METER;
self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x2B, REGISTER_INSTRUCTION_METER, REGISTER_PTR_TO_VM, 0, Some(X86IndirectAccess::Offset(self.slot_in_vm(RuntimeEnvironmentSlot::PreviousInstructionMeter))))); // REGISTER_INSTRUCTION_METER -= *PreviousInstructionMeter;
self.emit_ins(X86Instruction::alu(OperandSize::S64, 0xf7, 3, REGISTER_INSTRUCTION_METER, 0, None)); // REGISTER_INSTRUCTION_METER = -REGISTER_INSTRUCTION_METER;
self.emit_ins(X86Instruction::store(OperandSize::S64, REGISTER_INSTRUCTION_METER, REGISTER_PTR_TO_VM, X86IndirectAccess::Offset(self.slot_in_vm(RuntimeEnvironmentSlot::DueInsnCount)))); // *DueInsnCount = REGISTER_INSTRUCTION_METER;
}
// Print stop watch value
fn stopwatch_result(numerator: u64, denominator: u64) {
Expand Down
7 changes: 1 addition & 6 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,7 @@ impl<'a, C: ContextObject> EbpfVm<'a, C> {
Ok(compiled_program) => compiled_program,
Err(error) => return (0, ProgramResult::Err(error)),
};
let instruction_meter_final =
compiled_program.invoke(config, self, self.registers).max(0) as u64;
self.due_insn_count = self
.context_object_pointer
.get_remaining()
.saturating_sub(instruction_meter_final);
compiled_program.invoke(config, self, self.registers);
}
#[cfg(not(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64")))]
{
Expand Down

0 comments on commit 0097061

Please sign in to comment.