Skip to content

Commit 4fcdebc

Browse files
fyin1jren1
authored andcommitted
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>
1 parent ccc67ce commit 4fcdebc

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

devicemodel/core/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ main(int argc, char *argv[])
577577
{
578578
int c, error, gdb_port, err;
579579
int max_vcpus, mptgen, memflags;
580-
int rtc_localtime;
581580
struct vmctx *ctx;
582581
size_t memsize;
583582
char *optstr;
@@ -588,7 +587,6 @@ main(int argc, char *argv[])
588587
guest_ncpus = 1;
589588
memsize = 256 * MB;
590589
mptgen = 1;
591-
rtc_localtime = 1;
592590
memflags = 0;
593591
quit_vm_loop = 0;
594592
hugetlb = 0;
@@ -669,7 +667,7 @@ main(int argc, char *argv[])
669667
strictio = 1;
670668
break;
671669
case 'u':
672-
rtc_localtime = 0;
670+
vrtc_enable_localtime(0);
673671
break;
674672
case 'U':
675673
guest_uuid_str = optarg;
@@ -785,7 +783,7 @@ main(int argc, char *argv[])
785783
ioapic_init(ctx);
786784
ioc_init();
787785

788-
vrtc_init(ctx, rtc_localtime);
786+
vrtc_init(ctx);
789787
sci_init(ctx);
790788
init_bvmcons();
791789
monitor_init(ctx);

devicemodel/hw/platform/rtc.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ static const int month_days[12] = {
144144
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
145145
};
146146

147+
static int local_time = 1;
148+
147149
/*
148150
* This inline avoids some unnecessary modulo operations
149151
* as compared with the usual macro:
@@ -1096,8 +1098,14 @@ vrtc_reset(struct vrtc *vrtc)
10961098
pthread_mutex_unlock(&vrtc->mtx);
10971099
}
10981100

1099-
struct vrtc *
1100-
vrtc_init(struct vmctx *ctx, int local_time)
1101+
void
1102+
vrtc_enable_localtime(int l_time)
1103+
{
1104+
local_time = l_time;
1105+
}
1106+
1107+
int
1108+
vrtc_init(struct vmctx *ctx)
11011109
{
11021110
struct vrtc *vrtc;
11031111
struct rtcdev *rtc;
@@ -1158,7 +1166,7 @@ vrtc_init(struct vmctx *ctx, int local_time)
11581166
secs_to_rtc(curtime, vrtc, 0);
11591167
pthread_mutex_unlock(&vrtc->mtx);
11601168

1161-
return vrtc;
1169+
return 0;
11621170
}
11631171

11641172
void

devicemodel/include/rtc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
struct vrtc;
3737
struct vmctx;
3838

39-
struct vrtc *vrtc_init(struct vmctx *ctx, int local_time);
39+
int vrtc_init(struct vmctx *ctx);
40+
void vrtc_enable_localtime(int l_time);
4041
void vrtc_deinit(struct vmctx *ctx);
4142
void vrtc_reset(struct vrtc *vrtc);
4243
time_t vrtc_get_time(struct vrtc *vrtc);

devicemodel/include/vmmapi.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include "types.h"
3535
#include "vmm.h"
3636

37-
#include "atkbdc.h"
38-
3937
/*
4038
* API version for out-of-tree consumers for making compile time decisions.
4139
*/
@@ -47,8 +45,6 @@
4745
#define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
4846
#define ALIGN_DOWN(x, align) ((x) & ~((align)-1))
4947

50-
struct iovec;
51-
5248
struct vmctx {
5349
int fd;
5450
int vmid;
@@ -64,8 +60,8 @@ struct vmctx {
6460
uuid_t vm_uuid;
6561

6662
/* fields to track virtual devices */
67-
struct atkbdc_base *atkbdc_base;
68-
struct vrtc *vrtc;
63+
void *atkbdc_base;
64+
void *vrtc;
6965
};
7066

7167
/*

0 commit comments

Comments
 (0)