From 7c3dbcf249e0e217e5569993e39d18e79e29ee55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 30 Nov 2004 21:11:37 +0000 Subject: [PATCH] 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 --- src/kernel/core/main.c | 2 ++ src/kernel/core/system_info.c | 49 +++++++++++++++++++++-------------- src/kernel/core/team.c | 29 ++++++++++++++++++--- src/kernel/core/thread.c | 38 ++++++++++++++++++++++----- 4 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/kernel/core/main.c b/src/kernel/core/main.c index 1a1060ec3b..88942b6c47 100644 --- a/src/kernel/core/main.c +++ b/src/kernel/core/main.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,7 @@ _start(kernel_args *oldka, int cpu_num) debug_init_post_vm(&ka); int_init_post_vm(&ka); cpu_init_post_vm(&ka); + system_info_init(&ka); TRACE(("init faults\n")); faults_init(&ka); diff --git a/src/kernel/core/system_info.c b/src/kernel/core/system_info.c index efd15da5a5..5c15721cf3 100644 --- a/src/kernel/core/system_info.c +++ b/src/kernel/core/system_info.c @@ -1,19 +1,24 @@ /* -** Copyright 2004, Stefano Ceccherini. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004, Stefano Ceccherini. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include #include +#include + #include #include #include #include #include #include +#include +#include +#include #include @@ -29,17 +34,18 @@ _get_system_info(system_info *info, size_t size) return B_BAD_VALUE; 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->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->max_ports = port_max_ports(); 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_time, __TIME__, B_OS_NAME_LENGTH); - // TODO: Add arch specific stuff (arch_get_system_info() ?) - // - cpu_type - // - cpu_revision - // - various cpu_info - // - cpu_clock_speed - // - bus_clock_speed - // - platform_type - - return B_OK; + // all other stuff is architecture specific + return arch_get_system_info(info, size); } +status_t +system_info_init(struct kernel_args *args) +{ + return arch_system_info_init(args); +} + + +// #pragma mark - + + status_t _user_get_system_info(system_info *userInfo, size_t size) { diff --git a/src/kernel/core/team.c b/src/kernel/core/team.c index 55e748d1df..39fd0894da 100644 --- a/src/kernel/core/team.c +++ b/src/kernel/core/team.c @@ -61,6 +61,11 @@ static void *team_hash = NULL; static team_id next_team_id = 1; 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; 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 -team_init(kernel_args *ka) +status_t +team_init(kernel_args *args) { struct process_session *session; struct process_group *group; // 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); // 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. * * \param strings strings array @@ -703,6 +722,8 @@ void team_remove_team(struct team *team, struct process_group **_freeGroup) { hash_remove(team_hash, team); + sUsedTeams--; + team->state = TEAM_STATE_DEATH; // 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); insert_team_into_parent(parent, team); insert_team_into_group(parent->group, team); + sUsedTeams++; RELEASE_TEAM_LOCK(); restore_interrupts(state); @@ -1159,6 +1181,7 @@ fork_team(void) hash_insert(team_hash, team); insert_team_into_parent(parentTeam, team); insert_team_into_group(parentTeam->group, team); + sUsedTeams++; RELEASE_TEAM_LOCK(); restore_interrupts(state); diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index bbe64a40f0..e32b4f2d15 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -53,6 +53,11 @@ static struct thread *sIdleThreads[B_MAX_CPU_COUNT]; static void *sThreadHash = NULL; 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; // 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 hash_insert(sThreadHash, t); + sUsedThreads++; RELEASE_THREAD_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)); disable_interrupts(); + GRAB_TEAM_LOCK(); remove_thread_from_team(team_get_kernel_team(), args.thread); RELEASE_TEAM_LOCK(); + GRAB_THREAD_LOCK(); hash_remove(sThreadHash, args.thread); + sUsedThreads--; RELEASE_THREAD_LOCK(); // 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 thread_init(kernel_args *args) { @@ -1134,6 +1164,7 @@ thread_init(kernel_args *args) arch_thread_set_current_thread(t); t->cpu = &cpu[i]; } + sUsedThreads = args->num_cpus; // 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 - // public kernel exported functions