This is the mail archive of the mailing list for the elfutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Introduce tids cache for dwfl_getthreads

On Mon, 2013-12-16 at 15:07 +0900, Masatake YAMATO wrote:
> dwfl_getthreads can be called once for the same Dwfl object.  In
> dwfl_getthreads, directory entries under /proc/$pid/tasks are
> traversed and the directory descriptor points the end of
> /proc/$pid/tasks. Even if dwfl_getthreads called again, no
> more directory entry can be read from the descriptor.

Yes, that seems like a bug indeed.

> (1)rewinding the directory or (2) caching the threads at the initial
> traversing can permit calling dwfl_getthreads repeatedly.
> This patch implements (2). (2) is faster than (1) because
> (2) can avoid overheads of readdir.

I must say I would like (1) better. Because the process underlying the
Dwfl might have added/removed threads which would not been seen if we
cache the first readdir run.

It is also somewhat simpler to implement:

diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index 45a0732..3d0716a 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -164,6 +164,9 @@ pid_next_thread (Dwfl *dwfl __attribute__
((unused)), void *
   struct pid_arg *pid_arg = dwfl_arg;
   struct dirent *dirent;
+  /* Start fresh on first traversal. */
+  if (*thread_argp == NULL)
+    rewinddir (pid_arg->dir);
       errno = 0;

It is of course slower than your solution.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]