]> granicus.if.org Git - strace/commitdiff
time: use indexed lookups
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 15 May 2018 21:41:47 +0000 (21:41 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 May 2018 21:41:47 +0000 (21:41 +0000)
* defs.h (xlat_idx): New prototype.
* xlat.c (xlat_idx): Remove static qualifier.
* time.c (do_adjtimex): Use xlat_idx instead of xlookup.
(SYS_FUNC(getitimer), SYS_FUNC(setitimer)): Use printxval_index
instead of printxval.
[ALPHA] (SYS_FUNC(osf_getitimer), SYS_FUNC(osf_setitimer)): Likewise.
(printclockname) [CLOCKID_TO_FD]: Likewise.
* xlat/adjtimex_state.in: Add "#value_indexed" directive.
* xlat/clocknames.in: Likewise.
* xlat/cpuclocknames.in: Add "#value_indexed" directive, add default
values to constants.
* xlat/itimer_which.in: Likewise.

defs.h
time.c
xlat.c
xlat/adjtimex_state.in
xlat/clocknames.in
xlat/cpuclocknames.in
xlat/itimer_which.in

diff --git a/defs.h b/defs.h
index 9f8535c9fccab2c6080dd9a0abc11be16cc593eb..92f5fa6eccdd354399ccd9f9832251346bbaa5f6 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -536,6 +536,7 @@ extern enum sock_proto getfdproto(struct tcb *, int);
 
 extern const char *xlookup(const struct xlat *, const uint64_t);
 extern const char *xlat_search(const struct xlat *, const size_t, const uint64_t);
+extern const char *xlat_idx(const struct xlat *xlat, size_t nmemb, uint64_t val);
 
 struct dyxlat;
 struct dyxlat *dyxlat_alloc(size_t nmemb);
diff --git a/time.c b/time.c
index 038c32f84bd2f2c62d33a6a1c73b2da857dd26c8..1f44dca714e0693f25509a59635b73fee7b31ca3 100644 (file)
--- a/time.c
+++ b/time.c
@@ -116,7 +116,8 @@ SYS_FUNC(nanosleep)
 SYS_FUNC(getitimer)
 {
        if (entering(tcp)) {
-               printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
+               printxval_index(itimer_which, (unsigned int) tcp->u_arg[0],
+                               "ITIMER_???");
                tprints(", ");
        } else {
                print_itimerval(tcp, tcp->u_arg[1]);
@@ -128,7 +129,8 @@ SYS_FUNC(getitimer)
 SYS_FUNC(osf_getitimer)
 {
        if (entering(tcp)) {
-               printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
+               printxval_index(itimer_which, (unsigned int) tcp->u_arg[0],
+                               "ITIMER_???");
                tprints(", ");
        } else {
                print_itimerval32(tcp, tcp->u_arg[1]);
@@ -140,7 +142,8 @@ SYS_FUNC(osf_getitimer)
 SYS_FUNC(setitimer)
 {
        if (entering(tcp)) {
-               printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
+               printxval_index(itimer_which, (unsigned int) tcp->u_arg[0],
+                               "ITIMER_???");
                tprints(", ");
                print_itimerval(tcp, tcp->u_arg[1]);
                tprints(", ");
@@ -154,7 +157,8 @@ SYS_FUNC(setitimer)
 SYS_FUNC(osf_setitimer)
 {
        if (entering(tcp)) {
-               printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
+               printxval_index(itimer_which, (unsigned int) tcp->u_arg[0],
+                               "ITIMER_???");
                tprints(", ");
                print_itimerval32(tcp, tcp->u_arg[1]);
                tprints(", ");
@@ -172,7 +176,8 @@ do_adjtimex(struct tcb *const tcp, const kernel_ulong_t addr)
 {
        if (print_timex(tcp, addr))
                return 0;
-       tcp->auxstr = xlookup(adjtimex_state, (kernel_ulong_t) tcp->u_rval);
+       tcp->auxstr = xlat_idx(adjtimex_state, ARRAY_SIZE(adjtimex_state) - 1,
+                              (kernel_ulong_t) tcp->u_rval);
        return RVAL_STR;
 }
 
@@ -196,16 +201,19 @@ printclockname(int clockid)
                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_???");
+                       tprintf("%s(%d,",
+                               CPUCLOCK_PERTHREAD(clockid) ?
+                                       "MAKE_THREAD_CPUCLOCK" :
+                                       "MAKE_PROCESS_CPUCLOCK",
+                               CPUCLOCK_PID(clockid));
+                       printxval_index(cpuclocknames,
+                                       (unsigned int) clockid & CLOCKFD_MASK,
+                                       "CPUCLOCK_???");
                        tprints(")");
                }
        } else
 #endif
-               printxval(clocknames, clockid, "CLOCK_???");
+               printxval_index(clocknames, clockid, "CLOCK_???");
 }
 
 SYS_FUNC(clock_settime)
diff --git a/xlat.c b/xlat.c
index 476a89cd7ce1ea1cc4523835249b8bf594674514..88e42136761e0ab062c84680b63aa6a2cf4f7e3c 100644 (file)
--- a/xlat.c
+++ b/xlat.c
@@ -226,7 +226,7 @@ printxval_searchn_ex(const struct xlat *xlat, size_t xlat_size, uint64_t val,
                                  xlat_search);
 }
 
-static const char *
+const char *
 xlat_idx(const struct xlat *xlat, size_t nmemb, uint64_t val)
 {
        if (val >= nmemb)
index 875bdd3bb3b349e16dabd36966ced142a1510284..c4ec23c4ca97e94caef545186dc9ecdb32039174 100644 (file)
@@ -1,3 +1,4 @@
+#value_indexed
 TIME_OK                0
 TIME_INS       1
 TIME_DEL       2
index 1d0d372702a97cf41b5c2b87efbef1fb43a2da83..207ade8e720354c7f7b10b1db5ff79c6234a6d75 100644 (file)
@@ -1,3 +1,4 @@
+#value_indexed
 CLOCK_REALTIME 0
 CLOCK_MONOTONIC 1
 CLOCK_PROCESS_CPUTIME_ID 2
index e61fa8f60e29ba684ab73c4a6658b9c571d51165..b7b9a828ef3554898ea120c43cdfca0f1c027f36 100644 (file)
@@ -1,3 +1,4 @@
-CPUCLOCK_PROF
-CPUCLOCK_VIRT
-CPUCLOCK_SCHED
+#value_indexed
+CPUCLOCK_PROF  0
+CPUCLOCK_VIRT  1
+CPUCLOCK_SCHED 2
index 768b20f43cbb1be2910bc1a410653ce5c75e9ace..23635a23a7134d2c2d4f8c37fbfd02111e5911bb 100644 (file)
@@ -1,3 +1,4 @@
-ITIMER_REAL
-ITIMER_VIRTUAL
-ITIMER_PROF
+#value_indexed
+ITIMER_REAL    0
+ITIMER_VIRTUAL 1
+ITIMER_PROF    2