Skip to content

Commit a2e38fa

Browse files
Kenta TadaKenta Tada
Kenta Tada
authored and
Kenta Tada
committed
Add support for time namespace
The time namespace is a new kernel feature available in 5.6+ to isolate the system monotonic and boot-time clocks. Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
1 parent d438e29 commit a2e38fa

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

config-linux.md

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following parameters can be specified to set up namespaces:
3434
* **`uts`** the container will be able to have its own hostname and domain name.
3535
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups within the container.
3636
* **`cgroup`** the container will have an isolated view of the cgroup hierarchy.
37+
* **`time`** the container will be able to have its own system monotonic and boot-time clocks.
3738
* **`path`** *(string, OPTIONAL)* - namespace file.
3839
This value MUST be an absolute path in the [runtime mount namespace](glossary.md#runtime-namespace).
3940
The runtime MUST place the container process in the namespace associated with that `path`.
@@ -70,6 +71,9 @@ If a `namespaces` field contains duplicated namespaces with same `type`, the run
7071
},
7172
{
7273
"type": "cgroup"
74+
},
75+
{
76+
"type": "time"
7377
}
7478
]
7579
```
@@ -107,6 +111,16 @@ Note that the number of mapping entries MAY be limited by the [kernel][user-name
107111
]
108112
```
109113

114+
## <a name="configLinuxTimeOffset" />Offset for Time Namespace
115+
116+
**`timeOffset`** (object, OPTIONAL) sets the offset for Time Namespace. For more information
117+
see the [time_namespaces](time_namespaces.7).
118+
119+
* **`monotonicSecs`** *(int64, REQUIRED)* - is the offset of clock monotonic (in secs) in the container.
120+
* **`monotonicNanosecs`** *(int64, OPTIONAL)* - is the additional offset for MonotonicSecs (in nanosecs). The actual offset is monotonicSecs plus monotonicNanosecs.
121+
* **`boottimeSecs`** *(int64, REQUIRED)* - is the offset of clock boottime (in secs) in the container.
122+
* **`boottimeNanosecs`** *(int64, OPTIONAL)* - the additional offset for BoottimeSecs (in nanosecs). The actual offset is boottimeSecs plus boottimeNanosecs.
123+
110124
## <a name="configLinuxDevices" />Devices
111125

112126
**`devices`** (array of objects, OPTIONAL) lists devices that MUST be available in the container.
@@ -770,3 +784,4 @@ subset of the available options.
770784
[zero.4]: http://man7.org/linux/man-pages/man4/zero.4.html
771785
[user-namespaces]: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
772786
[intel-rdt-cat-kernel-interface]: https://www.kernel.org/doc/Documentation/x86/intel_rdt_ui.txt
787+
[time_namespaces.7]: https://man7.org/linux/man-pages/man7/time_namespaces.7.html

config.md

+9
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,12 @@ Here is a full example `config.json` for reference.
905905
}
906906
]
907907
},
908+
"timeOffset": {
909+
"monotonicSecs": 172800,
910+
"monotonicNanosecs": 0,
911+
"boottimeSecs": 604800
912+
"boottimeNanosecs": 0
913+
},
908914
"namespaces": [
909915
{
910916
"type": "pid"
@@ -926,6 +932,9 @@ Here is a full example `config.json` for reference.
926932
},
927933
{
928934
"type": "cgroup"
935+
},
936+
{
937+
"type": "time"
929938
}
930939
],
931940
"maskedPaths": [

schema/config-linux.json

+21
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,27 @@
253253
"personality": {
254254
"type": "object",
255255
"$ref": "defs-linux.json#/definitions/Personality"
256+
},
257+
"timeOffset": {
258+
"type": "object",
259+
"properties": {
260+
"monotonicSecs": {
261+
"$ref": "defs.json#/definitions/int64"
262+
},
263+
"monotonicNanosecs": {
264+
"$ref": "defs.json#/definitions/int64"
265+
},
266+
"boottimeSecs": {
267+
"$ref": "defs.json#/definitions/int64"
268+
},
269+
"boottimeNanosecs": {
270+
"$ref": "defs.json#/definitions/int64"
271+
}
272+
},
273+
"required": [
274+
"monotonicSecs",
275+
"boottimeSecs"
276+
]
256277
}
257278
}
258279
}

schema/defs-linux.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@
292292
"uts",
293293
"ipc",
294294
"user",
295-
"cgroup"
295+
"cgroup",
296+
"time"
296297
]
297298
},
298299
"NamespaceReference": {

schema/test/config/good/spec-example.json

+9
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@
349349
}
350350
]
351351
},
352+
"timeOffset": {
353+
"monotonicSecs": 172800,
354+
"monotonicNanosecs": 0,
355+
"boottimeSecs": 604800,
356+
"boottimeNanosecs": 0
357+
},
352358
"namespaces": [
353359
{
354360
"type": "pid"
@@ -370,6 +376,9 @@
370376
},
371377
{
372378
"type": "cgroup"
379+
},
380+
{
381+
"type": "time"
373382
}
374383
],
375384
"maskedPaths": [

specs-go/config.go

+16
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ type Linux struct {
182182
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
183183
// Personality contains configuration for the Linux personality syscall
184184
Personality *LinuxPersonality `json:"personality,omitempty"`
185+
// LinuxTimeOffset specifies the offset for supporting time namespaces.
186+
TimeOffset *LinuxTimeOffset `json:"timeOffset,omitempty"`
185187
}
186188

187189
// LinuxNamespace is the configuration for a Linux namespace
@@ -211,6 +213,8 @@ const (
211213
UserNamespace LinuxNamespaceType = "user"
212214
// CgroupNamespace for isolating cgroup hierarchies
213215
CgroupNamespace LinuxNamespaceType = "cgroup"
216+
// TimeNamespace for isolating the system monotonic and boot-time clocks
217+
TimeNamespace LinuxNamespaceType = "time"
214218
)
215219

216220
// LinuxIDMapping specifies UID/GID mappings
@@ -223,6 +227,18 @@ type LinuxIDMapping struct {
223227
Size uint32 `json:"size"`
224228
}
225229

230+
// LinuxTimeOffset specifies the offset for Time Namespace
231+
type LinuxTimeOffset struct {
232+
// MonotonicSecs is the offset of clock monotonic (in secs) in the container
233+
MonotonicSecs int64 `json:"monotonicSecs"`
234+
// MonotonicNanosecs is the additional offset for MonotonicSecs (in nanosecs)
235+
MonotonicNanosecs int64 `json:"monotonicNanosecs,omitempty"`
236+
// BoottimeSecs is the offset of clock boottime (in secs) in the container
237+
BoottimeSecs uint64 `json:"boottimeSecs"`
238+
// BoottimeNanosecs is the additional offset for BoottimeSecs (in nanosecs)
239+
BoottimeNanosecs int64 `json:"boottimeNanosecs,omitempty"`
240+
}
241+
226242
// POSIXRlimit type and restrictions
227243
type POSIXRlimit struct {
228244
// Type of the rlimit to set

0 commit comments

Comments
 (0)