@@ -38,7 +38,12 @@ type TimerFileDescription struct {
3838 vfs.NoLockFD
3939
4040 events waiter.Queue
41- timer ktime.Timer
41+ timer * ktime.SampledTimer
42+
43+ // clock is the clock that the timer fd was created with. timer runs on
44+ // clock, except when it is armed with a relative CLOCK_REALTIME time (see
45+ // SetTime). clock is immutable.
46+ clock ktime.SampledClock
4247
4348 // val is the number of timer expirations since the last successful
4449 // call to PRead, or SetTime. val must be accessed using atomic memory
@@ -50,11 +55,11 @@ var _ vfs.FileDescriptionImpl = (*TimerFileDescription)(nil)
5055var _ ktime.Listener = (* TimerFileDescription )(nil )
5156
5257// New returns a new timer fd.
53- func New (ctx context.Context , vfsObj * vfs.VirtualFilesystem , clock ktime.Clock , flags uint32 ) (* vfs.FileDescription , error ) {
58+ func New (ctx context.Context , vfsObj * vfs.VirtualFilesystem , clock ktime.SampledClock , flags uint32 ) (* vfs.FileDescription , error ) {
5459 vd := vfsObj .NewAnonVirtualDentry ("[timerfd]" )
5560 defer vd .DecRef (ctx )
56- tfd := & TimerFileDescription {}
57- tfd .timer = clock . NewTimer ( tfd )
61+ tfd := & TimerFileDescription {clock : clock }
62+ tfd .timer = ktime . NewSampledTimer ( clock , tfd )
5863 if err := tfd .vfsfd .Init (tfd , flags , auth .CredentialsFromContext (ctx ), vd .Mount (), vd .Dentry (), & vfs.FileDescriptionOptions {
5964 UseDentryMetadata : true ,
6065 DenyPRead : true ,
@@ -84,9 +89,9 @@ func (tfd *TimerFileDescription) Read(ctx context.Context, dst usermem.IOSequenc
8489 return 0 , linuxerr .ErrWouldBlock
8590}
8691
87- // Clock returns the timer fd's Clock .
88- func (tfd * TimerFileDescription ) Clock () ktime.Clock {
89- return tfd .timer . Clock ()
92+ // Clock returns the Clock that the timer fd was created with .
93+ func (tfd * TimerFileDescription ) Clock () ktime.SampledClock {
94+ return tfd .clock
9095}
9196
9297// GetTime returns the associated Timer's setting and the time at which it was
@@ -95,11 +100,11 @@ func (tfd *TimerFileDescription) GetTime() (ktime.Time, ktime.Setting) {
95100 return tfd .timer .Get ()
96101}
97102
98- // SetTime atomically changes the associated Timer's setting, resets the number
99- // of expirations to 0, and returns the previous setting and the time at which
100- // it was observed.
101- func (tfd * TimerFileDescription ) SetTime (s ktime.Setting ) (ktime.Time , ktime.Setting ) {
102- return tfd .timer .Set ( s , func () { tfd .val .Store (0 ) })
103+ // SetTime atomically changes the associated Timer's setting, and the clock it
104+ // runs on to c, resets the number of expirations to 0, and returns the
105+ // previous setting and the time at which it was observed.
106+ func (tfd * TimerFileDescription ) SetTime (c ktime. SampledClock , s ktime.Setting ) (ktime.Time , ktime.Setting ) {
107+ return tfd .timer .SetWithClock ( c , s , func () { tfd .val .Store (0 ) })
103108}
104109
105110// Readiness implements waiter.Waitable.Readiness.
0 commit comments