<p dir="ltr"><br>
Thank you for your advice<br>
Of course there are disadvantages to using a dynamic library, there are also advantages<br>
Maybe, I think that clock_gettime() function is unlikely going to be a lot of calls about impair performance</p>
<div class="gmail_quote">2015. 4. 23. 오후 11:34에 "Stéphane Graber" <<a href="mailto:stgraber@ubuntu.com">stgraber@ubuntu.com</a>>님이 작성:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Apr 23, 2015 at 05:19:54PM +0900, Gyeongmin Kim wrote:<br>
> Dear, All<br>
><br>
> In project, use both gettimeofday() and clock_gettime(). It's needless.<br>
> I think to use clock_gettime() better than gettimeofday(). becaues,<br>
> gettimeofday() function will be obsoletecent. (<br>
> <a href="http://pubs.opengroup.org/stage7tc1/functions/gettimeofday.html" target="_blank">http://pubs.opengroup.org/stage7tc1/functions/gettimeofday.html</a>)<br>
> and "time.h" is used only (Now, using "sys/time.h", "time.h")<br>
><br>
> also, clock_gettime() use to timespec structrue.<br>
> If function use to timeval structure, timespec structure also support to<br>
> function. But, different slightly name of function. such as, select() and<br>
> pselect ()<br>
><br>
> int select(int nfds, fd_set *readfds, fd_set *writefds,<br>
>            fd_set *exceptfds, struct timeval *timeout);<br>
><br>
> int pselect(int nfds, fd_set *readfds, fd_set *writefds,<br>
>             fd_set *exceptfds, const struct timespec *timeout,<br>
>             const sigset_t *sigmask<br>
<br>
One reason to prefer gettimeofday to clock_gettime is that on quite a<br>
few architecture it's implemented using a VDSO which avoids the need for<br>
a kernel roundtrip. However unless we call it very frequently in some<br>
kind of loop, that's unlikely to be a significant performance loss.<br>
<br>
><br>
> Signed-off-by: GyeongminKim <<a href="mailto:gyeongmintwo@gmail.com">gyeongmintwo@gmail.com</a>><br>
><br>
> # On branch master<br>
> # Changes to be committed:<br>
> #   (use "git reset HEAD <file>..." to unstage)<br>
> #<br>
> # modified:   src/lxc/conf.c<br>
> # modified:   src/lxc/confile.c<br>
> # modified:   src/lxc/log.c<br>
> # modified:   src/lxc/log.h<br>
> # modified:   src/lxc/lxc_stop.c<br>
> # modified:   src/lxc/lxclock.h<br>
> # modified:   src/lxc/monitor.c<br>
> # modified:   src/lxc/state.c<br>
> #<br>
><br>
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c<br>
> index d4855fd..d47907d 100644<br>
> --- a/src/lxc/conf.c<br>
> +++ b/src/lxc/conf.c<br>
> @@ -35,7 +35,6 @@<br>
> #include <sys/types.h><br>
> #include <pwd.h><br>
> #include <grp.h><br>
> -#include <time.h><br>
> #ifdef HAVE_STATVFS<br>
> #include <sys/statvfs.h><br>
> #endif<br>
> diff --git a/src/lxc/confile.c b/src/lxc/confile.c<br>
> index e3be6a6..dc12edf 100644<br>
> --- a/src/lxc/confile.c<br>
> +++ b/src/lxc/confile.c<br>
> @@ -36,7 +36,6 @@<br>
> #include <arpa/inet.h><br>
> #include <netinet/in.h><br>
> #include <net/if.h><br>
> -#include <time.h><br>
> #include <dirent.h><br>
><br>
> #include "parse.h"<br>
> diff --git a/src/lxc/log.c b/src/lxc/log.c<br>
> index 6633e62..0230724 100644<br>
> --- a/src/lxc/log.c<br>
> +++ b/src/lxc/log.c<br>
> @@ -89,7 +89,7 @@ static int log_append_logfile(const struct<br>
> lxc_log_appender *appender,<br>
>         if (lxc_log_fd == -1)<br>
>                 return 0;<br>
><br>
> -       ms = event->timestamp.tv_usec / 1000;<br>
> +       ms = event->timestamp.tv_nsec / 1000000;<br>
>         n = snprintf(buffer, sizeof(buffer),<br>
>                      "%15s %10ld.%03d %-8s %s - %s:%s:%d - ",<br>
>                      log_prefix,<br>
> diff --git a/src/lxc/log.h b/src/lxc/log.h<br>
> index b47f120..bccdf5f 100644<br>
> --- a/src/lxc/log.h<br>
> +++ b/src/lxc/log.h<br>
> @@ -28,7 +28,7 @@<br>
><br>
> #include <stdarg.h><br>
> #include <stdio.h><br>
> -#include <sys/time.h><br>
> +#include <time.h><br>
> #include <string.h><br>
> #include <strings.h><br>
> #include <stdbool.h><br>
> @@ -79,7 +79,7 @@ struct lxc_log_locinfo {<br>
> struct lxc_log_event {<br>
>         const char*             category;<br>
>         int                     priority;<br>
> -       struct timeval          timestamp;<br>
> +       struct timespec         timestamp;<br>
>         struct lxc_log_locinfo  *locinfo;<br>
>         const char              *fmt;<br>
>         va_list                 *vap;<br>
> @@ -203,7 +203,7 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct<br>
> lxc_log_locinfo* locinfo,      \<br>
>                 };                                                      \<br>
>                 va_list va_ref;                                         \<br>
>                                                                         \<br>
> -               gettimeofday(&evt.timestamp, NULL);                     \<br>
> +               clock_gettime(CLOCK_REALTIME, &evt.timestamp);          \<br>
>                                                                         \<br>
>                 va_start(va_ref, format);                               \<br>
>                 evt.vap = &va_ref;                                      \<br>
> diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c<br>
> index 7054532..3b891a6 100644<br>
> --- a/src/lxc/lxc_stop.c<br>
> +++ b/src/lxc/lxc_stop.c<br>
> @@ -104,14 +104,14 @@ static int do_reboot_and_check(struct lxc_arguments<br>
> *a, struct lxc_container *c)<br>
>                 /* can we use c-> wait for this, assuming it will<br>
>                  * re-enter RUNNING?  For now just sleep */<br>
>                 int elapsed_time, curtime = 0;<br>
> -               struct timeval tv;<br>
> +               struct timespec tv;<br>
><br>
>                 newpid = c->init_pid(c);<br>
>                 if (newpid != -1 && newpid != pid)<br>
>                         return 0;<br>
><br>
>                 if (timeout != -1) {<br>
> -                       ret = gettimeofday(&tv, NULL);<br>
> +                       ret = clock_gettime(CLOCK_REALTIME, &tv);<br>
>                         if (ret)<br>
>                                 break;<br>
>                         curtime = tv.tv_sec;<br>
> @@ -119,7 +119,7 @@ static int do_reboot_and_check(struct lxc_arguments *a,<br>
> struct lxc_container *c)<br>
><br>
>                 sleep(1);<br>
>                 if (timeout != -1) {<br>
> -                       ret = gettimeofday(&tv, NULL);<br>
> +                       ret = clock_gettime(CLOCK_REALTIME, &tv);<br>
>                         if (ret)<br>
>                                 break;<br>
>                         elapsed_time = tv.tv_sec - curtime;<br>
> diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h<br>
> index e00dd8a..74ea83f 100644<br>
> --- a/src/lxc/lxclock.h<br>
> +++ b/src/lxc/lxclock.h<br>
> @@ -28,7 +28,6 @@<br>
> #include <sys/file.h><br>
> #include <semaphore.h><br>
> #include <string.h><br>
> -#include <time.h><br>
><br>
> #define LXC_LOCK_ANON_SEM 1 /*!< Anonymous semaphore lock */<br>
> #define LXC_LOCK_FLOCK    2 /*!< flock(2) lock */<br>
> diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c<br>
> index 1e1c094..9f68af8 100644<br>
> --- a/src/lxc/monitor.c<br>
> +++ b/src/lxc/monitor.c<br>
> @@ -222,16 +222,16 @@ err1:<br>
> int lxc_monitor_read_fdset(fd_set *rfds, int nfds, struct lxc_msg *msg,<br>
>                            int timeout)<br>
> {<br>
> -       struct timeval tval,*tv = NULL;<br>
> +       struct timespec tspec,*tv = NULL;<br>
>         int ret,i;<br>
><br>
>         if (timeout != -1) {<br>
> -               tv = &tval;<br>
> +               tv = &tspec;<br>
>                 tv->tv_sec = timeout;<br>
> -               tv->tv_usec = 0;<br>
> +               tv->tv_nsec = 0;<br>
>         }<br>
><br>
> -       ret = select(nfds, rfds, NULL, NULL, tv);<br>
> +       ret = pselect(nfds, rfds, NULL, NULL, tv, NULL);<br>
>         if (ret == -1)<br>
>                 return -1;<br>
>         else if (ret == 0)<br>
> diff --git a/src/lxc/state.c b/src/lxc/state.c<br>
> index db833b0..a5e9d6f 100644<br>
> --- a/src/lxc/state.c<br>
> +++ b/src/lxc/state.c<br>
> @@ -134,12 +134,12 @@ extern int lxc_wait(const char *lxcname, const char<br>
> *states, int timeout, const<br>
><br>
>         for (;;) {<br>
>                 int elapsed_time, curtime = 0;<br>
> -               struct timeval tv;<br>
> +               struct timespec tv;<br>
>                 int stop = 0;<br>
>                 int retval;<br>
><br>
>                 if (timeout != -1) {<br>
> -                       retval = gettimeofday(&tv, NULL);<br>
> +                       retval = clock_gettime(CLOCK_REALTIME, &tv);<br>
>                         if (retval)<br>
>                                 goto out_close;<br>
>                         curtime = tv.tv_sec;<br>
> @@ -151,7 +151,7 @@ extern int lxc_wait(const char *lxcname, const char<br>
> *states, int timeout, const<br>
>                 }<br>
><br>
>                 if (timeout != -1) {<br>
> -                       retval = gettimeofday(&tv, NULL);<br>
> +                       retval = clock_gettime(CLOCK_REALTIME, &tv);<br>
>                         if (retval)<br>
>                                 goto out_close;<br>
>                         elapsed_time = tv.tv_sec - curtime;<br>
<br>
> _______________________________________________<br>
> lxc-devel mailing list<br>
> <a href="mailto:lxc-devel@lists.linuxcontainers.org">lxc-devel@lists.linuxcontainers.org</a><br>
> <a href="http://lists.linuxcontainers.org/listinfo/lxc-devel" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-devel</a><br>
<br>
<br>
--<br>
Stéphane Graber<br>
Ubuntu developer<br>
<a href="http://www.ubuntu.com" target="_blank">http://www.ubuntu.com</a><br>
<br>_______________________________________________<br>
lxc-devel mailing list<br>
<a href="mailto:lxc-devel@lists.linuxcontainers.org">lxc-devel@lists.linuxcontainers.org</a><br>
<a href="http://lists.linuxcontainers.org/listinfo/lxc-devel" target="_blank">http://lists.linuxcontainers.org/listinfo/lxc-devel</a><br>
<br></blockquote></div>