From 266d5b708ac9b61569c61d004441c78f8a929212 Mon Sep 17 00:00:00 2001 From: albert <> Date: Wed, 21 Jul 2004 21:17:35 +0000 Subject: [PATCH] wchan for multithreaded process is now ~0ull or "*" --- NEWS | 1 + proc/ksym.c | 12 +++++++----- proc/library.map | 5 ++++- proc/readproc.c | 9 +++++++-- proc/wchan.h | 2 +- ps/output.c | 4 ++-- top.c | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 6f67b455..98773984 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ avoid truncating long usernames avoid warning about -lncurses when not linking (more) new names for shared libraries (packagers: watch out!) "make install" no longer rebuilds everything +wchan now '*' for multi-threaded processes procps-3.2.1 --> procps-3.2.2 diff --git a/proc/ksym.c b/proc/ksym.c index 51c19542..83b27a40 100644 --- a/proc/ksym.c +++ b/proc/ksym.c @@ -109,9 +109,6 @@ typedef struct symb { unsigned KLONG addr; } symb; -static const symb fail = { "?", 0 }; -static const char dash[] = "-"; - /* These mostly rely on POSIX to make them zero. */ static symb hashtable[256]; @@ -602,10 +599,14 @@ static const char * read_wchan_file(unsigned pid){ /***************************************/ +static const symb fail = { .name = "?" }; +static const char dash[] = "-"; +static const char star[] = "*"; + #define MAX_OFFSET (0x1000*sizeof(long)) /* past this is generally junk */ /* return pointer to temporary static buffer with function name */ -const char * wchan(unsigned KLONG address, unsigned pid) { +const char * lookup_wchan(unsigned KLONG address, unsigned pid) { const symb *mod_symb; const symb *map_symb; const symb *good_symb; @@ -615,7 +616,8 @@ const char * wchan(unsigned KLONG address, unsigned pid) { // can't cache it due to a race condition :-( if(use_wchan_file) return read_wchan_file(pid); - if(!address) return dash; + if(!address) return dash; + if(!~address) return star; read_and_parse(); hash = (address >> 4) & 0xff; /* got 56/63 hits & 7/63 misses */ diff --git a/proc/library.map b/proc/library.map index c9d25100..810bb4b7 100644 --- a/proc/library.map +++ b/proc/library.map @@ -1,3 +1,6 @@ +# for --version-script +# WTF is the syntax for this file? +# Give me a BNF, man! _3_1_14 { global: __cyg_profile_func_enter; __cyg_profile_func_exit; main; @@ -5,7 +8,7 @@ global: readproc; readtask; readproctab; readproctab2; look_up_our_self; escape_command; escape_str; escape_strlist; openproc; closeproc; - tty_to_dev; dev_to_tty; open_psdb_message; open_psdb; wchan; + tty_to_dev; dev_to_tty; open_psdb_message; open_psdb; lookup_wchan; display_version; procps_version; linux_version_code; Hertz; smp_num_cpus; sprint_uptime; uptime; user_from_uid; print_uptime; loadavg; diff --git a/proc/readproc.c b/proc/readproc.c index 2a09bfda..d11fea17 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -521,7 +521,12 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons } } - /* some number->text resolving which is time consuming */ + // if multithreaded, some values are crap + if(p->nlwp > 1){ + p->wchan = (KLONG)~0ull; + } + + /* some number->text resolving which is time consuming and kind of insane */ if (flags & PROC_FILLUSR){ memcpy(p->euser, user_from_uid(p->euid), sizeof p->euser); if(flags & PROC_FILLSTATUS) { @@ -531,7 +536,7 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons } } - /* some number->text resolving which is time consuming */ + /* some number->text resolving which is time consuming and kind of insane */ if (flags & PROC_FILLGRP){ memcpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup); if(flags & PROC_FILLSTATUS) { diff --git a/proc/wchan.h b/proc/wchan.h index f721378c..dd83c2e0 100644 --- a/proc/wchan.h +++ b/proc/wchan.h @@ -5,7 +5,7 @@ EXTERN_C_BEGIN -extern const char * wchan(unsigned KLONG address, unsigned pid); +extern const char * lookup_wchan(unsigned KLONG address, unsigned pid); extern int open_psdb(const char *restrict override); extern int open_psdb_message(const char *restrict override, void (*message)(const char *, ...)); diff --git a/ps/output.c b/ps/output.c index cb674be6..bef6b130 100644 --- a/ps/output.c +++ b/ps/output.c @@ -502,7 +502,7 @@ static int pr_wchan(char *restrict const outbuf, const proc_t *restrict const pp */ if(!(pp->wchan & 0xffffff)) return snprintf(outbuf, COLWID, "%s", "-"); if(wchan_is_number) return snprintf(outbuf, COLWID, "%x", (unsigned)(pp->wchan) & 0xffffffu); - return snprintf(outbuf, COLWID, "%s", wchan(pp->wchan, pp->XXXID)); + return snprintf(outbuf, COLWID, "%s", lookup_wchan(pp->wchan, pp->XXXID)); } /* Terrible trunctuation, like BSD crap uses: I999 J999 K999 */ @@ -704,7 +704,7 @@ static int pr_wname(char *restrict const outbuf, const proc_t *restrict const pp * more than one thread waiting in the kernel. */ if(!(pp->wchan & 0xffffff)) return snprintf(outbuf, COLWID, "%s", "-"); - return snprintf(outbuf, COLWID, "%s", wchan(pp->wchan, pp->XXXID)); + return snprintf(outbuf, COLWID, "%s", lookup_wchan(pp->wchan, pp->XXXID)); } static int pr_nwchan(char *restrict const outbuf, const proc_t *restrict const pp){ diff --git a/top.c b/top.c index 57d2b52d..a50703e2 100644 --- a/top.c +++ b/top.c @@ -3024,7 +3024,7 @@ static void task_show (const WIN_t *q, const proc_t *p) f = " %08lx "; MKCOL((long)p->wchan); } else { - MKCOL(wchan(p->wchan, p->XXXID)); + MKCOL(lookup_wchan(p->wchan, p->XXXID)); } break;