Changeset a35b458 in mainline for kernel/generic/src/proc/task.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
r3061bc1 ra35b458 107 107 task_t *task = avltree_get_instance(node, task_t, tasks_tree_node); 108 108 size_t *cnt = (size_t *) arg; 109 109 110 110 if (task != TASK) { 111 111 (*cnt)++; 112 112 113 113 #ifdef CONFIG_DEBUG 114 114 printf("[%"PRIu64"] ", task->taskid); 115 115 #endif 116 116 117 117 task_kill_internal(task); 118 118 } 119 119 120 120 /* Continue the walk */ 121 121 return true; … … 138 138 task_release(task_0); 139 139 } 140 140 141 141 /* Repeat until there are any tasks except TASK */ 142 142 do { … … 144 144 printf("Killing tasks... "); 145 145 #endif 146 146 147 147 irq_spinlock_lock(&tasks_lock, true); 148 148 tasks_left = 0; 149 149 avltree_walk(&tasks_tree, task_done_walker, &tasks_left); 150 150 irq_spinlock_unlock(&tasks_lock, true); 151 151 152 152 thread_sleep(1); 153 153 154 154 #ifdef CONFIG_DEBUG 155 155 printf("\n"); … … 165 165 if (rc != EOK) 166 166 return rc; 167 167 168 168 atomic_set(&task->refcount, 0); 169 169 atomic_set(&task->lifecount, 0); 170 170 171 171 irq_spinlock_initialize(&task->lock, "task_t_lock"); 172 172 173 173 list_initialize(&task->threads); 174 174 175 175 ipc_answerbox_init(&task->answerbox, task); 176 176 177 177 spinlock_initialize(&task->active_calls_lock, "active_calls_lock"); 178 178 list_initialize(&task->active_calls); 179 179 180 180 #ifdef CONFIG_UDEBUG 181 181 /* Init kbox stuff */ … … 184 184 mutex_initialize(&task->kb.cleanup_lock, MUTEX_PASSIVE); 185 185 #endif 186 186 187 187 return EOK; 188 188 } … … 191 191 { 192 192 task_t *task = (task_t *) obj; 193 193 194 194 caps_task_free(task); 195 195 return 0; … … 210 210 return NULL; 211 211 } 212 212 213 213 task_create_arch(task); 214 214 215 215 task->as = as; 216 216 str_cpy(task->name, TASK_NAME_BUFLEN, name); 217 217 218 218 task->container = CONTAINER; 219 219 task->perms = 0; … … 231 231 232 232 event_task_init(task); 233 233 234 234 task->answerbox.active = true; 235 235 … … 237 237 /* Init debugging stuff */ 238 238 udebug_task_init(&task->udebug); 239 239 240 240 /* Init kbox stuff */ 241 241 task->kb.box.active = true; 242 242 task->kb.finished = false; 243 243 #endif 244 244 245 245 if ((ipc_phone_0) && 246 246 (container_check(ipc_phone_0->task->container, task->container))) { … … 253 253 return NULL; 254 254 } 255 255 256 256 kobject_t *phone_obj = kobject_get(task, phone_handle, 257 257 KOBJECT_TYPE_PHONE); 258 258 (void) ipc_phone_connect(phone_obj->phone, ipc_phone_0); 259 259 } 260 260 261 261 futex_task_init(task); 262 262 263 263 /* 264 264 * Get a reference to the address space. 265 265 */ 266 266 as_hold(task->as); 267 267 268 268 irq_spinlock_lock(&tasks_lock, true); 269 269 270 270 task->taskid = ++task_counter; 271 271 avltree_node_initialize(&task->tasks_tree_node); 272 272 task->tasks_tree_node.key = task->taskid; 273 273 avltree_insert(&tasks_tree, &task->tasks_tree_node); 274 274 275 275 irq_spinlock_unlock(&tasks_lock, true); 276 276 277 277 return task; 278 278 } … … 291 291 avltree_delete(&tasks_tree, &task->tasks_tree_node); 292 292 irq_spinlock_unlock(&tasks_lock, true); 293 293 294 294 /* 295 295 * Perform architecture specific task destruction. 296 296 */ 297 297 task_destroy_arch(task); 298 298 299 299 /* 300 300 * Free up dynamically allocated state. 301 301 */ 302 302 futex_task_deinit(task); 303 303 304 304 /* 305 305 * Drop our reference to the address space. 306 306 */ 307 307 as_release(task->as); 308 308 309 309 slab_free(task_cache, task); 310 310 } … … 388 388 { 389 389 char namebuf[TASK_NAME_BUFLEN]; 390 390 391 391 /* Cap length of name and copy it from userspace. */ 392 392 if (name_len > TASK_NAME_BUFLEN - 1) 393 393 name_len = TASK_NAME_BUFLEN - 1; 394 394 395 395 errno_t rc = copy_from_uspace(namebuf, uspace_name, name_len); 396 396 if (rc != EOK) 397 397 return (sys_errno_t) rc; 398 398 399 399 namebuf[name_len] = '\0'; 400 400 401 401 /* 402 402 * As the task name is referenced also from the … … 404 404 * of the update. 405 405 */ 406 406 407 407 irq_spinlock_lock(&tasks_lock, true); 408 408 irq_spinlock_lock(&TASK->lock, false); 409 409 irq_spinlock_lock(&threads_lock, false); 410 410 411 411 /* Set task name */ 412 412 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 413 413 414 414 irq_spinlock_unlock(&threads_lock, false); 415 415 irq_spinlock_unlock(&TASK->lock, false); 416 416 irq_spinlock_unlock(&tasks_lock, true); 417 417 418 418 return EOK; 419 419 } … … 432 432 if (rc != EOK) 433 433 return (sys_errno_t) rc; 434 434 435 435 return (sys_errno_t) task_kill(taskid); 436 436 } … … 453 453 avltree_node_t *node = 454 454 avltree_search(&tasks_tree, (avltree_key_t) id); 455 455 456 456 if (node) 457 457 return avltree_get_instance(node, task_t, tasks_tree_node); 458 458 459 459 return NULL; 460 460 } … … 478 478 uint64_t uret = task->ucycles; 479 479 uint64_t kret = task->kcycles; 480 480 481 481 /* Current values of threads */ 482 482 list_foreach(task->threads, th_link, thread_t, thread) { 483 483 irq_spinlock_lock(&thread->lock, false); 484 484 485 485 /* Process only counted threads */ 486 486 if (!thread->uncounted) { … … 489 489 thread_update_accounting(false); 490 490 } 491 491 492 492 uret += thread->ucycles; 493 493 kret += thread->kcycles; 494 494 } 495 495 496 496 irq_spinlock_unlock(&thread->lock, false); 497 497 } 498 498 499 499 *ucycles = uret; 500 500 *kcycles = kret; … … 505 505 irq_spinlock_lock(&task->lock, false); 506 506 irq_spinlock_lock(&threads_lock, false); 507 507 508 508 /* 509 509 * Interrupt all threads. 510 510 */ 511 511 512 512 list_foreach(task->threads, th_link, thread_t, thread) { 513 513 bool sleeping = false; 514 514 515 515 irq_spinlock_lock(&thread->lock, false); 516 516 517 517 thread->interrupted = true; 518 518 if (thread->state == Sleeping) 519 519 sleeping = true; 520 520 521 521 irq_spinlock_unlock(&thread->lock, false); 522 522 523 523 if (sleeping) 524 524 waitq_interrupt_sleep(thread); 525 525 } 526 526 527 527 irq_spinlock_unlock(&threads_lock, false); 528 528 irq_spinlock_unlock(&task->lock, false); … … 543 543 if (id == 1) 544 544 return EPERM; 545 545 546 546 irq_spinlock_lock(&tasks_lock, true); 547 547 548 548 task_t *task = task_find_by_id(id); 549 549 if (!task) { … … 551 551 return ENOENT; 552 552 } 553 553 554 554 task_kill_internal(task); 555 555 irq_spinlock_unlock(&tasks_lock, true); 556 556 557 557 return EOK; 558 558 } … … 583 583 } 584 584 } 585 585 586 586 irq_spinlock_lock(&tasks_lock, true); 587 587 task_kill_internal(TASK); 588 588 irq_spinlock_unlock(&tasks_lock, true); 589 589 590 590 thread_exit(); 591 591 } … … 599 599 { 600 600 task_kill_self(notify); 601 601 602 602 /* Unreachable */ 603 603 return EOK; … … 609 609 task_t *task = avltree_get_instance(node, task_t, tasks_tree_node); 610 610 irq_spinlock_lock(&task->lock, false); 611 611 612 612 uint64_t ucycles; 613 613 uint64_t kcycles; … … 616 616 order_suffix(ucycles, &ucycles, &usuffix); 617 617 order_suffix(kcycles, &kcycles, &ksuffix); 618 618 619 619 #ifdef __32_BITS__ 620 620 if (*additional) … … 627 627 ucycles, usuffix, kcycles, ksuffix); 628 628 #endif 629 629 630 630 #ifdef __64_BITS__ 631 631 if (*additional) … … 637 637 task->taskid, task->name, task->container, task, task->as); 638 638 #endif 639 639 640 640 irq_spinlock_unlock(&task->lock, false); 641 641 return true; … … 651 651 /* Messing with task structures, avoid deadlock */ 652 652 irq_spinlock_lock(&tasks_lock, true); 653 653 654 654 #ifdef __32_BITS__ 655 655 if (additional) … … 659 659 " [ucycles ] [kcycles ]\n"); 660 660 #endif 661 661 662 662 #ifdef __64_BITS__ 663 663 if (additional) … … 668 668 " [as ]\n"); 669 669 #endif 670 670 671 671 avltree_walk(&tasks_tree, task_print_walker, &additional); 672 672 673 673 irq_spinlock_unlock(&tasks_lock, true); 674 674 }
Note:
See TracChangeset
for help on using the changeset viewer.