[1] | 1 | /* |
---|
| 2 | This file is part of MutekP. |
---|
| 3 | |
---|
| 4 | MutekP is free software; you can redistribute it and/or modify it |
---|
| 5 | under the terms of the GNU General Public License as published by |
---|
| 6 | the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | (at your option) any later version. |
---|
| 8 | |
---|
| 9 | MutekP is distributed in the hope that it will be useful, but |
---|
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 12 | General Public License for more details. |
---|
| 13 | |
---|
| 14 | You should have received a copy of the GNU General Public License |
---|
| 15 | along with MutekP; if not, write to the Free Software Foundation, |
---|
| 16 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 17 | |
---|
| 18 | UPMC / LIP6 / SOC (c) 2008 |
---|
| 19 | Copyright Ghassan Almaless <ghassan.almaless@gmail.com> |
---|
| 20 | Copyright (c) 2009,2010,2011,2012,2013,2014,2015 UPMC Sorbonne Universites |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #include <list.h> |
---|
| 24 | #include <thread.h> |
---|
| 25 | #include <pid.h> |
---|
| 26 | #include <task.h> |
---|
| 27 | #include <cpu.h> |
---|
| 28 | #include <vfs.h> |
---|
| 29 | #include <rwlock.h> |
---|
| 30 | #include <system.h> |
---|
| 31 | #include <wait_queue.h> |
---|
| 32 | |
---|
| 33 | #define ksh_print(x, ...) printk(INFO,x, __VA_ARGS__) |
---|
| 34 | |
---|
| 35 | void ps_print_task(struct task_s *task, uint_t *usr_nr, uint_t *sys_nr, uint_t *tasks_nr) |
---|
| 36 | { |
---|
| 37 | struct thread_s *thread; |
---|
| 38 | struct list_entry *iter; |
---|
| 39 | struct list_entry *th_root; |
---|
| 40 | char *cmd; |
---|
| 41 | uint_t ppid; |
---|
| 42 | |
---|
| 43 | if(task != NULL) |
---|
| 44 | { |
---|
| 45 | th_root = &task->th_root; |
---|
| 46 | |
---|
| 47 | ppid = PID_MIN_GLOBAL; |
---|
| 48 | cmd = "N/A"; |
---|
| 49 | |
---|
| 50 | if(task->pid != PID_MIN_GLOBAL) |
---|
| 51 | ppid = task->parent; |
---|
| 52 | |
---|
| 53 | if(task->state == TASK_CREATE) |
---|
| 54 | cmd = "Under-Creation"; |
---|
| 55 | else |
---|
| 56 | if(VFS_FILE_IS_NULL(task->bin)) |
---|
| 57 | { |
---|
| 58 | //cmd = vfs_get_file_name(task->bin); |
---|
| 59 | cmd = "ENOTSUP"; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | printk(INFO,"\n[PID] %d [PPID] %d [Children] %d [Command] %s\n", |
---|
| 63 | task->pid, |
---|
| 64 | ppid, |
---|
| 65 | atomic_get(&task->childs_nr), |
---|
| 66 | cmd); |
---|
| 67 | |
---|
| 68 | if(task->state == TASK_CREATE) |
---|
| 69 | return; |
---|
| 70 | |
---|
| 71 | spinlock_lock(&task->th_lock); |
---|
| 72 | |
---|
| 73 | list_foreach_forward(th_root, iter) |
---|
| 74 | { |
---|
| 75 | thread = list_element(iter, struct thread_s, rope); |
---|
| 76 | assert(thread->signature == THREAD_ID); |
---|
| 77 | |
---|
| 78 | ksh_print(" |__ [TID] %x [ORD] %d [%s] [CPU] %d [TICKs] %d [Sched] %d [tm_sys] %u [tm_usr] %u [tm_sleep] %u %s [ %s ]\n", |
---|
| 79 | thread, |
---|
| 80 | thread->info.order, |
---|
| 81 | thread_get_attr_name(thread->type), |
---|
| 82 | thread_current_cpu(thread)->gid, |
---|
| 83 | thread->ticks_nr, |
---|
| 84 | thread->info.sched_nr, |
---|
| 85 | thread->info.tm_sys, |
---|
| 86 | thread->info.tm_usr, |
---|
| 87 | thread->info.tm_sleep, |
---|
| 88 | thread_get_state_name(thread->state), |
---|
| 89 | (thread->info.queue == NULL) ? "N/A" : thread->info.queue->name); |
---|
| 90 | |
---|
| 91 | if(thread->type == PTHREAD) |
---|
| 92 | *usr_nr = *usr_nr + 1; |
---|
| 93 | else |
---|
| 94 | *sys_nr = *sys_nr + 1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if(!(list_empty(th_root))) |
---|
| 98 | *tasks_nr = *tasks_nr + 1; |
---|
| 99 | |
---|
| 100 | spinlock_unlock(&task->th_lock); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | error_t ps_func(void *param) |
---|
| 105 | { |
---|
| 106 | uint_t usr_nr; |
---|
| 107 | uint_t sys_nr; |
---|
| 108 | uint_t tasks_nr; |
---|
| 109 | uint_t pid; |
---|
| 110 | struct task_locator_s *task_locator; |
---|
| 111 | |
---|
| 112 | usr_nr = 0; |
---|
| 113 | sys_nr = 0; |
---|
| 114 | tasks_nr = 0; |
---|
| 115 | |
---|
| 116 | ksh_print("\nOn cluster %u:\n", current_cid); |
---|
| 117 | |
---|
| 118 | tasks_manager_lock(); |
---|
| 119 | /* Don't print task0, it's irrelevant */ |
---|
| 120 | for(pid=PID_MIN_GLOBAL+1; pid <= PID_MAX_GLOBAL; pid ++) |
---|
| 121 | { |
---|
| 122 | task_locator = task_lookup(pid); |
---|
| 123 | if ( task_locator->cid != CID_NULL ) |
---|
| 124 | ps_print_task(task_locator->task, &usr_nr, &sys_nr, &tasks_nr); |
---|
| 125 | } |
---|
| 126 | tasks_manager_unlock(); |
---|
| 127 | |
---|
| 128 | ksh_print("\nTotal Active Tasks : %d\n", tasks_nr); |
---|
| 129 | ksh_print("Total Active User Threads : %d\n", usr_nr); |
---|
| 130 | ksh_print("-----------------\n", NULL); |
---|
| 131 | |
---|
| 132 | return 0; |
---|
| 133 | } |
---|