0001
0002
0003 #include <stdio.h>
0004 #include <sys/time.h>
0005 #include <linux/sysinfo.h>
0006 #include "thermal-tools.h"
0007
0008 static unsigned long __offset;
0009 static struct timeval __tv;
0010
0011 int uptimeofday_init(void)
0012 {
0013 struct sysinfo info;
0014
0015 if (sysinfo(&info))
0016 return -1;
0017
0018 gettimeofday(&__tv, NULL);
0019
0020 __offset = __tv.tv_sec - info.uptime;
0021
0022 return 0;
0023 }
0024
0025 unsigned long getuptimeofday_ms(void)
0026 {
0027 gettimeofday(&__tv, NULL);
0028
0029 return ((__tv.tv_sec - __offset) * 1000) + (__tv.tv_usec / 1000);
0030 }
0031
0032 struct timespec msec_to_timespec(int msec)
0033 {
0034 struct timespec tv = {
0035 .tv_sec = (msec / 1000),
0036 .tv_nsec = (msec % 1000) * 1000000,
0037 };
0038
0039 return tv;
0040 }