<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - mpv confuses the frequency scaling, leading to freqyency flapping and missed vsyncs"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=102683">102683</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>mpv confuses the frequency scaling, leading to freqyency flapping and missed vsyncs
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>DRI
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86-64 (AMD64)
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DRM/AMDgpu
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dri-devel@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bugs.freedesktop@haasn.xyz
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When rendering e.g. 24 Hz video on 60 Hz, `mpv`'s usage pattern consists of one
“fresh” frame (e.g. 20ms rendering time) followed by two “redraw” frames, each
of which are essentially just blits/mixes of already-rendered frames. This
results in a high-low-low-high-low GPU activity pattern.

Apparently this confuses the GPU frequency scaling quite heavily, which leads
to bad performance (under-scaling), inconsistent performance (“flapping” SCLK)
and missed vblanks (delayed/dropped frames and vsync jitter as measured by
mpv). If I `watch -n0.1 cat /sys/kernel/debug/dri/*/amdgpu_pm_info`, I can see
it varying wildly between `SCLK: 500 MHz` and `SCLK: 1000 MHz`, as the reported
`GPU Load:` varies between 0% and 100% from frame to frame. I can consistently
solve the issue by setting `power_dpm_force_performance_level` to `high`.

A graphical explanation of the issue, with mpv performance graphs:
`auto`: <a href="https://0x0.st/7qz.jpg">https://0x0.st/7qz.jpg</a>
`high`: <a href="https://0x0.st/7qi.jpg">https://0x0.st/7qi.jpg</a>

This is not just cosmetic, since it results in an increase in the number of
missed vsyncs, due to the occasional spikes. I've also had a different user
report significantly worse performance with 'auto', even more extreme than my
example: <a href="https://0x0.st/7Aw.jpg">https://0x0.st/7Aw.jpg</a> (Note: the third step in this image, going from
10k ms to 5k ms is due to switching from mesa 17.2 to 17.1; but that's an
unrelated, cosmetic bug). Using 'auto' makes mpv completely unusable for this
user.

I expect the solution would be adding a tiny bit of (top-weighted) smoothing of
this performance state / GPU load estimation across frames. The nvidia driver,
for example, gets this right: If I alter between 'high' performance and 'low'
performance states, it recognizes that and sticks to 'high' performance mode,
instead of varying the frequency wildly like amdgpu. This results in very flat
graphs, much like the 'high' screenshot I uploaded.

Kernel version is 4.12.4, mesa version is 17.2.0, device is a Sapphire RX 560.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>