Files
xen/m4/systemd.m4
T
Mykola Kvach e54a6cd6a1 systemd: Add hooks to stop/start xen-watchdog on suspend/resume
This patch adds a systemd sleep hook script to stop the xen-watchdog
service before system suspend and start it again after resume.

Stopping the watchdog before a system suspend operation may look unsafe.
Let's imagine the following situation: 'systemctl suspend' does not
interact with the running service at all. In such a case, the Xen
watchdog daemon freezes just before suspend. If this happens, for
example, right before sending a ping, and Xen has not yet marked the
domain as suspended (is_shutting_down), the Xen watchdog timer may
trigger a false alert.

This is an almost impossible situation, because typically:
    ping time = watchdog timeout / 2

and the watchdog timeout is usually set to a relatively large value
(dozens of seconds).

Still, this is more likely with very short watchdog timeouts. It may
happen in the following scenarios:
    * Significant delays occur between freezing Linux tasks and
      triggering the ACPI or PSCI sleep request or handler.
    * Long delays happen inside Xen between the entrance to the sleep
      trigger and the actual forwarding of the sleep request further.

A similar situation may occur on resume with short timeouts. During the
resume operation, Xen restores timers and the domain context. The Xen
watchdog timer also resumes. If it schedules the domain right before the
watchdog timeout expires, and the daemon responsible for pinging is not
yet running, a timeout might occur.

Both scenarios are rare and typically require very small watchdog
timeouts combined with significant delays in Xen or the Linux kernel
during suspend/resume flows.

Conceptually, however, if activating and pinging the Xen watchdog is the
responsibility of the domain and its services, then the domain should
also manage the watchdog service/daemon lifecycle. This is similar to
what is already done by the Xen watchdog driver inside the Linux kernel.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
Reviewed-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
2025-08-01 15:36:02 +02:00

124 lines
4.4 KiB
Plaintext

# systemd.m4 - Macros to check for and enable systemd -*- Autoconf -*-
#
# Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
dnl Some optional path options
AC_DEFUN([AX_SYSTEMD_OPTIONS], [
AC_ARG_WITH(systemd,
AS_HELP_STRING([--with-systemd=DIR],
[set directory for systemd service files [PREFIX/lib/systemd/system]]),
[SYSTEMD_DIR="$withval"],[SYSTEMD_DIR=""])
AC_SUBST(SYSTEMD_DIR)
AC_ARG_WITH(systemd-modules-load,
AS_HELP_STRING([--with-systemd-modules-load=DIR],
[set directory for systemd modules load files [PREFIX/lib/modules-load.d/]]),
[SYSTEMD_MODULES_LOAD="$withval"], [SYSTEMD_MODULES_LOAD=""])
AC_SUBST(SYSTEMD_MODULES_LOAD)
AC_ARG_WITH(systemd-sleep,
AS_HELP_STRING([--with-systemd-sleep=DIR],
[set directory for systemd sleep script files [PREFIX/lib/systemd/system-sleep/]]),
[SYSTEMD_SLEEP_DIR="$withval"], [SYSTEMD_SLEEP_DIR=""])
AC_SUBST(SYSTEMD_SLEEP_DIR)
])
AC_DEFUN([AX_ENABLE_SYSTEMD_OPTS], [
AX_ARG_DEFAULT_ENABLE([systemd], [Disable systemd support])
AX_SYSTEMD_OPTIONS()
])
AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
AX_ARG_DEFAULT_DISABLE([systemd], [Enable systemd support])
AX_SYSTEMD_OPTIONS()
])
AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
AS_IF([test "x$SYSTEMD_DIR" = x], [
dnl In order to use the line below we need to fix upstream systemd
dnl to properly ${prefix} for child variables in
dnl src/core/systemd.pc.in but this is a bit complex at the
dnl moment as they depend on another rootprefix, which can vary
dnl from prefix in practice. We provide our own definition as we
dnl *know* where systemd will dump this to, but this does limit
dnl us to stick to a non custom systemdsystemunitdir, to work
dnl around this we provide the additional configure option
dnl --with-systemd where you can specify the directory for the unit
dnl files. It would also be best to just extend the upstream
dnl pkg-config pkg.m4 with an AC_DEFUN() to do this neatly.
dnl SYSTEMD_DIR="`$PKG_CONFIG --define-variable=prefix=$PREFIX --variable=systemdsystemunitdir systemd`"
SYSTEMD_DIR="\$(prefix)/lib/systemd/system/"
], [])
AS_IF([test "x$SYSTEMD_DIR" = x], [
AC_MSG_ERROR([SYSTEMD_DIR is unset])
], [])
dnl There is no variable for this yet for some reason
AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
SYSTEMD_MODULES_LOAD="\$(prefix)/lib/modules-load.d/"
], [])
AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
AC_MSG_ERROR([SYSTEMD_MODULES_LOAD is unset])
], [])
AS_IF([test "x$SYSTEMD_SLEEP_DIR" = x], [
PKG_CHECK_VAR([SYSTEMD_SLEEP_DIR], [systemd], [systemdsleepdir])
], [])
AS_IF([test "x$SYSTEMD_SLEEP_DIR" = x], [
AC_MSG_ERROR([SYSTEMD_SLEEP_DIR is unset])
], [])
])
AC_DEFUN([AX_CHECK_SYSTEMD], [
dnl Respect user override to disable
AS_IF([test "x$enable_systemd" != "xno"], [
AS_IF([test "x$systemd" = "xy" ], [
AC_DEFINE([HAVE_SYSTEMD], [1], [Systemd available and enabled])
systemd=y
AX_CHECK_SYSTEMD_LIBS()
],[
AS_IF([test "x$enable_systemd" = "xyes"],
[AC_MSG_ERROR([Unable to find systemd development library])],
[systemd=n])
])
],[systemd=n])
])
dnl Enables systemd by default and requires a --disable-systemd option flag
dnl to configure if you want to disable.
AC_DEFUN([AX_ENABLE_SYSTEMD], [
AX_ENABLE_SYSTEMD_OPTS()
AX_CHECK_SYSTEMD()
])
dnl Systemd will be disabled by default and requires you to run configure with
dnl --enable-systemd to look for and enable systemd.
AC_DEFUN([AX_ALLOW_SYSTEMD], [
AX_ALLOW_SYSTEMD_OPTS()
AX_CHECK_SYSTEMD()
])
dnl Systemd will be disabled by default but if your build system is detected
dnl to have systemd build libraries it will be enabled. You can always force
dnl disable with --disable-systemd
AC_DEFUN([AX_AVAILABLE_SYSTEMD], [
AX_ALLOW_SYSTEMD_OPTS()
AX_CHECK_SYSTEMD()
])