PIdleScheduler.ipdl (2921B)
1 /* -*- 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/. */ 5 6 include protocol PBackground; 7 using mozilla::TimeDuration from "mozilla/TimeStamp.h"; 8 [MoveOnly] using mozilla::ipc::MutableSharedMemoryHandle from "mozilla/ipc/SharedMemoryHandle.h"; 9 namespace mozilla { 10 namespace ipc { 11 12 /** 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. 16 * 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 26 * less likely to run. 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. 34 */ 35 async protocol PIdleScheduler { 36 manager PBackground; 37 38 child: 39 async IdleTime(uint64_t id, TimeDuration budget); 40 41 parent: 42 async InitForIdleUse() returns (MutableSharedMemoryHandle? state, uint32_t childId); 43 async RequestIdleTime(uint64_t id, TimeDuration budget); 44 async IdleTimeUsed(uint64_t id); 45 46 // Child can send explicit Schedule message to parent if it thinks parent 47 // process might be able to let some other process to use idle time. 48 async Schedule(); 49 50 // Note, these two messages can be sent even before InitForIdleUse. 51 async RunningPrioritizedOperation(); 52 async PrioritizedOperationDone(); 53 54 // Ask if now would be a good time to GC 55 async RequestGC() returns(bool may_gc); 56 57 // Let the parent know when we start a GC without asking first. 58 async StartedGC(); 59 60 // Called for ending any kind of GC. 61 async DoneGC(); 62 63 // This message is never sent. Each PIdleScheduler actor will stay alive as 64 // long as its PBackground manager. 65 async __delete__(); 66 }; 67 68 } // namespace ipc 69 } // namespace mozilla