Changes in kernel/generic/src/proc/task.c [5ba201d:a307beb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
r5ba201d ra307beb 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->cycles = 0; 189 186 ta->ucycles = 0; 187 ta->kcycles = 0; 188 189 ta->ipc_info.call_sent = 0; 190 ta->ipc_info.call_recieved = 0; 191 ta->ipc_info.answer_sent = 0; 192 ta->ipc_info.answer_recieved = 0; 193 ta->ipc_info.irq_notif_recieved = 0; 194 ta->ipc_info.forwarded = 0; 195 190 196 #ifdef CONFIG_UDEBUG 191 197 /* Init debugging stuff */ 192 198 udebug_task_init(&ta->udebug); 193 199 194 200 /* Init kbox stuff */ 195 201 ta->kb.finished = false; 196 202 #endif 197 203 198 204 if ((ipc_phone_0) && 199 205 (context_check(ipc_phone_0->task->context, ta->context))) 200 206 ipc_phone_connect(&ta->phones[0], ipc_phone_0); 201 207 202 208 btree_create(&ta->futexes); 203 209 … … 217 223 /** Destroy task. 218 224 * 219 * @param t Task to be destroyed. 220 * 225 * @param t Task to be destroyed. 221 226 */ 222 227 void task_destroy(task_t *t) … … 228 233 avltree_delete(&tasks_tree, &t->tasks_tree_node); 229 234 spinlock_unlock(&tasks_lock); 230 235 231 236 /* 232 237 * Perform architecture specific task destruction. 233 238 */ 234 239 task_destroy_arch(t); 235 240 236 241 /* 237 242 * Free up dynamically allocated state. 238 243 */ 239 244 btree_destroy(&t->futexes); 240 245 241 246 /* 242 247 * Drop our reference to the address space. … … 251 256 /** Syscall for reading task ID from userspace. 252 257 * 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 * 258 * @param uspace_task_id userspace address of 8-byte buffer 259 * where to store current task ID. 260 * 261 * @return Zero on success or an error code from @ref errno.h. 258 262 */ 259 263 unative_t sys_task_get_id(task_id_t *uspace_task_id) … … 271 275 * The name simplifies identifying the task in the task list. 272 276 * 273 * @param name 274 * 277 * @param name The new name for the task. (typically the same 278 * as the command used to execute it). 275 279 * 276 280 * @return 0 on success or an error code from @ref errno.h. 277 *278 281 */ 279 282 unative_t sys_task_set_name(const char *uspace_name, size_t name_len) … … 281 284 int rc; 282 285 char namebuf[TASK_NAME_BUFLEN]; 283 286 284 287 /* Cap length of name and copy it from userspace. */ 285 288 286 289 if (name_len > TASK_NAME_BUFLEN - 1) 287 290 name_len = TASK_NAME_BUFLEN - 1; 288 291 289 292 rc = copy_from_uspace(namebuf, uspace_name, name_len); 290 293 if (rc != 0) 291 294 return (unative_t) rc; 292 295 293 296 namebuf[name_len] = '\0'; 294 297 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 295 298 296 299 return EOK; 297 300 } … … 302 305 * interrupts must be disabled. 303 306 * 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; 307 * @param id Task ID. 308 * 309 * @return Task structure address or NULL if there is no such task 310 * ID. 311 */ 312 task_t *task_find_by_id(task_id_t id) { avltree_node_t *node; 313 313 314 node = avltree_search(&tasks_tree, (avltree_key_t) id); 314 315 315 316 if (node) 316 317 return avltree_get_instance(node, task_t, tasks_tree_node); 317 318 318 return NULL; 319 319 } … … 324 324 * already disabled. 325 325 * 326 * @param t Pointer to task. 327 * 328 * @return Number of cycles used by the task and all its threads 329 * so far. 330 * 331 */ 332 uint64_t task_get_accounting(task_t *t) 333 { 334 /* Accumulated value of task */ 335 uint64_t ret = t->cycles; 326 * @param t Pointer to thread. 327 * @param ucycles Out pointer to sum of all user cycles. 328 * @param kcycles Out pointer to sum of all kernel cycles. 329 */ 330 void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles) 331 { 332 /* Accumulated values of task */ 333 uint64_t uret = t->ucycles; 334 uint64_t kret = t->kcycles; 336 335 337 336 /* Current values of threads */ … … 345 344 if (thr == THREAD) { 346 345 /* Update accounting of current thread */ 347 thread_update_accounting( );346 thread_update_accounting(false); 348 347 } 349 ret += thr->cycles; 348 uret += thr->ucycles; 349 kret += thr->kcycles; 350 350 } 351 351 spinlock_unlock(&thr->lock); 352 352 } 353 353 354 return ret; 354 *ucycles = uret; 355 *kcycles = kret; 355 356 } 356 357 … … 358 359 { 359 360 link_t *cur; 360 361 361 362 /* 362 363 * Interrupt all threads. … … 386 387 * It signals all the task's threads to bail it out. 387 388 * 388 * @param id ID of the task to be killed. 389 * 390 * @return Zero on success or an error code from errno.h. 391 * 389 * @param id ID of the task to be killed. 390 * 391 * @return Zero on success or an error code from errno.h. 392 392 */ 393 393 int task_kill(task_id_t id) … … 416 416 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 417 417 int j; 418 418 419 419 spinlock_lock(&t->lock); 420 421 uint64_t cycles; 422 char suffix; 423 order(task_get_accounting(t), &cycles, &suffix); 424 425 #ifdef __32_BITS__ 426 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 427 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, 428 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 429 #endif 430 420 421 uint64_t ucycles; 422 uint64_t kcycles; 423 char usuffix, ksuffix; 424 task_get_accounting(t, &ucycles, &kcycles); 425 order(ucycles, &ucycles, &usuffix); 426 order(kcycles, &kcycles, &ksuffix); 427 428 #ifdef __32_BITS__ 429 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9" 430 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, 431 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount), 432 atomic_get(&t->active_calls)); 433 #endif 434 431 435 #ifdef __64_BITS__ 432 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 433 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, cycles, 434 suffix, atomic_get(&t->refcount), atomic_get(&t->active_calls)); 435 #endif 436 436 printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9" 437 PRIu64 "%c %7ld %6ld", t->taskid, t->name, t->context, t, t->as, 438 ucycles, usuffix, kcycles, ksuffix, atomic_get(&t->refcount), 439 atomic_get(&t->active_calls)); 440 #endif 441 437 442 for (j = 0; j < IPC_MAX_PHONES; j++) { 438 443 if (t->phones[j].callee) … … 440 445 } 441 446 printf("\n"); 442 447 443 448 spinlock_unlock(&t->lock); 444 449 return true; … … 453 458 ipl = interrupts_disable(); 454 459 spinlock_lock(&tasks_lock); 455 456 #ifdef __32_BITS__ 457 printf("taskid name ctx address as 458 " cyclesthreads calls callee\n");459 printf("------ ------------ --- ---------- ---------- 460 " ---------- ------- ------ ------>\n");461 #endif 462 460 461 #ifdef __32_BITS__ 462 printf("taskid name ctx address as " 463 " ucycles kcycles threads calls callee\n"); 464 printf("------ ------------ --- ---------- ----------" 465 " ---------- ---------- ------- ------ ------>\n"); 466 #endif 467 463 468 #ifdef __64_BITS__ 464 printf("taskid name ctx address as 465 " cyclesthreads calls callee\n");466 printf("------ ------------ --- ------------------ ------------------ 467 " ---------- ------- ------ ------>\n");468 #endif 469 469 printf("taskid name ctx address as " 470 " ucycles kcycles threads calls callee\n"); 471 printf("------ ------------ --- ------------------ ------------------" 472 " ---------- ---------- ---------- ------- ------ ------>\n"); 473 #endif 474 470 475 avltree_walk(&tasks_tree, task_print_walker, NULL); 471 476 472 477 spinlock_unlock(&tasks_lock); 473 478 interrupts_restore(ipl);
Note:
See TracChangeset
for help on using the changeset viewer.