kvmexit(8)

πŸ’– kvmexit(8) πŸ’–

kvmexit(8) is from the System Manager's Manual, and it's giving main character energy πŸ’…βœ¨

✨ NAME ✨

kvmexit - Display the exit_reason and its statistics of each vm exit. πŸ¦‹

πŸŽ€ SYNOPSIS πŸŽ€

kvmexit [-h] [-p PID [-v VCPU | -a] ] [-t TID | -T 'TID1,TID2']
       [duration]

🌸 DESCRIPTION 🌸

okay so bestie, frequent VM exits can absolutely tank performance 😭 This tool helps you figure out which exit reasons are showing up the most, so you can go hunting for fixes that reduce or even avoid them. It shows the detailed exit reasons and the count of each VM exit for every VM running on one physical machine πŸ’œ

Under the hood, it uses a PERCPU_ARRAY called pcpuArrayA and a percpu_hash called hashA to team up and store each kvm exit reason along with its count. Here's the tea: when a vcpu exits and then re-enters, it usually keeps running on the same physical cpu it used last cycle. That's called a 'cache hit' 🧚 So the PERCPU_ARRAY tracks the 'cache hit' situation to keep things speedy, and everything else goes into the percpu_hash πŸ”₯

RAW_TRACEPOINT_PROBE(kvm_exit) uses fewer cpu cycles, so when you run this tool it tries raw tracepoints in modules first. If that fails, it falls back to a regular tracepoint πŸ™ˆ

⚠️ Limitation: Every architecture has its own hardware-assisted virtualization tech, so right now this only works with vmx on Intel. Not for everyone yet, bestie 🫢
πŸ‘‘ Since this uses BPF, only the root user can use this tool. No root, no tool, no cap.

πŸ“š REQUIREMENTS πŸ“š

  • CONFIG_BPF and bcc. πŸ“
  • Linux 4.7+ (BPF_PROG_TYPE_TRACEPOINT support) is also required. ✨

✨ OPTIONS ✨

  • -h β€” Prints the usage message. 🌈
  • -p PID β€” Shows only the process with this PID, collapses all tids together, and sorts the exit reasons in descending order. πŸ’…
  • -v VCPU β€” Shows only this VCPU for this PID. πŸ¦‹
  • -a ALLTIDS β€” Shows all TIDS for this PID. 🌸
  • -t TID β€” Shows only the thread with this TID, with exit reasons sorted in descending order. 🧚
  • -T 'TID1,TID2' β€” Shows threads for a union like {395490, 395491}. πŸ’œ
  • duration β€” How long to display, after sleeping for several seconds. ⭐

πŸŽ€ EXAMPLES πŸŽ€

Display kvm exit reasons and statistics for all threads. Hit Ctrl-C to end it, bestie πŸ’–

# kvmexit

Display kvm exit reasons and statistics for all threads after sleeping 6 secs:

# kvmexit 6

Display kvm exit reasons and statistics for PID 1273795 after sleeping 5 secs:

# kvmexit -p 1273795 5

Display kvm exit reasons and statistics for PID 1273795 and all of its threads after sleeping 5 secs:

# kvmexit -p 1273795 5 -a

Display kvm exit reasons and statistics for PID 1273795 VCPU 0. Hit Ctrl-C to end it 🫢

# kvmexit -p 1273795 -v 0

Display kvm exit reasons and statistics for PID 1273795 VCPU 0 after sleeping 4 secs:

# kvmexit -p 1273795 -v 0 4

Display kvm exit reasons and statistics for TID 1273819 after sleeping 10 secs:

# kvmexit -t 1273819 10

Display kvm exit reasons and statistics for TIDS ['1273820', '1273819']. Hit Ctrl-C to end it 🌈

# kvmexit -T '1273820,1273819'

πŸ”₯ OVERHEAD πŸ”₯

This traces the "kvm_exit" kernel function, records the exit reason, and calculates its counts. Compared to filling in more vm-exit reason debug entries, this one is way easier and more flexible 🧚 The bcc python logic gives you nice kernel aggregation and custom output, and the bpf in-kernel percpu_array and percpu_cache make it even faster πŸ’œ

The impact on the host should be negligible ✨ This tool is super efficient, but it does affect the guest virtual machine itself. Here are the average test results on the guest vm:

              | cpu cycles
   no TP      |   1127
   regular TP |   1277 (13% downgrade)
   RAW TP     |   1187 (5% downgrade)

Host setup: echo 1 > /proc/sys/net/core/bpf_jit_enable πŸ™ˆ

🌈 SOURCE 🌈

This is from bcc. πŸ¦‹

https://github.com/iovisor/bcc

Also check the bcc distribution for a companion _examples.txt file. It has example usage, output, and commentary for this tool πŸ’–

πŸ’» OS πŸ’»

Linux 🐧

⭐ STABILITY ⭐

Unstable - in development. Still cooking, bestie πŸ“

🫢 AUTHOR 🫢

Fei Li <lifei.shirley@bytedance.com> πŸ’œ


And that's the whole page, bestie πŸ’… It's filed under USER COMMANDS and was last updated 2021-07-08. Slay forever βœ¨πŸŽ€