1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 include protocol PBackground;
7 using mozilla::TimeDuration from "mozilla/TimeStamp.h";
8 using base::SharedMemoryHandle from "base/shared_memory.h";
13 * PIdleScheduler is the protocol for cross-process idle scheduling.
14 * Only child processes participate in the scheduling and parent process
15 * can run its idle tasks whenever it needs to.
17 * The scheduler keeps track of the following things.
18 * - Activity of the main thread of each child process. A process is active
19 * when it is running tasks. Because of performance cross-process
20 * counters in shared memory are used for the activity tracking. There is
21 * one counter counting the activity state of all the processes and one
22 * counter for each process. This way if a child process crashes, the global
23 * counter can be updated by decrementing the per process counter from it.
24 * - Child processes running prioritized operation. Top level page loads is an
25 * example of a prioritized operation. When such is ongoing, idle tasks are
27 * - Idle requests. When a child process locally has idle tasks to run, it
28 * requests idle time from the scheduler. Initially requests go to a wait list
29 * and the scheduler runs and if there are free logical cores for the child
30 * processes, idle time is given to the child process, and the process goes to
31 * the idle list. Once idle time has been consumed or there are no tasks to
32 * process, child process informs the scheduler and the process is moved back
33 * to the default queue.
35 async refcounted protocol PIdleScheduler
40 async IdleTime(uint64_t id, TimeDuration budget);
43 async InitForIdleUse() returns (SharedMemoryHandle? state, uint32_t childId);
44 async RequestIdleTime(uint64_t id, TimeDuration budget);
45 async IdleTimeUsed(uint64_t id);
47 // Child can send explicit Schedule message to parent if it thinks parent process
48 // might be able to let some other process to use idle time.
51 // Note, these two messages can be sent even before InitForIdleUse.
52 async RunningPrioritizedOperation();
53 async PrioritizedOperationDone();
55 // This message is never sent. Each PIdleScheduler actor will stay alive as long as
56 // its PBackground manager.
61 } // namespace mozilla