Skip to content

Commit

Permalink
Enable hardware acceleration for Linux hosts (KVM)
Browse files Browse the repository at this point in the history
GitHub Linux runners have been upgraded [1] and now hardware accelerated
nested virtualization is available.

This also removes all logic around accelerators, since QEMU can pick
the best one out of several specified.

[1] https://github.blog/2024-01-17-github-hosted-runners-double-the-power-for-open-source/
  • Loading branch information
jacob-carlborg committed Feb 16, 2024
1 parent 4a39284 commit 84344e0
Show file tree
Hide file tree
Showing 14 changed files with 10 additions and 71 deletions.
34 changes: 7 additions & 27 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions spec/operating_systems/freebsd/freebsd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import FreeBsd from '../../../src/operating_systems/freebsd/freebsd'
import hostModule from '../../../src/host'
import * as arch from '../../../src/architecture'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import * as hypervisor from '../../../src/hypervisor'
import {Input} from '../../../src/action/input'
import {Host} from '../../../src/host'
Expand Down Expand Up @@ -55,7 +54,6 @@ describe('FreeBSD OperatingSystem', () => {
...config,
ssHostPort: 2847,
cpu: 'max',
accelerator: Accelerator.tcg,
machineType: 'q35',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
Expand Down
2 changes: 0 additions & 2 deletions spec/operating_systems/freebsd/qemu_vm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {QemuVm} from '../../../src/operating_systems/freebsd/qemu_vm'
import * as arch from '../../../src/architecture'
import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/freebsd/freebsd'
import {Input} from '../../../src/action/input'

Expand All @@ -25,7 +24,6 @@ describe('FreeBSD QemuVm', () => {
diskImage: '',
ssHostPort: ssHostPort,
cpu: '',
accelerator: Accelerator.tcg,
machineType: '',
uuid: '',
resourcesDiskImage: '',
Expand Down
3 changes: 0 additions & 3 deletions spec/operating_systems/netbsd/netbsd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import NetBsd from '../../../src/operating_systems/netbsd/netbsd'
import * as hostModule from '../../../src/host'
import * as arch from '../../../src/architecture'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import HostQemu from '../../../src/host_qemu'
import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
Expand Down Expand Up @@ -82,7 +81,6 @@ describe('NetBSD OperatingSystem', () => {
...config,
ssHostPort: 2847,
cpu: 'max',
accelerator: Accelerator.tcg,
machineType: 'q35',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
Expand Down Expand Up @@ -150,7 +148,6 @@ describe('NetBSD OperatingSystem', () => {
...config,
ssHostPort: 2847,
cpu: 'max',
accelerator: Accelerator.hvf,
machineType: 'q35',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
Expand Down
2 changes: 0 additions & 2 deletions spec/operating_systems/netbsd/qemu_vm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Vm} from '../../../src/operating_systems/netbsd/qemu_vm'
import * as arch from '../../../src/architecture'
import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/netbsd/netbsd'
import {Input} from '../../../src/action/input'

Expand All @@ -25,7 +24,6 @@ describe('NetBSD QemuVm', () => {
diskImage: '',
ssHostPort: ssHostPort,
cpu: '',
accelerator: Accelerator.tcg,
machineType: '',
uuid: '',
resourcesDiskImage: '',
Expand Down
10 changes: 0 additions & 10 deletions src/architecture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {ResourceUrls} from './operating_systems/resource_urls'
import * as os from './operating_systems/kind'
import OpenBsd from './operating_systems/openbsd/openbsd'
import {getOrThrow, getOrDefaultOrThrow} from './utility'
import * as vm from './vm'

export enum Kind {
arm64,
Expand Down Expand Up @@ -50,7 +49,6 @@ export abstract class Architecture {
abstract get resourceUrl(): string
abstract get cpu(): string
abstract get machineType(): string
abstract get accelerator(): vm.Accelerator
abstract get hypervisor(): hypervisor.Hypervisor
abstract get efiHypervisor(): hypervisor.Hypervisor

Expand Down Expand Up @@ -100,10 +98,6 @@ export abstract class Architecture {
return 'virt'
}

override get accelerator(): vm.Accelerator {
return vm.Accelerator.tcg
}

override get hypervisor(): hypervisor.Hypervisor {
return new hypervisor.Qemu()
}
Expand Down Expand Up @@ -147,10 +141,6 @@ export abstract class Architecture {
return 'q35'
}

override get accelerator(): vm.Accelerator {
return this.hostQemu.accelerator
}

override get hypervisor(): hypervisor.Hypervisor {
return this.selectedHypervisor
}
Expand Down
11 changes: 0 additions & 11 deletions src/host_qemu.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import {Accelerator} from './vm'

// Contains host specific QEMU properties
export default abstract class HostQemu {
abstract get cpu(): string
abstract get accelerator(): Accelerator

static readonly LinuxHostQemu = class extends HostQemu {
override get accelerator(): Accelerator {
return Accelerator.tcg
}

override get cpu(): string {
return 'max'
}
}

static readonly MacosHostQemu = class extends HostQemu {
override get accelerator(): Accelerator {
return Accelerator.hvf
}

override get cpu(): string {
return 'max'
}
Expand Down
1 change: 0 additions & 1 deletion src/operating_systems/freebsd/freebsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default class FreeBsd extends os.OperatingSystem {

// qemu
cpu: this.architecture.cpu,
accelerator: this.architecture.accelerator,
machineType: this.architecture.machineType,

// xhyve
Expand Down
1 change: 0 additions & 1 deletion src/operating_systems/netbsd/netbsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class NetBsd extends Qemu {

// qemu
cpu: this.architecture.cpu,
accelerator: this.architecture.accelerator,
machineType: this.architecture.machineType,

// xhyve
Expand Down
1 change: 0 additions & 1 deletion src/operating_systems/openbsd/openbsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default class OpenBsd extends os.OperatingSystem {

// qemu
cpu: this.architecture.cpu,
accelerator: this.architecture.accelerator,
machineType: this.architecture.machineType,

// xhyve
Expand Down
4 changes: 1 addition & 3 deletions src/qemu_vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ export abstract class Vm extends vm.Vm {
}

override get command(): string[] {
const accel = vm.Accelerator[this.configuration.accelerator]

// prettier-ignore
return [
this.hypervisorPath.toString(),
'-daemonize',
'-machine', `type=${this.configuration.machineType},accel=${accel}`,
'-machine', `type=${this.configuration.machineType},accel=hvf:kvm:tcg`,
'-cpu', this.cpuFlagValue,
'-smp', this.configuration.cpuCount.toString(),
'-m', this.configuration.memory,
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const version = {
openbsd: 'v0.7.0'
},

resources: 'v0.10.0'
resources: 'v0.11.0-rc2'
}

export default version
6 changes: 0 additions & 6 deletions src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import {wait} from './wait'
import * as architecture from './architecture'
import {Input} from './action/input'

export enum Accelerator {
hvf,
tcg
}

export interface Configuration {
memory: string
cpuCount: number
Expand All @@ -24,7 +19,6 @@ export interface Configuration {

// qemu
cpu: string
accelerator: Accelerator
machineType: string

// xhyve
Expand Down

0 comments on commit 84344e0

Please sign in to comment.