Changeset 4b662f8c in mainline


Ignore:
Timestamp:
2007-04-20T18:43:49Z (18 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea63704
Parents:
cc85fb9
Message:

add fancy uptime kconsole command

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/time/clock.h

    rcc85fb9 r4b662f8c  
    3636#define KERN_CLOCK_H_
    3737
     38#include <arch/types.h>
     39
    3840#define HZ              100
     41
     42/** Uptime structure */
     43typedef struct {
     44        unative_t seconds1;
     45        unative_t useconds;
     46        unative_t seconds2;
     47} uptime_t;
     48
     49extern uptime_t *uptime;
    3950
    4051extern void clock(void);
  • kernel/generic/src/console/cmd.c

    rcc85fb9 r4b662f8c  
    9393};
    9494
     95static int cmd_uptime(cmd_arg_t *argv);
     96static cmd_info_t uptime_info = {
     97        .name = "uptime",
     98        .description = "Print uptime information.",
     99        .func = cmd_uptime,
     100        .argc = 0
     101};
     102
    95103static int cmd_continue(cmd_arg_t *argv);
    96104static cmd_info_t continue_info = {
     
    440448        &exit_info,
    441449        &reboot_info,
     450        &uptime_info,
    442451        &halt_info,
    443452        &help_info,
     
    530539}
    531540
     541
     542/** Print system uptime information.
     543 *
     544 * @param argv Argument vector.
     545 *
     546 * @return 0 on failure, 1 on success.
     547 */
     548int cmd_uptime(cmd_arg_t *argv)
     549{
     550        ASSERT(uptime);
     551       
     552        /* This doesn't have to be very accurate */
     553        unative_t sec = uptime->seconds1;
     554       
     555        printf("Up %u days, %u hours, %u minutes, %u seconds\n",
     556                sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
     557       
     558        return 1;
     559}
     560
    532561/** Describe specified command.
    533562 *
  • kernel/generic/src/time/clock.c

    rcc85fb9 r4b662f8c  
    4242#include <time/clock.h>
    4343#include <time/timeout.h>
    44 #include <arch/types.h>
    4544#include <config.h>
    4645#include <synch/spinlock.h>
     
    5857#include <ddi/ddi.h>
    5958
    60 /** Physical memory area of the real time clock. */
     59/* Pointer to variable with uptime */
     60uptime_t *uptime;
     61
     62/** Physical memory area of the real time clock */
    6163static parea_t clock_parea;
    6264
    63 /* Pointers to public variables with time */
    64 struct ptime {
    65         unative_t seconds1;
    66         unative_t useconds;
    67         unative_t seconds2;
    68 };
    69 struct ptime *public_time;
    7065/* Variable holding fragment of second, so that we would update
    7166 * seconds correctly
     
    8782                panic("Cannot allocate page for clock");
    8883       
    89         public_time = (struct ptime *) PA2KA(faddr);
    90 
    91         /* TODO: We would need some arch dependent settings here */
    92         public_time->seconds1 = 0;
    93         public_time->seconds2 = 0;
    94         public_time->useconds = 0;
     84        uptime = (uptime_t *) PA2KA(faddr);
     85       
     86        uptime->seconds1 = 0;
     87        uptime->seconds2 = 0;
     88        uptime->useconds = 0;
    9589
    9690        clock_parea.pbase = (uintptr_t) faddr;
    97         clock_parea.vbase = (uintptr_t) public_time;
     91        clock_parea.vbase = (uintptr_t) uptime;
    9892        clock_parea.frames = 1;
    9993        clock_parea.cacheable = true;
     
    117111{
    118112        if (CPU->id == 0) {
    119                 secfrag += 1000000/HZ;
     113                secfrag += 1000000 / HZ;
    120114                if (secfrag >= 1000000) {
    121115                        secfrag -= 1000000;
    122                         public_time->seconds1++;
     116                        uptime->seconds1++;
    123117                        write_barrier();
    124                         public_time->useconds = secfrag;
     118                        uptime->useconds = secfrag;
    125119                        write_barrier();
    126                         public_time->seconds2 = public_time->seconds1;
     120                        uptime->seconds2 = uptime->seconds1;
    127121                } else
    128                         public_time->useconds += 1000000/HZ;
     122                        uptime->useconds += 1000000 / HZ;
    129123        }
    130124}
Note: See TracChangeset for help on using the changeset viewer.