<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Arial",sans-serif;
        color:blue;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1440179117;
        mso-list-type:hybrid;
        mso-list-template-ids:1670531212 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1
        {mso-list-id:1999842065;
        mso-list-type:hybrid;
        mso-list-template-ids:-1161918596 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Hey guys,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">I have been noticing that Wayland apps like simple-egl only get about 40 FPS in Headless mode. I followed the logic and it seems to me that this is inevitable in the
 current code (unless of course I am miscalculating </span><span style="font-size:10.0pt;font-family:"Segoe UI Emoji",sans-serif;color:blue">😉</span><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Here’s the flow of events:<o:p></o:p></span></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l1 level1 lfo1">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">headless_output_repaint is called and sets a timer by doing this:<o:p></o:p></span></li></ol>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">wl_event_source_timer_update(output->finish_frame_timer, 16);<o:p></o:p></span></p>
<ol style="margin-top:0in" start="2" type="1">
<li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l1 level1 lfo1">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">The above timer when fired will call finish_frame_handler.<o:p></o:p></span></li><li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l1 level1 lfo1">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">finish_frame_handler will call weston_output_finish_frame.<o:p></o:p></span></li><li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l1 level1 lfo1">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">weston_output_finish_frame’s logic is such that it adds 16.66 (refresh to the current time stamp), then subtracts repaint_msec which is hardcoded to 7 ms and finally subtracts the current time from
 it. This will invariably lead to 9 ms (rounded down from 9.66) as the next repaint timer to fire and start a fresh repaint cycle which will again wait for 16 ms before calling finish_frame_handler.<o:p></o:p></span></li></ol>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">This means that there is always a gap of 16 + 9 = 25 ms. Sure enough, dividing 1000 / 25 gives us 40 FPS which is what I am getting. Please let me know if I went wrong
 anywhere in my logic above.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Now, I feel like there are two ways to fix this problem:<o:p></o:p></span></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l0 level1 lfo2">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">The easy way is to just change the code in headless_output_repaint<o:p></o:p></span></li></ol>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">from:<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">wl_event_source_timer_update(output->finish_frame_timer, 16);<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">to:<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">wl_event_source_timer_update(output->finish_frame_timer, 7);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">We know that the logic in weston_output_finish_frame arms the timer for 9 ms which will ultimately call the next repaint cycle. So when we
 get down to headless_output_repaint, we only wait for another 7 ms to get to a total of 16. This works for me but it looks weird when we are setting the timer to 7 ms which would left someone wondering what this is all about.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<ol style="margin-top:0in" start="2" type="1">
<li class="MsoListParagraph" style="color:blue;margin-left:0in;mso-list:l0 level1 lfo2">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif">Another way to fix the problem is to have weston_output_finish_frame arm a timer instantaneously rather than for 9 ms later. In fact, I see that there is already code in the beginning of that function
 that looks like this:<o:p></o:p></span></li></ol>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">    if (!stamp) {<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">        output->next_repaint = now;
<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">        goto out;
<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">    }   
<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Which means that from the caller (finish_frame_handler) we can just call with NULL for stamp and the timer will be armed immediately.<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">It’s just that there is an assert above it to check that stamp is not NULL:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:.5in"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID));<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">So, I was thinking that if I remove the check for stamp from this assert and then use NULL for stamp from the caller, then we will be firing the timer immediately.
 This also worked for me and it looks cleaner as well. However, it is changing a key function in compositor.c so I am wondering if that would be okay?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Please let me know your thoughts. Any ideas here would be appreciated.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">Satyeshwar<o:p></o:p></span></p>
<p class="MsoListParagraph"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue"><o:p> </o:p></span></p>
</div>
</body>
</html>