Skip to content

Commit

Permalink
config: option to use UTC/localtime for RTC
Browse files Browse the repository at this point in the history
Default to UTC unless Windows is chosen in the wizard. Existing VMs get
localtime since that was the previous default.

Fixes #3104
  • Loading branch information
osy committed Feb 25, 2022
1 parent 8aae037 commit 30c4bef
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions Configuration/UTMQemuConfiguration+System.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL useHypervisor;
@property (nonatomic, readonly) BOOL isTargetArchitectureMatchHost;
@property (nonatomic, readonly) BOOL defaultUseHypervisor;
@property (nonatomic, assign) BOOL rtcUseLocalTime;

- (void)migrateSystemConfigurationIfNecessary;

Expand Down
13 changes: 13 additions & 0 deletions Configuration/UTMQemuConfiguration+System.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
static const NSString *const kUTMConfigSystemUUIDKey = @"SystemUUID";
static const NSString *const kUTMConfigMachinePropertiesKey = @"MachineProperties";
static const NSString *const kUTMConfigUseHypervisorKey = @"UseHypervisor";
static const NSString *const kUTMConfigRTCUseLocalTimeKey = @"RTCUseLocalTime";

@interface UTMQemuConfiguration ()

Expand Down Expand Up @@ -93,6 +94,9 @@ - (void)migrateSystemConfigurationIfNecessary {
if (self.rootDict[kUTMConfigSystemKey][kUTMConfigRngEnabledKey] == nil) {
self.systemRngEnabled = [self.systemTarget hasPrefix:@"pc"] || [self.systemTarget hasPrefix:@"q35"] || [self.systemTarget hasPrefix:@"virt"];
}
if (self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] == nil) {
self.rtcUseLocalTime = YES; // used to be default, now only for Windows
}
}

#pragma mark - System Properties
Expand Down Expand Up @@ -214,6 +218,15 @@ - (void)setUseHypervisor:(BOOL)useHypervisor {
self.rootDict[kUTMConfigSystemKey][kUTMConfigUseHypervisorKey] = @(useHypervisor);
}

- (BOOL)rtcUseLocalTime {
return [self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] boolValue];
}

- (void)setRtcUseLocalTime:(BOOL)rtcUseLocalTime {
[self propertyWillChange];
self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] = @(rtcUseLocalTime);
}

#pragma mark - Additional arguments array handling

- (NSInteger)countArguments {
Expand Down
8 changes: 5 additions & 3 deletions Managers/UTMQemuSystem.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,11 @@ - (void)argsFromConfiguration {
[self pushArgv:self.configuration.systemUUID];
}

// fix windows time issues
[self pushArgv:@"-rtc"];
[self pushArgv:@"base=localtime"];
if (self.configuration.rtcUseLocalTime) {
// fix windows time issues
[self pushArgv:@"-rtc"];
[self pushArgv:@"base=localtime"];
}
}

- (void)argsFromUser {
Expand Down
9 changes: 6 additions & 3 deletions Platform/Shared/VMConfigQEMUView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ struct VMConfigQEMUView: View {
var body: some View {
VStack {
Form {
#if os(macOS)
Section(header: Text("Hypervisor")) {
Section(header: Text("Tweaks")) {
#if os(macOS)
Toggle(isOn: $config.useHypervisor, label: {
Text("Use Hypervisor")
}).disabled(!config.isTargetArchitectureMatchHost)
#endif
Toggle(isOn: $config.rtcUseLocalTime, label: {
Text("Use local time for base clock")
}).help(Text("If checked, use local time for RTC which is required for Windows. Otherwise, use UTC clock."))
}
#endif
Section(header: Text("Logging")) {
Toggle(isOn: $config.debugLogEnabled, label: {
Text("Debug Logging")
Expand Down
1 change: 1 addition & 0 deletions Platform/Shared/VMWizardState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ enum VMWizardOS: String, Identifiable {
}
case .Windows:
config.icon = "windows"
config.rtcUseLocalTime = true
if let windowsBootVhdx = windowsBootVhdx {
config.newDrive("drive0", path: destinationFilename(forExisting: windowsBootVhdx), type: .disk, interface: mainDriveInterface)
generateRemovableDrive() // order matters here
Expand Down

0 comments on commit 30c4bef

Please sign in to comment.