Skip to content

Commit

Permalink
Set ondemand cpu governer for Raspberry Pi
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Mar 18, 2024
1 parent ce74311 commit 7c0a377
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/umbreld/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Server from './modules/server/index.js'
import User from './modules/user.js'
import AppStore from './modules/apps/app-store.js'
import Apps from './modules/apps/apps.js'
import {detectDevice, setCpuGovernor} from './modules/system.js'

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

Expand Down Expand Up @@ -69,6 +70,20 @@ export default class Umbreld {
this.apps = new Apps(this)
}

async setupPiCpuGoverner() {
// TODO: Move this to a system module
// Set ondemand cpu governer for Raspberry Pi
try {
const {productName} = await detectDevice()
if (productName === 'Raspberry Pi') {
await setCpuGovernor('ondemand')
this.logger.log(`Set ondemand cpu governor`)
}
} catch (error) {
this.logger.error(`Failed to set ondemand cpu governor: ${(error as Error).message}`)
}
}

async start() {
this.logger.log(`☂️ Starting Umbrel v${this.version}`)
this.logger.log()
Expand All @@ -80,6 +95,9 @@ export default class Umbreld {
// If we've successfully booted then commit to the current OS partition
commitOsPartition(this)

// Set ondemand cpu governer for Raspberry Pi
this.setupPiCpuGoverner()

// Run migration module before anything else
// TODO: think through if we want to allow the server module to run before migration.
// It might be useful if we add more complicated migrations so we can signal progress.
Expand Down
4 changes: 4 additions & 0 deletions packages/umbreld/source/modules/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,7 @@ export async function detectDevice() {
export async function isUmbrelOS() {
return fse.exists('/umbrelOS')
}

export async function setCpuGovernor(governor: string) {
await fse.writeFile('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor', governor)
}

0 comments on commit 7c0a377

Please sign in to comment.