Changeset 944f2cab in mainline
- Timestamp:
- 2010-03-31T09:30:04Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e257ae3
- Parents:
- 3a10e34
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/ps/load.h
r3a10e34 r944f2cab 37 37 38 38 extern void kload_thread(void *); 39 extern int sys_ps_get_load(size_t *user_load); 39 40 40 41 #endif -
kernel/generic/include/syscall/syscall.h
r3a10e34 r944f2cab 91 91 SYS_PS_GET_TASK_INFO, 92 92 SYS_PS_GET_THREADS, 93 SYS_PS_GET_LOAD, 93 94 94 95 SYS_IPC_CONNECT_KBOX, -
kernel/generic/src/ps/load.c
r3a10e34 r944f2cab 40 40 #include <ps/load.h> 41 41 #include <arch.h> 42 #include <proc/scheduler.h> 43 #include <config.h> 44 #include <arch/types.h> 45 #include <time/clock.h> 46 #include <syscall/copy.h> 47 48 static size_t get_running_count(void); 49 50 size_t avenrun[3]; 51 52 #define FSHIFT 11 /* nr of bits of precision */ 53 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 54 #define LOAD_FREQ 5 /* 5 sec intervals */ 55 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 56 #define EXP_5 2014 /* 1/exp(5sec/5min) */ 57 #define EXP_15 2037 /* 1/exp(5sec/15min) */ 58 59 #define CALC_LOAD(load,exp,n) \ 60 load *= exp; \ 61 load += n*(FIXED_1-exp); \ 62 load >>= FSHIFT; 63 64 static inline unsigned long calc_load(size_t load, size_t exp, size_t active) 65 { 66 load *= exp; 67 load += active * (FIXED_1 - exp); 68 return load >> FSHIFT; 69 } 70 71 static inline void calc_load_global(void) 72 { 73 size_t active; 74 75 active = get_running_count(); 76 active = active > 0 ? active * FIXED_1 : 0; 77 avenrun[0] = calc_load(avenrun[0], EXP_1, active); 78 avenrun[1] = calc_load(avenrun[1], EXP_5, active); 79 avenrun[2] = calc_load(avenrun[2], EXP_15, active); 80 } 81 82 static size_t get_running_count(void) 83 { 84 size_t i; 85 size_t result = 0; 86 ipl_t ipl; 87 88 /* run queues should not change during reading */ 89 ipl = interrupts_disable(); 90 91 for (i = 0; i < config.cpu_active; ++i) { 92 cpu_t *cpu = &cpus[i]; 93 int j; 94 for (j = 0; j < RQ_COUNT; ++j) { 95 result += cpu->rq[j].n; 96 } 97 } 98 99 interrupts_restore(ipl); 100 return result; 101 } 42 102 43 103 /** Load thread main function. … … 51 111 /* Noone will thread_join us */ 52 112 thread_detach(THREAD); 113 avenrun[0] = 0; 114 avenrun[1] = 0; 115 avenrun[2] = 0; 53 116 54 117 while (true) { 55 printf("load thread alive\n"); 56 thread_sleep(5); 118 calc_load_global(); 119 printf("Computed loads: 0x%x 0x%x 0x%x\n", avenrun[0], avenrun[1], avenrun[2]); 120 thread_sleep(LOAD_FREQ); 57 121 } 122 } 123 124 int sys_ps_get_load(size_t *user_load) 125 { 126 copy_to_uspace(user_load, avenrun, sizeof(avenrun)); 127 return 0; 58 128 } 59 129 -
kernel/generic/src/syscall/syscall.c
r3a10e34 r944f2cab 55 55 #include <udebug/udebug.h> 56 56 #include <ps/ps.h> 57 #include <ps/load.h> 57 58 58 59 /** Dispatch system call */ … … 171 172 (syshandler_t) sys_ps_get_task_info, 172 173 (syshandler_t) sys_ps_get_threads, 174 (syshandler_t) sys_ps_get_load, 173 175 174 176 (syshandler_t) sys_ipc_connect_kbox -
uspace/app/ps/ps.c
r3a10e34 r944f2cab 42 42 #include <stdlib.h> 43 43 #include <malloc.h> 44 #include <load.h> 44 45 45 46 #include "func.h" … … 120 121 } 121 122 123 static void echo_load(void) 124 { 125 size_t load[3]; 126 load[0] = 0; 127 load[1] = 0; 128 load[2] = 0; 129 get_load(load); 130 printf("Current load: %d.%03d %d.%03d %d.%03d\n", load[0] >> 11, (load[0] & 0x7ff) / 2, load[1] >> 11, (load[1] & 0x7ff) / 2, load[2] >> 11, (load[2] & 0x7ff) / 2); 131 } 132 122 133 static void usage() 123 134 { 124 printf("Usage: ps [-t pid ]\n");135 printf("Usage: ps [-t pid -l]\n"); 125 136 } 126 137 … … 140 151 task_id_t taskid = strtol(*argv, NULL, 10); 141 152 list_threads(taskid); 153 } if (str_cmp(*argv, "-l") == 0) { 154 --argc; ++argv; 155 if (argc != 0) { 156 printf("Bad argument count!\n"); 157 usage(); 158 exit(1); 159 } 160 echo_load(); 142 161 } else { 143 162 printf("Unknown argument %s!\n", *argv); … … 145 164 exit(1); 146 165 } 147 148 166 } else { 149 167 list_tasks(); -
uspace/lib/c/Makefile
r3a10e34 r944f2cab 91 91 generic/vfs/canonify.c \ 92 92 generic/stacktrace.c \ 93 generic/ps.c 93 generic/ps.c \ 94 generic/load.c 94 95 95 96 SOURCES = \
Note:
See TracChangeset
for help on using the changeset viewer.