Changes in kernel/generic/src/proc/task.c [e535eeb:19f857a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
re535eeb r19f857a 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 *69 68 * @li the tasks_lock is held, 70 69 * @li the task's lock is held when task's lock is acquired before releasing … … 100 99 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 101 100 unsigned *cnt = (unsigned *) arg; 102 101 103 102 if (t != TASK) { 104 103 (*cnt)++; … … 108 107 task_kill_internal(t); 109 108 } 110 111 /* Continue the walk */ 112 return true; 109 110 return true; /* continue the walk */ 113 111 } 114 112 … … 117 115 { 118 116 unsigned tasks_left; 119 117 120 118 do { /* Repeat until there are any tasks except TASK */ 121 119 /* Messing with task structures, avoid deadlock */ … … 140 138 task_t *ta = obj; 141 139 int i; 142 140 143 141 atomic_set(&ta->refcount, 0); 144 142 atomic_set(&ta->lifecount, 0); 145 143 atomic_set(&ta->active_calls, 0); 146 144 147 145 spinlock_initialize(&ta->lock, "task_ta_lock"); 148 146 mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE); 149 147 150 148 list_initialize(&ta->th_head); 151 149 list_initialize(&ta->sync_box_head); 152 150 153 151 ipc_answerbox_init(&ta->answerbox, ta); 154 152 for (i = 0; i < IPC_MAX_PHONES; i++) 155 153 ipc_phone_init(&ta->phones[i]); 156 154 157 155 #ifdef CONFIG_UDEBUG 158 156 /* Init kbox stuff */ … … 161 159 mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE); 162 160 #endif 163 161 164 162 return 0; 165 163 } … … 167 165 /** Create new task with no threads. 168 166 * 169 * @param as 170 * @param name 171 * 172 * @return 167 * @param as Task's address space. 168 * @param name Symbolic name (a copy is made). 169 * 170 * @return New task's structure. 173 171 * 174 172 */ … … 183 181 memcpy(ta->name, name, TASK_NAME_BUFLEN); 184 182 ta->name[TASK_NAME_BUFLEN - 1] = 0; 185 183 186 184 ta->context = CONTEXT; 187 185 ta->capabilities = 0; 188 ta->ucycles = 0; 189 ta->kcycles = 0; 190 191 ta->ipc_info.call_sent = 0; 192 ta->ipc_info.call_recieved = 0; 193 ta->ipc_info.answer_sent = 0; 194 ta->ipc_info.answer_recieved = 0; 195 ta->ipc_info.irq_notif_recieved = 0; 196 ta->ipc_info.forwarded = 0; 186 ta->cycles = 0; 197 187 198 188 #ifdef CONFIG_UDEBUG 199 189 /* Init debugging stuff */ 200 190 udebug_task_init(&ta->udebug); 201 191 202 192 /* Init kbox stuff */ 203 193 ta->kb.finished = false; 204 194 #endif 205 195 206 196 if ((ipc_phone_0) && 207 197 (context_check(ipc_phone_0->task->context, ta->context))) 208 198 ipc_phone_connect(&ta->phones[0], ipc_phone_0); 209 199 210 200 btree_create(&ta->futexes); 211 201 … … 225 215 /** Destroy task. 226 216 * 227 * @param t Task to be destroyed. 228 * 217 * @param t Task to be destroyed. 229 218 */ 230 219 void task_destroy(task_t *t) … … 236 225 avltree_delete(&tasks_tree, &t->tasks_tree_node); 237 226 spinlock_unlock(&tasks_lock); 238 227 239 228 /* 240 229 * Perform architecture specific task destruction. 241 230 */ 242 231 task_destroy_arch(t); 243 232 244 233 /* 245 234 * Free up dynamically allocated state. 246 235 */ 247 236 btree_destroy(&t->futexes); 248 237 249 238 /* 250 239 * Drop our reference to the address space. … … 259 248 /** Syscall for reading task ID from userspace. 260 249 * 261 * @param uspace_task_id Userspace address of 8-byte buffer 262 * where to store current task ID. 263 * 264 * @return Zero on success or an error code from @ref errno.h. 265 * 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. 266 254 */ 267 255 unative_t sys_task_get_id(task_id_t *uspace_task_id) … … 279 267 * The name simplifies identifying the task in the task list. 280 268 * 281 * @param name 282 * 269 * @param name The new name for the task. (typically the same 270 * as the command used to execute it). 283 271 * 284 272 * @return 0 on success or an error code from @ref errno.h. 285 *286 273 */ 287 274 unative_t sys_task_set_name(const char *uspace_name, size_t name_len) … … 289 276 int rc; 290 277 char namebuf[TASK_NAME_BUFLEN]; 291 278 292 279 /* Cap length of name and copy it from userspace. */ 293 280 294 281 if (name_len > TASK_NAME_BUFLEN - 1) 295 282 name_len = TASK_NAME_BUFLEN - 1; 296 283 297 284 rc = copy_from_uspace(namebuf, uspace_name, name_len); 298 285 if (rc != 0) 299 286 return (unative_t) rc; 300 287 301 288 namebuf[name_len] = '\0'; 302 289 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 303 290 304 291 return EOK; 305 292 } … … 310 297 * interrupts must be disabled. 311 298 * 312 * @param id Task ID. 313 * 314 * @return Task structure address or NULL if there is no such task ID. 315 * 316 */ 317 task_t *task_find_by_id(task_id_t id) 318 { 319 avltree_node_t *node = 320 avltree_search(&tasks_tree, (avltree_key_t) id); 321 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 306 node = avltree_search(&tasks_tree, (avltree_key_t) id); 307 322 308 if (node) 323 309 return avltree_get_instance(node, task_t, tasks_tree_node); 324 325 310 return NULL; 326 311 } … … 331 316 * already disabled. 332 317 * 333 * @param t Pointer to thread. 334 * @param ucycles Out pointer to sum of all user cycles. 335 * @param kcycles Out pointer to sum of all kernel cycles. 336 * 337 */ 338 void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles) 339 { 340 /* Accumulated values of task */ 341 uint64_t uret = t->ucycles; 342 uint64_t kret = t->kcycles; 318 * @param t Pointer to thread. 319 * 320 * @return Number of cycles used by the task and all its threads 321 * so far. 322 */ 323 uint64_t task_get_accounting(task_t *t) 324 { 325 /* Accumulated value of task */ 326 uint64_t ret = t->cycles; 343 327 344 328 /* Current values of threads */ … … 352 336 if (thr == THREAD) { 353 337 /* Update accounting of current thread */ 354 thread_update_accounting( false);338 thread_update_accounting(); 355 339 } 356 uret += thr->ucycles; 357 kret += thr->kcycles; 340 ret += thr->cycles; 358 341 } 359 342 spinlock_unlock(&thr->lock); 360 343 } 361 344 362 *ucycles = uret; 363 *kcycles = kret; 345 return ret; 364 346 } 365 347 … … 367 349 { 368 350 link_t *cur; 369 351 370 352 /* 371 353 * Interrupt all threads. … … 395 377 * It signals all the task's threads to bail it out. 396 378 * 397 * @param id ID of the task to be killed. 398 * 399 * @return Zero on success or an error code from errno.h. 400 * 379 * @param id ID of the task to be killed. 380 * 381 * @return Zero on success or an error code from errno.h. 401 382 */ 402 383 int task_kill(task_id_t id) … … 425 406 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 426 407 int j; 427 408 428 409 spinlock_lock(&t->lock); 429 430 uint64_t ucycles; 431 uint64_t kcycles; 432 char usuffix, ksuffix; 433 task_get_accounting(t, &ucycles, &kcycles); 434 order_suffix(ucycles, &ucycles, &usuffix); 435 order_suffix(kcycles, &kcycles, &ksuffix); 436 410 411 uint64_t cycles; 412 char suffix; 413 order(task_get_accounting(t), &cycles, &suffix); 414 437 415 #ifdef __32_BITS__ 438 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9" 439 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, 440 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount), 441 atomic_get(&t->active_calls)); 442 #endif 443 416 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 417 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, 418 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 419 #endif 420 444 421 #ifdef __64_BITS__ 445 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9" 446 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, 447 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount), 448 atomic_get(&t->active_calls)); 449 #endif 450 422 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 423 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, 424 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 425 #endif 426 451 427 for (j = 0; j < IPC_MAX_PHONES; j++) { 452 428 if (t->phones[j].callee) … … 454 430 } 455 431 printf("\n"); 456 432 457 433 spinlock_unlock(&t->lock); 458 434 return true; … … 467 443 ipl = interrupts_disable(); 468 444 spinlock_lock(&tasks_lock); 469 470 #ifdef __32_BITS__ 471 printf("taskid name ctx address as "472 " ucycles kcyclesthreads calls callee\n");473 printf("------ ------------ --- ---------- ---------- "474 " -------------------- ------- ------ ------>\n");475 #endif 476 445 446 #ifdef __32_BITS__ 447 printf("taskid name ctx address as " 448 "cycles threads calls callee\n"); 449 printf("------ ------------ --- ---------- ---------- " 450 "---------- ------- ------ ------>\n"); 451 #endif 452 477 453 #ifdef __64_BITS__ 478 printf("taskid name ctx address as "479 " ucycles kcyclesthreads calls callee\n");480 printf("------ ------------ --- ------------------ ------------------ "481 " ---------- -------------------- ------- ------ ------>\n");482 #endif 483 454 printf("taskid name ctx address as " 455 "cycles threads calls callee\n"); 456 printf("------ ------------ --- ------------------ ------------------ " 457 "---------- ------- ------ ------>\n"); 458 #endif 459 484 460 avltree_walk(&tasks_tree, task_print_walker, NULL); 485 461 486 462 spinlock_unlock(&tasks_lock); 487 463 interrupts_restore(ipl);
Note:
See TracChangeset
for help on using the changeset viewer.