Subversion Repositories HelenOS

Rev

Rev 2141 | Rev 3613 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2141 Rev 2275
Line 39... Line 39...
39
 * timeouts.
39
 * timeouts.
40
 */
40
 */
41
 
41
 
42
#include <time/clock.h>
42
#include <time/clock.h>
43
#include <time/timeout.h>
43
#include <time/timeout.h>
44
#include <arch/types.h>
-
 
45
#include <config.h>
44
#include <config.h>
46
#include <synch/spinlock.h>
45
#include <synch/spinlock.h>
47
#include <synch/waitq.h>
46
#include <synch/waitq.h>
48
#include <func.h>
47
#include <func.h>
49
#include <proc/scheduler.h>
48
#include <proc/scheduler.h>
Line 55... Line 54...
55
#include <sysinfo/sysinfo.h>
54
#include <sysinfo/sysinfo.h>
56
#include <arch/barrier.h>
55
#include <arch/barrier.h>
57
#include <mm/frame.h>
56
#include <mm/frame.h>
58
#include <ddi/ddi.h>
57
#include <ddi/ddi.h>
59
 
58
 
-
 
59
/* Pointer to variable with uptime */
-
 
60
uptime_t *uptime;
-
 
61
 
60
/** Physical memory area of the real time clock. */
62
/** Physical memory area of the real time clock */
61
static parea_t clock_parea;
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
/* Variable holding fragment of second, so that we would update
65
/* Variable holding fragment of second, so that we would update
71
 * seconds correctly
66
 * seconds correctly
72
 */
67
 */
73
static unative_t secfrag = 0;
68
static unative_t secfrag = 0;
74
 
69
 
Line 84... Line 79...
84
 
79
 
85
    faddr = frame_alloc(ONE_FRAME, FRAME_ATOMIC);
80
    faddr = frame_alloc(ONE_FRAME, FRAME_ATOMIC);
86
    if (!faddr)
81
    if (!faddr)
87
        panic("Cannot allocate page for clock");
82
        panic("Cannot allocate page for clock");
88
   
83
   
89
    public_time = (struct ptime *) PA2KA(faddr);
84
    uptime = (uptime_t *) PA2KA(faddr);
90
 
85
   
91
        /* TODO: We would need some arch dependent settings here */
-
 
92
    public_time->seconds1 = 0;
86
    uptime->seconds1 = 0;
93
    public_time->seconds2 = 0;
87
    uptime->seconds2 = 0;
94
    public_time->useconds = 0;
88
    uptime->useconds = 0;
95
 
89
 
96
    clock_parea.pbase = (uintptr_t) faddr;
90
    clock_parea.pbase = (uintptr_t) faddr;
97
    clock_parea.vbase = (uintptr_t) public_time;
91
    clock_parea.vbase = (uintptr_t) uptime;
98
    clock_parea.frames = 1;
92
    clock_parea.frames = 1;
99
    clock_parea.cacheable = true;
93
    clock_parea.cacheable = true;
100
    ddi_parea_register(&clock_parea);
94
    ddi_parea_register(&clock_parea);
101
 
95
 
102
    /*
96
    /*
Line 114... Line 108...
114
 * TODO: Do we really need so many write barriers?
108
 * TODO: Do we really need so many write barriers?
115
 */
109
 */
116
static void clock_update_counters(void)
110
static void clock_update_counters(void)
117
{
111
{
118
    if (CPU->id == 0) {
112
    if (CPU->id == 0) {
119
        secfrag += 1000000/HZ;
113
        secfrag += 1000000 / HZ;
120
        if (secfrag >= 1000000) {
114
        if (secfrag >= 1000000) {
121
            secfrag -= 1000000;
115
            secfrag -= 1000000;
122
            public_time->seconds1++;
116
            uptime->seconds1++;
123
            write_barrier();
117
            write_barrier();
124
            public_time->useconds = secfrag;
118
            uptime->useconds = secfrag;
125
            write_barrier();
119
            write_barrier();
126
            public_time->seconds2 = public_time->seconds1;
120
            uptime->seconds2 = uptime->seconds1;
127
        } else
121
        } else
128
            public_time->useconds += 1000000/HZ;
122
            uptime->useconds += 1000000 / HZ;
129
    }
123
    }
130
}
124
}
131
 
125
 
132
/** Clock routine
126
/** Clock routine
133
 *
127
 *