470 likes | 697 Views
Squeeze the Juice out of CPUs Post Mortem of a Data-Driven Scheduler. Remi QUENIN. Michael LAVAIRE. Technical Lead Ubisoft Montreal. Technical Architect Ubisoft Montreal. Table of Contents. Issues on common MT Archi . “Shears” Solution Tips and Tricks. Usual multithreading patterns.
E N D
Squeeze the Juice out of CPUs Post Mortem of a Data-Driven Scheduler Remi QUENIN Michael LAVAIRE Technical Lead Ubisoft Montreal Technical Architect Ubisoft Montreal
Table of Contents Issues on common MT Archi. “Shears” Solution Tips and Tricks
Usual multithreading patterns 1. Common architectural DesignS
Folded loop Smaller Engine Loop Gameplay Thread 1 Graphic Thread 2 Engine Loop Background Loading Thread 3 Frame N N+1 N+2
Sync point Applying modifications Applying modifications Applying modifications Gameplay Sync Sync Graphic Sync Sync Applying modifications Background Loading
Tasks Scheduling Stage 1 Stage 2 Stage 3 Task C Task E Task A Task D Gate Task B Task F Waiting
60 FPS for everyone 2. « SHEARS » SOLution
Focus on data, not on the code 2.1 Data Driven Scheduling
Data drivenscheduling Data D0 Task A Task A Task A Task A Task A Task A Task A Data D0 Task C Task A Task A Task A Task B Data D1 Data D1
Data drivenscheduling Data D0 D0 D1 Task A Task A Task A Task A Task A Task A Task A Task C Task A Task A Task A Task B Data D1
Data driven scheduling D0 D1 Task A Task B Task C
Data driven scheduling D0 D1 Task A Task B Task C
No locks, be scalable 2.2 workloads
Lock-free : Internal Thread 1 Container::Add() Thread 2 Container::Remove() Container State State State State State State State Test &Set Test &Set SUCCESS ! FAILED ! SUCCESS !
Easy cross-platforming, easydebugging 2.3 Workingwith SPU
Working with SPUCross Platform API DMA Impl Main Memory Impl Memory Access Interface SatelliteTask
Working with SPU Easy Debugging DMA Impl Main Memory Impl Memory Access Interface SatelliteTask
Working with SPU Easy Debugging Named Pipe DMA Impl Main Memory Impl Memory Access Interface SatelliteTask
Multithreading & peace of mind 3. Tips & tricks
Trick 1: Perturbation Loop n Loop n+1 Test A Test B Test A Test B Thread A Test C Test D Test C Test D Thread B New thread synchronization
Trick 2: State validation Process A Process B Process C State 1 State 2 State 3 State X Assert ! Process X
Trick 2: State validation classStateChecker { public: enum State { State1, State2, State3 }; StateChecker() { m_state = State1; } boolSetState( State oldState, State newState ) { return Atomic::TestAndSet ( &m_state, oldState, newState ) == oldState; } private: volatile State m_state; };
Trick 3: Access verification classAccessChecker { public: AccessChecker() { m_access = 0; } boolStartReadAccess() { returnAtomic::Inc( &m_access ) > 0; } boolEndReadAccess() { returnAtomic::Dec( &m_access ) >= 0; } boolStartWriteAccess() { return Atomic::Dec( &m_access ) == -1; } boolEndWriteAccess() { return Atomic::Inc( &m_access ) == 0; } private: volatileintm_access; };
Trick 4: Multithreaded Assert extern volatile boolg_waitOnAssert = false; #define ASSERT( condition ) \while(g_waitOnAssert) {} \if( !(condition) ) \{ \g_waitOnAssert = true; \DoAssert(); \g_waitOnAssert = false; \}
Inspiration • Game Programming Gems 6: Lock-free Algorithmsby Toby Jones • Design and Implementation of Multi-Threaded Gamesby Bruce Dawson • Floodgate: Maximizing SPU parallelism without sacrificing cross platform developmentby David Asbell & Michael Noland • SPU Shadersby Mike Acton
michael.lavaire@ubisoft.com remi.quenin@ubisoft.com
Ubisoft is recruiting!Come see us at the Ubisoft Booth in the Career Pavilion (CP 2308, South Hall)You can also check out:www.creatorsofemotions.com