commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 01/21: libps: fix task/thread times fetching


From: Samuel Thibault
Subject: [hurd] 01/21: libps: fix task/thread times fetching
Date: Tue, 04 Feb 2014 17:25:27 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 9bebcd38f42da289a3eaf9f473a9529f8d3c4664
Author: Richard Braun <address@hidden>
Date:   Thu Jan 16 23:59:00 2014 +0100

    libps: fix task/thread times fetching
    
    Introduce PSTAT_TIMES to force the retrieval of both PSTAT_TASK_BASIC
    and PSTAT_THREAD_BASIC. Task basic info contain the user and system
    times of terminated threads which the code wrongly assumes is always
    present along with process info.
    
    * libps/procstat.c (add_preconditions): Set both PSTAT_TASK_BASIC and
    PSTAT_THREAD_BASIC as preconditions for PSTAT_TIMES.
    (summarize_thread_basic_info): Add terminated threads times only if
    task basic info are available.
    (set_procinfo_flags): Provide summarize_thread_basic_info with flags of
    available info.
    (proc_stat_set_flags): Set PSTAT_TIMES as available if it was needed and
    any of PSTAT_TASK_BASIC or PSTAT_THREAD_BASIC could be fetched.
    * libps/ps.h (PSTAT_TIMES): New macro.
    * libps/spec.c (ps_get_usr_time): Indicate the getter needs PSTAT_TIMES
    instead of PSTAT_THREAD_BASIC.
    (ps_sys_time_getter): Likewise.
    (ps_tot_time_getter): Likewise.
---
 libps/procstat.c | 24 ++++++++++++++++--------
 libps/ps.h       |  1 +
 libps/spec.c     |  6 +++---
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/libps/procstat.c b/libps/procstat.c
index e732f75..0d4a565 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -294,6 +294,8 @@ add_preconditions (ps_flags_t flags, struct ps_context 
*context)
     /* We just request the resources require for both the thread and task
        versions, as the extraneous info won't be possible to acquire anyway. */
     flags |= PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC;
+  if (flags & PSTAT_TIMES)
+    flags |= PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC;
   if (flags & (PSTAT_CTTYID | PSTAT_CWDIR | PSTAT_AUTH | PSTAT_UMASK)
       && !(flags & PSTAT_NO_MSGPORT))
     {
@@ -348,11 +350,10 @@ should_suppress_msgport (struct proc_stat *ps)
    thread take precedence over waiting ones, and if there are any other
    incompatible states, simply using a bogus value of -1.  */
 static struct thread_basic_info *
-summarize_thread_basic_info (struct procinfo *pi)
+summarize_thread_basic_info (struct procinfo *pi, ps_flags_t have)
 {
   int i;
   unsigned num_threads = 0, num_run_threads = 0;
-  task_basic_info_t taskinfo = &pi->taskinfo;
   thread_basic_info_t tbi = malloc (sizeof (struct thread_basic_info));
   int run_base_priority = 0, run_cur_priority = 0;
   int total_base_priority = 0, total_cur_priority = 0;
@@ -427,11 +428,14 @@ summarize_thread_basic_info (struct procinfo *pi)
        }
     }
 
-  /* Include the run time of terminated threads.  */
-  tbi->user_time.seconds += taskinfo->user_time.seconds;
-  tbi->user_time.microseconds += taskinfo->user_time.microseconds;
-  tbi->system_time.seconds += taskinfo->system_time.seconds;
-  tbi->system_time.microseconds += taskinfo->system_time.microseconds;
+  /* For tasks, include the run time of terminated threads.  */
+  if (have & PSTAT_TASK_BASIC)
+    {
+      tbi->user_time.seconds += pi->taskinfo.user_time.seconds;
+      tbi->user_time.microseconds += pi->taskinfo.user_time.microseconds;
+      tbi->system_time.seconds += pi->taskinfo.system_time.seconds;
+      tbi->system_time.microseconds += pi->taskinfo.system_time.microseconds;
+    }
 
   tbi->user_time.seconds += tbi->user_time.microseconds / 1000000;
   tbi->user_time.microseconds %= 1000000;
@@ -655,7 +659,7 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, 
ps_flags_t have)
       if (had & PSTAT_THREAD_BASIC)
        free (ps->thread_basic_info);
       if (have & PSTAT_THREAD_BASIC)
-       ps->thread_basic_info = summarize_thread_basic_info (pi);
+       ps->thread_basic_info = summarize_thread_basic_info (pi, have);
       if (had & PSTAT_THREAD_SCHED)
        free (ps->thread_sched_info);
       if (have & PSTAT_THREAD_SCHED)
@@ -1007,6 +1011,10 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t 
flags)
   MGET (PSTAT_NUM_PORTS, PSTAT_PID,
         proc_getnports (server, ps->pid, &ps->num_ports));
 
+  /* User and system times.  */
+  if ((need & PSTAT_TIMES) && (have & (PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC)))
+    have |= PSTAT_TIMES;
+
   /* Update PS's flag state.  We haven't tried user flags yet, so don't mark
      them as having failed.  We do this before checking user bits so that the
      user fetch hook sees PS in a consistent state.  */
diff --git a/libps/ps.h b/libps/ps.h
index bcc43f8..06af96b 100644
--- a/libps/ps.h
+++ b/libps/ps.h
@@ -343,6 +343,7 @@ struct proc_stat
 #define PSTAT_UMASK          0x400000 /* The proc's current umask */
 #define PSTAT_HOOK           0x800000 /* Has a non-zero hook */
 #define PSTAT_NUM_PORTS      0x4000000 /* Number of Mach ports in the task */
+#define PSTAT_TIMES          0x8000000 /* Task/thread user and system times */
 
 /* Flag bits that don't correspond precisely to any field.  */
 #define PSTAT_NO_MSGPORT     0x1000000 /* Don't use the msgport at all */
diff --git a/libps/spec.c b/libps/spec.c
index 146aba5..d645b82 100644
--- a/libps/spec.c
+++ b/libps/spec.c
@@ -196,7 +196,7 @@ ps_get_usr_time (struct proc_stat *ps, struct timeval *tv)
   tv->tv_usec = tvt.microseconds;
 }
 const struct ps_getter ps_usr_time_getter =
-{"usr_time", PSTAT_THREAD_BASIC, ps_get_usr_time};
+{"usr_time", PSTAT_TIMES, ps_get_usr_time};
 
 static void
 ps_get_sys_time (struct proc_stat *ps, struct timeval *tv)
@@ -206,7 +206,7 @@ ps_get_sys_time (struct proc_stat *ps, struct timeval *tv)
   tv->tv_usec = tvt.microseconds;
 }
 const struct ps_getter ps_sys_time_getter =
-{"sys_time", PSTAT_THREAD_BASIC, ps_get_sys_time};
+{"sys_time", PSTAT_TIMES, ps_get_sys_time};
 
 static void
 ps_get_tot_time (struct proc_stat *ps, struct timeval *tv)
@@ -217,7 +217,7 @@ ps_get_tot_time (struct proc_stat *ps, struct timeval *tv)
   tv->tv_usec = tvt.microseconds;
 }
 const struct ps_getter ps_tot_time_getter =
-{"tot_time", PSTAT_THREAD_BASIC, ps_get_tot_time};
+{"tot_time", PSTAT_TIMES, ps_get_tot_time};
 
 static void
 ps_get_start_time (struct proc_stat *ps, struct timeval *tv)

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]