[PATCH 2/3] remove unused fields
Denys Vlasenko
dvlasenk at redhat.com
Mon Feb 9 19:23:57 UTC 2009
On Mon, 2009-02-09 at 20:17 +0100, Denys Vlasenko wrote:
> These patches are not intended for inclusion, at least not
> right now. I seek your comments and patch review, and also
> am interested in hearing whether this is a viable idea at all.
>
> This is the first patch. It removes special handling of waitXXX
> syscalls.
Second patch: get rid of some tcp->xxx members which were
used for parent/child accounting, but which are useless
since internal_wait() function is removed. "Useless" in a sense
that they are either only assigned to now, or stay zero always,
and thus conditionals on them can be eliminated:
nchildren - only assigned to
nzombies - only assigned to
nclone_waiting - never > 0
--
vda
diff -d -urpN strace.6/defs.h strace.7/defs.h
--- strace.6/defs.h 2009-02-09 18:04:25.000000000 +0100
+++ strace.7/defs.h 2009-02-09 18:04:29.000000000 +0100
@@ -319,15 +319,12 @@ struct tcb {
/* Support for tracing forked processes */
//TODO: try to get rid of:
struct tcb *parent; /* Parent of this process */
- int nchildren; /* # of traced children */
- int waitpid; /* pid(s) this process is waiting for */
- int nzombies; /* # of formerly traced children now dead */
+ int waitpid; /* pid(s) this process is waiting for */ // used only by resume_from_tcp()
#ifdef LINUX
- int nclone_threads; /* # of nchildren with CLONE_THREAD */
- int nclone_detached; /* # of nchildren with CLONE_DETACHED */
- int nclone_waiting; /* clone threads in wait4 (TCB_SUSPENDED) */
- /* (1st arg of wait4()) */
+ int nclone_threads; /* # of children with CLONE_THREAD */
+ int nclone_detached; /* # of children with CLONE_DETACHED */ // used only in handle_group_exit()
#endif
+
long baddr; /* `Breakpoint' address */
long inst[2]; /* Instructions on above */
int pfd; /* proc file descriptor */
diff -d -urpN strace.6/process.c strace.7/process.c
--- strace.6/process.c 2009-02-09 16:27:14.000000000 +0100
+++ strace.7/process.c 2009-02-09 16:44:11.000000000 +0100
@@ -954,7 +954,6 @@ internal_clone(struct tcb *tcp)
sizeof tcpchild->inst);
}
tcpchild->parent = tcp;
- tcp->nchildren++;
if (tcpchild->flags & TCB_SUSPENDED) {
/* The child was born suspended, due to our having
forced CLONE_PTRACE. */
@@ -997,10 +996,8 @@ Process %u resumed (parent %d ready)\n",
new thread, there will never be a
TCB_CLONE_THREAD process that has
children. */
- --tcp->nchildren;
tcp = tcp->parent;
tcpchild->parent = tcp;
- ++tcp->nchildren;
}
if (call_flags & CLONE_THREAD) {
tcpchild->flags |= TCB_CLONE_THREAD;
@@ -1124,7 +1121,6 @@ struct tcb *tcp;
sizeof tcpchild->inst);
}
tcpchild->parent = tcp;
- tcp->nchildren++;
if (!qflag)
fprintf(stderr, "Process %d attached\n", pid);
}
diff -d -urpN strace.6/strace.c strace.7/strace.c
--- strace.6/strace.c 2009-02-09 16:47:51.000000000 +0100
+++ strace.7/strace.c 2009-02-09 17:09:46.000000000 +0100
@@ -441,7 +441,6 @@ startup_attach(void)
else if (tid != tcbtab[tcbi]->pid) {
tcp = alloctcb(tid);
tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_CLONE_DETACHED|TCB_FOLLOWFORK;
- tcbtab[tcbi]->nchildren++;
tcbtab[tcbi]->nclone_threads++;
tcbtab[tcbi]->nclone_detached++;
tcp->parent = tcbtab[tcbi];
@@ -1362,19 +1361,14 @@ struct tcb *tcp;
tcp->pid = 0;
if (tcp->parent != NULL) {
- tcp->parent->nchildren--;
#ifdef TCB_CLONE_THREAD
if (tcp->flags & TCB_CLONE_DETACHED)
tcp->parent->nclone_detached--;
if (tcp->flags & TCB_CLONE_THREAD)
tcp->parent->nclone_threads--;
#endif
-#ifdef TCB_CLONE_DETACHED
- if (!(tcp->flags & TCB_CLONE_DETACHED))
-#endif
- tcp->parent->nzombies++;
#ifdef LINUX
- /* Update `tcp->parent->parent->nchildren' and the other fields
+ /* Update `tcp->parent->parent->xxx' fields
like NCLONE_DETACHED, only for zombie group leader that has
already reported and been short-circuited at the top of this
function. The same condition as at the top of DETACH. */
@@ -1425,10 +1419,6 @@ struct tcb *tcp;
return -1;
}
tcp->flags &= ~TCB_SUSPENDED;
-#ifdef TCB_CLONE_THREAD
- if (tcp->flags & TCB_CLONE_THREAD)
- tcp->parent->nclone_waiting--;
-#endif
if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0)
return -1;
@@ -1442,7 +1432,6 @@ static int
resume_from_tcp (struct tcb *tcp)
{
int error = 0;
- int resumed = 0;
/* XXX This won't always be quite right (but it never was).
A waiter with argument 0 or < -1 is waiting for any pid in
@@ -1464,41 +1453,7 @@ resume_from_tcp (struct tcb *tcp)
(tcp->parent->flags & TCB_SUSPENDED) &&
(tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid)) {
error = resume(tcp->parent);
- ++resumed;
}
-#ifdef TCB_CLONE_THREAD
- if (tcp->parent && tcp->parent->nclone_waiting > 0) {
- /* Some other threads of our parent are waiting too. */
- unsigned int i;
-
- /* Resume all the threads that were waiting for this PID. */
- for (i = 0; i < tcbtabsize; i++) {
- struct tcb *t = tcbtab[i];
- if (t->parent == tcp->parent && t != tcp
- && ((t->flags & (TCB_CLONE_THREAD|TCB_SUSPENDED))
- == (TCB_CLONE_THREAD|TCB_SUSPENDED))
- && t->waitpid == tcp->pid) {
- error |= resume (t);
- ++resumed;
- }
- }
- if (resumed == 0)
- /* Noone was waiting for this PID in particular,
- so now we might need to resume some wildcarders. */
- for (i = 0; i < tcbtabsize; i++) {
- struct tcb *t = tcbtab[i];
- if (t->parent == tcp->parent && t != tcp
- && ((t->flags
- & (TCB_CLONE_THREAD|TCB_SUSPENDED))
- == (TCB_CLONE_THREAD|TCB_SUSPENDED))
- && t->waitpid <= 0
- ) {
- error |= resume (t);
- break;
- }
- }
- }
-#endif
return error;
}
More information about the Strace-devel
mailing list