--- Gnu-Mach/kern/task.c 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/kern/task.c 2020/09/02 04:45:19 1.1.1.3 @@ -1,25 +1,25 @@ -/* +/* * Mach Operating System * Copyright (c) 1993-1988 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -31,11 +31,7 @@ * Task management primitives implementation. */ -#include -#include -#include -#include -#include +#include #include #include @@ -43,10 +39,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include /* for thread_wakeup */ @@ -54,16 +50,8 @@ #include /* for kernel_map, ipc_kernel_map */ #include /* for splsched */ -#if NET_ATM -#include -#endif - -#if NORMA_TASK -#define task_create task_create_local -#endif /* NORMA_TASK */ - task_t kernel_task = TASK_NULL; -zone_t task_zone; +struct kmem_cache task_cache; extern void eml_init(void); extern void eml_task_reference(task_t, task_t); @@ -71,13 +59,11 @@ extern void eml_task_deallocate(task_t); void task_init(void) { - task_zone = zinit( - sizeof(struct task), - TASK_MAX * sizeof(struct task), - TASK_CHUNK * sizeof(struct task), - 0, "tasks"); + kmem_cache_init(&task_cache, "task", sizeof(struct task), 0, + NULL, NULL, NULL, 0); eml_init(); + machine_task_module_init (); /* * Create the kernel task as the first task. @@ -87,38 +73,6 @@ void task_init(void) (void) task_create(TASK_NULL, FALSE, &kernel_task); } -/* - * Create a task running in the kernel address space. It may - * have its own map of size mem_size (if 0, it uses the kernel map), - * and may have ipc privileges. - */ -task_t kernel_task_create( - task_t parent_task, - vm_size_t map_size) -{ - task_t new_task; - vm_offset_t min, max; - - /* - * Create the task. - */ - (void) task_create(parent_task, FALSE, &new_task); - - /* - * Task_create creates the task with a user-space map. - * Remove the map and replace it with the kernel map - * or a submap of the kernel map. - */ - vm_map_deallocate(new_task->map); - if (map_size == 0) - new_task->map = kernel_map; - else - new_task->map = kmem_suballoc(kernel_map, &min, &max, - map_size, FALSE); - - return new_task; -} - kern_return_t task_create( task_t parent_task, boolean_t inherit_memory, @@ -126,9 +80,11 @@ kern_return_t task_create( { register task_t new_task; register processor_set_t pset; +#if FAST_TAS int i; +#endif - new_task = (task_t) zalloc(task_zone); + new_task = (task_t) kmem_cache_alloc(&task_cache); if (new_task == TASK_NULL) { panic("task_create: no memory for task structure"); } @@ -137,7 +93,7 @@ kern_return_t task_create( new_task->ref_count = 2; if (child_task == &kernel_task) { - new_task->map = kernel_map; + new_task->map = kernel_map; } else if (inherit_memory) { new_task->map = vm_map_fork(parent_task->map); } else { @@ -152,20 +108,26 @@ kern_return_t task_create( new_task->active = TRUE; new_task->user_stop_count = 0; new_task->thread_count = 0; + new_task->faults = 0; + new_task->zero_fills = 0; + new_task->reactivations = 0; + new_task->pageins = 0; + new_task->cow_faults = 0; + new_task->messages_sent = 0; + new_task->messages_received = 0; eml_task_reference(new_task, parent_task); ipc_task_init(new_task, parent_task); - -#if NET_ATM - new_task->nw_ep_owned = 0; -#endif + machine_task_init (new_task); new_task->total_user_time.seconds = 0; new_task->total_user_time.microseconds = 0; 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; @@ -204,12 +166,8 @@ kern_return_t task_create( } } #endif /* FAST_TAS */ - - ipc_task_enable(new_task); -#if NORMA_TASK - new_task->child_node = -1; -#endif /* NORMA_TASK */ + ipc_task_enable(new_task); *child_task = new_task; return KERN_SUCCESS; @@ -237,13 +195,7 @@ void task_deallocate( if (c != 0) return; -#if NORMA_TASK - if (task->map == VM_MAP_NULL) { - /* norma placeholder task */ - zfree(task_zone, (vm_offset_t) task); - return; - } -#endif /* NORMA_TASK */ + machine_task_terminate (task); eml_task_deallocate(task); @@ -254,7 +206,7 @@ void task_deallocate( pset_deallocate(pset); vm_map_deallocate(task->map); is_release(task->itk_space); - zfree(task_zone, (vm_offset_t) task); + kmem_cache_free(&task_cache, (vm_offset_t) task); } void task_reference( @@ -289,13 +241,6 @@ kern_return_t task_terminate( cur_task = current_task(); cur_thread = current_thread(); -#if NET_ATM - /* - * Shut down networking. - */ - mk_endpoint_collect(task); -#endif - /* * Deactivate task so that it can't be terminated again, * and so lengthy operations in progress will abort. @@ -660,7 +605,7 @@ kern_return_t task_threads( return KERN_RESOURCE_SHORTAGE; } - bcopy((char *) addr, (char *) newaddr, size_needed); + memcpy((void *) newaddr, (void *) addr, size_needed); kfree(addr, size); threads = (thread_t *) newaddr; } @@ -774,7 +719,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 two words 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 - 2) { return KERN_INVALID_ARGUMENT; } @@ -795,11 +744,37 @@ kern_return_t task_info( = task->total_user_time.microseconds; basic_info->system_time.seconds = task->total_system_time.seconds; - basic_info->system_time.microseconds + 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; + } + + case TASK_EVENTS_INFO: + { + register task_events_info_t event_info; + + if (*task_info_count < TASK_EVENTS_INFO_COUNT) { + return KERN_INVALID_ARGUMENT; + } + + event_info = (task_events_info_t) task_info_out; + + task_lock(&task); + event_info->faults = task->faults; + event_info->zero_fills = task->zero_fills; + event_info->reactivations = task->reactivations; + event_info->pageins = task->pageins; + event_info->cow_faults = task->cow_faults; + event_info->messages_sent = task->messages_sent; + event_info->messages_received = task->messages_received; + task_unlock(&task); + + *task_info_count = TASK_EVENTS_INFO_COUNT; break; } @@ -1027,7 +1002,7 @@ task_assign( return KERN_FAILURE; } #endif /* MACH_HOST */ - + /* * task_assign_default: @@ -1118,6 +1093,7 @@ void task_collect_scan(void) pset_unlock(pset); simple_unlock(&all_psets_lock); + machine_task_collect (task); pmap_collect(task->map->pmap); if (prev_task != TASK_NULL) @@ -1176,7 +1152,7 @@ task_ras_control( int flavor) { kern_return_t ret = KERN_FAILURE; - + #if FAST_TAS int i; @@ -1206,7 +1182,7 @@ task_ras_control( ret = KERN_INVALID_ADDRESS; } break; - case TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE: + case TASK_RAS_CONTROL_PURGE_ALL_AND_INSTALL_ONE: /* remove all RAS an install this RAS */ for (i = 0; i < TASK_FAST_TAS_NRAS; i++) { task->fast_tas_base[i] = task->fast_tas_end[i] = 0; @@ -1227,7 +1203,7 @@ task_ras_control( } if (i == TASK_FAST_TAS_NRAS) { ret = KERN_RESOURCE_SHORTAGE; - } + } break; default: ret = KERN_INVALID_VALUE; break;