Changeset 79edc36 in mainline
- Timestamp:
- 2010-04-01T15:21:03Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 62550dce
- Parents:
- 83a957a
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/ps/load.h
r83a957a r79edc36 36 36 #define KERN_LOAD_H_ 37 37 38 extern void get_avenrun(unsigned long *loads, int shift); 38 39 extern void kload_thread(void *); 39 extern int sys_ps_get_load( size_t*user_load);40 extern int sys_ps_get_load(unsigned long *user_load); 40 41 41 42 #endif -
kernel/generic/src/ps/load.c
r83a957a r79edc36 47 47 static size_t get_running_count(void); 48 48 49 size_tavenrun[3];49 unsigned long avenrun[3]; 50 50 51 51 #define FSHIFT 11 /* nr of bits of precision */ … … 56 56 #define EXP_15 2037 /* 1/exp(5sec/15min) */ 57 57 58 #define CALC_LOAD(load,exp,n) \ 59 load *= exp; \ 60 load += n*(FIXED_1-exp); \ 61 load >>= FSHIFT; 58 void get_avenrun(unsigned long *loads, int shift) 59 { 60 loads[0] = avenrun[0] << shift; 61 loads[1] = avenrun[1] << shift; 62 loads[2] = avenrun[2] << shift; 63 } 62 64 63 static inline unsigned long calc_load( size_tload, size_t exp, size_t active)65 static inline unsigned long calc_load(unsigned long load, size_t exp, size_t active) 64 66 { 65 67 load *= exp; … … 120 122 } 121 123 122 int sys_ps_get_load( size_t*user_load)124 int sys_ps_get_load(unsigned long *user_load) 123 125 { 124 copy_to_uspace(user_load, avenrun, sizeof(avenrun)); 126 unsigned long loads[3]; 127 get_avenrun(loads, 5); 128 copy_to_uspace(user_load, loads, sizeof(loads)); 125 129 return 0; 126 130 } -
uspace/app/ps/ps.c
r83a957a r79edc36 130 130 static void echo_load(void) 131 131 { 132 size_tload[3];132 unsigned long load[3]; 133 133 get_load(load); 134 printf("System load: %d.%03d %d.%03d %d.%03d\n", ECHOLOAD1(load[0]), ECHOLOAD2(load[0]), ECHOLOAD1(load[1]), ECHOLOAD2(load[1]), ECHOLOAD1(load[2]), ECHOLOAD2(load[2])); 134 printf("load avarage: "); 135 print_load_fragment(load[0], 2); 136 puts(" "); 137 print_load_fragment(load[1], 2); 138 puts(" "); 139 print_load_fragment(load[2], 2); 140 puts("\n"); 135 141 } 136 142 -
uspace/app/top/input.c
r83a957a r79edc36 62 62 #include <ipc/console.h> 63 63 64 #define READ_TIMEOUT 100000064 #define USEC_COUNT 1000000 65 65 66 66 /* return true iff the given timeval is positive */ … … 154 154 * Eat any input that might be available. 155 155 */ 156 void tsleep( void)156 void tsleep(unsigned int sec) 157 157 { 158 158 struct timeval tv; 159 159 160 160 tv.tv_sec = 0; 161 tv.tv_usec = READ_TIMEOUT;161 tv.tv_usec = sec * USEC_COUNT; 162 162 while (TV_POS(&tv)) 163 163 if (rwait(&tv)) { … … 170 170 * getchar with timeout. 171 171 */ 172 int tgetchar( void)172 int tgetchar(unsigned int sec) 173 173 { 174 174 static struct timeval timeleft; … … 176 176 177 177 /* 178 * Reset timeleft to READ_TIMEOUT whenever it is not positive.178 * Reset timeleft to USEC_COUNT whenever it is not positive. 179 179 * In any case, wait to see if there is any input. If so, 180 180 * take it, and update timeleft so that the next call to … … 186 186 if (!TV_POS(&timeleft)) { 187 187 timeleft.tv_sec = 0; 188 timeleft.tv_usec = READ_TIMEOUT;188 timeleft.tv_usec = sec * USEC_COUNT; 189 189 } 190 190 -
uspace/app/top/input.h
r83a957a r79edc36 45 45 #define TOP_INPUT_ 46 46 47 #include <sys/time.h> 48 47 49 extern int rwait(struct timeval *); 48 extern int tgetchar( void);49 extern void tsleep( void);50 extern int tgetchar(unsigned int sec); 51 extern void tsleep(unsigned int sec); 50 52 51 53 #endif -
uspace/app/top/screen.c
r83a957a r79edc36 38 38 #include <io/console.h> 39 39 #include <vfs/vfs.h> 40 #include <futex.h>41 40 #include "screen.h" 42 43 futex_t screen_lock; 41 #include "top.h" 44 42 45 43 static void resume_normal(void) … … 68 66 } 69 67 68 static inline void print_time(data_t *data) 69 { 70 printf("%02d:%02d:%02d ", data->hours, data->minutes, data->seconds); 71 } 72 73 static inline void print_uptime(data_t *data) 74 { 75 printf("up %4d days, %02d:%02d:%02d ", data->uptime_d, data->uptime_h, 76 data->uptime_m, data->uptime_s); 77 } 78 79 static int i = 0; 80 void print_data(data_t *data) 81 { 82 clear_screen(); 83 fflush(stdout); 84 printf("top - "); 85 print_time(data); 86 print_uptime(data); 87 puts(" ... \n"); 88 printf("A dalsi radek topu - jiz po %dte", ++i); 89 fflush(stdout); 90 } 91 70 92 /** @} 71 93 */ -
uspace/app/top/screen.h
r83a957a r79edc36 34 34 #define TOP_SCREEN_H_ 35 35 36 #include <futex.h> 37 38 extern futex_t screen_lock; 36 #include "top.h" 39 37 40 38 extern void screen_init(void); 41 39 extern void clear_screen(void); 42 40 extern void moveto(int r, int c); 41 extern void print_data(data_t *data); 43 42 44 43 #endif -
uspace/app/top/top.c
r83a957a r79edc36 37 37 #include <stdio.h> 38 38 #include <stdlib.h> 39 #include <async.h>40 39 #include <unistd.h> 41 40 #include <io/console.h> 42 #include <vfs/vfs.h> 41 #include <uptime.h> 42 #include <task.h> 43 #include <thread.h> 44 #include <sys/time.h> 45 #include <load.h> 43 46 #include "screen.h" 44 47 #include "input.h" 48 #include "top.h" 49 50 #define UPDATE_INTERVAL 1 51 52 #define DAY 86400 53 #define HOUR 3600 54 #define MINUTE 60 55 56 static void read_vars(data_t *target) 57 { 58 /* Read current time */ 59 struct timeval time; 60 if (gettimeofday(&time, NULL) != 0) { 61 printf("Cannot get time of day!\n"); 62 exit(1); 63 } 64 target->hours = (time.tv_sec % DAY) / HOUR; 65 target->minutes = (time.tv_sec % HOUR) / MINUTE; 66 target->seconds = time.tv_sec % MINUTE; 67 68 /* Read uptime */ 69 uint64_t uptime; 70 get_uptime(&uptime); 71 target->uptime_d = uptime / DAY; 72 target->uptime_h = (uptime % DAY) / HOUR; 73 target->uptime_m = (uptime % HOUR) / MINUTE; 74 target->uptime_s = uptime % MINUTE; 75 76 /* Read load */ 77 get_load(target->load); 78 } 45 79 46 80 int main(int argc, char *argv[]) 47 81 { 82 data_t old_data; 83 data_t new_data; 84 85 /* Read initial stats */ 86 printf("Reading initial data...\n"); 87 read_vars(&old_data); 88 sleep(UPDATE_INTERVAL); 89 read_vars(&new_data); 90 48 91 screen_init(); 49 92 50 93 /* And paint screen until death... */ 51 int i = 0;52 94 while (true) { 53 char c = tgetchar( );95 char c = tgetchar(UPDATE_INTERVAL); 54 96 if (c < 0) { 55 clear_screen(); 56 moveto(0,0); 57 printf("Still running;-) for %d...", i++); 58 fflush(stdout); 97 read_vars(&new_data); 98 print_data(&new_data); 59 99 continue; 60 100 } … … 68 108 break; 69 109 } 110 70 111 } 71 112 113 puts("\n\n"); 72 114 fflush(stdout); 73 115 return 0; -
uspace/app/uptime/uptime.c
r83a957a r79edc36 61 61 uint64_t uptime; 62 62 get_uptime(&uptime); 63 printf(" \tUp %4llu days, %02llu:%02llu:%02llu",63 printf(", up %4llu days, %02llu:%02llu:%02llu", 64 64 uptime / DAY, (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE); 65 65 66 size_tload[3];66 unsigned long load[3]; 67 67 get_load(load); 68 printf("\t load: %d.%03d %d.%03d %d.%03d ", ECHOLOAD1(load[0]), ECHOLOAD2(load[0]), ECHOLOAD1(load[1]), ECHOLOAD2(load[1]), ECHOLOAD1(load[2]), ECHOLOAD2(load[2])); 68 puts(", load avarage: "); 69 print_load_fragment(load[0], 2); 70 puts(" "); 71 print_load_fragment(load[1], 2); 72 puts(" "); 73 print_load_fragment(load[2], 2); 69 74 70 p rintf("\n");75 puts("\n"); 71 76 return 0; 72 77 } -
uspace/lib/c/generic/load.c
r83a957a r79edc36 35 35 #include <load.h> 36 36 #include <libc.h> 37 #include <stdio.h> 37 38 38 39 /** Get current system load … … 43 44 * 44 45 */ 45 int get_load( size_t*load)46 int get_load(unsigned long *load) 46 47 { 47 48 return __SYSCALL1(SYS_PS_GET_LOAD, (sysarg_t) load); 48 49 } 49 50 51 void print_load_fragment(unsigned long upper, int dec_length) 52 { 53 int i; 54 /* Magic value from BSD */ 55 unsigned long lower = 65536; 56 /* Print whole part */ 57 printf("%u.", upper / lower); 58 unsigned long rest = (upper % lower) * 10; 59 for (i = 0; i < dec_length; ++i) { 60 printf("%d", rest / lower); 61 rest = (rest % lower) * 10; 62 } 63 } 64 50 65 /** @} 51 66 */ -
uspace/lib/c/include/load.h
r83a957a r79edc36 39 39 #include <libarch/types.h> 40 40 41 extern int get_load(size_t *load); 41 extern int get_load(unsigned long *load); 42 extern void print_load_fragment(unsigned long upper, int dec_length); 42 43 43 44 #endif
Note:
See TracChangeset
for help on using the changeset viewer.