Exponential backoff strategy for gfx thread

This commit is contained in:
Pavel 2023-03-14 15:45:33 +03:00
parent 711bc11b47
commit b214aee42f

View File

@ -423,9 +423,47 @@ begin
end; end;
end; end;
type
gfx_backoff_exp=object
private
Const
lower_bound = 1000;
upper_bound = 100000;
Var
m_nExpCur:SizeUInt;
public
Procedure Wait;
Procedure Reset;
end;
Procedure gfx_backoff_exp.Wait;
Var
time:Int64;
begin
if (m_nExpCur<=upper_bound) then
begin
m_nExpCur:=m_nExpCur*2;
end;
time:=-m_nExpCur;
NtDelayExecution(True,@time);
end;
Procedure gfx_backoff_exp.Reset; inline;
begin
m_nExpCur:=lower_bound;
end;
Procedure WaitSubmit; inline;
Var
time:Int64;
begin
time:=Int64(NT_INFINITE);
NtDelayExecution(True,@time);
end;
function GFX_thread(p:pointer):ptrint; function GFX_thread(p:pointer):ptrint;
var var
time:Int64; backoff:gfx_backoff_exp;
work_do:Boolean; work_do:Boolean;
begin begin
Result:=0; Result:=0;
@ -434,6 +472,7 @@ begin
SetThreadDebugName(GetCurrentThreadId, 'GFX Thread'); SetThreadDebugName(GetCurrentThreadId, 'GFX Thread');
backoff.Reset;
repeat repeat
work_do:=False; work_do:=False;
@ -453,24 +492,24 @@ begin
//end; //end;
end else end else
begin begin
time:=-1000; backoff.Wait;
NtDelayExecution(True,@time);
Continue; Continue;
end; end;
work_do:=True; work_do:=True;
backoff.Reset;
end; end;
if GFXMicroEngine.Next then if GFXMicroEngine.Next then
begin begin
me_node_submit(GFXMicroEngine.Current); me_node_submit(GFXMicroEngine.Current);
work_do:=True; work_do:=True;
backoff.Reset;
end; end;
if not work_do then if not work_do then
begin begin
SetEvent(FIdleEvent); SetEvent(FIdleEvent);
time:=Int64(NT_INFINITE); WaitSubmit;
NtDelayExecution(True,@time);
end; end;
until false; until false;