job: make the run queue order deterministic
Jobs are added to the run queue in random order. This happens because most jobs are added by iterating over the transaction or dependency hash maps. As a result, jobs that can be executed at the same time are started in a different order each time. On small embedded devices this can cause a measurable jitter for the point in time when a job starts (~100ms jitter for 10 units that are started in random order). This results is a similar jitter for the boot time. This is undesirable in general and make optimizing the boot time a lot harder. Also, jobs that should have a higher priority because the unit has a higher CPU weight might get executed later than others. Fix this by turning the job run_queue into a Prioq and sort by the following criteria (use the next if the values are equal): - CPU weight - nice level - unit type - unit name The last one is just there for deterministic sorting to avoid any jitter.
This commit is contained in:
+2
-1
@@ -13,6 +13,7 @@
|
||||
#include "hashmap.h"
|
||||
#include "ip-address-access.h"
|
||||
#include "list.h"
|
||||
#include "prioq.h"
|
||||
#include "ratelimit.h"
|
||||
|
||||
struct libmnt_monitor;
|
||||
@@ -145,7 +146,7 @@ struct Manager {
|
||||
LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */
|
||||
|
||||
/* Jobs that need to be run */
|
||||
LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */
|
||||
struct Prioq *run_queue;
|
||||
|
||||
/* Units and jobs that have not yet been announced via
|
||||
* D-Bus. When something about a job changes it is added here
|
||||
|
||||
Reference in New Issue
Block a user