Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 79edc36 in mainline


Ignore:
Timestamp:
2010-04-01T15:21:03Z (12 years ago)
Author:
Stanislav Kozina <stanislav.kozina@…>
Branches:
lfn, master
Children:
62550dce
Parents:
83a957a
Message:

System load echo fix, now it looks realistic
top echoes first values (uptime)
Several ps and uptime fixes

Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ps/load.h

    r83a957a r79edc36  
    3636#define KERN_LOAD_H_
    3737
     38extern void get_avenrun(unsigned long *loads, int shift);
    3839extern void kload_thread(void *);
    39 extern int sys_ps_get_load(size_t *user_load);
     40extern int sys_ps_get_load(unsigned long *user_load);
    4041
    4142#endif
  • kernel/generic/src/ps/load.c

    r83a957a r79edc36  
    4747static size_t get_running_count(void);
    4848
    49 size_t avenrun[3];
     49unsigned long avenrun[3];
    5050
    5151#define FSHIFT   11             /* nr of bits of precision */
     
    5656#define EXP_15 2037             /* 1/exp(5sec/15min) */
    5757
    58 #define CALC_LOAD(load,exp,n) \
    59         load *= exp; \
    60         load += n*(FIXED_1-exp); \
    61         load >>= FSHIFT;
     58void 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}
    6264
    63 static inline unsigned long calc_load(size_t load, size_t exp, size_t active)
     65static inline unsigned long calc_load(unsigned long load, size_t exp, size_t active)
    6466{
    6567        load *= exp;
     
    120122}
    121123
    122 int sys_ps_get_load(size_t *user_load)
     124int sys_ps_get_load(unsigned long *user_load)
    123125{
    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));
    125129        return 0;
    126130}
  • uspace/app/ps/ps.c

    r83a957a r79edc36  
    130130static void echo_load(void)
    131131{
    132         size_t load[3];
     132        unsigned long load[3];
    133133        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");
    135141}
    136142
  • uspace/app/top/input.c

    r83a957a r79edc36  
    6262#include <ipc/console.h>
    6363
    64 #define READ_TIMEOUT 1000000
     64#define USEC_COUNT 1000000
    6565
    6666/* return true iff the given timeval is positive */
     
    154154 * Eat any input that might be available.
    155155 */
    156 void tsleep(void)
     156void tsleep(unsigned int sec)
    157157{
    158158        struct timeval tv;
    159159       
    160160        tv.tv_sec = 0;
    161         tv.tv_usec = READ_TIMEOUT;
     161        tv.tv_usec = sec * USEC_COUNT;
    162162        while (TV_POS(&tv))
    163163                if (rwait(&tv)) {
     
    170170 * getchar with timeout.
    171171 */
    172 int tgetchar(void)
     172int tgetchar(unsigned int sec)
    173173{
    174174        static struct timeval timeleft;
     
    176176       
    177177        /*
    178          * Reset timeleft to READ_TIMEOUT whenever it is not positive.
     178         * Reset timeleft to USEC_COUNT whenever it is not positive.
    179179         * In any case, wait to see if there is any input.  If so,
    180180         * take it, and update timeleft so that the next call to
     
    186186        if (!TV_POS(&timeleft)) {
    187187                timeleft.tv_sec = 0;
    188                 timeleft.tv_usec = READ_TIMEOUT;
     188                timeleft.tv_usec = sec * USEC_COUNT;
    189189        }
    190190       
  • uspace/app/top/input.h

    r83a957a r79edc36  
    4545#define TOP_INPUT_
    4646
     47#include <sys/time.h>
     48
    4749extern int rwait(struct timeval *);
    48 extern int tgetchar(void);
    49 extern void tsleep(void);
     50extern int tgetchar(unsigned int sec);
     51extern void tsleep(unsigned int sec);
    5052
    5153#endif
  • uspace/app/top/screen.c

    r83a957a r79edc36  
    3838#include <io/console.h>
    3939#include <vfs/vfs.h>
    40 #include <futex.h>
    4140#include "screen.h"
    42 
    43 futex_t screen_lock;
     41#include "top.h"
    4442
    4543static void resume_normal(void)
     
    6866}
    6967
     68static inline void print_time(data_t *data)
     69{
     70        printf("%02d:%02d:%02d ", data->hours, data->minutes, data->seconds);
     71}
     72
     73static 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
     79static int i = 0;
     80void 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
    7092/** @}
    7193 */
  • uspace/app/top/screen.h

    r83a957a r79edc36  
    3434#define TOP_SCREEN_H_
    3535
    36 #include <futex.h>
    37 
    38 extern futex_t screen_lock;
     36#include "top.h"
    3937
    4038extern void screen_init(void);
    4139extern void clear_screen(void);
    4240extern void moveto(int r, int c);
     41extern void print_data(data_t *data);
    4342
    4443#endif
  • uspace/app/top/top.c

    r83a957a r79edc36  
    3737#include <stdio.h>
    3838#include <stdlib.h>
    39 #include <async.h>
    4039#include <unistd.h>
    4140#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>
    4346#include "screen.h"
    4447#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
     56static 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}
    4579
    4680int main(int argc, char *argv[])
    4781{
     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
    4891        screen_init();
    4992
    5093        /* And paint screen until death... */
    51         int i = 0;
    5294        while (true) {
    53                 char c = tgetchar();
     95                char c = tgetchar(UPDATE_INTERVAL);
    5496                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);
    5999                        continue;
    60100                }
     
    68108                                break;
    69109                }
     110
    70111        }
    71112
     113        puts("\n\n");
    72114        fflush(stdout);
    73115        return 0;
  • uspace/app/uptime/uptime.c

    r83a957a r79edc36  
    6161        uint64_t uptime;
    6262        get_uptime(&uptime);
    63         printf("\tUp %4llu days, %02llu:%02llu:%02llu",
     63        printf(", up %4llu days, %02llu:%02llu:%02llu",
    6464                uptime / DAY, (uptime % DAY) / HOUR, (uptime % HOUR) / MINUTE, uptime % MINUTE);
    6565
    66         size_t load[3];
     66        unsigned long load[3];
    6767        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);
    6974
    70         printf("\n");
     75        puts("\n");
    7176        return 0;
    7277}
  • uspace/lib/c/generic/load.c

    r83a957a r79edc36  
    3535#include <load.h>
    3636#include <libc.h>
     37#include <stdio.h>
    3738
    3839/** Get current system load
     
    4344 *
    4445 */
    45 int get_load(size_t *load)
     46int get_load(unsigned long *load)
    4647{
    4748        return __SYSCALL1(SYS_PS_GET_LOAD, (sysarg_t) load);
    4849}
    4950
     51void 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
    5065/** @}
    5166 */
  • uspace/lib/c/include/load.h

    r83a957a r79edc36  
    3939#include <libarch/types.h>
    4040
    41 extern int get_load(size_t *load);
     41extern int get_load(unsigned long *load);
     42extern void print_load_fragment(unsigned long upper, int dec_length);
    4243
    4344#endif
Note: See TracChangeset for help on using the changeset viewer.