1 of 11

TaskGraphRunner

go/task-graph-runner

7 OCT 2015

2 of 11

TaskGraphRunner

TaskGraphRunner

Interface for scheduling and running tasks in the order defined by a dependency graph.

3 of 11

TaskGraphRunner

Potential Use Cases

Existing Use Cases

SW/GPU Raster

Image Decode

Video Decode

4 of 11

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

5 of 11

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

6 of 11

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

7 of 11

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

8 of 11

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

9 of 11

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

10 of 11

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

11 of 11

Thanks.

reveman@google.com

go/task-graph-runner