Re: [RFC 01/20] ns: Introduce Time Namespace

From: Laurent Vivier
Date: Fri Sep 28 2018 - 14:20:27 EST


On 19/09/2018 22:50, Dmitry Safonov wrote:
> From: Andrei Vagin <avagin@xxxxxxxxxx>
>
> Time Namespace isolates clock values.
>
> The kernel provides access to several clocks CLOCK_REALTIME,
> CLOCK_MONOTONIC, CLOCK_BOOTTIME, etc.
>
> CLOCK_REALTIME
> System-wide clock that measures real (i.e., wall-clock) time.
>
> CLOCK_MONOTONIC
> Clock that cannot be set and represents monotonic time since
> some unspecified starting point.
>
> CLOCK_BOOTTIME
> Identical to CLOCK_MONOTONIC, except it also includes any time
> that the system is suspended.
>
> For many users, the time namespace means the ability to changes time in
> a container (CLOCK_REALTIME).
>
> But in a context of the checkpoint/restore functionality, monotonic and
> bootime clocks become interesting. Both clocks are monotonic with
> unspecified staring points. These clocks are widely used to measure time
> slices, set timers. After restoring or migrating processes, we have to
> guarantee that they never go backward. In an ideal case, the behavior of
> these clocks should be the same as for a case when a whole system is
> suspended. All this means that we need to be able to set CLOCK_MONOTONIC
> and CLOCK_BOOTTIME clocks, what can be done by adding per-namespace
> offsets for clocks.
>
> Link: https://criu.org/Time_namespace
> Link: https://lists.openvz.org/pipermail/criu/2018-June/041504.html
> Signed-off-by: Andrei Vagin <avagin@xxxxxxxxxx>
> Co-developed-by: Dmitry Safonov <dima@xxxxxxxxxx>
> Signed-off-by: Dmitry Safonov <dima@xxxxxxxxxx>
> ---
> fs/proc/namespaces.c | 3 +
> include/linux/nsproxy.h | 1 +
> include/linux/proc_ns.h | 1 +
> include/linux/time_namespace.h | 59 ++++++++++++++
> include/linux/user_namespace.h | 1 +
> include/uapi/linux/sched.h | 1 +
> init/Kconfig | 7 ++
> kernel/Makefile | 1 +
> kernel/fork.c | 3 +-
> kernel/nsproxy.c | 19 ++++-
> kernel/time_namespace.c | 169 +++++++++++++++++++++++++++++++++++++++++
> 11 files changed, 262 insertions(+), 3 deletions(-)
> create mode 100644 include/linux/time_namespace.h
> create mode 100644 kernel/time_namespace.c
>
...
> diff --git a/kernel/time_namespace.c b/kernel/time_namespace.c
> new file mode 100644
> index 000000000000..902cd9c22159
> --- /dev/null
> +++ b/kernel/time_namespace.c
...
> +
> +struct time_namespace init_time_ns = {
> + .kref = KREF_INIT(2),
> + .user_ns = &init_user_ns,
> + .ns.inum = PROC_UTS_INIT_INO,

Do you mean PROC_TIME_INIT_INO?

> +#ifdef CONFIG_UTS_NS
> + .ns.ops = &timens_operations,
> +#endif

Do you mean CONFIG_TIME_NS?

Thanks,
Laurent