Threads and teams now maintain a used counter - they also provide a maximum

limit, but this is not yet enforced. Added getter functions.
team_init() now returns a status_t.
System info stuff is now globally initialized in main().
get_system_info() now also reports the number of used pages, and calls the
architecture dependent function.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10315 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-11-30 21:11:37 +00:00
parent e774a942a9
commit 7c3dbcf249
4 changed files with 88 additions and 30 deletions
+2
View File
@@ -30,6 +30,7 @@
#include <kmodule.h> #include <kmodule.h>
#include <int.h> #include <int.h>
#include <team.h> #include <team.h>
#include <system_info.h>
#include <kdevice_manager.h> #include <kdevice_manager.h>
#include <real_time_clock.h> #include <real_time_clock.h>
#include <kernel_daemon.h> #include <kernel_daemon.h>
@@ -101,6 +102,7 @@ _start(kernel_args *oldka, int cpu_num)
debug_init_post_vm(&ka); debug_init_post_vm(&ka);
int_init_post_vm(&ka); int_init_post_vm(&ka);
cpu_init_post_vm(&ka); cpu_init_post_vm(&ka);
system_info_init(&ka);
TRACE(("init faults\n")); TRACE(("init faults\n"));
faults_init(&ka); faults_init(&ka);
+29 -20
View File
@@ -1,19 +1,24 @@
/* /*
** Copyright 2004, Stefano Ceccherini. All rights reserved. * Copyright 2004, Stefano Ceccherini. All rights reserved.
** Distributed under the terms of the OpenBeOS License. * Distributed under the terms of the MIT License.
*/ */
#include <OS.h> #include <OS.h>
#include <KernelExport.h> #include <KernelExport.h>
#include <system_info.h> #include <system_info.h>
#include <arch/system_info.h>
#include <vm.h> #include <vm.h>
#include <debug.h> #include <debug.h>
#include <port.h> #include <port.h>
#include <real_time_clock.h> #include <real_time_clock.h>
#include <sem.h> #include <sem.h>
#include <smp.h> #include <smp.h>
#include <team.h>
#include <thread.h>
#include <vm_page.h>
#include <string.h> #include <string.h>
@@ -29,17 +34,18 @@ _get_system_info(system_info *info, size_t size)
return B_BAD_VALUE; return B_BAD_VALUE;
memset(info, 0, sizeof(system_info)); memset(info, 0, sizeof(system_info));
// TODO: Add:
// - max_pages
// - used_pages
// - page_faults
// - max_threads
// - used_threads
// - max_teams
// - used_teams
info->boot_time = rtc_boot_time(); info->boot_time = rtc_boot_time();
info->cpu_count = smp_get_num_cpus(); info->cpu_count = smp_get_num_cpus();
// ToDo: Add page_faults
info->max_pages = vm_page_num_pages();
info->used_pages = vm_page_num_pages() - vm_page_num_free_pages();
info->used_threads = thread_used_threads();
info->max_threads = thread_max_threads();
info->used_teams = team_used_teams();
info->max_teams = team_max_teams();
info->used_ports = port_used_ports(); info->used_ports = port_used_ports();
info->max_ports = port_max_ports(); info->max_ports = port_max_ports();
info->used_sems = sem_used_sems(); info->used_sems = sem_used_sems();
@@ -50,18 +56,21 @@ _get_system_info(system_info *info, size_t size)
strlcpy(info->kernel_build_date, __DATE__, B_OS_NAME_LENGTH); strlcpy(info->kernel_build_date, __DATE__, B_OS_NAME_LENGTH);
strlcpy(info->kernel_build_time, __TIME__, B_OS_NAME_LENGTH); strlcpy(info->kernel_build_time, __TIME__, B_OS_NAME_LENGTH);
// TODO: Add arch specific stuff (arch_get_system_info() ?) // all other stuff is architecture specific
// - cpu_type return arch_get_system_info(info, size);
// - cpu_revision
// - various cpu_info
// - cpu_clock_speed
// - bus_clock_speed
// - platform_type
return B_OK;
} }
status_t
system_info_init(struct kernel_args *args)
{
return arch_system_info_init(args);
}
// #pragma mark -
status_t status_t
_user_get_system_info(system_info *userInfo, size_t size) _user_get_system_info(system_info *userInfo, size_t size)
{ {
+26 -3
View File
@@ -61,6 +61,11 @@ static void *team_hash = NULL;
static team_id next_team_id = 1; static team_id next_team_id = 1;
static struct team *kernel_team = NULL; static struct team *kernel_team = NULL;
// some arbitrary chosen limits - should probably depend on the available
// memory (the limit is not yet enforced)
static int32 sMaxTeams = 2048;
static int32 sUsedTeams = 1;
spinlock team_spinlock = 0; spinlock team_spinlock = 0;
static void insert_group_into_session(struct process_session *session, struct process_group *group); static void insert_group_into_session(struct process_session *session, struct process_group *group);
@@ -136,14 +141,14 @@ dump_team_info(int argc, char **argv)
} }
int status_t
team_init(kernel_args *ka) team_init(kernel_args *args)
{ {
struct process_session *session; struct process_session *session;
struct process_group *group; struct process_group *group;
// create the team hash table // create the team hash table
team_hash = hash_init(15, (addr_t)&kernel_team->next - (addr_t)kernel_team, team_hash = hash_init(15, offsetof(struct team, next),
&team_struct_compare, &team_struct_hash); &team_struct_compare, &team_struct_hash);
// create initial session and process groups // create initial session and process groups
@@ -181,6 +186,20 @@ team_init(kernel_args *ka)
} }
int32
team_max_teams(void)
{
return sMaxTeams;
}
int32
team_used_teams(void)
{
return sUsedTeams;
}
/** Frees an array of strings in kernel space. /** Frees an array of strings in kernel space.
* *
* \param strings strings array * \param strings strings array
@@ -703,6 +722,8 @@ void
team_remove_team(struct team *team, struct process_group **_freeGroup) team_remove_team(struct team *team, struct process_group **_freeGroup)
{ {
hash_remove(team_hash, team); hash_remove(team_hash, team);
sUsedTeams--;
team->state = TEAM_STATE_DEATH; team->state = TEAM_STATE_DEATH;
// reparent each of the team's children // reparent each of the team's children
@@ -965,6 +986,7 @@ load_image_etc(int32 argCount, char **args, int32 envCount, char **env, int32 pr
hash_insert(team_hash, team); hash_insert(team_hash, team);
insert_team_into_parent(parent, team); insert_team_into_parent(parent, team);
insert_team_into_group(parent->group, team); insert_team_into_group(parent->group, team);
sUsedTeams++;
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
restore_interrupts(state); restore_interrupts(state);
@@ -1159,6 +1181,7 @@ fork_team(void)
hash_insert(team_hash, team); hash_insert(team_hash, team);
insert_team_into_parent(parentTeam, team); insert_team_into_parent(parentTeam, team);
insert_team_into_group(parentTeam->group, team); insert_team_into_group(parentTeam->group, team);
sUsedTeams++;
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
restore_interrupts(state); restore_interrupts(state);
+31 -7
View File
@@ -53,6 +53,11 @@ static struct thread *sIdleThreads[B_MAX_CPU_COUNT];
static void *sThreadHash = NULL; static void *sThreadHash = NULL;
static thread_id sNextThreadID = 1; static thread_id sNextThreadID = 1;
// some arbitrary chosen limits - should probably depend on the available
// memory (the limit is not yet enforced)
static int32 sMaxThreads = 4096;
static int32 sUsedThreads = 0;
static sem_id sSnoozeSem = -1; static sem_id sSnoozeSem = -1;
// death stacks - used temporarily as a thread cleans itself up // death stacks - used temporarily as a thread cleans itself up
@@ -343,6 +348,7 @@ create_thread(const char *name, team_id teamID, thread_entry_func entry,
// insert into global list // insert into global list
hash_insert(sThreadHash, t); hash_insert(sThreadHash, t);
sUsedThreads++;
RELEASE_THREAD_LOCK(); RELEASE_THREAD_LOCK();
GRAB_TEAM_LOCK(); GRAB_TEAM_LOCK();
@@ -712,11 +718,14 @@ thread_exit2(void *_args)
TRACE(("thread_exit2: removing thread 0x%lx from global lists\n", args.thread->id)); TRACE(("thread_exit2: removing thread 0x%lx from global lists\n", args.thread->id));
disable_interrupts(); disable_interrupts();
GRAB_TEAM_LOCK(); GRAB_TEAM_LOCK();
remove_thread_from_team(team_get_kernel_team(), args.thread); remove_thread_from_team(team_get_kernel_team(), args.thread);
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
GRAB_THREAD_LOCK(); GRAB_THREAD_LOCK();
hash_remove(sThreadHash, args.thread); hash_remove(sThreadHash, args.thread);
sUsedThreads--;
RELEASE_THREAD_LOCK(); RELEASE_THREAD_LOCK();
// restore former thread interrupts (doesn't matter much at this point anyway) // restore former thread interrupts (doesn't matter much at this point anyway)
@@ -1078,6 +1087,27 @@ thread_dequeue_id(struct thread_queue *q, thread_id thr_id)
} }
thread_id
spawn_kernel_thread_etc(thread_func function, const char *name, int32 priority, void *arg, team_id team)
{
return create_thread(name, team, (thread_entry_func)function, arg, NULL, priority, true);
}
int32
thread_max_threads(void)
{
return sMaxThreads;
}
int32
thread_used_threads(void)
{
return sUsedThreads;
}
status_t status_t
thread_init(kernel_args *args) thread_init(kernel_args *args)
{ {
@@ -1134,6 +1164,7 @@ thread_init(kernel_args *args)
arch_thread_set_current_thread(t); arch_thread_set_current_thread(t);
t->cpu = &cpu[i]; t->cpu = &cpu[i];
} }
sUsedThreads = args->num_cpus;
// create a set of death stacks // create a set of death stacks
@@ -1184,13 +1215,6 @@ thread_per_cpu_init(int32 cpu_num)
} }
thread_id
spawn_kernel_thread_etc(thread_func function, const char *name, int32 priority, void *arg, team_id team)
{
return create_thread(name, team, (thread_entry_func)function, arg, NULL, priority, true);
}
// #pragma mark - // #pragma mark -
// public kernel exported functions // public kernel exported functions