Skip to contentSkip to conversation

timerfd -- implement missing parts to checkpoint and restore timerfd state

RFC In review Cyrill Gorcunov 4 participants 7 messages Mar 31, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover timerfd -- implement missing parts to checkpoint and restore timerfd state

Timerfd interface provides to user-space almost all data needed to checkpoint and restore it, the only missing parts are @clockid (and while @ticks can be read by simple read() call there is no way to write its value back). The series exports them to userspace via /proc/pid/fdinfo/N interface and with write() call one can setup @ticks back to a timer.

Please take a look. This is rfc to figure out if there a better way to handle timerfds (maybe ioctls with complete timer context or somthing). Also I'm not sure in one aspect -- if someone sets non-zero @ticks to a timer, should I mark it as expired? Thomas, could you please give me some advice on it?

Cyrill

#1 lore raw

RFC 1/2 timerfd: Implement show_fdinfo method

For checkpoint/restore of timerfd files we need to know the clock type being used on timerfd creation. Thus implement show_fdinfo method where we print out the type.

Also to minimize the number of calls print out the ticks as well (thus one read of fdinfo entry would eliminate the need of doing
read() over timerfd itself).

CC Shawn Landden <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Andrew Morton <[email protected]>
CC Andrey Vagin <[email protected]>
CC Pavel Emelyanov <[email protected]>
---
 fs/timerfd.c |    9 +++++++++
 1 file changed, 9 insertions(+)
fs/timerfd.c +9 -0
Index: linux-2.6.git/fs/timerfd.c
===================================================================
@@ -284,11 +284,20 @@ static ssize_t timerfd_read(struct file
 	return res;
 }
 
+static int timerfd_show(struct seq_file *m, struct file *file)
+{
+	struct timerfd_ctx *ctx = file->private_data;
+
+	return seq_printf(m, "clockid: %d ticks: %llu\n",
+			  ctx->clockid, (unsigned long long)ctx->ticks);
+}
+
 static const struct file_operations timerfd_fops = {
 	.release	= timerfd_release,
 	.poll		= timerfd_poll,
 	.read		= timerfd_read,
 	.llseek		= noop_llseek,
+	.show_fdinfo	= timerfd_show,
 };
 
 static int timerfd_fget(int fd, struct fd *p)
#2 lore raw

Re: [rfc 1/2] timerfd: Implement show_fdinfo method

Quoted 23 lines · Cyrill Gorcunov

For checkpoint/restore of timerfd files we need to know the clock type being used on timerfd creation. Thus implement show_fdinfo method where we print out the type.

Also to minimize the number of calls print out the ticks as well (thus one read of fdinfo entry would eliminate the need of doing
read() over timerfd itself).

CC Shawn Landden <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Andrew Morton <[email protected]>
CC Andrey Vagin <[email protected]>
CC Pavel Emelyanov <[email protected]>
---
 fs/timerfd.c |    9 +++++++++
 1 file changed, 9 insertions(+)

Index: linux-2.6.git/fs/timerfd.c
===================================================================

fs/timerfd.c static ssize_t timerfd_read(struct file · line 293

Quoted 10 lines
fs/timerfd.c +7 -0
@@ -284,11 +284,20 @@ static ssize_t timerfd_read(struct file
 	return res;
 }
 
+static int timerfd_show(struct seq_file *m, struct file *file)
+{
+	struct timerfd_ctx *ctx = file->private_data;
+
+	return seq_printf(m, "clockid: %d ticks: %llu\n",
+			  ctx->clockid, (unsigned long long)ctx->ticks);
+}

And what gives you the flags which were used in timerfd_settime() along with the remaining time to expiry and the interval?

Thanks,

tglx

#3 lore raw

Re: [rfc 1/2] timerfd: Implement show_fdinfo method

Quoted 8 lines · Thomas Gleixner
Quoted 8 lines

Index: linux-2.6.git/fs/timerfd.c
===================================================================

fs/timerfd.c +0 -0
@@ -284,11 +284,20 @@ static ssize_t timerfd_read(struct file
 	return res;
 }
 
Quoted 10 lines

fs/timerfd.c static ssize_t timerfd_read(struct file · line 293

Quoted 7 lines
fs/timerfd.c +7 -0
+static int timerfd_show(struct seq_file *m, struct file *file)
+{
+	struct timerfd_ctx *ctx = file->private_data;
+
+	return seq_printf(m, "clockid: %d ticks: %llu\n",
+			  ctx->clockid, (unsigned long long)ctx->ticks);
+}

And what gives you the flags which were used in timerfd_settime() along with the remaining time to expiry and the interval?

Ouch, indeed, I need to export them as well. Thanks a lot!

#4 lore raw

RFC 2/2 docs: procfs -- Document timerfd output

In reply to Cyrill Gorcunov
CC Shawn Landden <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Andrew Morton <[email protected]>
CC Andrey Vagin <[email protected]>
CC Pavel Emelyanov <[email protected]>
---
 Documentation/filesystems/proc.txt |    9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/filesystems/proc.txt +9 -0
Index: linux-2.6.git/Documentation/filesystems/proc.txt
===================================================================
@@ -1741,6 +1741,15 @@ pair provide additional information part
 	While the first three lines are mandatory and always printed, the rest is
 	optional and may be omitted if no marks created yet.
 
+	Timerfd files
+	~~~~~~~~~~~~~
+	pos:	0
+	flags:	02
+	mnt_id:	9
+	clockid: 0 ticks: 0
+
+	where 'clockid' is the clock type and 'ticks' is the number of the timer expirations
+	that have occurred [see timerfd_create(2) for details].
 
 ------------------------------------------------------------------------------
 Configuring procfs
#5 lore raw

Re: [rfc 2/2] docs: procfs -- Document timerfd output

2014-03-31 21:54 GMT+04:00 Cyrill Gorcunov <[email protected]>:

Quoted 15 lines
CC Shawn Landden <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Andrew Morton <[email protected]>
CC Andrey Vagin <[email protected]>
CC Pavel Emelyanov <[email protected]>
---
 Documentation/filesystems/proc.txt |    9 +++++++++
 1 file changed, 9 insertions(+)

Index: linux-2.6.git/Documentation/filesystems/proc.txt
===================================================================

Documentation/filesystems/proc.txt pair provide additional information part · line 1749

Quoted 9 lines
Documentation/filesystems/proc.txt +6 -0
@@ -1741,6 +1741,15 @@ pair provide additional information part
        While the first three lines are mandatory and always printed, the rest is
        optional and may be omitted if no marks created yet.
 
+       Timerfd files
+       ~~~~~~~~~~~~~
+       pos:    0
+       flags:  02
+       mnt_id: 9
+       clockid: 0 ticks: 0

I would prefer to print "tick" on a separate line.

And we can print the current setting of the timer here. It can be useful not only for CRIU but for other users too.

it_value: (5, 149234)
it_interval: (10, 0)

Quoted 7 lines
Documentation/filesystems/proc.txt +3 -0
+
+       where 'clockid' is the clock type and 'ticks' is the number of the timer expirations
+       that have occurred [see timerfd_create(2) for details].
 
 ------------------------------------------------------------------------------
 Configuring procfs
#6 lore raw

Re: [rfc 2/2] docs: procfs -- Document timerfd output

Quoted 8 lines · Andrey Wagin

Documentation/filesystems/proc.txt pair provide additional information part · line 1749

Quoted 6 lines
Documentation/filesystems/proc.txt +6 -0
+       Timerfd files
+       ~~~~~~~~~~~~~
+       pos:    0
+       flags:  02
+       mnt_id: 9
+       clockid: 0 ticks: 0

I would prefer to print "tick" on a separate line.

Sure, this is not a problem to make it so.

Quoted 5 lines

And we can print the current setting of the timer here. It can be useful not only for CRIU but for other users too.

it_value: (5, 149234)
it_interval: (10, 0)

Yeah, moreover I think this is needed because if the timer is expired and it's interval timer the gettime method will rearm it which we defenitely not needed. Will update, thanks.