Changeset 4b662f8c in mainline
- Timestamp:
- 2007-04-20T18:43:49Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea63704
- Parents:
- cc85fb9
- Location:
- kernel/generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/time/clock.h
rcc85fb9 r4b662f8c 36 36 #define KERN_CLOCK_H_ 37 37 38 #include <arch/types.h> 39 38 40 #define HZ 100 41 42 /** Uptime structure */ 43 typedef struct { 44 unative_t seconds1; 45 unative_t useconds; 46 unative_t seconds2; 47 } uptime_t; 48 49 extern uptime_t *uptime; 39 50 40 51 extern void clock(void); -
kernel/generic/src/console/cmd.c
rcc85fb9 r4b662f8c 93 93 }; 94 94 95 static int cmd_uptime(cmd_arg_t *argv); 96 static cmd_info_t uptime_info = { 97 .name = "uptime", 98 .description = "Print uptime information.", 99 .func = cmd_uptime, 100 .argc = 0 101 }; 102 95 103 static int cmd_continue(cmd_arg_t *argv); 96 104 static cmd_info_t continue_info = { … … 440 448 &exit_info, 441 449 &reboot_info, 450 &uptime_info, 442 451 &halt_info, 443 452 &help_info, … … 530 539 } 531 540 541 542 /** Print system uptime information. 543 * 544 * @param argv Argument vector. 545 * 546 * @return 0 on failure, 1 on success. 547 */ 548 int 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 532 561 /** Describe specified command. 533 562 * -
kernel/generic/src/time/clock.c
rcc85fb9 r4b662f8c 42 42 #include <time/clock.h> 43 43 #include <time/timeout.h> 44 #include <arch/types.h>45 44 #include <config.h> 46 45 #include <synch/spinlock.h> … … 58 57 #include <ddi/ddi.h> 59 58 60 /** Physical memory area of the real time clock. */ 59 /* Pointer to variable with uptime */ 60 uptime_t *uptime; 61 62 /** Physical memory area of the real time clock */ 61 63 static parea_t clock_parea; 62 64 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;70 65 /* Variable holding fragment of second, so that we would update 71 66 * seconds correctly … … 87 82 panic("Cannot allocate page for clock"); 88 83 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; 95 89 96 90 clock_parea.pbase = (uintptr_t) faddr; 97 clock_parea.vbase = (uintptr_t) public_time;91 clock_parea.vbase = (uintptr_t) uptime; 98 92 clock_parea.frames = 1; 99 93 clock_parea.cacheable = true; … … 117 111 { 118 112 if (CPU->id == 0) { 119 secfrag += 1000000 /HZ;113 secfrag += 1000000 / HZ; 120 114 if (secfrag >= 1000000) { 121 115 secfrag -= 1000000; 122 public_time->seconds1++;116 uptime->seconds1++; 123 117 write_barrier(); 124 public_time->useconds = secfrag;118 uptime->useconds = secfrag; 125 119 write_barrier(); 126 public_time->seconds2 = public_time->seconds1;120 uptime->seconds2 = uptime->seconds1; 127 121 } else 128 public_time->useconds += 1000000/HZ;122 uptime->useconds += 1000000 / HZ; 129 123 } 130 124 }
Note:
See TracChangeset
for help on using the changeset viewer.