Add "-u" option to bhyve(8) to indicate that the RTC should maintain UTC time.

The default remains localtime for compatibility with the original device model
in bhyve(8). This is required for OpenBSD guests which assume that the RTC
keeps UTC time.

Reviewed by:	grehan
Pointed out by:	Jason Tubnor (jason@tubnor.net)
MFC after:	2 weeks
This commit is contained in:
Neel Natu
2015-02-24 02:04:16 +00:00
parent 9e251ed6d5
commit c974767896
4 changed files with 21 additions and 13 deletions
+3 -1
View File
@@ -32,7 +32,7 @@
.Nd "run a guest operating system inside a virtual machine"
.Sh SYNOPSIS
.Nm
.Op Fl abehwxACHPWY
.Op Fl abehuwxACHPWY
.Op Fl c Ar numcpus
.Op Fl g Ar gdbport
.Op Fl l Ar lpcdev Ns Op , Ns Ar conf
@@ -239,6 +239,8 @@ The host device must have been reserved at boot-time using the
loader variable as described in
.Xr vmm 4 .
.El
.It Fl u
RTC keeps UTC time.
.It Fl U Ar uuid
Set the universally unique identifier
.Pq UUID
+9 -3
View File
@@ -122,7 +122,7 @@ usage(int code)
{
fprintf(stderr,
"Usage: %s [-abehwxACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n"
"Usage: %s [-abehuwxACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n"
" %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
" -a: local apic is in xAPIC mode (deprecated)\n"
" -A: create ACPI tables\n"
@@ -137,6 +137,7 @@ usage(int code)
" -p: pin 'vcpu' to 'hostcpu'\n"
" -P: vmexit from the guest on pause\n"
" -s: <slot,driver,configinfo> PCI slot config\n"
" -u: RTC keeps UTC time\n"
" -U: uuid\n"
" -w: ignore unimplemented MSRs\n"
" -W: force virtio to use single-vector MSI\n"
@@ -685,6 +686,7 @@ main(int argc, char *argv[])
{
int c, error, gdb_port, err, bvmcons;
int dump_guest_memory, max_vcpus, mptgen;
int rtc_localtime;
struct vmctx *ctx;
uint64_t rip;
size_t memsize;
@@ -696,8 +698,9 @@ main(int argc, char *argv[])
guest_ncpus = 1;
memsize = 256 * MB;
mptgen = 1;
rtc_localtime = 1;
while ((c = getopt(argc, argv, "abehwxACHIPWYp:g:c:s:m:l:U:")) != -1) {
while ((c = getopt(argc, argv, "abehuwxACHIPWYp:g:c:s:m:l:U:")) != -1) {
switch (c) {
case 'a':
x2apic_mode = 0;
@@ -757,6 +760,9 @@ main(int argc, char *argv[])
case 'e':
strictio = 1;
break;
case 'u':
rtc_localtime = 0;
break;
case 'U':
guest_uuid_str = optarg;
break;
@@ -820,7 +826,7 @@ main(int argc, char *argv[])
pci_irq_init(ctx);
ioapic_init(ctx);
rtc_init(ctx);
rtc_init(ctx, rtc_localtime);
sci_init(ctx);
/*
+8 -8
View File
@@ -55,23 +55,23 @@ __FBSDID("$FreeBSD$");
/*
* Returns the current RTC time as number of seconds since 00:00:00 Jan 1, 1970
*
* XXX this always returns localtime to maintain compatibility with the
* original device model.
*/
static time_t
rtc_time(struct vmctx *ctx)
rtc_time(struct vmctx *ctx, int use_localtime)
{
struct tm tm;
time_t t;
time(&t);
localtime_r(&t, &tm);
return (timegm(&tm));
if (use_localtime) {
localtime_r(&t, &tm);
t = timegm(&tm);
}
return (t);
}
void
rtc_init(struct vmctx *ctx)
rtc_init(struct vmctx *ctx, int use_localtime)
{
size_t himem;
size_t lomem;
@@ -99,7 +99,7 @@ rtc_init(struct vmctx *ctx)
err = vm_rtc_write(ctx, RTC_HMEM_MSB, himem >> 16);
assert(err == 0);
err = vm_rtc_settime(ctx, rtc_time(ctx));
err = vm_rtc_settime(ctx, rtc_time(ctx, use_localtime));
assert(err == 0);
}
+1 -1
View File
@@ -29,6 +29,6 @@
#ifndef _RTC_H_
#define _RTC_H_
void rtc_init(struct vmctx *ctx);
void rtc_init(struct vmctx *ctx, int use_localtime);
#endif /* _RTC_H_ */