OSSP CVS Repository

ossp - Check-in [2721]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2721
Date: 2002-Nov-03 12:15:04 (local)
2002-Nov-03 11:15:04 (UTC)
User:rse
Branch:
Comment: Added thread attribute PTH_ATTR_DISPATCHES which (in bounded attribute objects) is incremented every time the context is switched to the associated thread. This can be used for statistical information.
Tickets:
Inspections:
Files:
ossp-pkg/pth/ChangeLog      1.583 -> 1.584     6 inserted, 0 deleted
ossp-pkg/pth/pth.h.in      1.135 -> 1.136     1 inserted, 0 deleted
ossp-pkg/pth/pth.pod      1.158 -> 1.159     18 inserted, 8 deleted
ossp-pkg/pth/pth_attr.c      1.17 -> 1.18     15 inserted, 0 deleted
ossp-pkg/pth/pth_lib.c      1.53 -> 1.54     3 inserted, 0 deleted
ossp-pkg/pth/pth_sched.c      1.81 -> 1.82     1 inserted, 0 deleted
ossp-pkg/pth/pth_tcb.c      1.39 -> 1.40     1 inserted, 0 deleted

ossp-pkg/pth/ChangeLog 1.583 -> 1.584

--- ChangeLog    2002/11/03 09:59:32     1.583
+++ ChangeLog    2002/11/03 11:15:04     1.584
@@ -21,6 +21,12 @@
 
   Changes between 1.4.1 and 1.5.0 (27-Jan-2002 to xx-Oct-2002)
 
+   *) Added thread attribute PTH_ATTR_DISPATCHES which (in bounded
+      attribute objects) is incremented every time the context
+      is switched to the associated thread. This can be used for
+      statistical information.
+      [Ralf S. Engelschall]
+
    *) Added a stand-alone sub-API for manual user-space context
       switching. It is somewhat modeled after the POSIX ucontext(3)
       facility and consists of an opaque data type pth_uctx_t and


ossp-pkg/pth/pth.h.in 1.135 -> 1.136

--- pth.h.in     2002/11/03 09:59:32     1.135
+++ pth.h.in     2002/11/03 11:15:04     1.136
@@ -151,6 +151,7 @@
     PTH_ATTR_CANCEL_STATE,   /* RW [unsigned int]      thread cancellation state         */
     PTH_ATTR_STACK_SIZE,     /* RW [unsigned int]      stack size                        */
     PTH_ATTR_STACK_ADDR,     /* RW [char *]            stack lower address               */
+    PTH_ATTR_DISPATCHES,     /* RO [int]               total number of thread dispatches */
     PTH_ATTR_TIME_SPAWN,     /* RO [pth_time_t]        time thread was spawned           */
     PTH_ATTR_TIME_LAST,      /* RO [pth_time_t]        time thread was last dispatched   */
     PTH_ATTR_TIME_RAN,       /* RO [pth_time_t]        time thread was running           */


ossp-pkg/pth/pth.pod 1.158 -> 1.159

--- pth.pod      2002/11/03 09:59:33     1.158
+++ pth.pod      2002/11/03 11:15:04     1.159
@@ -714,6 +714,11 @@
 Name of thread (up to 40 characters are stored only), mainly for debugging
 purposes.
 
+=item C<PTH_ATTR_DISPATCHES> (read-write) [C<int>]
+
+In bounded attribute objects, this field is incremented every time the
+context is switched to the associated thread.
+
 =item C<PTH_ATTR_JOINABLE> (read-write> [C<int>]
 
 The thread detachment type, C<TRUE> indicates a joinable thread,
@@ -799,8 +804,9 @@
 
 This initializes an attribute object I<attr> to the default values:
 C<PTH_ATTR_PRIO> := C<PTH_PRIO_STD>, C<PTH_ATTR_NAME> := `C<unknown>',
-C<PTH_ATTR_JOINABLE> := C<TRUE>, C<PTH_ATTR_CANCELSTATE> :=
-C<PTH_CANCEL_DEFAULT>, C<PTH_ATTR_STACK_SIZE> := 64*1024 and
+C<PTH_ATTR_DISPATCHES> := C<0>, C<PTH_ATTR_JOINABLE> := C<TRUE>,
+C<PTH_ATTR_CANCELSTATE> := C<PTH_CANCEL_DEFAULT>,
+C<PTH_ATTR_STACK_SIZE> := 64*1024 and
 C<PTH_ATTR_STACK_ADDR> := C<NULL>. All other C<PTH_ATTR_*> attributes are
 read-only attributes and don't receive default values in I<attr>, because they
 exists only for bounded attribute objects.
@@ -814,6 +820,7 @@
 
  PTH_ATTR_PRIO           int
  PTH_ATTR_NAME           char *
+ PTH_ATTR_DISPATCHES     int
  PTH_ATTR_JOINABLE       int
  PTH_ATTR_CANCEL_STATE   unsigned int
  PTH_ATTR_STACK_SIZE     unsigned int
@@ -828,6 +835,7 @@
 
  PTH_ATTR_PRIO           int *
  PTH_ATTR_NAME           char **
+ PTH_ATTR_DISPATCHES     int *
  PTH_ATTR_JOINABLE       int *
  PTH_ATTR_CANCEL_STATE   unsigned int *
  PTH_ATTR_STACK_SIZE     unsigned int *
@@ -860,12 +868,14 @@
 This spawns a new thread with the attributes given in I<attr> (or
 C<PTH_ATTR_DEFAULT> for default attributes - which means that thread priority,
 joinability and cancel state are inherited from the current thread) with the
-starting point at routine I<entry>. This entry routine is called as
-`pth_exit(I<entry>(I<arg>))' inside the new thread unit, i.e., I<entry>'s
-return value is fed to an implicit pth_exit(3). So the thread usually can exit
-by just returning. Nevertheless the thread can also exit explicitly at any
-time by calling pth_exit(3). But keep in mind that calling the POSIX function
-exit(3) still terminates the complete process and not just the current thread.
+starting point at routine I<entry>; the dispatch count is not inherited from
+the current thread if I<attr> is not specified - rather, it is initialized
+to zero.  This entry routine is called as `pth_exit(I<entry>(I<arg>))' inside
+the new thread unit, i.e., I<entry>'s return value is fed to an implicit
+pth_exit(3). So the thread can also exit by just returning. Nevertheless
+the thread can also exit explicitly at any time by calling pth_exit(3). But
+keep in mind that calling the POSIX function exit(3) still terminates the
+complete process and not just the current thread.
 
 There is no B<Pth>-internal limit on the number of threads one can spawn,
 except the limit implied by the available virtual memory. B<Pth> internally


ossp-pkg/pth/pth_attr.c 1.17 -> 1.18

--- pth_attr.c   2002/10/24 15:21:13     1.17
+++ pth_attr.c   2002/11/03 11:15:04     1.18
@@ -37,6 +37,7 @@
 struct pth_attr_st {
     pth_t        a_tid;
     int          a_prio;
+    int          a_dispatches;
     char         a_name[PTH_TCB_NAMELEN];
     int          a_joinable;
     unsigned int a_cancelstate;
@@ -85,6 +86,7 @@
         return pth_error(FALSE, EPERM);
     a->a_prio = PTH_PRIO_STD;
     pth_util_cpystrn(a->a_name, "unknown", PTH_TCB_NAMELEN);
+    a->a_dispatches = 0;
     a->a_joinable = TRUE;
     a->a_cancelstate = PTH_CANCEL_DEFAULT;
     a->a_stacksize = 64*1024;
@@ -149,6 +151,19 @@
             }
             break;
         }
+        case PTH_ATTR_DISPATCHES: {
+            /* incremented on every context switch */
+            int val, *src, *dst;
+            if (cmd == PTH_ATTR_SET) {
+                src = &val; val = va_arg(ap, int);
+                dst = (a->a_tid != NULL ? &a->a_tid->dispatches : &a->a_dispatches);
+            }
+            else {
+                src = (a->a_tid != NULL ? &a->a_tid->dispatches : &a->a_dispatches);
+                dst = va_arg(ap, int *);
+            }
+            *dst = *src;
+        }
         case PTH_ATTR_JOINABLE: {
             /* detachment type */
             int val, *src, *dst;


ossp-pkg/pth/pth_lib.c 1.53 -> 1.54

--- pth_lib.c    2002/10/24 15:21:13     1.53
+++ pth_lib.c    2002/11/03 11:15:04     1.54
@@ -239,6 +239,7 @@
         t->prio        = attr->a_prio;
         t->joinable    = attr->a_joinable;
         t->cancelstate = attr->a_cancelstate;
+        t->dispatches  = attr->a_dispatches;
         pth_util_cpystrn(t->name, attr->a_name, PTH_TCB_NAMELEN);
     }
     else if (pth_current != NULL) {
@@ -246,6 +247,7 @@
         t->prio        = pth_current->prio;
         t->joinable    = pth_current->joinable;
         t->cancelstate = pth_current->cancelstate;
+        t->dispatches  = 0;
         pth_snprintf(t->name, PTH_TCB_NAMELEN, "%s.child@%d=0x%lx",
                      pth_current->name, (unsigned int)time(NULL),
                      (unsigned long)pth_current);
@@ -255,6 +257,7 @@
         t->prio        = PTH_PRIO_STD;
         t->joinable    = TRUE;
         t->cancelstate = PTH_CANCEL_DEFAULT;
+        t->dispatches  = 0;
         pth_snprintf(t->name, PTH_TCB_NAMELEN,
                      "user/%x", (unsigned int)time(NULL));
     }


ossp-pkg/pth/pth_sched.c 1.81 -> 1.82

--- pth_sched.c  2002/01/27 11:03:41     1.81
+++ pth_sched.c  2002/11/03 11:15:05     1.82
@@ -240,6 +240,7 @@
         pth_time_add(&pth_sched->running, &running);
 
         /* ** ENTERING THREAD ** - by switching the machine context */
+        pth_current->dispatches++;
         pth_mctx_switch(&pth_sched->mctx, &pth_current->mctx);
 
         /* update scheduler times */


ossp-pkg/pth/pth_tcb.c 1.39 -> 1.40

--- pth_tcb.c    2002/10/24 15:21:14     1.39
+++ pth_tcb.c    2002/11/03 11:15:05     1.40
@@ -40,6 +40,7 @@
     /* standard thread control block ingredients */
     int            prio;                 /* base priority of thread                     */
     char           name[PTH_TCB_NAMELEN];/* name of thread (mainly for debugging)       */
+    int            dispatches;           /* total number of thread dispatches           */
     pth_state_t    state;                /* current state indicator for thread          */
 
     /* timing */

CVSTrac 2.0.1