Skip to content

Commit 5fbd6ca

Browse files
author
Derek
committed
fix: tune RDP software encoding for virtio-gpu VMs without VA-API H.264
- Install mesa-va-drivers alongside vainfo/libva-utils (eliminates VA-API init errors in apps like VS Code even when H.264 encode unavailable) - Add Nice=-10 systemd drop-ins for both the GRD system service and user handover service to prevent encoder starvation under load - Add configurable refresh rate cap (default 30Hz) via XDG autostart to reduce software RFX encoding load on VMs without hardware encoding - Simplify vaapi.yml package install (always install, remove which check) - Add verification checks for new components
1 parent fb063a8 commit 5fbd6ca

9 files changed

Lines changed: 177 additions & 23 deletions

File tree

ansible/roles/rdp/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
# Change these in your inventory or playbook vars to customize
77
rdp_username: "hyperi"
88
rdp_password: "hyperi"
9+
10+
# Display refresh rate (Hz) - lower values reduce software encoding CPU load
11+
# Only relevant for VMs using software RFX encoding (no VA-API H.264)
12+
rdp_refresh_rate: 30
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Boost gnome-remote-desktop encoding priority
2+
# Software RFX encoding is CPU-intensive on virtio-gpu VMs without VA-API H.264
3+
# Deployed by dfe-developer ansible role
4+
[Service]
5+
Nice=-10
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=RDP Refresh Rate
4+
Comment=Set display refresh rate for RDP performance
5+
Exec=/usr/local/bin/rdp-set-refresh-rate
6+
Hidden=false
7+
NoDisplay=true
8+
X-GNOME-Autostart-enabled=true
9+
X-GNOME-Autostart-Phase=Applications
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Set display refresh rate for RDP sessions
3+
# Reduces software encoding load on VMs without hardware video encoding
4+
# Deployed by dfe-developer ansible role
5+
6+
set -euo pipefail
7+
8+
RATE_FILE="/etc/dfe-developer/rdp-refresh-rate"
9+
10+
# Read configured rate or default to 30
11+
RATE=30
12+
if [[ -f "$RATE_FILE" ]]; then
13+
RATE=$(cat "$RATE_FILE" 2>/dev/null || echo 30)
14+
fi
15+
16+
# Wait for display to be ready
17+
sleep 2
18+
19+
# Apply to all connected outputs
20+
for output in $(xrandr --query 2>/dev/null | grep ' connected' | awk '{print $1}'); do
21+
xrandr --output "$output" --rate "$RATE" 2>/dev/null || true
22+
done
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# Display refresh rate configuration for RDP performance
3+
# Reduces software encoding load by capping refresh rate
4+
# Only affects VMs using software RFX encoding (no VA-API H.264)
5+
6+
# ============================================================================
7+
# DEPLOY REFRESH RATE SCRIPT AND AUTOSTART
8+
# ============================================================================
9+
10+
- name: Deploy refresh rate script
11+
ansible.builtin.copy:
12+
src: rdp-set-refresh-rate
13+
dest: /usr/local/bin/rdp-set-refresh-rate
14+
mode: '0755'
15+
when:
16+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
17+
- has_gnome
18+
19+
- name: Ensure dfe-developer config directory exists
20+
ansible.builtin.file:
21+
path: /etc/dfe-developer
22+
state: directory
23+
mode: '0755'
24+
when:
25+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
26+
- has_gnome
27+
28+
- name: Write configured refresh rate
29+
ansible.builtin.copy:
30+
content: "{{ rdp_refresh_rate }}"
31+
dest: /etc/dfe-developer/rdp-refresh-rate
32+
mode: '0644'
33+
when:
34+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
35+
- has_gnome
36+
37+
- name: Deploy refresh rate autostart entry
38+
ansible.builtin.copy:
39+
src: rdp-refresh-rate.desktop
40+
dest: /etc/xdg/autostart/rdp-refresh-rate.desktop
41+
mode: '0644'
42+
when:
43+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
44+
- has_gnome
45+
46+
- name: Display refresh rate status
47+
ansible.builtin.debug:
48+
msg: "Display refresh rate will be capped at {{ rdp_refresh_rate }}Hz on login (reduces software encoding load)"
49+
when:
50+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
51+
- has_gnome

ansible/roles/rdp/tasks/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
file: vaapi.yml
5858
tags: ['vaapi']
5959

60+
- name: Configure display refresh rate
61+
ansible.builtin.include_tasks:
62+
file: display.yml
63+
tags: ['display']
64+
6065
- name: Verify RDP optimizations
6166
ansible.builtin.include_tasks:
6267
file: verify.yml

ansible/roles/rdp/tasks/service.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,48 @@
2323
failed_when: false
2424
changed_when: false
2525

26+
# ============================================================================
27+
# GRD PROCESS PRIORITY (reduce lag from software encoding)
28+
# ============================================================================
29+
# Software RFX encoding on virtio-gpu VMs is CPU-intensive. Boosting the GRD
30+
# process priority prevents it from being starved by other workloads.
31+
32+
- name: Create GRD system service drop-in directory
33+
ansible.builtin.file:
34+
path: /etc/systemd/system/gnome-remote-desktop.service.d
35+
state: directory
36+
mode: '0755'
37+
when:
38+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
39+
- has_gnome
40+
41+
- name: Create GRD user handover service drop-in directory
42+
ansible.builtin.file:
43+
path: /etc/systemd/user/gnome-remote-desktop-handover.service.d
44+
state: directory
45+
mode: '0755'
46+
when:
47+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
48+
- has_gnome
49+
50+
- name: Deploy GRD priority override (system service)
51+
ansible.builtin.copy:
52+
src: grd-priority.conf
53+
dest: /etc/systemd/system/gnome-remote-desktop.service.d/priority.conf
54+
mode: '0644'
55+
when:
56+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
57+
- has_gnome
58+
59+
- name: Deploy GRD priority override (user handover service)
60+
ansible.builtin.copy:
61+
src: grd-priority.conf
62+
dest: /etc/systemd/user/gnome-remote-desktop-handover.service.d/priority.conf
63+
mode: '0644'
64+
when:
65+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
66+
- has_gnome
67+
2668
# ============================================================================
2769
# ENABLE GNOME REMOTE DESKTOP SERVICE
2870
# ============================================================================

ansible/roles/rdp/tasks/vaapi.yml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,30 @@
55
# 2. Runtime: Deploy service that auto-enables when VA-API becomes available later
66

77
# ============================================================================
8-
# INSTALL VAINFO FOR VA-API DETECTION
8+
# INSTALL VA-API DRIVERS AND DETECTION TOOLS
99
# ============================================================================
10+
# mesa-va-drivers provides the Gallium VA-API state tracker for virtio-gpu
11+
# Without it, VA-API init fails system-wide causing errors in apps (VS Code, etc.)
1012

11-
- name: Check if vainfo is available
12-
ansible.builtin.command:
13-
cmd: which vainfo
14-
register: vainfo_check
15-
failed_when: false
16-
changed_when: false
17-
when:
18-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
19-
- has_gnome
20-
21-
- name: Install libva-utils for VA-API detection (Fedora)
13+
- name: Install mesa-va-drivers (Fedora)
2214
ansible.builtin.dnf:
23-
name: libva-utils
15+
name:
16+
- mesa-va-drivers
17+
- libva-utils
2418
state: present
2519
when:
2620
- ansible_facts['distribution'] == 'Fedora'
2721
- has_gnome
28-
- vainfo_check.rc != 0
2922

30-
- name: Install vainfo for VA-API detection (Ubuntu)
23+
- name: Install mesa-va-drivers (Ubuntu)
3124
ansible.builtin.apt:
32-
name: vainfo
25+
name:
26+
- mesa-va-drivers
27+
- vainfo
3328
state: present
3429
when:
3530
- ansible_facts['distribution'] == 'Ubuntu'
3631
- has_gnome
37-
- vainfo_check.rc != 0
3832

3933
# ============================================================================
4034
# DEPLOY AUTO-DETECTION SERVICE (runs on every boot)

ansible/roles/rdp/tasks/verify.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,35 @@
3838
register: verify_rdp_mtu_conf
3939
failed_when: not verify_rdp_mtu_conf.stat.exists
4040

41+
- name: Verify GRD priority override exists
42+
ansible.builtin.stat:
43+
path: /etc/systemd/system/gnome-remote-desktop.service.d/priority.conf
44+
register: verify_grd_priority
45+
failed_when: not verify_grd_priority.stat.exists
46+
47+
- name: Verify mesa-va-drivers installed
48+
ansible.builtin.command:
49+
cmd: "{{ 'rpm -q mesa-va-drivers' if ansible_facts['distribution'] == 'Fedora' else 'dpkg -l mesa-va-drivers' }}"
50+
register: verify_mesa_va
51+
failed_when: false
52+
changed_when: false
53+
54+
- name: Verify refresh rate script deployed
55+
ansible.builtin.stat:
56+
path: /usr/local/bin/rdp-set-refresh-rate
57+
register: verify_refresh_rate
58+
failed_when: not verify_refresh_rate.stat.exists
59+
4160
- name: Display RDP optimizer verification
4261
ansible.builtin.debug:
4362
msg: |
44-
✅ RDP Optimizer Configured (reboot required):
45-
- gnome-remote-desktop: {{ verify_grd_service.status.UnitFileState }} ✅
46-
- TLS Cert: {{ verify_rdp_cert.stat.mode }} ✅
47-
- TLS Key: {{ verify_rdp_key.stat.mode }} ✅
48-
- TCP config: /etc/sysctl.d/99-rdp-optimization.conf ✅
49-
- MTU config: /etc/sysctl.d/99-rdp-mtu.conf ✅
63+
RDP Optimizer Configured (reboot required):
64+
- gnome-remote-desktop: {{ verify_grd_service.status.UnitFileState }}
65+
- TLS Cert: {{ verify_rdp_cert.stat.mode }}
66+
- TLS Key: {{ verify_rdp_key.stat.mode }}
67+
- TCP config: /etc/sysctl.d/99-rdp-optimization.conf
68+
- MTU config: /etc/sysctl.d/99-rdp-mtu.conf
69+
- GRD priority (Nice=-10): {{ 'CONFIGURED' if verify_grd_priority.stat.exists else 'MISSING' }}
70+
- mesa-va-drivers: {{ 'INSTALLED' if verify_mesa_va.rc == 0 else 'NOT INSTALLED' }}
71+
- Refresh rate cap ({{ rdp_refresh_rate }}Hz): {{ 'CONFIGURED' if verify_refresh_rate.stat.exists else 'MISSING' }}
5072
- Status: RDP with auto-resize will be active after reboot on port 3389

0 commit comments

Comments
 (0)