Skip to content

Commit 39ad263

Browse files
authored
Merge pull request #15 from NVIDIA/add-tuned-scripts
feat(tuned): tuned scripts can now be used by the tuned package
2 parents dd7a068 + 231d17e commit 39ad263

File tree

4 files changed

+162
-5
lines changed

4 files changed

+162
-5
lines changed

tuned/README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ The package expects configmaps to be available in `${SKYHOOK_DIR}/configmaps/`:
145145
146146
#### Optional Configmaps
147147
148-
- **Custom profile files**: Any other files in the configmaps directory will be treated as custom tuned profile configurations
148+
- **Custom profile files**: Any files in the configmaps directory (except `tuned_profile` and `*_script` files) will be treated as custom tuned profile configurations
149149
- File name becomes the profile name
150150
- File contents become the `tuned.conf` for that profile
151151
- Files are deployed to `/etc/tuned/<profile_name>/tuned.conf`
152152
153+
- **Script files**: Any files ending with `_script` will be deployed as executable scripts to `/etc/tuned/scripts/`
154+
- File name pattern: `<name>_script` (e.g., `setup_script`, `my_optimization_script`)
155+
- Scripts are deployed to `/etc/tuned/scripts/<name>` (the `_script` suffix is removed)
156+
- Scripts are automatically made executable (`chmod +x`)
157+
- Can be referenced in tuned profiles using the `[script]` plugin
158+
153159
### Example Custom Profile
154160
155161
```ini
@@ -168,6 +174,49 @@ readahead=4096
168174
transparent_hugepages=never
169175
```
170176

177+
### Example Custom Profile with Scripts
178+
179+
```ini
180+
# configmaps/ai-optimized-profile
181+
[main]
182+
summary=AI/ML optimized profile with custom scripts
183+
184+
[cpu]
185+
governor=performance
186+
energy_perf_bias=performance
187+
188+
[script]
189+
type=script
190+
script=/etc/tuned/scripts/ai_setup
191+
192+
[vm]
193+
transparent_hugepages=always
194+
```
195+
196+
```bash
197+
# configmaps/ai_setup_script
198+
#!/bin/bash
199+
# This script will be deployed to /etc/tuned/scripts/ai_setup
200+
201+
echo "Setting up AI/ML optimizations..."
202+
203+
# Configure GPU memory settings
204+
if [ -d /sys/class/drm ]; then
205+
echo "Configuring GPU settings for AI workloads"
206+
# Add GPU-specific optimizations here
207+
fi
208+
209+
# Set up NUMA topology optimizations
210+
echo "Configuring NUMA settings for AI workloads"
211+
for node in /sys/devices/system/node/node*; do
212+
if [ -d "$node" ]; then
213+
echo 0 > "$node/compact"
214+
fi
215+
done
216+
217+
echo "AI optimization setup complete"
218+
```
219+
171220
## Usage Examples
172221

173222
### Basic Installation
@@ -223,6 +272,9 @@ spec:
223272
224273
[bootloader]
225274
cmdline_myprofile=-kernel.panic +kernel.panic=20
275+
276+
[script]
277+
script=/etc/tuned/scripts/ai_init
226278
custom_profile_1: |-
227279
[main]
228280
summary=AI/ML performance profile
@@ -238,13 +290,31 @@ spec:
238290
[vm]
239291
transparent_hugepages=always # large pages help with tensor allocations
240292
swappiness=10 # avoid swapping under load
293+
ai_init_script: |-
294+
#!/bin/bash
295+
# Custom AI/ML initialization script
296+
echo "Initializing AI/ML optimizations..."
297+
298+
# Configure GPU memory pools
299+
if command -v nvidia-smi >/dev/null 2>&1; then
300+
echo "Configuring NVIDIA GPU settings"
301+
nvidia-smi -pm 1 # Enable persistence mode
302+
fi
303+
304+
# Set up memory allocation patterns for AI workloads
305+
echo "Configuring memory allocation for AI workloads"
306+
echo 1 > /proc/sys/vm/overcommit_memory
307+
308+
echo "AI initialization complete"
241309
```
242310
243311
This example demonstrates:
244312
- **Node targeting**: Using `nodeSelectors` to target specific node groups
245313
- **Interrupt handling**: Configuring reboot interrupts for kernel-level changes
246314
- **Environment variables**: Setting `INTERRUPT=true` to handle verification during config changes
247315
- **Custom profiles**: Creating hierarchical profiles with `include` directive
316+
- **Custom scripts**: Using `_script` configmaps to deploy executable scripts
317+
- **Script integration**: Referencing deployed scripts in profiles using the `[script]` plugin
248318
- **AI/ML optimizations**: Performance settings optimized for machine learning workloads
249319
- **Kernel parameters**: Using `[sysctl]` and `[bootloader]` sections for low-level tuning
250320

tuned/skyhook_dir/apply_tuned_profile.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,39 @@ set -u
2121

2222
CONFIGMAP_DIR="${SKYHOOK_DIR}/configmaps"
2323
TUNED_DIR="/etc/tuned"
24+
SCRIPTS_DIR="/etc/tuned/scripts"
2425

2526
# ensure tuned directory exists
2627
sudo mkdir -p "$TUNED_DIR"
28+
sudo mkdir -p "$SCRIPTS_DIR"
2729

28-
# process all other files as custom profiles
30+
# First, deploy all scripts ending with "_script" to the shared scripts directory
31+
echo "Deploying scripts to $SCRIPTS_DIR..."
32+
for file in "$CONFIGMAP_DIR"/*_script; do
33+
[ -f "$file" ] || continue # make sure file exists
34+
35+
script_name=$(basename "$file")
36+
script_path="$SCRIPTS_DIR/${script_name#*_script}"
37+
38+
# If the script name is just "_script", use the full filename
39+
if [ "${script_name#*_script}" = "" ]; then
40+
script_path="$SCRIPTS_DIR/$(basename "$file")"
41+
fi
42+
43+
# Copy the script and make it executable
44+
sudo cp "$file" "$script_path"
45+
sudo chmod +x "$script_path"
46+
echo "deployed script: $script_name -> $script_path"
47+
done
48+
49+
# process all other files as custom profiles (skip tuned_profile and *_script files)
2950
for file in "$CONFIGMAP_DIR"/*; do
3051
[ -f "$file" ] || continue # make sure file exists
31-
[ "$(basename "$file")" = "tuned_profile" ] && continue # skip tuned_profile
3252

3353
profile_name=$(basename "$file")
54+
[ "$profile_name" = "tuned_profile" ] && continue # skip tuned_profile
55+
[[ "$profile_name" == *"_script" ]] && continue # skip script files
56+
3457
custom_profile_dir="$TUNED_DIR/$profile_name"
3558

3659
# Create a directory for the custom profile if it doesn't exist

tuned/skyhook_dir/apply_tuned_profile_check.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set -x
2020

2121
CONFIGMAP_DIR="${SKYHOOK_DIR}/configmaps"
2222
TUNED_DIR="/etc/tuned"
23+
SCRIPTS_DIR="/etc/tuned/scripts"
2324

2425
# check tuned service is installed and running
2526
if ! command -v tuned-adm >/dev/null 2>&1; then
@@ -38,12 +39,43 @@ if [ ! -d "$CONFIGMAP_DIR" ]; then
3839
exit 1
3940
fi
4041

41-
# verify custom profiles
42+
if [ ! -d "$SCRIPTS_DIR" ]; then
43+
echo "ERROR: scripts directory does not exist: $SCRIPTS_DIR"
44+
exit 1
45+
fi
46+
47+
# verify deployed scripts
48+
for file in "$CONFIGMAP_DIR"/*_script; do
49+
[ -f "$file" ] || continue
50+
51+
script_name=$(basename "$file")
52+
script_path="$SCRIPTS_DIR/${script_name#*_script}"
53+
54+
# If the script name is just "_script", use the full filename
55+
if [ "${script_name#*_script}" = "" ]; then
56+
script_path="$SCRIPTS_DIR/$(basename "$file")"
57+
fi
58+
59+
if [ ! -f "$script_path" ]; then
60+
echo "ERROR: deployed script missing: $script_path"
61+
exit 1
62+
fi
63+
64+
if [ ! -x "$script_path" ]; then
65+
echo "ERROR: deployed script not executable: $script_path"
66+
exit 1
67+
fi
68+
69+
echo "verified deployed script: $script_name -> $script_path"
70+
done
71+
72+
# verify custom profiles (skip tuned_profile and *_script files)
4273
for file in "$CONFIGMAP_DIR"/*; do
4374
[ -f "$file" ] || continue
4475

4576
base_file=$(basename "$file")
4677
[ "$base_file" = "tuned_profile" ] && continue
78+
[[ "$base_file" == *"_script" ]] && continue # skip script files
4779

4880
custom_profile_dir="$TUNED_DIR/$base_file"
4981
custom_profile_file="$custom_profile_dir/tuned.conf"

tuned/skyhook_dir/post_interrupt_tuned_check.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set -x
2020

2121
CONFIGMAP_DIR="${SKYHOOK_DIR}/configmaps"
2222
TUNED_DIR="/etc/tuned"
23+
SCRIPTS_DIR="/etc/tuned/scripts"
2324

2425
# check tuned service is installed and running
2526
if ! command -v tuned-adm >/dev/null 2>&1; then
@@ -38,12 +39,43 @@ if [ ! -d "$CONFIGMAP_DIR" ]; then
3839
exit 1
3940
fi
4041

41-
# verify custom profiles
42+
if [ ! -d "$SCRIPTS_DIR" ]; then
43+
echo "ERROR: scripts directory does not exist: $SCRIPTS_DIR"
44+
exit 1
45+
fi
46+
47+
# verify deployed scripts
48+
for file in "$CONFIGMAP_DIR"/*_script; do
49+
[ -f "$file" ] || continue
50+
51+
script_name=$(basename "$file")
52+
script_path="$SCRIPTS_DIR/${script_name#*_script}"
53+
54+
# If the script name is just "_script", use the full filename
55+
if [ "${script_name#*_script}" = "" ]; then
56+
script_path="$SCRIPTS_DIR/$(basename "$file")"
57+
fi
58+
59+
if [ ! -f "$script_path" ]; then
60+
echo "ERROR: deployed script missing: $script_path"
61+
exit 1
62+
fi
63+
64+
if [ ! -x "$script_path" ]; then
65+
echo "ERROR: deployed script not executable: $script_path"
66+
exit 1
67+
fi
68+
69+
echo "verified deployed script: $script_name -> $script_path"
70+
done
71+
72+
# verify custom profiles (skip tuned_profile and *_script files)
4273
for file in "$CONFIGMAP_DIR"/*; do
4374
[ -f "$file" ] || continue
4475

4576
base_file=$(basename "$file")
4677
[ "$base_file" = "tuned_profile" ] && continue
78+
[[ "$base_file" == *"_script" ]] && continue # skip script files
4779

4880
custom_profile_dir="$TUNED_DIR/$base_file"
4981
custom_profile_file="$custom_profile_dir/tuned.conf"

0 commit comments

Comments
 (0)