# kvm\_pio

During some test with "perf stat", we found event "kvm\_pio" is heavy. So we decide to see who is the criminal.

## Record Events

First step is use perf record to record events.

```
perf record -e 'kvm:kvm_pio' -a sleep 30
```

This will general perf.data file.

## Dump raw data

After this, we need to take a look into the raw data.

```
perf script > pio_stat
```

Now pio\_stat contains the raw data. Here is a glance of the raw data.

```
qemu-system-x86 10042 [000] 313831.754508: kvm:kvm_pio: pio_read at 0x3fd size 1 count 1 val 0x60
qemu-system-x86 10042 [000] 313831.754515: kvm:kvm_pio: pio_read at 0x3fd size 1 count 1 val 0x60
```

## Use awk to analysis

Execute this:

```
awk -f pio_calculate.awk pio_stat | sort -nk 2 -r
```

The pio\_calculate.awk looks like:

```
{
    if ($0 ~ /pio_write/) {
        ops["W:"$8]++
    } else if ($0 ~ /pio_read/) {
        ops["R:"$8]++
    }
}

END {
    for (op in ops) {
        printf "%-16.16s %d\n", op, ops[op]
    }
}
```

Then you will get this output:

```
R:0x3fd          9994
R:0x3fb          4
W:0x20           1
```

This shows most pio operation happens at port 0x3fd.

## Find the criminal

Then we can use file /proc/ioport to find the port 0x3fd belongs to who.

Go and find it!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://richardweiyang-2.gitbook.io/perf-usage/00-index/01-kvm_pio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
