Changeset 5ba201d in mainline
- Timestamp:
- 2010-04-17T09:25:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 88dea9d
- Parents:
- b658c5d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
rb658c5d r5ba201d 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Task management. 36 36 */ 37 37 … … 66 66 * The task is guaranteed to exist after it was found in the tasks_tree as 67 67 * long as: 68 * 68 69 * @li the tasks_lock is held, 69 70 * @li the task's lock is held when task's lock is acquired before releasing … … 99 100 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 100 101 unsigned *cnt = (unsigned *) arg; 101 102 102 103 if (t != TASK) { 103 104 (*cnt)++; … … 107 108 task_kill_internal(t); 108 109 } 109 110 return true; /* continue the walk */ 110 111 /* Continue the walk */ 112 return true; 111 113 } 112 114 … … 115 117 { 116 118 unsigned tasks_left; 117 119 118 120 do { /* Repeat until there are any tasks except TASK */ 119 121 /* Messing with task structures, avoid deadlock */ … … 138 140 task_t *ta = obj; 139 141 int i; 140 142 141 143 atomic_set(&ta->refcount, 0); 142 144 atomic_set(&ta->lifecount, 0); 143 145 atomic_set(&ta->active_calls, 0); 144 146 145 147 spinlock_initialize(&ta->lock, "task_ta_lock"); 146 148 mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE); 147 149 148 150 list_initialize(&ta->th_head); 149 151 list_initialize(&ta->sync_box_head); 150 152 151 153 ipc_answerbox_init(&ta->answerbox, ta); 152 154 for (i = 0; i < IPC_MAX_PHONES; i++) 153 155 ipc_phone_init(&ta->phones[i]); 154 156 155 157 #ifdef CONFIG_UDEBUG 156 158 /* Init kbox stuff */ … … 159 161 mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE); 160 162 #endif 161 163 162 164 return 0; 163 165 } … … 165 167 /** Create new task with no threads. 166 168 * 167 * @param as 168 * @param name 169 * 170 * @return 169 * @param as Task's address space. 170 * @param name Symbolic name (a copy is made). 171 * 172 * @return New task's structure. 171 173 * 172 174 */ … … 181 183 memcpy(ta->name, name, TASK_NAME_BUFLEN); 182 184 ta->name[TASK_NAME_BUFLEN - 1] = 0; 183 185 184 186 ta->context = CONTEXT; 185 187 ta->capabilities = 0; 186 188 ta->cycles = 0; 187 189 188 190 #ifdef CONFIG_UDEBUG 189 191 /* Init debugging stuff */ 190 192 udebug_task_init(&ta->udebug); 191 193 192 194 /* Init kbox stuff */ 193 195 ta->kb.finished = false; 194 196 #endif 195 197 196 198 if ((ipc_phone_0) && 197 199 (context_check(ipc_phone_0->task->context, ta->context))) 198 200 ipc_phone_connect(&ta->phones[0], ipc_phone_0); 199 201 200 202 btree_create(&ta->futexes); 201 203 … … 215 217 /** Destroy task. 216 218 * 217 * @param t Task to be destroyed. 219 * @param t Task to be destroyed. 220 * 218 221 */ 219 222 void task_destroy(task_t *t) … … 225 228 avltree_delete(&tasks_tree, &t->tasks_tree_node); 226 229 spinlock_unlock(&tasks_lock); 227 230 228 231 /* 229 232 * Perform architecture specific task destruction. 230 233 */ 231 234 task_destroy_arch(t); 232 235 233 236 /* 234 237 * Free up dynamically allocated state. 235 238 */ 236 239 btree_destroy(&t->futexes); 237 240 238 241 /* 239 242 * Drop our reference to the address space. … … 248 251 /** Syscall for reading task ID from userspace. 249 252 * 250 * @param uspace_task_id userspace address of 8-byte buffer 251 * where to store current task ID. 252 * 253 * @return Zero on success or an error code from @ref errno.h. 253 * @param uspace_task_id Userspace address of 8-byte buffer 254 * where to store current task ID. 255 * 256 * @return Zero on success or an error code from @ref errno.h. 257 * 254 258 */ 255 259 unative_t sys_task_get_id(task_id_t *uspace_task_id) … … 267 271 * The name simplifies identifying the task in the task list. 268 272 * 269 * @param name 270 * 273 * @param name The new name for the task. (typically the same 274 * as the command used to execute it). 271 275 * 272 276 * @return 0 on success or an error code from @ref errno.h. 277 * 273 278 */ 274 279 unative_t sys_task_set_name(const char *uspace_name, size_t name_len) … … 276 281 int rc; 277 282 char namebuf[TASK_NAME_BUFLEN]; 278 283 279 284 /* Cap length of name and copy it from userspace. */ 280 285 281 286 if (name_len > TASK_NAME_BUFLEN - 1) 282 287 name_len = TASK_NAME_BUFLEN - 1; 283 288 284 289 rc = copy_from_uspace(namebuf, uspace_name, name_len); 285 290 if (rc != 0) 286 291 return (unative_t) rc; 287 292 288 293 namebuf[name_len] = '\0'; 289 294 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 290 295 291 296 return EOK; 292 297 } … … 297 302 * interrupts must be disabled. 298 303 * 299 * @param id Task ID. 300 * 301 * @return Task structure address or NULL if there is no such task 302 * ID. 303 */ 304 task_t *task_find_by_id(task_id_t id) { avltree_node_t *node; 305 304 * @param id Task ID. 305 * 306 * @return Task structure address or NULL if there is no such task 307 * ID. 308 * 309 */ 310 task_t *task_find_by_id(task_id_t id) 311 { 312 avltree_node_t *node; 306 313 node = avltree_search(&tasks_tree, (avltree_key_t) id); 307 314 308 315 if (node) 309 316 return avltree_get_instance(node, task_t, tasks_tree_node); 317 310 318 return NULL; 311 319 } … … 316 324 * already disabled. 317 325 * 318 * @param t Pointer to thread. 319 * 320 * @return Number of cycles used by the task and all its threads 321 * so far. 326 * @param t Pointer to task. 327 * 328 * @return Number of cycles used by the task and all its threads 329 * so far. 330 * 322 331 */ 323 332 uint64_t task_get_accounting(task_t *t) … … 349 358 { 350 359 link_t *cur; 351 360 352 361 /* 353 362 * Interrupt all threads. … … 377 386 * It signals all the task's threads to bail it out. 378 387 * 379 * @param id ID of the task to be killed. 380 * 381 * @return Zero on success or an error code from errno.h. 388 * @param id ID of the task to be killed. 389 * 390 * @return Zero on success or an error code from errno.h. 391 * 382 392 */ 383 393 int task_kill(task_id_t id) … … 406 416 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 407 417 int j; 408 418 409 419 spinlock_lock(&t->lock); 410 420 411 421 uint64_t cycles; 412 422 char suffix; 413 423 order(task_get_accounting(t), &cycles, &suffix); 414 415 #ifdef __32_BITS__ 424 425 #ifdef __32_BITS__ 416 426 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 417 427 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, 418 428 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 419 429 #endif 420 430 421 431 #ifdef __64_BITS__ 422 432 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 … … 424 434 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 425 435 #endif 426 436 427 437 for (j = 0; j < IPC_MAX_PHONES; j++) { 428 438 if (t->phones[j].callee) … … 430 440 } 431 441 printf("\n"); 432 442 433 443 spinlock_unlock(&t->lock); 434 444 return true; … … 443 453 ipl = interrupts_disable(); 444 454 spinlock_lock(&tasks_lock); 445 446 #ifdef __32_BITS__ 455 456 #ifdef __32_BITS__ 447 457 printf("taskid name ctx address as " 448 458 "cycles threads calls callee\n"); … … 450 460 "---------- ------- ------ ------>\n"); 451 461 #endif 452 462 453 463 #ifdef __64_BITS__ 454 464 printf("taskid name ctx address as " … … 457 467 "---------- ------- ------ ------>\n"); 458 468 #endif 459 469 460 470 avltree_walk(&tasks_tree, task_print_walker, NULL); 461 471 462 472 spinlock_unlock(&tasks_lock); 463 473 interrupts_restore(ipl);
Note:
See TracChangeset
for help on using the changeset viewer.