TaskGraphRunner
go/task-graph-runner
7 OCT 2015
TaskGraphRunner
TaskGraphRunner
Interface for scheduling and running tasks in the order defined by a dependency graph.
TaskGraphRunner
Potential Use Cases
Existing Use Cases
SW/GPU Raster
Image Decode
Video Decode
TaskGraphRunner
Examples
Example – Raster
Rasterization of each tile depends on a number of images having been decoded
Multiple tiles depend on the same image having been decoded
The compositor thread should be notified when some set of tasks finish running
Ready to draw
Ready to activate
Tile 1
Tile 2
Tile 3
Tile 4
Tile 5
Image 1
Image 2
Image 3
TaskGraphRunner
Benefits
Features
Executes complicated task dependencies without unnecessary context switches
Cancel and/or re-prioritize already scheduled tasks
Low task processing overhead
Fine-grained task priorities (using TaskPriority = unsigned)
Thread-safe scheduling of tasks
Schedule tasks on from any thread. Tasks can run on any thread
Task namespaces
One implementation and one set of worker threads per process
API - Task
class Task : public base::RefCountedThreadSafe<Task> {
public:
virtual void RunOnWorkerThread() = 0;
private:
friend class base::RefCountedThreadSafe<Task>;
};
TaskGraphRunner
API
C++
1
2
3
4
5
6
7
API - TaskGraph
struct TaskGraph {
struct Node {
Task* task;� int priority;� int dependencies;
};
struct Edge {
const Task* task;
Task* dependent;
};
std::vector<Node> nodes;
std::vector<Edge> edges;
};
TaskGraphRunner
API
C++
1
2
3
4
5
6 7 8 9 10 11 12 13
14
API - TaskGraphRunner
class TaskGraphRunner {
public:
NamespaceToken GetNamespaceToken();
void ScheduleTasks(NamespaceToken token, TaskGraph* graph);
void WaitForTasksToFinishRunning(NamespaceToken token);
void CollectCompletedTasks(NamespaceToken token,
Task::Vector* completed_tasks);
};
TaskGraphRunner
API
C++
1
2
3
4
5
6 7 8 9 10 11 12 13
14
TaskGraphRunner
Implementation Details
Implementation Details
Implemented by content::RasterWorkerPoolWorkerPool
Available in each renderer as content::RenderThreadImpl::raster_worker_pool_
Optimized for a relatively small task graphs (~256 tasks or less)
Also implements base::TaskRunner and base::SequencedTaskRunner interfaces
TaskGraphRunner
Future Improvements
Future Improvements
Priority groups
Improve responsiveness and also increase throughput by allowing more cores to be used
Thread affinity
GPU raster on specific thread
Thanks.
reveman@google.com
go/task-graph-runner