summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
Diffstat (limited to 'kern')
-rw-r--r--kern/mach_clock.c13
-rw-r--r--kern/task.c12
-rw-r--r--kern/task.h2
-rw-r--r--kern/thread.c12
-rw-r--r--kern/thread.h3
-rw-r--r--kern/time_out.h3
6 files changed, 41 insertions, 4 deletions
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index 9076ef4..ee9896a 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -369,6 +369,19 @@ void init_timeout()
}
/*
+ * Record a timestamp in STAMP.
+ */
+void
+record_time_stamp (time_value_t *stamp)
+{
+ do {
+ stamp->seconds = mtime->seconds;
+ stamp->microseconds = mtime->microseconds;
+ } while (stamp->seconds != mtime->check_seconds);
+}
+
+
+/*
* Read the time.
*/
kern_return_t
diff --git a/kern/task.c b/kern/task.c
index f72bb0f..9302e6a 100644
--- a/kern/task.c
+++ b/kern/task.c
@@ -166,6 +166,8 @@ kern_return_t task_create(
new_task->total_system_time.seconds = 0;
new_task->total_system_time.microseconds = 0;
+ record_time_stamp (&new_task->creation_time);
+
if (parent_task != TASK_NULL) {
task_lock(parent_task);
pset = parent_task->processor_set;
@@ -774,7 +776,11 @@ kern_return_t task_info(
{
register task_basic_info_t basic_info;
- if (*task_info_count < TASK_BASIC_INFO_COUNT) {
+ /* Allow *task_info_count to be one smaller than
+ the usual amount, because creation_time is a new member
+ that some callers might not know about. */
+
+ if (*task_info_count < TASK_BASIC_INFO_COUNT - 1) {
return KERN_INVALID_ARGUMENT;
}
@@ -797,9 +803,11 @@ kern_return_t task_info(
= task->total_system_time.seconds;
basic_info->system_time.microseconds
= task->total_system_time.microseconds;
+ basic_info->creation_time = task->creation_time;
task_unlock(task);
- *task_info_count = TASK_BASIC_INFO_COUNT;
+ if (*task_info_count > TASK_BASIC_INFO_COUNT)
+ *task_info_count = TASK_BASIC_INFO_COUNT;
break;
}
diff --git a/kern/task.h b/kern/task.h
index 52733b9..ec80058 100644
--- a/kern/task.h
+++ b/kern/task.h
@@ -86,6 +86,8 @@ struct task {
time_value_t total_system_time;
/* total system time for dead threads */
+ time_value_t creation_time; /* time stamp at creation */
+
/* IPC structures */
decl_simple_lock_data(, itk_lock_data)
struct ipc_port *itk_self; /* not a right, doesn't hold ref */
diff --git a/kern/thread.c b/kern/thread.c
index 1d7a378..d186298 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -429,6 +429,8 @@ kern_return_t thread_create(
*new_thread = thread_template;
+ record_time_stamp (&new_thread->creation_time);
+
/*
* Initialize runtime-dependent fields
*/
@@ -1473,7 +1475,11 @@ kern_return_t thread_info(
if (flavor == THREAD_BASIC_INFO) {
register thread_basic_info_t basic_info;
- if (*thread_info_count < THREAD_BASIC_INFO_COUNT) {
+ /* Allow *thread_info_count to be one smaller than the
+ usual amount, because creation_time is a new member
+ that some callers might not know about. */
+
+ if (*thread_info_count < THREAD_BASIC_INFO_COUNT - 1) {
return KERN_INVALID_ARGUMENT;
}
@@ -1496,6 +1502,7 @@ kern_return_t thread_info(
&basic_info->system_time);
basic_info->base_priority = thread->priority;
basic_info->cur_priority = thread->sched_pri;
+ basic_info->creation_time = thread->creation_time;
/*
* To calculate cpu_usage, first correct for timer rate,
@@ -1547,7 +1554,8 @@ kern_return_t thread_info(
thread_unlock(thread);
splx(s);
- *thread_info_count = THREAD_BASIC_INFO_COUNT;
+ if (*thread_info_count > THREAD_BASIC_INFO_COUNT)
+ *thread_info_count = THREAD_BASIC_INFO_COUNT;
return KERN_SUCCESS;
}
else if (flavor == THREAD_SCHED_INFO) {
diff --git a/kern/thread.h b/kern/thread.h
index 07b7463..9958e2b 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -195,6 +195,9 @@ struct thread {
unsigned int cpu_delta; /* cpu usage since last update */
unsigned int sched_delta; /* weighted cpu usage since update */
+ /* Creation time stamp */
+ time_value_t creation_time;
+
/* Time-outs */
timer_elt_data_t timer; /* timer for thread */
timer_elt_data_t depress_timer; /* timer for priority depression */
diff --git a/kern/time_out.h b/kern/time_out.h
index 4dff7df..5fbf4e3 100644
--- a/kern/time_out.h
+++ b/kern/time_out.h
@@ -43,6 +43,9 @@ extern unsigned long elapsed_ticks; /* number of ticks elapsed since bootup */
extern int hz; /* number of ticks per second */
extern int tick; /* number of usec per tick */
+/* Read the current time into STAMP */
+void record_time_stamp (time_value_t *stamp);
+
/*
* Time-out element.
*/