|
|
ff6046 |
From 0412acb95ffac94d5916ee19991cc7194e55953c Mon Sep 17 00:00:00 2001
|
|
|
ff6046 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
ff6046 |
Date: Tue, 13 Nov 2018 12:48:49 +0100
|
|
|
ff6046 |
Subject: [PATCH] core: make sure we don't throttle change signal generator
|
|
|
ff6046 |
when a reload is pending
|
|
|
ff6046 |
|
|
|
ff6046 |
Fixes: #10627
|
|
|
ff6046 |
(cherry picked from commit b8d381c47776ea0440af175cbe0c02cb743bde08)
|
|
|
ff6046 |
|
|
|
ff6046 |
Resolves: #1647359
|
|
|
ff6046 |
---
|
|
|
ff6046 |
src/core/manager.c | 64 ++++++++++++++++++++++++++++------------------
|
|
|
ff6046 |
1 file changed, 39 insertions(+), 25 deletions(-)
|
|
|
ff6046 |
|
|
|
ff6046 |
diff --git a/src/core/manager.c b/src/core/manager.c
|
|
|
ff6046 |
index a24bfcacdf..3b2fe11e87 100644
|
|
|
ff6046 |
--- a/src/core/manager.c
|
|
|
ff6046 |
+++ b/src/core/manager.c
|
|
|
ff6046 |
@@ -2074,56 +2074,70 @@ static unsigned manager_dispatch_dbus_queue(Manager *m) {
|
|
|
ff6046 |
|
|
|
ff6046 |
assert(m);
|
|
|
ff6046 |
|
|
|
ff6046 |
+ /* Avoid recursion */
|
|
|
ff6046 |
if (m->dispatching_dbus_queue)
|
|
|
ff6046 |
return 0;
|
|
|
ff6046 |
|
|
|
ff6046 |
- /* Anything to do at all? */
|
|
|
ff6046 |
- if (!m->dbus_unit_queue && !m->dbus_job_queue && !m->send_reloading_done && !m->pending_reload_message)
|
|
|
ff6046 |
- return 0;
|
|
|
ff6046 |
+ /* When we are reloading, let's not wait with generating signals, since we need to exit the manager as quickly
|
|
|
ff6046 |
+ * as we can. There's no point in throttling generation of signals in that case. */
|
|
|
ff6046 |
+ if (MANAGER_IS_RELOADING(m) || m->send_reloading_done || m->pending_reload_message)
|
|
|
ff6046 |
+ budget = (unsigned) -1; /* infinite budget in this case */
|
|
|
ff6046 |
+ else {
|
|
|
ff6046 |
+ /* Anything to do at all? */
|
|
|
ff6046 |
+ if (!m->dbus_unit_queue && !m->dbus_job_queue)
|
|
|
ff6046 |
+ return 0;
|
|
|
ff6046 |
|
|
|
ff6046 |
- /* Do we have overly many messages queued at the moment? If so, let's not enqueue more on top, let's sit this
|
|
|
ff6046 |
- * cycle out, and process things in a later cycle when the queues got a bit emptier. */
|
|
|
ff6046 |
- if (manager_bus_n_queued_write(m) > MANAGER_BUS_BUSY_THRESHOLD)
|
|
|
ff6046 |
- return 0;
|
|
|
ff6046 |
+ /* Do we have overly many messages queued at the moment? If so, let's not enqueue more on top, let's
|
|
|
ff6046 |
+ * sit this cycle out, and process things in a later cycle when the queues got a bit emptier. */
|
|
|
ff6046 |
+ if (manager_bus_n_queued_write(m) > MANAGER_BUS_BUSY_THRESHOLD)
|
|
|
ff6046 |
+ return 0;
|
|
|
ff6046 |
|
|
|
ff6046 |
- /* Only process a certain number of units/jobs per event loop iteration. Even if the bus queue wasn't overly
|
|
|
ff6046 |
- * full before this call we shouldn't increase it in size too wildly in one step, and we shouldn't monopolize
|
|
|
ff6046 |
- * CPU time with generating these messages. Note the difference in counting of this "budget" and the
|
|
|
ff6046 |
- * "threshold" above: the "budget" is decreased only once per generated message, regardless how many
|
|
|
ff6046 |
- * busses/direct connections it is enqueued on, while the "threshold" is applied to each queued instance of bus
|
|
|
ff6046 |
- * message, i.e. if the same message is enqueued to five busses/direct connections it will be counted five
|
|
|
ff6046 |
- * times. This difference in counting ("references" vs. "instances") is primarily a result of the fact that
|
|
|
ff6046 |
- * it's easier to implement it this way, however it also reflects the thinking that the "threshold" should put
|
|
|
ff6046 |
- * a limit on used queue memory, i.e. space, while the "budget" should put a limit on time. Also note that
|
|
|
ff6046 |
- * the "threshold" is currently chosen much higher than the "budget". */
|
|
|
ff6046 |
- budget = MANAGER_BUS_MESSAGE_BUDGET;
|
|
|
ff6046 |
+ /* Only process a certain number of units/jobs per event loop iteration. Even if the bus queue wasn't
|
|
|
ff6046 |
+ * overly full before this call we shouldn't increase it in size too wildly in one step, and we
|
|
|
ff6046 |
+ * shouldn't monopolize CPU time with generating these messages. Note the difference in counting of
|
|
|
ff6046 |
+ * this "budget" and the "threshold" above: the "budget" is decreased only once per generated message,
|
|
|
ff6046 |
+ * regardless how many busses/direct connections it is enqueued on, while the "threshold" is applied to
|
|
|
ff6046 |
+ * each queued instance of bus message, i.e. if the same message is enqueued to five busses/direct
|
|
|
ff6046 |
+ * connections it will be counted five times. This difference in counting ("references"
|
|
|
ff6046 |
+ * vs. "instances") is primarily a result of the fact that it's easier to implement it this way,
|
|
|
ff6046 |
+ * however it also reflects the thinking that the "threshold" should put a limit on used queue memory,
|
|
|
ff6046 |
+ * i.e. space, while the "budget" should put a limit on time. Also note that the "threshold" is
|
|
|
ff6046 |
+ * currently chosen much higher than the "budget". */
|
|
|
ff6046 |
+ budget = MANAGER_BUS_MESSAGE_BUDGET;
|
|
|
ff6046 |
+ }
|
|
|
ff6046 |
|
|
|
ff6046 |
m->dispatching_dbus_queue = true;
|
|
|
ff6046 |
|
|
|
ff6046 |
- while (budget > 0 && (u = m->dbus_unit_queue)) {
|
|
|
ff6046 |
+ while (budget != 0 && (u = m->dbus_unit_queue)) {
|
|
|
ff6046 |
|
|
|
ff6046 |
assert(u->in_dbus_queue);
|
|
|
ff6046 |
|
|
|
ff6046 |
bus_unit_send_change_signal(u);
|
|
|
ff6046 |
- n++, budget--;
|
|
|
ff6046 |
+ n++;
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ if (budget != (unsigned) -1)
|
|
|
ff6046 |
+ budget--;
|
|
|
ff6046 |
}
|
|
|
ff6046 |
|
|
|
ff6046 |
- while (budget > 0 && (j = m->dbus_job_queue)) {
|
|
|
ff6046 |
+ while (budget != 0 && (j = m->dbus_job_queue)) {
|
|
|
ff6046 |
assert(j->in_dbus_queue);
|
|
|
ff6046 |
|
|
|
ff6046 |
bus_job_send_change_signal(j);
|
|
|
ff6046 |
- n++, budget--;
|
|
|
ff6046 |
+ n++;
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ if (budget != (unsigned) -1)
|
|
|
ff6046 |
+ budget--;
|
|
|
ff6046 |
}
|
|
|
ff6046 |
|
|
|
ff6046 |
m->dispatching_dbus_queue = false;
|
|
|
ff6046 |
|
|
|
ff6046 |
- if (budget > 0 && m->send_reloading_done) {
|
|
|
ff6046 |
+ if (m->send_reloading_done) {
|
|
|
ff6046 |
m->send_reloading_done = false;
|
|
|
ff6046 |
bus_manager_send_reloading(m, false);
|
|
|
ff6046 |
- n++, budget--;
|
|
|
ff6046 |
+ n++;
|
|
|
ff6046 |
}
|
|
|
ff6046 |
|
|
|
ff6046 |
- if (budget > 0 && m->pending_reload_message) {
|
|
|
ff6046 |
+ if (m->pending_reload_message) {
|
|
|
ff6046 |
bus_send_pending_reload_message(m);
|
|
|
ff6046 |
n++;
|
|
|
ff6046 |
}
|