From: Dmitry V. Levin Date: Tue, 15 May 2018 21:41:47 +0000 (+0000) Subject: time: use indexed lookups X-Git-Tag: v4.23~152 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e0c0becf975c6e370c1e4e28b659ec63914b936;p=strace time: use indexed lookups * 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. --- diff --git a/defs.h b/defs.h index 9f8535c9..92f5fa6e 100644 --- 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 038c32f8..1f44dca7 100644 --- 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 476a89cd..88e42136 100644 --- 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) diff --git a/xlat/adjtimex_state.in b/xlat/adjtimex_state.in index 875bdd3b..c4ec23c4 100644 --- a/xlat/adjtimex_state.in +++ b/xlat/adjtimex_state.in @@ -1,3 +1,4 @@ +#value_indexed TIME_OK 0 TIME_INS 1 TIME_DEL 2 diff --git a/xlat/clocknames.in b/xlat/clocknames.in index 1d0d3727..207ade8e 100644 --- a/xlat/clocknames.in +++ b/xlat/clocknames.in @@ -1,3 +1,4 @@ +#value_indexed CLOCK_REALTIME 0 CLOCK_MONOTONIC 1 CLOCK_PROCESS_CPUTIME_ID 2 diff --git a/xlat/cpuclocknames.in b/xlat/cpuclocknames.in index e61fa8f6..b7b9a828 100644 --- a/xlat/cpuclocknames.in +++ b/xlat/cpuclocknames.in @@ -1,3 +1,4 @@ -CPUCLOCK_PROF -CPUCLOCK_VIRT -CPUCLOCK_SCHED +#value_indexed +CPUCLOCK_PROF 0 +CPUCLOCK_VIRT 1 +CPUCLOCK_SCHED 2 diff --git a/xlat/itimer_which.in b/xlat/itimer_which.in index 768b20f4..23635a23 100644 --- a/xlat/itimer_which.in +++ b/xlat/itimer_which.in @@ -1,3 +1,4 @@ -ITIMER_REAL -ITIMER_VIRTUAL -ITIMER_PROF +#value_indexed +ITIMER_REAL 0 +ITIMER_VIRTUAL 1 +ITIMER_PROF 2