Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HVS Core Rate Requirements for KMS #4365

Merged
merged 3 commits into from
Jun 16, 2021

Conversation

mripard
Copy link
Contributor

@mripard mripard commented May 26, 2021

Hi,

It turns out the HVS has a bunch of requirements for the clock rate while it operates depending on both the input and output. Those requirements were completely ignored so far and were ultimately resulting in a vblank timeout.

This implements a proper boost of the core clock based on the planes being used and the pixel valves modes.

@HiassofT
Copy link
Contributor

Thanks, this helped a bit with 4096x2160-30 but the issues are not fully resolved.

Testing on LibreELEC (kernel 5.10.39, May 24 fw) initial boot-up in 4096x2160-30 is fine. But after switching to 1920x1080-60 and then switching to 4096x2160-30 in kodi the screen blanked out after a few seconds (no signal on TV) - and I got flip_done timeout in dmesg.

I could also reproduce that with just modetest (kodi not started at all), simply running modetest -M vc4 -s 32:4096x2160-24 (that shows a picture) and then pressing a key to exit modetest gives no signal, too.

I monitored core freq (with bcmstat), before and during modetest it ran at 277MHz but after exiting modetest it reported 267MHz.

Here's dmesg: http://ix.io/3nX4

drm_atomic_get_crtc_state relies on drm_atomic_get_existing_crtc_state
that is deprecated and isn't really clear on which state it provides.

Even worse, after the states have been swapped, if the CRTC is present
in the state drm_atomic_get_existing_crtc_state will return the old
state, whereas if the CRTC is not present, we'll use a copy of
crtc->state. crtc->state for the CRTC that is there at that point is the new
state though, which leads to confusion.

Let's provide two new helpers that make it clear what our expectations
are.

Signed-off-by: Maxime Ripard <[email protected]>
We'll need that function in vc4_kms to compute the core clock rate
requirements.

Signed-off-by: Maxime Ripard <[email protected]>
Depending on a given HVS output (HVS to PixelValves) and input (planes
attached to a channel) load, the HVS needs for the core clock to be
raised above its boot time default.

Failing to do so will result in a vblank timeout and a stalled display
pipeline.

Signed-off-by: Maxime Ripard <[email protected]>
@mripard mripard force-pushed the rpi/5.10-core-clock-request branch from 2e37303 to 59c7fa8 Compare May 31, 2021 18:05
@mripard
Copy link
Contributor Author

mripard commented May 31, 2021

I've pushed two fixes that should address the issue you pointed out

@HiassofT
Copy link
Contributor

HiassofT commented Jun 4, 2021

Thanks, with the updated version 4096x2160-30 is working fine!

When running modetest -M vc4 -s 32:4096x2160-24 core freq now correctly goes down to 267MHz when switching to p24 mode and back to 277MHz when switching back to p30.

Compared to fkms kms doesn't seem to scale core below 267MHz (or 533 with hdmi_enable_4kp60=1) - fkms switches to 220MHz at 640x480-60 but kms runs core at 267 (or 533) MHz.

@mripard
Copy link
Contributor Author

mripard commented Jun 7, 2021

I had a look and while I don't have 640x480, 720x480 puts the core clock at 200MHz. The firmware reports 200MHz as the minimum clock rate so Linux doesn't try to go below it, but I can't see the 267MHz?

@HiassofT
Copy link
Contributor

HiassofT commented Jun 8, 2021

I just tested with my 1920x1200 monitor and with that I get 200MHz core clock as well (also on 1920x1200p60 mode). I saw the 267MHz clock when testng with my LG 55C8. Which monitor / edid did you use?

I did another test with my 1920x1200 monitor, using firmware edid override with the LG edid but no kernel / DRM edid override - so FW had the LG edid, configured 3840x2160p30, then linux/DRM read the edid from the monitor and switched to 1920x1200p60 - and that gave 267MHz core clock as well. Quite interestingly clk debug info reported 200MHz min rate. Puzzling.

LibreELEC:~ # vcgencmd measure_clock core
frequency(1)=267231440
LibreELEC:~ # modetest | grep -A 1 ^76
76	224	(0,0)	(1920x1200)
  #0 1920x1200 59.95 1920 1968 2000 2080 1200 1203 1209 1235 154000 flags: phsync, nvsync; type: preferred, driver
LibreELEC:~ # tvservice -s
state 0x120009 [HDMI CEA (95) RGB lim 16:9], 3840x2160 @ 30.00Hz, progressive
LibreELEC:~ # cat /sys/kernel/debug/clk/fw-clk-core/clk_min_rate 
200000000

Here's the config.txt settings I added (I also attached the EDD file):

hdmi_edid_file=1
hdmi_edid_filename=lg-55c8.dat

And these are the KMS config.txt settings we use in LibreELEC:

dtoverlay=vc4-kms-v3d,cma-512
dtoverlay=rpivid-v4l2
disable_overscan=1
disable_fw_kms_setup=1

Anyways, the initial issue of 4096x2160p30 not working is fixed by the PR and this may be a different issue - just wanted to report it.

lg-55c8.zip

@HiassofT
Copy link
Contributor

HiassofT commented Jun 8, 2021

I did another test: if I force 1920x1080p60 via config.txt, in addition to the fw edid override, I get 200MHz core clock.

LibreELEC:~ # tvservice -s
state 0x120009 [HDMI CEA (16) RGB lim 16:9], 1920x1080 @ 60.00Hz, progressive
LibreELEC:~ # vcgencmd measure_clock core
frequency(1)=199995120

config.txt:

hdmi_edid_file=1
hdmi_edid_filename=lg-55c8.dat
hdmi_group=1
hdmi_mode=16

@popcornmix could that be a FW (or fw clock driver) issue, like initial/boot FW core boost not being cleared when kms takes over?

BTW: I also checked with latest FW/kernel, same result (267MHz at 2160p30)

LibreELEC:~ # vcgencmd measure_clock core
frequency(1)=267218256
LibreELEC:~ # tvservice -s
state 0x120009 [HDMI CEA (95) RGB lim 16:9], 3840x2160 @ 30.00Hz, progressive
LibreELEC:~ # vcgencmd version
Jun  8 2021 13:07:19 
Copyright (c) 2012 Broadcom
version 03df0e450c356822f03454c27edea347fd8d211b (clean) (release) (start_x)
LibreELEC:~ # uname -a
Linux LibreELEC 5.10.42 #1 SMP Tue Jun 8 19:10:55 CEST 2021 armv7l GNU/Linux

@popcornmix
Copy link
Collaborator

Your guess is likely correct. Initially hdmi mode and framebuffer requires clock boost and are inherited by simple framebuffer in kernel. We don't have a mechanism to know when these are finished with.
We'll have a think about what can be done (may need a new message, so kernel+firmware change).

Forcing a lower pixel clock mode in config.txt is a temporary workaround.

@popcornmix
Copy link
Collaborator

I think this is okay to merge. It improves broken 4k output with kms driver.
Getting the correct minimum core frequency needs more work (likely a new kernel->firmware message indicating simple fb is finished with), but is not related to this PR.

@pelwell pelwell merged commit 1c38342 into raspberrypi:rpi-5.10.y Jun 16, 2021
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jun 16, 2021
See: raspberrypi/linux#4365

kernel: overlays: ghost-amp: Change early-disable sequence
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jun 16, 2021
See: raspberrypi/linux#4365

kernel: overlays: ghost-amp: Change early-disable sequence
@mripard mripard deleted the rpi/5.10-core-clock-request branch June 16, 2021 09:26
@pelwell
Copy link
Contributor

pelwell commented Jun 17, 2021

These commits are now in rpi-5.11.y as well, but they'll need patching up for 5.12.

@mripard
Copy link
Contributor Author

mripard commented Jun 17, 2021

How should we handle this? I guess the easiest would be for me to rebase the branch and send a new PR?

@popcornmix
Copy link
Collaborator

@mripard yes, a PR to 5.12 would be welcome.

@6by9
Copy link
Contributor

6by9 commented Jun 21, 2021

We appear to have a regression with drm/vc4: Increase the core clock based on HVS load.
See #4401, and reported in passing on dri-devel.
Some flips will blow up tripping the WARN_ON(ctx->contended) in modeset_lock, and then a Unable to handle kernel paging request.

Revert, or wait for a fix?

@popcornmix
Copy link
Collaborator

Can you reproduce?

@mripard
Copy link
Contributor Author

mripard commented Jun 21, 2021

I noticed that some things were off indeed on friday and am working on a fix.

It's taking a bit longer than anticipated, sorry. A revert is fine by me

@6by9
Copy link
Contributor

6by9 commented Jun 21, 2021

Can you reproduce?

Yes. Build https://github.com/tomba/kmsxx/ and run utils/kmstest --flip and it'll fall over.
That was with a DSI display attached as well, but I don't think that is a requirement. #4401 is just in X11/Wayland

@popcornmix
Copy link
Collaborator

Confirmed - it falls over with hdmi display and utils/kmstest --flip

graysky2 added a commit to archlinuxarm/PKGBUILDs that referenced this pull request Jun 22, 2021
Revert breakage to graphic stack by PR#4365 util fixed upstream

1. raspberrypi/linux#4365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants