Repository navigation
Add power management to hevc_d, and add a few other controls - #7720
jc-kynesim wants to merge 6 commits into
Conversation
|
Claude: Review: Add power management to hevc_d, and add a few other controlsLooks good overall. A few points: 1. HEVC clock is now held at max from boot (power off doesn't drop the rate)
On rpi-6.18.y the HEVC firmware clock is void hevc_d_hw_power_off(struct hevc_d_dev *dev)
{
clk_disable_unprepare(dev->clock);
clk_set_min_rate(dev->clock, 0);
}(Same applies to the clock "off" claim in the commit message: as things stand runtime suspend saves nothing, so the rate drop is where the saving actually comes from.) 2.
if (vb2_is_streaming(vq))
return -EBUSY;
peer_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (vb2_is_busy(peer_vq))
return -EBUSY;OUTPUT buffer size itself is fine since 3. Minor
PM paths (probe set_active/enable, remove, |
| fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; | ||
| fsize->stepwise.min_width = HEVC_D_MIN_WIDTH; | ||
| fsize->stepwise.max_width = HEVC_D_MAX_WIDTH; | ||
| fsize->stepwise.step_width = 1; |
There was a problem hiding this comment.
Do we actually handle odd widths/heights even with chroma subsampling?
Hantro claims _STEPWISE.
https://elixir.bootlin.com/linux/v7.3/source/drivers/media/platform/verisilicon/hantro_v4l2.c#L210
If I read it correctly, it sets the step to the tile macroblock size of 4.
https://elixir.bootlin.com/linux/v7.3/source/drivers/media/platform/verisilicon/imx8m_vpu_hw.c#L210
There was a problem hiding this comment.
I wondered about that and I thought I had copied Hantros block but I'm happy to make it stepwise 4
| u32 irq_stat; | ||
| int rv; | ||
|
|
||
| dev_dbg(dev->dev, "Power (clock) on\n"); |
| dev->vfd = hevc_d_video_device; | ||
| dev->dev = &pdev->dev; | ||
| dev->pdev = pdev; | ||
| /* Must be set before runtime PM is enabled in hevc_d_hw_probe */ |
I'll do this if you want but I thought the outcome of our previous clock discussions was that we didn't want this as the firmware tended to become confused. The current code doesn't do it. Once you make clk on/off work the CLK_IS_CRITCAL should go away and it should all work.
Actually more recent Hantro code doesn't do that as it allows for size changes on the fly, The width / height set on OUTPUT are ignored. The values we care about are set in SPS.
OK
I'll look at this - it seems we have CONFIG_PM set in our current tree - I did check that everything was called in the right order on a Pi4 on a current 6.18.y branch and it was.
Can do - I just nicked what Hantro did.
Good |
I think the plan is for the drivers to do the right thing - request clocks when needed and release them when no longer needed. I think having both lines is wanted. When you find the existing driver fails due to firmware issues, you use CRITICAL as the sticking plaster (so clocks don't really switch off). If this goes wrong, then let me know. The hope is when better firmware arrives, removing CRITICAL will be possible and clocks will be at zero (or whatever firmware considers the min frequency) when not required. |
|
I'm happy to do whatever I'm told is the right answer re. clocks, but I do feel that if I disable a clock it really shouldn't matter what frequency it was previously set to otherwise what does disable even mean? |
50841ae to
3c14b93
Compare
|
Fixed up most of the above comments with the following exceptions:
|
I think the issue is you have said you want a min freq, of, say 500MHz. You enable then disable. The clock rate chosen is the max of all clients min_rates. |
|
Fair enough if the min_freq is global rather than bound to my device, but if it is global then if we have multiple devices with differing min_freq requests then no-one can ever set anything for fear of overwriting someone else's value. But if it is bound to the device then it should be ignored when that device is disabled (disabling should IMHO have an implicit min-freq 0). |
|
@jc-kynesim I think this is a similar situation in vc4_v3d where it made a difference. e27916f |
3c14b93 to
976a286
Compare
|
Added the clk_set_min_rate. I still feel it shouldn't be wanted, but I accept that it is. |
Chrome tries to read the framesizes. It is handy info to have so supply it. Code taken from Hantro. Signed-off-by: John Cox <[email protected]>
976a286 to
3822893
Compare
|
Added a trivial extra commit to fix bad debug. Also to ping. Is there anything I still need to do here? |
|
Claude: Review of #7720: hevc_d power management and extra controlsThe power management (PM) work looks right to me. I have one real concern, about the relaxed
|
There is no requirement to reject S_FMT if buffers are allocated and Chrome changes the format having alloced OUTPUT buffers. Relax so we only reject if streaming. Remove the linkage between setting OUTPUT and invalidating CAPTURE, it was never required and allowing later OUTPUT changes makes it unsafe. Stop default dst format changing once buffers are allocated. Signed-off-by: John Cox <[email protected]>
Add controls to indicate supported profiles and levels, copied from Hantro. Also whitespace fix to the ctrl table Signed-off-by: John Cox <[email protected]>
vidioc_remove_bufs was invented after this code was taken from Cedrus. Add the missing ioctl as there is no reason not to. Signed-off-by: John Cox <[email protected]>
Replace the manual clock enable/disable on stream start/stop with runtime PM, and add system sleep callbacks. The IRQ enables in the interrupt controller were only set at probe. Move them into the power on path so they are restored on every resume. On system suspend, stop new m2m jobs being run and then sync with the IRQ machinery. v4l2_m2m_suspend() only waits for the current job to finish, but jobs are finished before the h/w has completed phase 1 and phase 2, so that alone does not leave the h/w idle. Signed-off-by: John Cox <[email protected]>
Debug prints the size of the PU buffers on coeff alloc failure. Fix so it prints the requested size of the coeff buffers Signed-off-by: John Cox <[email protected]>
3822893 to
54843ac
Compare
|
My Claude likes it now, yours may have a different opinion! I've fixed up the get_dst_fmt issues. I'm not going to add a lazy clock off in this patchset - if it becomes an issue we can think about it later. |
|
My Claude is less happy: Re-review of #7720 (head 54843ac)Clock, PM, framesizes, controls,
|
|
The important word in the spec is MAY. That is not MUST. So what I have is spec compliant. Claudes example also assumes inconsistent behaviour from the client where it sets the format the first time round and doesn't the second. |
popcornmix
left a comment
There was a problem hiding this comment.
Claude has backed off a little. I think we are into minor issues though, so happy for this to be merged if your are.
Claude's (reluctant) acceptance:
Fair enough. The next sentence in the spec ("The driver will derive a new CAPTURE format from the OUTPUT format being set") reads more firmly than "may", but if FFmpeg and GStreamer always reopen and always set the CAPTURE format, nobody will hit it. I'm happy to leave it.
On the "format changes when CAPTURE buffers are freed" oddity: I think that already happens with the current code when the client never sets CAPTURE (dst_fmt_set == 0). get_dst_fmt() holds the old format while buffers exist, then jumps to the SPS-derived one once they are freed. Clearing the flag only while CAPTURE is idle wouldn't add a new case. Not a blocker though.
|
Probably worth doing the traditional "try it out with Kodi" thing and see if it breaks anything. My fairly simple testing thinks it is OK, but I think your usage is probably a bit different to what I test. |
|
Kodi seems to work with this. |
Adds power management and some controls that Chrome wated when scanning devices that seem like good things to have in any case. All these probably want to go into out next attempt to upstream.