Backport time tracking fix from NewOS:

thread code now properly traces time spent in user vs kernel mode. The code was
just plain broken before
http://www.newos.org/cgi-bin/perfbrowse.perl?@describe+1704


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2599 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2003-01-29 21:59:37 +00:00
parent 1241a21542
commit f3eabb6abd
3 changed files with 18 additions and 3 deletions

View File

@ -44,6 +44,10 @@ enum team_state {
TEAM_STATE_DEATH // being killed
};
enum {
KERNEL_TIME,
USER_TIME
};
#define THREAD_RETURN_EXIT 0x1
#define THREAD_RETURN_INTERRUPTED 0x2
@ -129,7 +133,8 @@ struct thread {
bigtime_t user_time;
bigtime_t kernel_time;
bigtime_t last_time;
int last_time_type; // KERNEL_TIME or USER_TIME
// architecture dependant section
struct arch_thread arch_info;
};

View File

@ -129,9 +129,12 @@ context_switch(struct thread *fromThread, struct thread *toThread)
{
bigtime_t now;
// track kernel time
// track kernel & user time
now = system_time();
fromThread->kernel_time += now - fromThread->last_time;
if(fromThread->last_time_type == KERNEL_TIME)
fromThread->kernel_time += now - fromThread->last_time;
else
fromThread->user_time += now - fromThread->last_time;
toThread->last_time = now;
toThread->cpu = fromThread->cpu;

View File

@ -187,6 +187,7 @@ create_thread_struct(const char *name)
t->user_time = 0;
t->kernel_time = 0;
t->last_time = 0;
t->last_time_type = KERNEL_TIME;
t->return_code = 0;
t->return_flags = 0;
@ -248,7 +249,9 @@ _create_user_thread_kentry(void)
// a signal may have been delivered here
// thread_atkernel_exit();
// start tracking kernel & user time
thread->last_time = system_time();
thread->last_time_type = KERNEL_TIME;
thread->in_kernel = false;
// jump to the entry point in user space
@ -268,7 +271,9 @@ _create_kernel_thread_kentry(void)
struct thread *thread = thread_get_current_thread();
int (*func)(void *args);
// start tracking kernel & user time
thread->last_time = system_time();
thread->last_time_type = KERNEL_TIME;
// call the entry function with the appropriate args
func = (void *)thread->entry;
@ -905,6 +910,7 @@ thread_atkernel_entry(void)
now = system_time();
t->user_time += now - t->last_time;
t->last_time = now;
t->last_time_type = KERNEL_TIME;
t->in_kernel = true;
@ -937,6 +943,7 @@ thread_atkernel_exit(void)
now = system_time();
t->kernel_time += now - t->last_time;
t->last_time = now;
t->last_time_type = USER_TIME;
RELEASE_THREAD_LOCK();
restore_interrupts(state);