[systemd-commits] 4 commits - TODO man/systemd-system.conf.xml man/systemd.timer.xml src/core src/systemctl units/systemd-networkd.service.in
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Mar 24 08:49:52 PDT 2014
TODO | 4 --
man/systemd-system.conf.xml | 28 +++++++++++++--
man/systemd.timer.xml | 17 +++++++++
src/core/dbus-timer.c | 40 +++++++++++++++++++--
src/core/load-fragment-gperf.gperf.m4 | 1
src/core/load-fragment.c | 6 ---
src/core/main.c | 3 +
src/core/manager.c | 1
src/core/manager.h | 2 +
src/core/system.conf | 1
src/core/timer.c | 63 ++++++++++++++++++++++++----------
src/core/timer.h | 7 +--
src/core/user.conf | 1
src/systemctl/systemctl.c | 2 -
units/systemd-networkd.service.in | 1
15 files changed, 138 insertions(+), 39 deletions(-)
New commits:
commit 48791a98be997ed22e8c45a89d8d728a2151c074
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 16:48:39 2014 +0100
units: networkd shouldn't have PrivateTmp= set, since it runs in early-boot
/tmp is only available in later boot, and we shouldn't create private
subdirs in it hence, while we are still in early boot.
diff --git a/units/systemd-networkd.service.in b/units/systemd-networkd.service.in
index 793381f..ca40691 100644
--- a/units/systemd-networkd.service.in
+++ b/units/systemd-networkd.service.in
@@ -20,7 +20,6 @@ Restart=always
RestartSec=0
ExecStart=@rootlibexecdir@/systemd-networkd
WatchdogSec=1min
-PrivateTmp=yes
[Install]
WantedBy=multi-user.target
commit 777920bc039f3b1af08eae7e59a598b2bb7e5aaa
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 16:23:56 2014 +0100
update TODO
diff --git a/TODO b/TODO
index 03e7233..febfc3a 100644
--- a/TODO
+++ b/TODO
@@ -36,8 +36,6 @@ Features:
* sd-event: define more intervals where we will shift wakeup intervals around in, 1h, 6h, 24h, ...
-* maybe add DefaultTimerAccuracySec= as global config option to set AccuracySec='s default value in .timer units
-
* gpt-auto-generator:
- Support LUKS for root devices
- Define new partition type for encrypted swap? Support probed LUKS for encrypted swap?
@@ -368,7 +366,6 @@ Features:
- rework wait filter to not require match callback
- better error message if you run systemctl without systemd running
- systemctl status output should should include list of triggering units and their status
- - in systemctl list-timers show time triggering units ran last
* unit install:
- "systemctl mask" should find all names by which a unit is accessible
@@ -384,7 +381,6 @@ Features:
* deal with sendmail/postfix exclusivity
* timer units:
- - timer events with system resume
- timer units should get the ability to trigger when:
o CLOCK_REALTIME makes jumps (TFD_TIMER_CANCEL_ON_SET)
o DST changes
commit bd8f585b9996667db89764ece1cacf37672e3223
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 16:22:34 2014 +0100
core: add a setting to globally control the default for timer unit accuracy
diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml
index a7dfc03..e2b2bd8 100644
--- a/man/systemd-system.conf.xml
+++ b/man/systemd-system.conf.xml
@@ -259,8 +259,8 @@
<term><varname>TimerSlackNSec=</varname></term>
<listitem><para>Sets the timer slack
- in nanoseconds for PID 1 which is then
- inherited to all executed processes,
+ in nanoseconds for PID 1, which is
+ inherited by all executed processes,
unless overridden individually, for
example with the
<varname>TimerSlackNSec=</varname>
@@ -268,7 +268,8 @@
see
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>). The
timer slack controls the accuracy of
- wake-ups triggered by timers. See
+ wake-ups triggered by system
+ timers. See
<citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
for more information. Note that in
contrast to most other time span
@@ -280,6 +281,27 @@
</varlistentry>
<varlistentry>
+ <term><varname>DefaultTimerAccuracySec=</varname></term>
+
+ <listitem><para>Sets the default
+ accuracy of timer units. This controls
+ the global default for the
+ <varname>AccuracySec=</varname>
+ setting of timer units, see
+ <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ for
+ details. <varname>AccuracySec=</varname>
+ set in individual units override the
+ global default for the specific
+ unit. Defaults to 1min. Note that the
+ accuracy of timer units is also
+ affected by the configured timer slack
+ for PID 1, see
+ <varname>TimerSlackNSec=</varname>
+ above.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><varname>DefaultTimeoutStartSec=</varname></term>
<term><varname>DefaultTimeoutStopSec=</varname></term>
<term><varname>DefaultRestartSec=</varname></term>
diff --git a/src/core/main.c b/src/core/main.c
index e0fbb6e..41605ee 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -108,6 +108,7 @@ static char **arg_default_environment = NULL;
static struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {};
static uint64_t arg_capability_bounding_set_drop = 0;
static nsec_t arg_timer_slack_nsec = (nsec_t) -1;
+static usec_t arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
static Set* arg_syscall_archs = NULL;
static FILE* arg_serialization = NULL;
static bool arg_default_cpu_accounting = false;
@@ -686,6 +687,7 @@ static int parse_config_file(void) {
{ "Manager", "SystemCallArchitectures", config_parse_syscall_archs, 0, &arg_syscall_archs },
#endif
{ "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec },
+ { "Manager", "DefaultTimerAccuracySec", config_parse_sec, 0, &arg_default_timer_accuracy_usec },
{ "Manager", "DefaultStandardOutput", config_parse_output, 0, &arg_default_std_output },
{ "Manager", "DefaultStandardError", config_parse_output, 0, &arg_default_std_error },
{ "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec },
@@ -1635,6 +1637,7 @@ int main(int argc, char *argv[]) {
}
m->confirm_spawn = arg_confirm_spawn;
+ m->default_timer_accuracy_usec = arg_default_timer_accuracy_usec;
m->default_std_output = arg_default_std_output;
m->default_std_error = arg_default_std_error;
m->default_restart_usec = arg_default_restart_usec;
diff --git a/src/core/manager.c b/src/core/manager.c
index a3ff85c..224106c 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -428,6 +428,7 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
m->running_as = running_as;
m->exit_code = _MANAGER_EXIT_CODE_INVALID;
+ m->default_timer_accuracy_usec = USEC_PER_MINUTE;
m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1;
diff --git a/src/core/manager.h b/src/core/manager.h
index 38f1c89..14cdf81 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -241,6 +241,8 @@ struct Manager {
bool default_memory_accounting;
bool default_blockio_accounting;
+ usec_t default_timer_accuracy_usec;
+
struct rlimit *rlimit[_RLIMIT_MAX];
/* non-zero if we are reloading or reexecuting, */
diff --git a/src/core/system.conf b/src/core/system.conf
index 5be158d..65a35a0 100644
--- a/src/core/system.conf
+++ b/src/core/system.conf
@@ -23,6 +23,7 @@
#CapabilityBoundingSet=
#SystemCallArchitectures=
#TimerSlackNSec=
+#DefaultTimerAccuracySec=1min
#DefaultStandardOutput=journal
#DefaultStandardError=inherit
#DefaultTimeoutStartSec=90s
diff --git a/src/core/timer.c b/src/core/timer.c
index 62baf57..6c85304 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -48,7 +48,7 @@ static void timer_init(Unit *u) {
t->next_elapse_monotonic_or_boottime = (usec_t) -1;
t->next_elapse_realtime = (usec_t) -1;
- t->accuracy_usec = USEC_PER_MINUTE;
+ t->accuracy_usec = u->manager->default_timer_accuracy_usec;
}
void timer_free_values(Timer *t) {
diff --git a/src/core/user.conf b/src/core/user.conf
index f19ac75..8c7ecde 100644
--- a/src/core/user.conf
+++ b/src/core/user.conf
@@ -14,6 +14,7 @@
#LogLocation=no
#SystemCallArchitectures=
#TimerSlackNSec=
+#DefaultTimerAccuracySec=1min
#DefaultStandardOutput=inherit
#DefaultStandardError=inherit
#DefaultTimeoutStartSec=90s
commit dedabea4b3d61a87cedb5c8d7ccce5b86ea84afe
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Mar 24 16:09:54 2014 +0100
timer: support timers that can resume the system from suspend
diff --git a/man/systemd.timer.xml b/man/systemd.timer.xml
index b60199c..58eaab0 100644
--- a/man/systemd.timer.xml
+++ b/man/systemd.timer.xml
@@ -271,6 +271,23 @@
<varname>OnCalendar=</varname>.
</para></listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><varname>WakeSystem=</varname></term>
+
+ <listitem><para>Takes a boolean
+ argument. If true an elapsing timer
+ will cause the system to resume from
+ suspend, should it be suspended and if
+ the system supports this. Note that
+ this option will only make sure the
+ system resumes on the appropriate
+ times, it will not take care of
+ suspending it again after any work
+ that is to be done is
+ finished. Defaults to
+ <varname>false</varname>.</para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c
index c9b80a0..f1f8c54 100644
--- a/src/core/dbus-timer.c
+++ b/src/core/dbus-timer.c
@@ -135,17 +135,51 @@ static int property_get_unit(
return sd_bus_message_append(reply, "s", trigger ? trigger->id : "");
}
+static int property_get_next_elapse_monotonic(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ Timer *t = userdata;
+ usec_t x;
+
+ assert(bus);
+ assert(reply);
+ assert(t);
+
+ if (t->next_elapse_monotonic_or_boottime <= 0)
+ x = 0;
+ else if (t->wake_system) {
+ usec_t a, b;
+
+ a = now(CLOCK_MONOTONIC);
+ b = now(CLOCK_BOOTTIME);
+
+ if (t->next_elapse_monotonic_or_boottime + a > b)
+ x = t->next_elapse_monotonic_or_boottime + a - b;
+ else
+ x = 0;
+ } else
+ x = t->next_elapse_monotonic_or_boottime;
+
+ return sd_bus_message_append(reply, "t", x);
+}
+
const sd_bus_vtable bus_timer_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Unit", "s", property_get_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("TimersMonotonic", "a(stt)", property_get_monotonic_timers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
SD_BUS_PROPERTY("TimersCalendar", "a(sst)", property_get_calendar_timers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
SD_BUS_PROPERTY("NextElapseUSecRealtime", "t", bus_property_get_usec, offsetof(Timer, next_elapse_realtime), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
- SD_BUS_PROPERTY("NextElapseUSecMonotonic", "t", bus_property_get_usec, offsetof(Timer, next_elapse_monotonic), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
- SD_BUS_PROPERTY("LastTriggerUSecRealtime", "t", bus_property_get_usec, offsetof(Timer, last_trigger.realtime), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
- SD_BUS_PROPERTY("LastTriggerUSecMonotonic", "t", bus_property_get_usec, offsetof(Timer, last_trigger.monotonic), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("NextElapseUSecMonotonic", "t", property_get_next_elapse_monotonic, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ BUS_PROPERTY_DUAL_TIMESTAMP("LastTriggerUSec", offsetof(Timer, last_trigger), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Timer, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("AccuracyUSec", "t", bus_property_get_usec, offsetof(Timer, accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Persistent", "b", bus_property_get_bool, offsetof(Timer, persistent), SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("WakeSystem", "b", bus_property_get_bool, offsetof(Timer, wake_system), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_VTABLE_END
};
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 55fd3da..3a77234 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -286,6 +286,7 @@ Timer.OnStartupSec, config_parse_timer, 0,
Timer.OnUnitActiveSec, config_parse_timer, 0, 0
Timer.OnUnitInactiveSec, config_parse_timer, 0, 0
Timer.Persistent, config_parse_bool, 0, offsetof(Timer, persistent)
+Timer.WakeSystem, config_parse_bool, 0, offsetof(Timer, wake_system)
Timer.AccuracySec, config_parse_sec, 0, offsetof(Timer, accuracy_usec)
Timer.Unit, config_parse_trigger_unit, 0, 0
m4_dnl
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index fa4e931..e7779d1 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -1254,7 +1254,6 @@ int config_parse_timer(const char *unit,
TimerValue *v;
TimerBase b;
CalendarSpec *c = NULL;
- clockid_t id;
assert(filename);
assert(lvalue);
@@ -1281,8 +1280,6 @@ int config_parse_timer(const char *unit,
rvalue);
return 0;
}
-
- id = CLOCK_REALTIME;
} else {
if (parse_sec(rvalue, &u) < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
@@ -1290,8 +1287,6 @@ int config_parse_timer(const char *unit,
rvalue);
return 0;
}
-
- id = CLOCK_MONOTONIC;
}
v = new0(TimerValue, 1);
@@ -1299,7 +1294,6 @@ int config_parse_timer(const char *unit,
return log_oom();
v->base = b;
- v->clock_id = id;
v->value = u;
v->calendar_spec = c;
diff --git a/src/core/timer.c b/src/core/timer.c
index 95416f3..62baf57 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -46,7 +46,7 @@ static void timer_init(Unit *u) {
assert(u);
assert(u->load_state == UNIT_STUB);
- t->next_elapse_monotonic = (usec_t) -1;
+ t->next_elapse_monotonic_or_boottime = (usec_t) -1;
t->next_elapse_realtime = (usec_t) -1;
t->accuracy_usec = USEC_PER_MINUTE;
}
@@ -203,10 +203,14 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
"%sTimer State: %s\n"
"%sResult: %s\n"
"%sUnit: %s\n"
+ "%sPersistent: %s\n"
+ "%sWakeSystem: %s\n"
"%sAccuracy: %s\n",
prefix, timer_state_to_string(t->state),
prefix, timer_result_to_string(t->result),
prefix, trigger ? trigger->id : "n/a",
+ prefix, yes_no(t->persistent),
+ prefix, yes_no(t->wake_system),
prefix, format_timespan(buf, sizeof(buf), t->accuracy_usec, 1));
LIST_FOREACH(value, v, t->values) {
@@ -282,15 +286,34 @@ static void timer_enter_dead(Timer *t, TimerResult f) {
timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
}
+static usec_t monotonic_to_boottime(usec_t t) {
+ usec_t a, b;
+
+ if (t <= 0)
+ return 0;
+
+ a = now(CLOCK_BOOTTIME);
+ b = now(CLOCK_MONOTONIC);
+
+ if (t + a > b)
+ return t + a - b;
+ else
+ return 0;
+}
+
static void timer_enter_waiting(Timer *t, bool initial) {
- TimerValue *v;
- usec_t base = 0;
- dual_timestamp ts;
bool found_monotonic = false, found_realtime = false;
+ usec_t ts_realtime, ts_monotonic;
+ usec_t base = 0;
+ TimerValue *v;
int r;
- dual_timestamp_get(&ts);
- t->next_elapse_monotonic = t->next_elapse_realtime = 0;
+ /* If we shall wake the system we use the boottime clock
+ * rather than the monotonic clock. */
+
+ ts_realtime = now(CLOCK_REALTIME);
+ ts_monotonic = now(t->wake_system ? CLOCK_BOOTTIME : CLOCK_MONOTONIC);
+ t->next_elapse_monotonic_or_boottime = t->next_elapse_realtime = 0;
LIST_FOREACH(value, v, t->values) {
@@ -305,7 +328,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
* to that. If we don't just start from
* now. */
- b = t->last_trigger.realtime > 0 ? t->last_trigger.realtime : ts.realtime;
+ b = t->last_trigger.realtime > 0 ? t->last_trigger.realtime : ts_realtime;
r = calendar_spec_next_usec(v->calendar_spec, b, &v->next_elapse);
if (r < 0)
@@ -325,7 +348,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
if (state_translation_table[t->state] == UNIT_ACTIVE)
base = UNIT(t)->inactive_exit_timestamp.monotonic;
else
- base = ts.monotonic;
+ base = ts_monotonic;
break;
case TIMER_BOOT:
@@ -365,18 +388,21 @@ static void timer_enter_waiting(Timer *t, bool initial) {
assert_not_reached("Unknown timer base");
}
+ if (t->wake_system)
+ base = monotonic_to_boottime(base);
+
v->next_elapse = base + v->value;
- if (!initial && v->next_elapse < ts.monotonic && IN_SET(v->base, TIMER_ACTIVE, TIMER_BOOT, TIMER_STARTUP)) {
+ if (!initial && v->next_elapse < ts_monotonic && IN_SET(v->base, TIMER_ACTIVE, TIMER_BOOT, TIMER_STARTUP)) {
/* This is a one time trigger, disable it now */
v->disabled = true;
continue;
}
if (!found_monotonic)
- t->next_elapse_monotonic = v->next_elapse;
+ t->next_elapse_monotonic_or_boottime = v->next_elapse;
else
- t->next_elapse_monotonic = MIN(t->next_elapse_monotonic, v->next_elapse);
+ t->next_elapse_monotonic_or_boottime = MIN(t->next_elapse_monotonic_or_boottime, v->next_elapse);
found_monotonic = true;
}
@@ -390,10 +416,13 @@ static void timer_enter_waiting(Timer *t, bool initial) {
if (found_monotonic) {
char buf[FORMAT_TIMESPAN_MAX];
- log_debug_unit(UNIT(t)->id, "%s: Monotonic timer elapses in %s.", UNIT(t)->id, format_timespan(buf, sizeof(buf), t->next_elapse_monotonic > ts.monotonic ? t->next_elapse_monotonic - ts.monotonic : 0, 0));
+
+ log_debug_unit(UNIT(t)->id, "%s: Monotonic timer elapses in %s.",
+ UNIT(t)->id,
+ format_timespan(buf, sizeof(buf), t->next_elapse_monotonic_or_boottime > ts_monotonic ? t->next_elapse_monotonic_or_boottime - ts_monotonic : 0, 0));
if (t->monotonic_event_source) {
- r = sd_event_source_set_time(t->monotonic_event_source, t->next_elapse_monotonic);
+ r = sd_event_source_set_time(t->monotonic_event_source, t->next_elapse_monotonic_or_boottime);
if (r < 0)
goto fail;
@@ -402,8 +431,8 @@ static void timer_enter_waiting(Timer *t, bool initial) {
r = sd_event_add_time(
UNIT(t)->manager->event,
&t->monotonic_event_source,
- CLOCK_MONOTONIC,
- t->next_elapse_monotonic, t->accuracy_usec,
+ t->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC,
+ t->next_elapse_monotonic_or_boottime, t->accuracy_usec,
timer_dispatch, t);
if (r < 0)
goto fail;
@@ -429,7 +458,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
r = sd_event_add_time(
UNIT(t)->manager->event,
&t->realtime_event_source,
- CLOCK_REALTIME,
+ t->wake_system ? CLOCK_REALTIME_ALARM : CLOCK_REALTIME,
t->next_elapse_realtime, t->accuracy_usec,
timer_dispatch, t);
if (r < 0)
diff --git a/src/core/timer.h b/src/core/timer.h
index 712cced..de412a0 100644
--- a/src/core/timer.h
+++ b/src/core/timer.h
@@ -50,7 +50,6 @@ typedef enum TimerBase {
typedef struct TimerValue {
TimerBase base;
bool disabled;
- clockid_t clock_id;
usec_t value; /* only for monotonic events */
CalendarSpec *calendar_spec; /* only for calendar events */
@@ -72,8 +71,9 @@ struct Timer {
usec_t accuracy_usec;
LIST_HEAD(TimerValue, values);
- usec_t next_elapse_monotonic;
usec_t next_elapse_realtime;
+ usec_t next_elapse_monotonic_or_boottime;
+ dual_timestamp last_trigger;
TimerState state, deserialized_state;
@@ -83,8 +83,7 @@ struct Timer {
TimerResult result;
bool persistent;
-
- dual_timestamp last_trigger;
+ bool wake_system;
char *stamp_path;
};
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index cceb2b6..0887bc3 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -964,7 +964,7 @@ static int get_last_trigger(
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Timer",
- "LastTriggerUSecRealtime",
+ "LastTriggerUSec",
&error,
't',
last);
More information about the systemd-commits
mailing list