DM: vrtc code cleanup

- Move the variable local_time from main.c to rtc.c
- Change vrtc_init to return int instead of pointer to vrtc. We do
  track vrtc in struct vmctx.

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
Yin Fengwei 2018-04-20 17:54:07 +08:00 committed by Jack Ren
parent ccc67ceae4
commit 4fcdebc434
4 changed files with 17 additions and 14 deletions

View File

@ -577,7 +577,6 @@ main(int argc, char *argv[])
{ {
int c, error, gdb_port, err; int c, error, gdb_port, err;
int max_vcpus, mptgen, memflags; int max_vcpus, mptgen, memflags;
int rtc_localtime;
struct vmctx *ctx; struct vmctx *ctx;
size_t memsize; size_t memsize;
char *optstr; char *optstr;
@ -588,7 +587,6 @@ main(int argc, char *argv[])
guest_ncpus = 1; guest_ncpus = 1;
memsize = 256 * MB; memsize = 256 * MB;
mptgen = 1; mptgen = 1;
rtc_localtime = 1;
memflags = 0; memflags = 0;
quit_vm_loop = 0; quit_vm_loop = 0;
hugetlb = 0; hugetlb = 0;
@ -669,7 +667,7 @@ main(int argc, char *argv[])
strictio = 1; strictio = 1;
break; break;
case 'u': case 'u':
rtc_localtime = 0; vrtc_enable_localtime(0);
break; break;
case 'U': case 'U':
guest_uuid_str = optarg; guest_uuid_str = optarg;
@ -785,7 +783,7 @@ main(int argc, char *argv[])
ioapic_init(ctx); ioapic_init(ctx);
ioc_init(); ioc_init();
vrtc_init(ctx, rtc_localtime); vrtc_init(ctx);
sci_init(ctx); sci_init(ctx);
init_bvmcons(); init_bvmcons();
monitor_init(ctx); monitor_init(ctx);

View File

@ -144,6 +144,8 @@ static const int month_days[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}; };
static int local_time = 1;
/* /*
* This inline avoids some unnecessary modulo operations * This inline avoids some unnecessary modulo operations
* as compared with the usual macro: * as compared with the usual macro:
@ -1096,8 +1098,14 @@ vrtc_reset(struct vrtc *vrtc)
pthread_mutex_unlock(&vrtc->mtx); pthread_mutex_unlock(&vrtc->mtx);
} }
struct vrtc * void
vrtc_init(struct vmctx *ctx, int local_time) vrtc_enable_localtime(int l_time)
{
local_time = l_time;
}
int
vrtc_init(struct vmctx *ctx)
{ {
struct vrtc *vrtc; struct vrtc *vrtc;
struct rtcdev *rtc; struct rtcdev *rtc;
@ -1158,7 +1166,7 @@ vrtc_init(struct vmctx *ctx, int local_time)
secs_to_rtc(curtime, vrtc, 0); secs_to_rtc(curtime, vrtc, 0);
pthread_mutex_unlock(&vrtc->mtx); pthread_mutex_unlock(&vrtc->mtx);
return vrtc; return 0;
} }
void void

View File

@ -36,7 +36,8 @@
struct vrtc; struct vrtc;
struct vmctx; struct vmctx;
struct vrtc *vrtc_init(struct vmctx *ctx, int local_time); int vrtc_init(struct vmctx *ctx);
void vrtc_enable_localtime(int l_time);
void vrtc_deinit(struct vmctx *ctx); void vrtc_deinit(struct vmctx *ctx);
void vrtc_reset(struct vrtc *vrtc); void vrtc_reset(struct vrtc *vrtc);
time_t vrtc_get_time(struct vrtc *vrtc); time_t vrtc_get_time(struct vrtc *vrtc);

View File

@ -34,8 +34,6 @@
#include "types.h" #include "types.h"
#include "vmm.h" #include "vmm.h"
#include "atkbdc.h"
/* /*
* API version for out-of-tree consumers for making compile time decisions. * API version for out-of-tree consumers for making compile time decisions.
*/ */
@ -47,8 +45,6 @@
#define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1)) #define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
#define ALIGN_DOWN(x, align) ((x) & ~((align)-1)) #define ALIGN_DOWN(x, align) ((x) & ~((align)-1))
struct iovec;
struct vmctx { struct vmctx {
int fd; int fd;
int vmid; int vmid;
@ -64,8 +60,8 @@ struct vmctx {
uuid_t vm_uuid; uuid_t vm_uuid;
/* fields to track virtual devices */ /* fields to track virtual devices */
struct atkbdc_base *atkbdc_base; void *atkbdc_base;
struct vrtc *vrtc; void *vrtc;
}; };
/* /*