Skip to content

Commit

Permalink
add timestamp counter information into the vcpu_t class
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Aug 1, 2019
1 parent 3a41720 commit 56fc522
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/hvpp/hvpp/vcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ auto vcpu_t::guest_write_memory(va_t guest_va, const void* buffer, size_t size,
return translator_.write(guest_va, ::detail::kernel_cr3(guest_cr3()), buffer, size, ignore_errors);
}

auto vcpu_t::tsc_entry() const noexcept -> uint64_t
{
return tsc_entry_;
}

auto vcpu_t::tsc_delta_previous() const noexcept -> uint64_t
{
return tsc_delta_previous_;
}

auto vcpu_t::tsc_delta_sum() const noexcept -> uint64_t
{
return tsc_delta_sum_;
}

//
// Private
//
Expand Down Expand Up @@ -748,6 +763,8 @@ void vcpu_t::entry_host() noexcept
hvpp_assert(state_ == state::running ||
state_ == state::terminating);

tsc_entry_ = ia32_asm_read_tsc();

//
// Reset RIP-adjust flag.
//
Expand Down Expand Up @@ -840,6 +857,9 @@ void vcpu_t::entry_host() noexcept

exit:
ia32_asm_fx_restore(&fxsave_area_);

tsc_delta_previous_ = ia32_asm_read_tsc() - tsc_entry_;
tsc_delta_sum_ += tsc_delta_previous_;
}

void vcpu_t::entry_guest() noexcept
Expand Down
7 changes: 7 additions & 0 deletions src/hvpp/hvpp/vcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class vcpu_t final
auto guest_read_memory(va_t guest_va, void* buffer, size_t size, bool ignore_errors = false) noexcept -> va_t;
auto guest_write_memory(va_t guest_va, const void* buffer, size_t size, bool ignore_errors = false) noexcept -> va_t;

auto tsc_entry() const noexcept -> uint64_t;
auto tsc_delta_previous() const noexcept -> uint64_t;
auto tsc_delta_sum() const noexcept -> uint64_t;

//
// VMCS manipulation. Implementation is in vcpu.inl.
//
Expand Down Expand Up @@ -399,6 +403,9 @@ class vcpu_t final
mm::memory_mapper mapper_;
mm::memory_translator translator_;

uint64_t tsc_entry_;
uint64_t tsc_delta_previous_;
uint64_t tsc_delta_sum_;

//
// Pending interrupt queue (FIFO).
Expand Down

0 comments on commit 56fc522

Please sign in to comment.