From 4fcdebc4342b7b9d36e79d95efaefee5940a44e0 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Fri, 20 Apr 2018 17:54:07 +0800 Subject: [PATCH] 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 Acked-by: Anthony Xu --- devicemodel/core/main.c | 6 ++---- devicemodel/hw/platform/rtc.c | 14 +++++++++++--- devicemodel/include/rtc.h | 3 ++- devicemodel/include/vmmapi.h | 8 ++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index fa32c1b42..e1b0dfaab 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -577,7 +577,6 @@ main(int argc, char *argv[]) { int c, error, gdb_port, err; int max_vcpus, mptgen, memflags; - int rtc_localtime; struct vmctx *ctx; size_t memsize; char *optstr; @@ -588,7 +587,6 @@ main(int argc, char *argv[]) guest_ncpus = 1; memsize = 256 * MB; mptgen = 1; - rtc_localtime = 1; memflags = 0; quit_vm_loop = 0; hugetlb = 0; @@ -669,7 +667,7 @@ main(int argc, char *argv[]) strictio = 1; break; case 'u': - rtc_localtime = 0; + vrtc_enable_localtime(0); break; case 'U': guest_uuid_str = optarg; @@ -785,7 +783,7 @@ main(int argc, char *argv[]) ioapic_init(ctx); ioc_init(); - vrtc_init(ctx, rtc_localtime); + vrtc_init(ctx); sci_init(ctx); init_bvmcons(); monitor_init(ctx); diff --git a/devicemodel/hw/platform/rtc.c b/devicemodel/hw/platform/rtc.c index 8a5ffad88..04643eeee 100644 --- a/devicemodel/hw/platform/rtc.c +++ b/devicemodel/hw/platform/rtc.c @@ -144,6 +144,8 @@ static const int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +static int local_time = 1; + /* * This inline avoids some unnecessary modulo operations * as compared with the usual macro: @@ -1096,8 +1098,14 @@ vrtc_reset(struct vrtc *vrtc) pthread_mutex_unlock(&vrtc->mtx); } -struct vrtc * -vrtc_init(struct vmctx *ctx, int local_time) +void +vrtc_enable_localtime(int l_time) +{ + local_time = l_time; +} + +int +vrtc_init(struct vmctx *ctx) { struct vrtc *vrtc; struct rtcdev *rtc; @@ -1158,7 +1166,7 @@ vrtc_init(struct vmctx *ctx, int local_time) secs_to_rtc(curtime, vrtc, 0); pthread_mutex_unlock(&vrtc->mtx); - return vrtc; + return 0; } void diff --git a/devicemodel/include/rtc.h b/devicemodel/include/rtc.h index fedb0975c..d6b8ff777 100644 --- a/devicemodel/include/rtc.h +++ b/devicemodel/include/rtc.h @@ -36,7 +36,8 @@ struct vrtc; 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_reset(struct vrtc *vrtc); time_t vrtc_get_time(struct vrtc *vrtc); diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index 8433ae0a5..409621476 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -34,8 +34,6 @@ #include "types.h" #include "vmm.h" -#include "atkbdc.h" - /* * 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_DOWN(x, align) ((x) & ~((align)-1)) -struct iovec; - struct vmctx { int fd; int vmid; @@ -64,8 +60,8 @@ struct vmctx { uuid_t vm_uuid; /* fields to track virtual devices */ - struct atkbdc_base *atkbdc_base; - struct vrtc *vrtc; + void *atkbdc_base; + void *vrtc; }; /*