Skip to content

Commit e0efa1a

Browse files
committed
Refactoring:
- explicit values file for privileged direct method, - hide (into docs directory) "unprivileged" direct method (and fixes), - remove unnessesary mounts (mcfg, /dev/cpu/dev/mem for privileged access), - add instructions to collection methods, - fixes (extra builder) for build local development image, - silent mode - move collection methods to the top
1 parent a8bab79 commit e0efa1a

File tree

10 files changed

+124
-50
lines changed

10 files changed

+124
-50
lines changed

deployment/pcm/README.md

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ Helm chart instructions
44

55
### Features:
66

7-
- Configurable as non-privileged container (value: `privileged=false` / default) and privileged container,
8-
- Support for bare-metal and VM host configurations (files: [values-metal.yaml](values-metal.yaml), [values-vm.yaml](values-metal.yaml)),
7+
- Configurable as non-privileged container (value: `privileged=false`, default) and privileged container,
8+
- Support for bare-metal and VM host configurations (files: [values-metal.yaml](values-metal.yaml), [values-vm.yaml](values-vm.yaml)),
99
- Ability to deploy multiple releases alongside configured differently to handle different kinds of machines (bare-metal, VM) at the [same time](#heterogeneous-mixed-vmmetal-instances-cluster),
10-
- Controllable set of metrics and method of collection (RDT, uncore), support direct (msr) and indirect (Linux abstractions perf/resctrl) counter accesses (file: [values-indirect.yaml](values-indirect.yaml)).
1110
- Linux Watchdog handling (controlled with `PCM_KEEP_NMI_WATCHDOG`, `PCM_NO_AWS_WORKAROUND`, `nmiWatchdogMount` values).
1211
- Deploy to own namespace with "helm install ... **-n pcm --create-namespace**"
12+
- Silent mode (value: `silent=false`, default)
13+
14+
Here are available methods in this chart of metrics collection w.r.t interfaces and required access:
15+
16+
| Method | Used interfaces | default | Notes | instructions |
17+
|-------------------------|----------------------| ------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
18+
| unprivileged "indirect" | perf, resctrl | v | recommended, missing metrics: energy metrics (TODO link to issues/PR or node_exporter/rapl_collector) | `helm install . pcm` |
19+
| privileged "indirect" | perf, resctrl | | not recommended, unsecure, no advantages over unprivileged), missing metrics: energy metrics | `helm install . pcm --set privileged=true` |
20+
| privileged "direct" | msr | | not recommended, unsecure and requires msr module pre loaded on host | `helm install . pcm -f values-direct-privileged.yaml` |
21+
| unprivileged "direct" | msr | | not recommended, requires msr module and access to /dev/cpu and /dev/mem (non trivial, like using 3rd plugins) | [link for detailed documentation](docs/direct-unprivileged-deployment.md) |
1322

1423
For more information about direct/indirect collection methods please see [here](#metric-collection-methods-capabilites-vs-requirements)
1524

@@ -47,7 +56,7 @@ helm install ... --set nfd=true --set podMonitor=true
4756
### Requirements
4857

4958
- Full set of metrics (uncore/UPI, RDT, energy) requires bare-metal or .metal cloud instance.
50-
- /sys/fs/resctrl has to be mounted on host OS (for default indirect deployment method),
59+
- /sys/fs/resctrl has to be mounted on host OS (for default indirect deployment method)
5160
- pod is allowed to be run with privileged capabilities (SYS_ADMIN, SYS_RAWIO) on given namespace in other words: Pod Security Standards allow to run on privileged level,
5261

5362
```
@@ -78,12 +87,14 @@ More information here: https://kubernetes.io/docs/tutorials/security/ns-level-ps
7887
#### 1) (Optionally) mount resctrl filesystem (for RDT metrics) to unload "msr" kernel module for validation
7988

8089
```
90+
echo 0 > /proc/sys/kernel/perf_event_paranoid
8191
mount -t resctrl resctrl /sys/fs/resctrl
8292
```
8393

84-
For validation to verify that all metrics are available without msr, unload "msr" module from kernel:
94+
For validation to verify that all metrics are available without msr, unload "msr" module from kernel and perf_event_paranoid has default value
8595
```
8696
rmmod msr
97+
echo 2 > /proc/sys/kernel/perf_event_paranoid
8798
```
8899

89100
#### 2) Create kind based Kubernetes cluster
@@ -123,11 +134,24 @@ bash kind-with-registry.sh
123134
Check that resctrl is available inside kind node:
124135
```
125136
docker exec kind-control-plane ls /sys/fs/resctrl/info
137+
# expected output:
138+
# L3_MON
139+
# MB
140+
# ...
141+
```
142+
143+
144+
and optionally local registry is running (to be used with local pcm build images, more detail [below](development-with-local-images-and-testing))
145+
```
146+
docker ps | grep kind-registry
147+
# expected output:
148+
# e57529be23ea registry:2 "/entrypoint.sh /etc…" 3 weeks ago Up 3 weeks 127.0.0.1:5001->5000/tcp kind-registry
126149
```
127150

128151
Export kind kubeconfig as default for further kubectl commands:
129152
```
130153
kind export kubeconfig
154+
kubectl get pods -A
131155
```
132156

133157
#### 3) (Optionally) Deploy Node Feature Discovery (nfd)
@@ -200,9 +224,9 @@ promtool query instant http://127.0.0.1:8001/api/v1/namespaces/default/services/
200224

201225
### Deploy alternative options
202226

203-
#### Direct as privileged container
227+
#### Direct (msr access) as privileged container
204228
```
205-
helm install pcm . -f values-direct.yaml --set privileged=true
229+
helm install pcm . -f values-direct-privileged.yaml
206230
```
207231

208232
#### Homogeneous bare metal instances cluster (full set of metrics)
@@ -243,14 +267,21 @@ wget https://kind.sigs.k8s.io/examples/kind-with-registry.sh
243267
bash kind-with-registry.sh
244268
```
245269

246-
2) Build docker image and upload to local registry
270+
2) Build docker image and upload to local registry (from project root directory)
247271
```
248272
docker build . -t localhost:5001/pcm-local
249273
docker push localhost:5001/pcm-local
250274
251-
# or with single line
275+
# optionally create buildx based builder
276+
mkdir ~/.docker/cli-plugins
277+
curl -sL https://github.com/docker/buildx/releases/download/v0.14.0/buildx-v0.14.0.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx
278+
chmod +x ~/.docker/cli-plugins/docker-buildx
279+
docker buildx create --driver docker-container --name mydocker --use --bootstrap
280+
281+
# or with single line (from deployment/pcm/ directory)
252282
# Build local image for tests/development + fix /pcm/resctrl mounting (assuming project was configured with cmake previously):
253-
(cd ../.. ; (cd build ; make -j pcm pcm-sensor-server) ; docker build . -t localhost:5001/pcm-local && docker push localhost:5001/pcm-local; docker run -ti --rm --name pcmtest --entrypoint bash localhost:5001/pcm-local -c "pcm 2>&1 | head -5" )
283+
# Note: Warning: we're using patched Dockerfile (TODO to be removed, because "build" directory conflits with existing root "build" directory and for caching ability)
284+
(cd ../.. ; (cd build ; make -j pcm pcm-sensor-server) ; docker build . -t localhost:5001/pcm-local && docker push localhost:5001/pcm-local)
254285
```
255286

256287
3) When deploying to kind cluster pcm use values to switch to local pcm-local image
@@ -274,12 +305,8 @@ kubectl exec -ti ds/pcm -- bash
274305
kubectl logs ds/pcm
275306
```
276307

277-
#### Metric collection methods (capabilities vs requirements)
308+
### Metric collection methods (capabilities vs requirements)
278309

279-
| Method | Used interfaces | default | Notes |
280-
|---------------|------------------------------------------------------------| -------- | ------------------------------------------------------------------------------------- |
281-
| indirect | perf, resctrl | v | missing energy metrics, |
282-
| direct | msr | | requires msr module and access to /dev/cpu (non trivial) or privileged access |
283310

284311

285312
| Metrics | Available on Hardware | Available through interface | Available through method |

deployment/pcm/docs/direct-unprivileged-deployment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ helm install smarter-device-plugin --create-namespace --namespace smarter-device
2828
kubectl get node kind-control-plane -o json | jq .status.capacity
2929
3030
# Install pcm helm chart in unprivileged mode with extraResources for cpu and memory devices.
31-
helm install pcm . --set privileged=false -f values-direct.yaml -f values-smarter-devices-cpu-mem.yaml
31+
helm install pcm . -f docs/direct-unprivileged-examples/values-direct-unprivileged.yaml -f docs/direct-unprivileged-examples/values-smarter-devices-cpu-mem.yaml
3232
```
3333

3434
##### b) Device injection using NRI plugin device-injection
@@ -63,5 +63,5 @@ docker exec kind-control-plane systemctl restart containerd
6363
docker exec kind-control-plane systemd-run -u device-injector /device-injector -idx 10 -verbose
6464
docker exec kind-control-plane systemctl status device-injector
6565
66-
helm install pcm-device-injector . --set privileged=false --set hostPort= --set debugSleep=true -f values-opcm-local-image.yaml -f values-device-injector.yaml
66+
helm install pcm . -f docs/direct-unprivileged-examples/values-direct-unprivileged.yaml -f docs/direct-unprivileged-examples/values-device-injector.yaml
6767
```
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
# Warning: this file is to be used or direct unprivilegd access which requires 3rd party plugin
2+
# e.g. device-injector NRI or smarter-devices-cpu-mem
3+
privileged: false
4+
5+
# Swtich to using MSR
16
PCM_NO_MSR: 0 # use MSR
27
PCM_NO_PERF: 1 # do not use Linux perf
38
PCM_USE_UNCORE_PERF: 0 # also use MSR for uncore
49
PCM_NO_RDT: 0 # Collect RDT data
510
PCM_USE_RESCTRL: 0 # using MSR (no resctrl)
6-
resctrlHostMount: false # with MSR resctrl mount is not needed
11+
12+
# RDT metrics will be used by direct msr programming
13+
resctrlHostMount: false
714
resctrlInsideMount: false
15+
16+
# sys and pci mounts are required for uncore PMU devices discovery
817
sysMount: true # /pcm/sys is required
918
pciMount: true # /pcm/proc/bus/pci is required
19+

deployment/pcm/templates/_helpers.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ securityContext:
6262
add:
6363
- SYS_ADMIN
6464
- SYS_RAWIO
65+
#- PERFMON
6566
{{- end }}
6667
{{- end }}
6768

deployment/pcm/templates/daemonset.yaml

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ spec:
5454
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5555
imagePullPolicy: {{ .Values.image.pullPolicy }}
5656
{{- include "pcm.securityContext" . | nindent 8 }}
57+
{{- if .Values.silent }}
58+
command:
59+
- "/usr/local/bin/pcm-sensor-server"
60+
- "-p"
61+
- "9738"
62+
- "-r"
63+
- "-silent"
64+
{{- end -}}
5765
{{- if .Values.debugSleep }}
5866
command:
5967
- /usr/bin/sleep
@@ -63,7 +71,7 @@ spec:
6371
command:
6472
- /bin/bash
6573
- -c
66-
- "/usr/local/bin/pcm 2 -r -nc -nsys"
74+
- "/usr/local/bin/pcm 2 -r -nc -nsys{{ if .Values.silent }} -silent{{ end }}"
6775
{{- end -}}
6876
{{- if .Values.resctrlInternalMount }}
6977
# Ugly hack to mount resctrl inside only for baremetal when we want use resctrl abstraction and is not mounted on HOST: TBC conflicts with
@@ -116,14 +124,14 @@ spec:
116124
protocol: TCP
117125
{{- end }}
118126
volumeMounts:
119-
{{- if .Values.privileged }}
120-
- mountPath: /pcm/dev/cpu
121-
name: dev-cpu
122-
readOnly: false
123-
- mountPath: /pcm/dev/mem
124-
name: dev-mem
125-
readOnly: false
126-
{{- end }}
127+
# {{- if .Values.privileged }}
128+
# - mountPath: /pcm/dev/cpu
129+
# name: dev-cpu
130+
# readOnly: false
131+
# - mountPath: /pcm/dev/mem
132+
# name: dev-mem
133+
# readOnly: false
134+
# {{- end }}
127135
{{- if .Values.pciMount }}
128136
- mountPath: /pcm/proc/bus/pci
129137
name: proc-pci
@@ -136,26 +144,27 @@ spec:
136144
{{- if .Values.nmiWatchdogMount }}
137145
- mountPath: /pcm/proc/sys/kernel/nmi_watchdog
138146
name: nmi-watchdog
139-
readOnly: true # RW?
147+
readOnly: true # RW? # TODO
140148
{{- end }}
141149
{{- if .Values.resctrlHostMount }}
142150
- mountPath: /sys/fs/resctrl
143151
name: sysfs-resctrl
144152
{{- end }}
145-
{{- if .Values.mcfgMount }}
146-
- mountPath: /pcm/sys/firmware/acpi/tables/MCFG
147-
name: sys-acpi
148-
readOnly: true
149-
{{- end }}
153+
# TODO: to be removed, already handled by /sysMount
154+
# {{- if .Values.mcfgMount }}
155+
# - mountPath: /pcm/sys/firmware/acpi/tables/MCFG
156+
# name: sys-acpi
157+
# readOnly: true
158+
# {{- end }}
150159
volumes:
151-
{{- if .Values.privileged }}
152-
- name: dev-cpu
153-
hostPath:
154-
path: /dev/cpu
155-
- name: dev-mem
156-
hostPath:
157-
path: /dev/mem
158-
{{- end}}
160+
# {{- if .Values.privileged }}
161+
# - name: dev-cpu
162+
# hostPath:
163+
# path: /dev/cpu
164+
# - name: dev-mem
165+
# hostPath:
166+
# path: /dev/mem
167+
# {{- end}}
159168
{{- if .Values.sysMount }}
160169
- name: sysfs
161170
hostPath:
@@ -171,11 +180,12 @@ spec:
171180
hostPath:
172181
path: /proc/sys/kernel/nmi_watchdog
173182
{{- end }}
174-
{{- if .Values.mcfgMount }}
175-
- name: sys-acpi
176-
hostPath:
177-
path: /sys/firmware/acpi/tables/MCFG
178-
{{- end }}
183+
# TODO: to be removed, already handled by /sysMount
184+
# {{- if .Values.mcfgMount }}
185+
# - name: sys-acpi
186+
# hostPath:
187+
# path: /sys/firmware/acpi/tables/MCFG
188+
# {{- end }}
179189
{{- if .Values.resctrlHostMount }}
180190
- name: sysfs-resctrl
181191
hostPath:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#### Tunning for "direct" privilaged access
2+
privileged: true
3+
4+
# Switch PCM to use msr access always
5+
PCM_NO_MSR: 0 # use MSR
6+
PCM_NO_PERF: 1 # do not use Linux perf
7+
PCM_USE_UNCORE_PERF: 0 # also use MSR for uncore
8+
PCM_NO_RDT: 0 # Enable RDT metrics ...
9+
PCM_USE_RESCTRL: 0 # but using MSR (no resctrl filesystem)
10+
11+
# with privileged container addtional mounts aren't required
12+
resctrlHostMount: false # with MSR resctrl mount is not needed
13+
resctrlInsideMount: false
14+
sysMount: false
15+
pciMount: false
16+
mcfgMount: false

deployment/pcm/values-vm.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#### ================ Tunning for VM ================
22
nmiWatchdogMount: true
3+
34
# Disable RDT because is not avaiable for VM instances
45
PCM_NO_RDT: 1
56
resctrlHostMount: false

deployment/pcm/values.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ imagePullSecrets: {}
1818
# Configures SecurityContext to not privileged (by default) so SYS_ADMIN/SYS_RAWIO capabilietes are required for running pod
1919
privileged: false
2020

21+
# Run pcm in silent mode (additional -silent argument to pcm-sensor-server binary)
22+
# Removes some of debug outputs (like warnings about unability to open some /sys... /proc... files)
23+
silent: false
24+
2125
### -------------- Required OS affinity -------
2226
# Should only running on linux
2327
nodeSelector:
@@ -29,10 +33,15 @@ probes: false
2933
### ================ Metrics configuration ======================
3034

3135
### -------------- Metrics: Uncore ------------
32-
# required for uncore metrics, only in baremetal, not available for VM
33-
mcfgMount: false
34-
sysMount: false
35-
pciMount: false
36+
# Mounts section
37+
# NOTE: only required for direct mode
38+
# required for uncore metrics discovery and working only in baremetal, not available for VM
39+
sysMount: false # mounts host /sys into container /pcm/sys/
40+
pciMount: false # mounts host /proc/bus/pci into container /pcm/proc/bus/pci/
41+
42+
# NOTE this is only required for direct unprivileged mode ?!?!?!
43+
# TODO: to be removed!!!?!?!!?!? (already coverred sysMounts !!!!)
44+
#mcfgMount: false # mounts hosts: /sys/firmware/acpi/tables/MCFG -> /pcm/sys/firmware/acpi/tables/MCFG
3645

3746
### linux Perf (indirect) vs msr(direct)
3847
# Lets try "indirect" as default

0 commit comments

Comments
 (0)