Changes in kernel/generic/src/proc/task.c [a307beb:5ba201d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
ra307beb 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 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 188 ta->cycles = 0; 189 196 190 #ifdef CONFIG_UDEBUG 197 191 /* Init debugging stuff */ 198 192 udebug_task_init(&ta->udebug); 199 193 200 194 /* Init kbox stuff */ 201 195 ta->kb.finished = false; 202 196 #endif 203 197 204 198 if ((ipc_phone_0) && 205 199 (context_check(ipc_phone_0->task->context, ta->context))) 206 200 ipc_phone_connect(&ta->phones[0], ipc_phone_0); 207 201 208 202 btree_create(&ta->futexes); 209 203 … … 223 217 /** Destroy task. 224 218 * 225 * @param t Task to be destroyed. 219 * @param t Task to be destroyed. 220 * 226 221 */ 227 222 void task_destroy(task_t *t) … … 233 228 avltree_delete(&tasks_tree, &t->tasks_tree_node); 234 229 spinlock_unlock(&tasks_lock); 235 230 236 231 /* 237 232 * Perform architecture specific task destruction. 238 233 */ 239 234 task_destroy_arch(t); 240 235 241 236 /* 242 237 * Free up dynamically allocated state. 243 238 */ 244 239 btree_destroy(&t->futexes); 245 240 246 241 /* 247 242 * Drop our reference to the address space. … … 256 251 /** Syscall for reading task ID from userspace. 257 252 * 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. 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 * 262 258 */ 263 259 unative_t sys_task_get_id(task_id_t *uspace_task_id) … … 275 271 * The name simplifies identifying the task in the task list. 276 272 * 277 * @param name 278 * 273 * @param name The new name for the task. (typically the same 274 * as the command used to execute it). 279 275 * 280 276 * @return 0 on success or an error code from @ref errno.h. 277 * 281 278 */ 282 279 unative_t sys_task_set_name(const char *uspace_name, size_t name_len) … … 284 281 int rc; 285 282 char namebuf[TASK_NAME_BUFLEN]; 286 283 287 284 /* Cap length of name and copy it from userspace. */ 288 285 289 286 if (name_len > TASK_NAME_BUFLEN - 1) 290 287 name_len = TASK_NAME_BUFLEN - 1; 291 288 292 289 rc = copy_from_uspace(namebuf, uspace_name, name_len); 293 290 if (rc != 0) 294 291 return (unative_t) rc; 295 292 296 293 namebuf[name_len] = '\0'; 297 294 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 298 295 299 296 return EOK; 300 297 } … … 305 302 * interrupts must be disabled. 306 303 * 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 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; 314 313 node = avltree_search(&tasks_tree, (avltree_key_t) id); 315 314 316 315 if (node) 317 316 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 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; 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; 335 336 336 337 /* Current values of threads */ … … 344 345 if (thr == THREAD) { 345 346 /* Update accounting of current thread */ 346 thread_update_accounting( false);347 thread_update_accounting(); 347 348 } 348 uret += thr->ucycles; 349 kret += thr->kcycles; 349 ret += thr->cycles; 350 350 } 351 351 spinlock_unlock(&thr->lock); 352 352 } 353 353 354 *ucycles = uret; 355 *kcycles = kret; 354 return ret; 356 355 } 357 356 … … 359 358 { 360 359 link_t *cur; 361 360 362 361 /* 363 362 * Interrupt all threads. … … 387 386 * It signals all the task's threads to bail it out. 388 387 * 389 * @param id ID of the task to be killed. 390 * 391 * @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 * 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 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 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 435 431 #ifdef __64_BITS__ 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 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 442 437 for (j = 0; j < IPC_MAX_PHONES; j++) { 443 438 if (t->phones[j].callee) … … 445 440 } 446 441 printf("\n"); 447 442 448 443 spinlock_unlock(&t->lock); 449 444 return true; … … 458 453 ipl = interrupts_disable(); 459 454 spinlock_lock(&tasks_lock); 460 461 #ifdef __32_BITS__ 462 printf("taskid name ctx address as "463 " ucycles kcyclesthreads calls callee\n");464 printf("------ ------------ --- ---------- ---------- "465 " -------------------- ------- ------ ------>\n");466 #endif 467 455 456 #ifdef __32_BITS__ 457 printf("taskid name ctx address as " 458 "cycles threads calls callee\n"); 459 printf("------ ------------ --- ---------- ---------- " 460 "---------- ------- ------ ------>\n"); 461 #endif 462 468 463 #ifdef __64_BITS__ 469 printf("taskid name ctx address as "470 " ucycles kcyclesthreads calls callee\n");471 printf("------ ------------ --- ------------------ ------------------ "472 " ---------- -------------------- ------- ------ ------>\n");473 #endif 474 464 printf("taskid name ctx address as " 465 "cycles threads calls callee\n"); 466 printf("------ ------------ --- ------------------ ------------------ " 467 "---------- ------- ------ ------>\n"); 468 #endif 469 475 470 avltree_walk(&tasks_tree, task_print_walker, NULL); 476 471 477 472 spinlock_unlock(&tasks_lock); 478 473 interrupts_restore(ipl);
Note:
See TracChangeset
for help on using the changeset viewer.