Decode dynamic posix clocks
authorStefan Sørensen <stefan.sorensen@spectralink.com>
Mon, 3 Feb 2014 09:01:27 +0000 (10:01 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 3 Feb 2014 22:24:09 +0000 (22:24 +0000)
* time.c (cpuclocknames): New xlat structure.
(printclockname): New function that decodes posix clock names,
including dynamic fd encoded clocks.
(sys_clock_settime, sys_clock_gettime, sys_clock_nanosleep,
sys_clock_adjtime, sys_timer_create, sys_timerfd, sys_timerfd_create):
Use it.

Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
time.c

diff --git a/time.c b/time.c
index 877613bf6a23d7b264018907b3bc95f146dccac1..9a27bca81ade556fb2891d128a3e210ee6fe11cf 100644 (file)
--- a/time.c
+++ b/time.c
@@ -668,11 +668,41 @@ static const struct xlat clocknames[] = {
        { 0,                            NULL }
 };
 
+#ifdef CLOCKID_TO_FD
+static const struct xlat cpuclocknames[] = {
+       { CPUCLOCK_PROF,        "CPUCLOCK_PROF" },
+       { CPUCLOCK_VIRT,        "CPUCLOCK_VIRT" },
+       { CPUCLOCK_SCHED,       "CPUCLOCK_SCHED" },
+       { 0, NULL }
+};
+#endif
+
+static void
+printclockname(int clockid)
+{
+#ifdef CLOCKID_TO_FD
+       if (clockid < 0) {
+               if ((clockid & CLOCKFD_MASK) == CLOCKFD)
+                       tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
+               else {
+                       if(CPUCLOCK_PERTHREAD(clockid))
+                               tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
+                       else
+                               tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
+                       printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
+                       tprints(")");
+               }
+       }
+       else
+#endif
+               printxval(clocknames, clockid, "CLOCK_???");
+}
+
 int
 sys_clock_settime(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
                printtv(tcp, tcp->u_arg[1]);
        }
@@ -683,7 +713,7 @@ int
 sys_clock_gettime(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
        } else {
                if (syserror(tcp))
@@ -698,7 +728,7 @@ int
 sys_clock_nanosleep(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
                printflags(clockflags, tcp->u_arg[1], "TIMER_???");
                tprints(", ");
@@ -718,7 +748,7 @@ sys_clock_adjtime(struct tcb *tcp)
 {
        if (exiting(tcp))
                return do_adjtimex(tcp, tcp->u_arg[1]);
-       printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+       printclockname(tcp->u_arg[0]);
        tprints(", ");
        return 0;
 }
@@ -820,7 +850,7 @@ int
 sys_timer_create(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
                printsigevent(tcp, tcp->u_arg[1]);
                tprints(", ");
@@ -968,7 +998,7 @@ sys_timerfd(struct tcb *tcp)
        if (entering(tcp)) {
                /* It does not matter that the kernel uses itimerspec.  */
                tprintf("%ld, ", tcp->u_arg[0]);
-               printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
                printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
                tprints(", ");
@@ -981,7 +1011,7 @@ int
 sys_timerfd_create(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
+               printclockname(tcp->u_arg[0]);
                tprints(", ");
                printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
        }