Rev 1854 | Rev 2032 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1854 | Rev 2030 | ||
|---|---|---|---|
| Line 40... | Line 40... | ||
| 40 | #include <proc/task.h> |
40 | #include <proc/task.h> |
| 41 | #include <proc/uarg.h> |
41 | #include <proc/uarg.h> |
| 42 | #include <mm/frame.h> |
42 | #include <mm/frame.h> |
| 43 | #include <mm/page.h> |
43 | #include <mm/page.h> |
| 44 | #include <arch/asm.h> |
44 | #include <arch/asm.h> |
| - | 45 | #include <arch/cycle.h> |
|
| 45 | #include <arch.h> |
46 | #include <arch.h> |
| 46 | #include <synch/synch.h> |
47 | #include <synch/synch.h> |
| 47 | #include <synch/spinlock.h> |
48 | #include <synch/spinlock.h> |
| 48 | #include <synch/waitq.h> |
49 | #include <synch/waitq.h> |
| 49 | #include <synch/rwlock.h> |
50 | #include <synch/rwlock.h> |
| Line 323... | Line 324... | ||
| 323 | memcpy(t->name, name, THREAD_NAME_BUFLEN); |
324 | memcpy(t->name, name, THREAD_NAME_BUFLEN); |
| 324 | 325 | ||
| 325 | t->thread_code = func; |
326 | t->thread_code = func; |
| 326 | t->thread_arg = arg; |
327 | t->thread_arg = arg; |
| 327 | t->ticks = -1; |
328 | t->ticks = -1; |
| - | 329 | t->cycles = 0; |
|
| 328 | t->priority = -1; /* start in rq[0] */ |
330 | t->priority = -1; /* start in rq[0] */ |
| 329 | t->cpu = NULL; |
331 | t->cpu = NULL; |
| 330 | t->flags = flags; |
332 | t->flags = flags; |
| 331 | t->state = Entering; |
333 | t->state = Entering; |
| 332 | t->call_me = NULL; |
334 | t->call_me = NULL; |
| Line 527... | Line 529... | ||
| 527 | ipl_t ipl; |
529 | ipl_t ipl; |
| 528 | 530 | ||
| 529 | /* Messing with thread structures, avoid deadlock */ |
531 | /* Messing with thread structures, avoid deadlock */ |
| 530 | ipl = interrupts_disable(); |
532 | ipl = interrupts_disable(); |
| 531 | spinlock_lock(&threads_lock); |
533 | spinlock_lock(&threads_lock); |
| - | 534 | ||
| - | 535 | printf("tid name address state task ctx code stack cycles cpu kst wq\n"); |
|
| - | 536 | printf("------ ---------- ---------- -------- ---------- --- ---------- ---------- ---------- ---- ---------- ----------\n"); |
|
| 532 | 537 | ||
| 533 | for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) { |
538 | for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) { |
| 534 | btree_node_t *node; |
539 | btree_node_t *node; |
| 535 | int i; |
540 | int i; |
| 536 | 541 | ||
| 537 | node = list_get_instance(cur, btree_node_t, leaf_link); |
542 | node = list_get_instance(cur, btree_node_t, leaf_link); |
| 538 | for (i = 0; i < node->keys; i++) { |
543 | for (i = 0; i < node->keys; i++) { |
| 539 | thread_t *t; |
544 | thread_t *t; |
| 540 | 545 | ||
| 541 | t = (thread_t *) node->value[i]; |
546 | t = (thread_t *) node->value[i]; |
| - | 547 | ||
| - | 548 | uint64_t cycles; |
|
| - | 549 | char suffix; |
|
| - | 550 | ||
| - | 551 | if (t->cycles > 1000000000000000000LL) { |
|
| - | 552 | cycles = t->cycles / 1000000000000000000LL; |
|
| - | 553 | suffix = 'E'; |
|
| 542 | printf("%s: address=%#zx, tid=%zd, state=%s, task=%#zx, context=%ld, code=%#zx, stack=%#zx, cpu=", |
554 | } else if (t->cycles > 1000000000000LL) { |
| - | 555 | cycles = t->cycles / 1000000000000LL; |
|
| - | 556 | suffix = 'T'; |
|
| - | 557 | } else if (t->cycles > 1000000LL) { |
|
| - | 558 | cycles = t->cycles / 1000000LL; |
|
| - | 559 | suffix = 'M'; |
|
| - | 560 | } else { |
|
| - | 561 | cycles = t->cycles; |
|
| - | 562 | suffix = ' '; |
|
| - | 563 | } |
|
| - | 564 | ||
| 543 | t->name, t, t->tid, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack); |
565 | printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", t->tid, t->name, t, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack, cycles, suffix); |
| - | 566 | ||
| 544 | if (t->cpu) |
567 | if (t->cpu) |
| 545 | printf("cpu%zd", t->cpu->id); |
568 | printf("%-4zd", t->cpu->id); |
| 546 | else |
569 | else |
| 547 | printf("none"); |
570 | printf("none"); |
| - | 571 | ||
| 548 | if (t->state == Sleeping) { |
572 | if (t->state == Sleeping) |
| 549 | printf(", kst=%#zx", t->kstack); |
- | |
| 550 | printf(", wq=%#zx", t->sleep_queue); |
573 | printf(" %#10zx %#10zx", t->kstack, t->sleep_queue); |
| 551 | } |
574 | |
| 552 | printf("\n"); |
575 | printf("\n"); |
| 553 | } |
576 | } |
| 554 | } |
577 | } |
| 555 | 578 | ||
| 556 | spinlock_unlock(&threads_lock); |
579 | spinlock_unlock(&threads_lock); |
| Line 571... | Line 594... | ||
| 571 | btree_node_t *leaf; |
594 | btree_node_t *leaf; |
| 572 | 595 | ||
| 573 | return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), &leaf) != NULL; |
596 | return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), &leaf) != NULL; |
| 574 | } |
597 | } |
| 575 | 598 | ||
| - | 599 | ||
| - | 600 | /** Update accounting of current thread. |
|
| - | 601 | * |
|
| - | 602 | * Note that thread_lock on THREAD must be already held and |
|
| - | 603 | * interrupts must be already disabled. |
|
| - | 604 | * |
|
| - | 605 | * @param t Pointer to thread. |
|
| - | 606 | * |
|
| - | 607 | */ |
|
| - | 608 | void thread_update_accounting(void) |
|
| - | 609 | { |
|
| - | 610 | uint64_t time = get_cycle(); |
|
| - | 611 | THREAD->cycles += time - THREAD->last_cycle; |
|
| - | 612 | THREAD->last_cycle = time; |
|
| - | 613 | } |
|
| - | 614 | ||
| 576 | /** Process syscall to create new thread. |
615 | /** Process syscall to create new thread. |
| 577 | * |
616 | * |
| 578 | */ |
617 | */ |
| 579 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name) |
618 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name) |
| 580 | { |
619 | { |