<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>Something like?</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>for_each_plane_id() {</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>       for_each_dbuf_slice() {</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>               skl_ddb_entry_for_slices(BIT(slice), &ddb_slice);</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>               </span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>                if (skl_ddb_entries_overlap(&ddb_slice, &ddb[plane_id])))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>                       bw[slice] += data_rate;</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>        }</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>}</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">In fact even in your example this is not fully correct:</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">it should be then</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">for_each_new_crtc_in_state()   => because there are multiple crtcs</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"> 
 for_each_plane_id() {</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">       for_each_dbuf_slice() {</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">               skl_ddb_entry_for_slices(BIT(slice), &ddb_slice);</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">               </span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">                if (skl_ddb_entries_overlap(&ddb_slice, &ddb[plane_id])))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">                       bw[slice] += data_rate;</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">        }</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">}</span><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">which
 would be in fact same complexity or even worse because in the patch</span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">we
 get a mask of only used slices per plane ddb and then account for those</span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">while
 here it would be iterating all slices everytime.</span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">Slight
 difference but still. </span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">I
 can of course make this function shorter, by implementing some helpers - </span></span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">that's
 for sure.</span></span></p>
<p><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>But this seems to borked anyway since we only consider the crtcs in the</span><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>state, and there are those ugly FIXMEs below.</span></p>
<p><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"></span>Those ugly FIXME's are there because of same issue that we don't </p>
<p>have a parent state for crtc_state in some situations. </p>
<p><br>
</p>
<p>Not this patch fault or subject in fact. We probably need some series</p>
<p>to somehow tackle this everywhere, so that those functions which</p>
<p>need intel_atomic_state can always find it.</p>
<p> </p>
<p>So it is not those FIXME's in the patch which are ugly, but the code </p>
<p>which <span style="font-size:12pt">is calling this function, so that even though we have a crtc_state</span></p>
<p><span style="font-size:12pt">we never now if we can have a parent atomic state, which is violating</span></p>
<p><span style="font-size:12pt">OOP principles.</span></p>
<p></p>
<p><br>
</p>
<p>I.e it is called from <span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">intel_modeset_setup_hw_state _already_ in a hacky way.</span></p>
<p><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>I have a feeling what we want is dbuf_state, and track the bw used for</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>each slice therein. Should also allow us to flag the cdclk recalculation</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>only when things actually change in a way that needs more cdclk, instead</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">>of pessimising every plane enable/disable like you do below.</span><br>
</p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">I think CDCLK recalculation itself is pretty trivial - it is actually when we really</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">needs to be changed, that is what we don't want to often, right?</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">To estimate if it needs to be flagged or not you will need exatly same code, i.e</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">calculating BW used per slice, while determining which ddb entries are related</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">to which slice.</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">In fact there are already IGT results(which pass) and CDCLK doesn't change too</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">often at all - because we change it only when we really need it otherwise</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">intel_crtc_compute_min_cdclk will return same value as before and nothing changes.</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px"><br>
</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">If you really want so, we can start tracking it, once your dbuf_state patches land - currently</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">the main problem is that we need finally a proper way to estimate CDCLK</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">without keeping it bumped all the time to make 8K happy, at the same time</span></p>
<p><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:13.3333px">we don't want FIFO underruns again.</span></p>
<p><br>
</p>
<div id="x_Signature">
<div style="font-family:Tahoma; font-size:13px"><font size="2"><span style="font-size:10pt">Best Regards,<br>
<br>
Lisovskiy Stanislav <br>
</span></font></div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Ville Syrjälä <ville.syrjala@linux.intel.com><br>
<b>Sent:</b> Tuesday, March 17, 2020 3:46:35 PM<br>
<b>To:</b> Lisovskiy, Stanislav<br>
<b>Cc:</b> intel-gfx@lists.freedesktop.org; Ausmus, James; Saarinen, Jani; Roper, Matthew D<br>
<b>Subject:</b> Re: [PATCH v2 2/3] drm/i915: Adjust CDCLK accordingly to our DBuf bw needs</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On Tue, Mar 17, 2020 at 12:43:38AM +0200, Stanislav Lisovskiy wrote:<br>
> According to BSpec max BW per slice is calculated using formula<br>
> Max BW = CDCLK * 64. Currently when calculating min CDCLK we<br>
> account only per plane requirements, however in order to avoid<br>
> FIFO underruns we need to estimate accumulated BW consumed by<br>
> all planes(ddb entries basically) residing on that particular<br>
> DBuf slice. This will allow us to put CDCLK lower and save power<br>
> when we don't need that much bandwidth or gain additional<br>
> performance once plane consumption grows.<br>
> <br>
> v2: - Fix long line warning<br>
>     - Limited new DBuf bw checks to only gens >= 11<br>
> <br>
> Signed-off-by: Stanislav Lisovskiy <stanislav.lisovskiy@intel.com><br>
> ---<br>
>  drivers/gpu/drm/i915/display/intel_bw.c       | 46 +++++++++++++++++++<br>
>  drivers/gpu/drm/i915/display/intel_bw.h       |  1 +<br>
>  drivers/gpu/drm/i915/display/intel_cdclk.c    | 25 ++++++++++<br>
>  drivers/gpu/drm/i915/display/intel_display.c  | 10 +++-<br>
>  .../drm/i915/display/intel_display_power.h    |  1 +<br>
>  drivers/gpu/drm/i915/intel_pm.c               | 34 +++++++++++++-<br>
>  drivers/gpu/drm/i915/intel_pm.h               |  3 ++<br>
>  7 files changed, 117 insertions(+), 3 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/i915/display/intel_bw.c b/drivers/gpu/drm/i915/display/intel_bw.c<br>
> index 58b264bc318d..a85125110d7e 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_bw.c<br>
> +++ b/drivers/gpu/drm/i915/display/intel_bw.c<br>
> @@ -6,6 +6,7 @@<br>
>  #include <drm/drm_atomic_state_helper.h><br>
>  <br>
>  #include "intel_bw.h"<br>
> +#include "intel_pm.h"<br>
>  #include "intel_display_types.h"<br>
>  #include "intel_sideband.h"<br>
>  <br>
> @@ -334,6 +335,51 @@ static unsigned int intel_bw_crtc_data_rate(const struct intel_crtc_state *crtc_<br>
>        return data_rate;<br>
>  }<br>
>  <br>
> +int intel_bw_calc_min_cdclk(struct intel_atomic_state *state)<br>
> +{<br>
> +     struct drm_i915_private *dev_priv = to_i915(state->base.dev);<br>
> +     int max_bw_per_dbuf[DBUF_SLICE_MAX];<br>
> +     int i = 0;<br>
> +     enum plane_id plane_id;<br>
> +     struct intel_crtc_state *crtc_state;<br>
> +     struct intel_crtc *crtc;<br>
> +     int max_bw = 0;<br>
> +     int min_cdclk;<br>
> +<br>
> +     memset(max_bw_per_dbuf, 0, sizeof(max_bw_per_dbuf[0]) * DBUF_SLICE_MAX);<br>
> +<br>
> +     for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {<br>
> +             for_each_plane_id_on_crtc(crtc, plane_id) {<br>
> +                     struct skl_ddb_entry *plane_alloc =<br>
> +                             &crtc_state->wm.skl.plane_ddb_y[plane_id];<br>
> +                     struct skl_ddb_entry *uv_plane_alloc =<br>
> +                             &crtc_state->wm.skl.plane_ddb_uv[plane_id];<br>
> +                     unsigned int data_rate = crtc_state->data_rate[plane_id];<br>
> +                     int slice_id = 0;<br>
> +                     u32 dbuf_mask = skl_ddb_dbuf_slice_mask(dev_priv, plane_alloc);<br>
> +<br>
> +                     dbuf_mask |= skl_ddb_dbuf_slice_mask(dev_priv, uv_plane_alloc);<br>
> +<br>
> +                     DRM_DEBUG_KMS("Got dbuf mask %x for pipe %c ddb %d-%d plane %d data rate %d\n",<br>
> +                                   dbuf_mask, pipe_name(crtc->pipe), plane_alloc->start,<br>
> +                                   plane_alloc->end, plane_id, data_rate);<br>
> +<br>
> +                     while (dbuf_mask != 0) {<br>
> +                             if (dbuf_mask & 1) {<br>
> +                                     max_bw_per_dbuf[slice_id] += data_rate;<br>
> +                                     max_bw = max(max_bw, max_bw_per_dbuf[slice_id]);<br>
> +                             }<br>
> +                             slice_id++;<br>
> +                             dbuf_mask >>= 1;<br>
> +                     }<br>
> +             }<br>
> +     }<br>
<br>
Something like?<br>
<br>
for_each_plane_id() {<br>
        for_each_dbuf_slice() {<br>
                skl_ddb_entry_for_slices(BIT(slice), &ddb_slice);<br>
                <br>
                if (skl_ddb_entries_overlap(&ddb_slice, &ddb[plane_id])))<br>
                        bw[slice] += data_rate;<br>
        }<br>
}<br>
<br>
But this seems to borked anyway since we only consider the crtcs in the<br>
state, and there are those ugly FIXMEs below.<br>
<br>
I have a feeling what we want is dbuf_state, and track the bw used for <br>
each slice therein. Should also allow us to flag the cdclk recalculation<br>
only when things actually change in a way that needs more cdclk, instead <br>
of pessimising every plane enable/disable like you do below.<br>
<br>
> +<br>
> +     min_cdclk = max_bw / 64;<br>
> +<br>
> +     return min_cdclk;<br>
> +}<br>
> +<br>
>  void intel_bw_crtc_update(struct intel_bw_state *bw_state,<br>
>                          const struct intel_crtc_state *crtc_state)<br>
>  {<br>
> diff --git a/drivers/gpu/drm/i915/display/intel_bw.h b/drivers/gpu/drm/i915/display/intel_bw.h<br>
> index a8aa7624c5aa..8a522b571c51 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_bw.h<br>
> +++ b/drivers/gpu/drm/i915/display/intel_bw.h<br>
> @@ -29,5 +29,6 @@ int intel_bw_init(struct drm_i915_private *dev_priv);<br>
>  int intel_bw_atomic_check(struct intel_atomic_state *state);<br>
>  void intel_bw_crtc_update(struct intel_bw_state *bw_state,<br>
>                          const struct intel_crtc_state *crtc_state);<br>
> +int intel_bw_calc_min_cdclk(struct intel_atomic_state *state);<br>
>  <br>
>  #endif /* __INTEL_BW_H__ */<br>
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c b/drivers/gpu/drm/i915/display/intel_cdclk.c<br>
> index 0741d643455b..9f2de613642e 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.c<br>
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c<br>
> @@ -25,6 +25,7 @@<br>
>  #include "intel_cdclk.h"<br>
>  #include "intel_display_types.h"<br>
>  #include "intel_sideband.h"<br>
> +#include "intel_bw.h"<br>
>  <br>
>  /**<br>
>   * DOC: CDCLK / RAWCLK<br>
> @@ -1979,11 +1980,19 @@ int intel_crtc_compute_min_cdclk(const struct intel_crtc_state *crtc_state)<br>
>  {<br>
>        struct drm_i915_private *dev_priv =<br>
>                to_i915(crtc_state->uapi.crtc->dev);<br>
> +     struct intel_atomic_state *state = NULL;<br>
>        int min_cdclk;<br>
>  <br>
>        if (!crtc_state->hw.enable)<br>
>                return 0;<br>
>  <br>
> +     /*<br>
> +      * FIXME: Unfortunately when this gets called from intel_modeset_setup_hw_state<br>
> +      * there is no intel_atomic_state at all. So lets not then use it.<br>
> +      */<br>
> +     if (crtc_state->uapi.state)<br>
> +             state = to_intel_atomic_state(crtc_state->uapi.state);<br>
> +<br>
>        min_cdclk = intel_pixel_rate_to_cdclk(crtc_state);<br>
>  <br>
>        /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */<br>
> @@ -2058,6 +2067,22 @@ int intel_crtc_compute_min_cdclk(const struct intel_crtc_state *crtc_state)<br>
>        if (IS_TIGERLAKE(dev_priv))<br>
>                min_cdclk = max(min_cdclk, (int)crtc_state->pixel_rate);<br>
>  <br>
> +     /*<br>
> +      * Similar story as with skl_write_plane_wm and intel_enable_sagv<br>
> +      * - in some certain driver parts, we don't have any guarantee that<br>
> +      * parent exists. So we might be having a crtc_state without<br>
> +      * parent state.<br>
> +      */<br>
> +     if (INTEL_GEN(dev_priv) >= 11) {<br>
> +             if (state) {<br>
> +                     int dbuf_bw_cdclk = intel_bw_calc_min_cdclk(state);<br>
> +<br>
> +                     DRM_DEBUG_KMS("DBuf bw min cdclk %d current min_cdclk %d\n",<br>
> +                                   dbuf_bw_cdclk, min_cdclk);<br>
> +                     min_cdclk = max(min_cdclk, dbuf_bw_cdclk);<br>
> +             }<br>
> +     }<br>
> +<br>
>        if (min_cdclk > dev_priv->max_cdclk_freq) {<br>
>                drm_dbg_kms(&dev_priv->drm,<br>
>                            "required cdclk (%d kHz) exceeds max (%d kHz)\n",<br>
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c<br>
> index cdff3054b344..aae5521424c6 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_display.c<br>
> +++ b/drivers/gpu/drm/i915/display/intel_display.c<br>
> @@ -14632,7 +14632,7 @@ static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)<br>
>        /* See {hsw,vlv,ivb}_plane_ratio() */<br>
>        return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||<br>
>                IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||<br>
> -             IS_IVYBRIDGE(dev_priv);<br>
> +             IS_IVYBRIDGE(dev_priv) || (INTEL_GEN(dev_priv) >= 11);<br>
>  }<br>
>  <br>
>  static int intel_atomic_check_planes(struct intel_atomic_state *state,<br>
> @@ -14681,6 +14681,14 @@ static int intel_atomic_check_planes(struct intel_atomic_state *state,<br>
>                if (hweight8(old_active_planes) == hweight8(new_active_planes))<br>
>                        continue;<br>
>  <br>
> +             /*<br>
> +              * active_planes bitmask has been updated, whenever amount<br>
> +              * of active planes had changed we need to recalculate CDCLK<br>
> +              * as it depends on total bandwidth now, not only min_cdclk<br>
> +              * per plane.<br>
> +              */<br>
> +             *need_cdclk_calc = true;<br>
> +<br>
>                ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);<br>
>                if (ret)<br>
>                        return ret;<br>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_power.h b/drivers/gpu/drm/i915/display/intel_display_power.h<br>
> index da64a5edae7a..3446c3ce6a4f 100644<br>
> --- a/drivers/gpu/drm/i915/display/intel_display_power.h<br>
> +++ b/drivers/gpu/drm/i915/display/intel_display_power.h<br>
> @@ -311,6 +311,7 @@ intel_display_power_put_async(struct drm_i915_private *i915,<br>
>  enum dbuf_slice {<br>
>        DBUF_S1,<br>
>        DBUF_S2,<br>
> +     DBUF_SLICE_MAX<br>
>  };<br>
>  <br>
>  #define with_intel_display_power(i915, domain, wf) \<br>
> diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c<br>
> index 8375054ba27d..15300c44d9dc 100644<br>
> --- a/drivers/gpu/drm/i915/intel_pm.c<br>
> +++ b/drivers/gpu/drm/i915/intel_pm.c<br>
> @@ -3844,10 +3844,9 @@ icl_get_first_dbuf_slice_offset(u32 dbuf_slice_mask,<br>
>        return offset;<br>
>  }<br>
>  <br>
> -static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv)<br>
> +u16 intel_get_ddb_size(struct drm_i915_private *dev_priv)<br>
>  {<br>
>        u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size;<br>
> -<br>
>        drm_WARN_ON(&dev_priv->drm, ddb_size == 0);<br>
>  <br>
>        if (INTEL_GEN(dev_priv) < 11)<br>
> @@ -3856,6 +3855,37 @@ static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv)<br>
>        return ddb_size;<br>
>  }<br>
>  <br>
> +u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv,<br>
> +                         const struct skl_ddb_entry *entry)<br>
> +{<br>
> +     u32 slice_mask = 0;<br>
> +     u16 ddb_size = intel_get_ddb_size(dev_priv);<br>
> +     u16 num_supported_slices = INTEL_INFO(dev_priv)->num_supported_dbuf_slices;<br>
> +     u16 slice_size = ddb_size / num_supported_slices;<br>
> +     u16 start_slice;<br>
> +     u16 end_slice;<br>
> +<br>
> +     if (!skl_ddb_entry_size(entry))<br>
> +             return 0;<br>
> +<br>
> +     start_slice = entry->start / slice_size;<br>
> +     end_slice = (entry->end - 1) / slice_size;<br>
> +<br>
> +     DRM_DEBUG_KMS("ddb size %d slices %d slice size %d start slice %d end slice %d\n",<br>
> +                   ddb_size, num_supported_slices, slice_size, start_slice, end_slice);<br>
> +<br>
> +     /*<br>
> +      * Per plane DDB entry can in a really worst case be on multiple slices<br>
> +      * but single entry is anyway contigious.<br>
> +      */<br>
> +     while (start_slice <= end_slice) {<br>
> +             slice_mask |= 1 << start_slice;<br>
> +             start_slice++;<br>
> +     }<br>
> +<br>
> +     return slice_mask;<br>
> +}<br>
> +<br>
>  static u8 skl_compute_dbuf_slices(const struct intel_crtc_state *crtc_state,<br>
>                                  u8 active_pipes);<br>
>  <br>
> diff --git a/drivers/gpu/drm/i915/intel_pm.h b/drivers/gpu/drm/i915/intel_pm.h<br>
> index d60a85421c5a..a9e3835927a8 100644<br>
> --- a/drivers/gpu/drm/i915/intel_pm.h<br>
> +++ b/drivers/gpu/drm/i915/intel_pm.h<br>
> @@ -37,6 +37,9 @@ void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc,<br>
>                               struct skl_ddb_entry *ddb_y,<br>
>                               struct skl_ddb_entry *ddb_uv);<br>
>  void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv);<br>
> +u16 intel_get_ddb_size(struct drm_i915_private *dev_priv);<br>
> +u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv,<br>
> +                         const struct skl_ddb_entry *entry);<br>
>  void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc,<br>
>                              struct skl_pipe_wm *out);<br>
>  void g4x_wm_sanitize(struct drm_i915_private *dev_priv);<br>
> -- <br>
> 2.24.1.485.gad05a3d8e5<br>
<br>
-- <br>
Ville Syrjälä<br>
Intel<br>
</div>
</span></font>
</body>
</html>