Skip to content

Commit 7c0a377

Browse files
committed
Set ondemand cpu governer for Raspberry Pi
1 parent ce74311 commit 7c0a377

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/umbreld/source/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Server from './modules/server/index.js'
1212
import User from './modules/user.js'
1313
import AppStore from './modules/apps/app-store.js'
1414
import Apps from './modules/apps/apps.js'
15+
import {detectDevice, setCpuGovernor} from './modules/system.js'
1516

1617
import {commitOsPartition} from './modules/system.js'
1718

@@ -69,6 +70,20 @@ export default class Umbreld {
6970
this.apps = new Apps(this)
7071
}
7172

73+
async setupPiCpuGoverner() {
74+
// TODO: Move this to a system module
75+
// Set ondemand cpu governer for Raspberry Pi
76+
try {
77+
const {productName} = await detectDevice()
78+
if (productName === 'Raspberry Pi') {
79+
await setCpuGovernor('ondemand')
80+
this.logger.log(`Set ondemand cpu governor`)
81+
}
82+
} catch (error) {
83+
this.logger.error(`Failed to set ondemand cpu governor: ${(error as Error).message}`)
84+
}
85+
}
86+
7287
async start() {
7388
this.logger.log(`☂️ Starting Umbrel v${this.version}`)
7489
this.logger.log()
@@ -80,6 +95,9 @@ export default class Umbreld {
8095
// If we've successfully booted then commit to the current OS partition
8196
commitOsPartition(this)
8297

98+
// Set ondemand cpu governer for Raspberry Pi
99+
this.setupPiCpuGoverner()
100+
83101
// Run migration module before anything else
84102
// TODO: think through if we want to allow the server module to run before migration.
85103
// It might be useful if we add more complicated migrations so we can signal progress.

packages/umbreld/source/modules/system.ts

+4
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,7 @@ export async function detectDevice() {
214214
export async function isUmbrelOS() {
215215
return fse.exists('/umbrelOS')
216216
}
217+
218+
export async function setCpuGovernor(governor: string) {
219+
await fse.writeFile('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor', governor)
220+
}

0 commit comments

Comments
 (0)