[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH] Adding RTC device (work in progress)
From: |
Zhaoming Luo |
Subject: |
Re: [RFC PATCH] Adding RTC device (work in progress) |
Date: |
Wed, 20 Nov 2024 20:17:48 +0800 |
User-agent: |
Mozilla Thunderbird |
On 11/9/24 10:58 PM, Sergey Bugaev wrote:
I know that RTC can be configured to either represent local time, or
in UTC. MS Windows prefers the former, GNU/Linux (or rather systemd?)
prefers the latter [6]. Would it maybe make sense for the driver to
have an --option to *pretend* the RTC stores UTC time when it's
actually storing local time, transparently converting the time on
read/write? The driver would learn the local timezone the same way all
processes do (tzset?).
[6]: https://wiki.archlinux.org/title/System_time
I think we don't need to add an option to pretend the RTC stores UTC
time when it's actually storing local time, because I think the Hurd
expects RTC storing UTC time.As mentioned in [6], 'The standard used by
the hardware clock (CMOS clock, the BIOS time) is set by the operating
system'. I did the following experiments in the virtual machine:
I changed the timezone to Chongqing:
```
sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Chongqing /etc/localtime
```
Running `date` to get the following output:
```
Wed Nov 20 19:55:58 CST 2024
```
When I reboot the virtual machine I saw a line of log saying `saving
system time to CMOS clock`.
After the reboot I setup the rtc translator and used the following
program to read rtc. The time I read is UTC time, and the timezone I got
by running `date` is still Chongqing. Therefore, I think the RTC time is
independent of timezone for the Hurd.
This program reads the /tmp/rtc. (Please ignore the coding style :P, it
was written before I started being aware of GNU coding style)
```
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <hurd/ioctl.h>
struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#define RTC_RD_TIME _IOR('p', 0x09, struct rtc_time)
#define _IOT_rtc_time _IOT(_IOTS(int),9,0,0,0,0)
int main() {
int fd = open("/tmp/rtc", O_RDONLY);
if (fd == -1) {
printf("Cannot open rtc!\n");
return 1;
}
printf("The fd of rtc is %d\n", fd);
struct rtc_time time;
int err = ioctl(fd, RTC_RD_TIME, &time);
if (err == -1) {
printf ("ioctl error!\n");
return 1;
}
printf("tm_sec : %d\n", time.tm_sec );
printf("tm_min : %d\n", time.tm_min );
printf("tm_hour : %d\n", time.tm_hour );
printf("tm_mday : %d\n", time.tm_mday );
printf("tm_mon : %d\n", time.tm_mon );
printf("tm_year : %d\n", time.tm_year );
printf("tm_wday : %d\n", time.tm_wday );
printf("tm_yday : %d\n", time.tm_yday );
printf("tm_isdst: %d\n", time.tm_isdst);
return 0;
}
```
--
Zhaoming Luo
- Re: [RFC PATCH] Adding RTC device (work in progress), (continued)
- Re: [RFC PATCH] Adding RTC device (work in progress), Samuel Thibault, 2024/11/01
- Re: [RFC PATCH] Adding RTC device (work in progress), Sergey Bugaev, 2024/11/01
- Re: [RFC PATCH] Adding RTC device (work in progress), Samuel Thibault, 2024/11/01
- Re: [RFC PATCH] Adding RTC device (work in progress), Zhaoming Luo, 2024/11/03
- Re: [RFC PATCH] Adding RTC device (work in progress), Sergey Bugaev, 2024/11/05
- Re: [RFC PATCH] Adding RTC device (work in progress), Samuel Thibault, 2024/11/05
- Re: [RFC PATCH] Adding RTC device (work in progress), Zhaoming Luo, 2024/11/05
- Re: [RFC PATCH] Adding RTC device (work in progress), Sergey Bugaev, 2024/11/07
- Re: [RFC PATCH] Adding RTC device (work in progress), Zhaoming Luo, 2024/11/07
- Re: [RFC PATCH] Adding RTC device (work in progress), Sergey Bugaev, 2024/11/09
- Re: [RFC PATCH] Adding RTC device (work in progress),
Zhaoming Luo <=
- Re: [RFC PATCH] Adding RTC device (work in progress), Samuel Thibault, 2024/11/20
- Re: [RFC PATCH] Adding RTC device (work in progress), Zhaoming Luo, 2024/11/22
- Re: [RFC PATCH] Adding RTC device (work in progress), jbranso, 2024/11/10