Message type for PM_ time-related calls

- Message type for PM_CLOCK_SETTIME, PM_CLOCK_GETTIME,
   PM_CLOCK_GETRES, PM_GETTIMEOFDAY, PM_SETTIME.

 - Small adaptation, message only transfert sub-second time in
   nanoseconds, instead of both nano- and micro-seconds. Conversion
   is done in userland, as required.

Change-Id: Ie4a6e0c457cc12626e85d2102c086a95311cf3e7
This commit is contained in:
Lionel Sambuc 2014-05-12 23:40:11 +02:00
parent ee2f1ee4cd
commit 1ae60bd2e8
9 changed files with 52 additions and 38 deletions

View file

@ -64,14 +64,6 @@
/* Field names for the exit(2) call. */
#define PM_EXIT_STATUS m1_i1 /* int */
/* Field names for the gettimeofday(2), clock_*(2), adjtime(2), stime(2) calls.
*/
#define PM_TIME_CLK_ID m2_i1 /* clockid_t */
#define PM_TIME_NOW m2_i2 /* int */
#define PM_TIME_SEC m2_ll1 /* time_t */
#define PM_TIME_USEC m2_l2 /* long */
#define PM_TIME_NSEC m2_l2 /* long */
/* Field names for the ptrace(2) call. */
#define PM_PTRACE_PID m2_i1 /* pid_t */
#define PM_PTRACE_REQ m2_i2 /* int */

View file

@ -145,6 +145,26 @@ typedef struct {
} mess_sigcalls;
_ASSERT_MSG_SIZE(mess_sigcalls);
typedef struct {
time_t sec;
clockid_t clk_id;
int now;
long nsec;
uint8_t padding[36];
} mess_lc_pm_time;
_ASSERT_MSG_SIZE(mess_lc_pm_time);
typedef struct {
time_t sec;
long nsec;
uint8_t padding[44];
} mess_pm_lc_time;
_ASSERT_MSG_SIZE(mess_pm_lc_time);
typedef struct {
pid_t pid;
int options;
@ -902,6 +922,7 @@ typedef struct {
mess_fs_vfs_readsuper m_fs_vfs_readsuper;
mess_fs_vfs_readwrite m_fs_vfs_readwrite;
mess_lc_pm_time m_lc_pm_time;
mess_lc_pm_waitpid m_lc_pm_waitpid;
mess_lc_vfs_chown m_lc_vfs_chown;
@ -936,6 +957,7 @@ typedef struct {
mess_lsys_vfs_copyfd m_lsys_vfs_copyfd;
mess_lsys_vfs_mapdriver m_lsys_vfs_mapdriver;
mess_pm_lc_time m_pm_lc_time;
mess_pm_lc_waitpid m_pm_lc_waitpid;
mess_pm_lsys_getepinfo m_pm_lsys_getepinfo;

View file

@ -15,10 +15,10 @@ int adjtime(const struct timeval *delta, struct timeval *olddelta)
message m;
memset(&m, 0, sizeof(m));
m.PM_TIME_CLK_ID = (clockid_t) CLOCK_REALTIME;
m.PM_TIME_NOW = 0; /* use adjtime() method to slowly adjust the clock. */
m.PM_TIME_SEC = delta->tv_sec;
m.PM_TIME_NSEC = delta->tv_usec * 1000; /* convert usec to nsec */
m.m_lc_pm_time.clk_id = CLOCK_REALTIME;
m.m_lc_pm_time.now = 0; /* use adjtime() method to slowly adjust the clock. */
m.m_lc_pm_time.sec = delta->tv_sec;
m.m_lc_pm_time.nsec = delta->tv_usec * 1000; /* convert usec to nsec */
if (_syscall(PM_PROC_NR, PM_CLOCK_SETTIME, &m) < 0)
return -1;

View file

@ -14,13 +14,13 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
message m;
memset(&m, 0, sizeof(m));
m.PM_TIME_CLK_ID = clock_id;
m.m_lc_pm_time.clk_id = clock_id;
if (_syscall(PM_PROC_NR, PM_CLOCK_GETRES, &m) < 0)
return -1;
res->tv_sec = m.PM_TIME_SEC;
res->tv_nsec = m.PM_TIME_NSEC;
res->tv_sec = m.m_pm_lc_time.sec;
res->tv_nsec = m.m_pm_lc_time.nsec;
return 0;
}

View file

@ -14,13 +14,13 @@ int clock_gettime(clockid_t clock_id, struct timespec *res)
message m;
memset(&m, 0, sizeof(m));
m.PM_TIME_CLK_ID = clock_id;
m.m_lc_pm_time.clk_id = clock_id;
if (_syscall(PM_PROC_NR, PM_CLOCK_GETTIME, &m) < 0)
return -1;
res->tv_sec = m.PM_TIME_SEC;
res->tv_nsec = m.PM_TIME_NSEC;
res->tv_sec = m.m_pm_lc_time.sec;
res->tv_nsec = m.m_pm_lc_time.nsec;
return 0;
}

View file

@ -14,10 +14,10 @@ int clock_settime(clockid_t clock_id, const struct timespec *ts)
message m;
memset(&m, 0, sizeof(m));
m.PM_TIME_CLK_ID = clock_id;
m.PM_TIME_NOW = 1; /* set time immediately. don't use adjtime() method. */
m.PM_TIME_SEC = ts->tv_sec;
m.PM_TIME_NSEC = ts->tv_nsec;
m.m_lc_pm_time.clk_id = clock_id;
m.m_lc_pm_time.now = 1; /* set time immediately. don't use adjtime() method. */
m.m_lc_pm_time.sec = ts->tv_sec;
m.m_lc_pm_time.nsec = ts->tv_nsec;
if (_syscall(PM_PROC_NR, PM_CLOCK_SETTIME, &m) < 0)
return -1;

View file

@ -18,8 +18,8 @@ int gettimeofday(struct timeval *__restrict tp, void *__restrict tzp)
if (_syscall(PM_PROC_NR, PM_GETTIMEOFDAY, &m) < 0)
return -1;
tp->tv_sec = m.PM_TIME_SEC;
tp->tv_usec = m.PM_TIME_USEC;
tp->tv_sec = m.m_pm_lc_time.sec;
tp->tv_usec = m.m_pm_lc_time.nsec / 1000;
return 0;
}

View file

@ -12,6 +12,6 @@ int stime(time_t *top)
message m;
memset(&m, 0, sizeof(m));
m.PM_TIME_SEC = *top;
m.m_lc_pm_time.sec = *top;
return(_syscall(PM_PROC_NR, PM_STIME, &m));
}

View file

@ -27,7 +27,7 @@ int do_gettime()
if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
panic("do_time couldn't get uptime: %d", s);
switch (m_in.PM_TIME_CLK_ID) {
switch (m_in.m_lc_pm_time.clk_id) {
case CLOCK_REALTIME:
clock = realtime;
break;
@ -38,8 +38,8 @@ int do_gettime()
return EINVAL; /* invalid/unsupported clock_id */
}
mp->mp_reply.PM_TIME_SEC = boottime + (clock / system_hz);
mp->mp_reply.PM_TIME_NSEC =
mp->mp_reply.m_pm_lc_time.sec = boottime + (clock / system_hz);
mp->mp_reply.m_pm_lc_time.nsec =
(uint32_t) ((clock % system_hz) * 1000000000ULL / system_hz);
return(OK);
@ -50,12 +50,12 @@ int do_gettime()
*===========================================================================*/
int do_getres()
{
switch (m_in.PM_TIME_CLK_ID) {
switch (m_in.m_lc_pm_time.clk_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
/* tv_sec is always 0 since system_hz is an int */
mp->mp_reply.PM_TIME_SEC = 0;
mp->mp_reply.PM_TIME_NSEC = 1000000000 / system_hz;
mp->mp_reply.m_pm_lc_time.sec = 0;
mp->mp_reply.m_pm_lc_time.nsec = 1000000000 / system_hz;
return(OK);
default:
return EINVAL; /* invalid/unsupported clock_id */
@ -73,10 +73,10 @@ int do_settime()
return(EPERM);
}
switch (m_in.PM_TIME_CLK_ID) {
switch (m_in.m_lc_pm_time.clk_id) {
case CLOCK_REALTIME:
s= sys_settime(m_in.PM_TIME_NOW, m_in.PM_TIME_CLK_ID,
m_in.PM_TIME_SEC, m_in.PM_TIME_NSEC);
s = sys_settime(m_in.m_lc_pm_time.now, m_in.m_lc_pm_time.clk_id,
m_in.m_lc_pm_time.sec, m_in.m_lc_pm_time.nsec);
return(s);
case CLOCK_MONOTONIC: /* monotonic cannot be changed */
default:
@ -101,9 +101,9 @@ int do_time()
if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
panic("do_time couldn't get uptime: %d", s);
mp->mp_reply.PM_TIME_SEC = boottime + (realtime / system_hz);
mp->mp_reply.PM_TIME_USEC =
(uint32_t) ((realtime % system_hz) * 1000000ULL / system_hz);
mp->mp_reply.m_pm_lc_time.sec = boottime + (realtime / system_hz);
mp->mp_reply.m_pm_lc_time.nsec =
(uint32_t) ((realtime % system_hz) * 1000000000ULL / system_hz);
return(OK);
}
@ -124,7 +124,7 @@ int do_stime()
}
if ( (s=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("do_stime couldn't get uptime: %d", s);
boottime = m_in.PM_TIME_SEC - (realtime/system_hz);
boottime = m_in.m_lc_pm_time.sec - (realtime/system_hz);
s= sys_stime(boottime); /* Tell kernel about boottime */
if (s != OK)