Subversion Repositories HelenOS

Rev

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

Rev 2131 Rev 2422
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
    /*
103
     * Prepare information for the userspace so that it can successfully
97
     * Prepare information for the userspace so that it can successfully
104
     * physmem_map() the clock_parea.
98
     * physmem_map() the clock_parea.
105
     */
99
     */
106
    sysinfo_set_item_val("clock.cacheable", NULL, (unative_t) true);
100
    sysinfo_set_item_val("clock.cacheable", NULL, (unative_t) true);
107
    sysinfo_set_item_val("clock.fcolor", NULL, (unative_t)
-
 
108
        PAGE_COLOR(clock_parea.vbase));
-
 
109
    sysinfo_set_item_val("clock.faddr", NULL, (unative_t) faddr);
101
    sysinfo_set_item_val("clock.faddr", NULL, (unative_t) faddr);
110
}
102
}
111
 
103
 
112
 
104
 
113
/** Update public counters
105
/** Update public counters
Line 116... Line 108...
116
 * TODO: Do we really need so many write barriers?
108
 * TODO: Do we really need so many write barriers?
117
 */
109
 */
118
static void clock_update_counters(void)
110
static void clock_update_counters(void)
119
{
111
{
120
    if (CPU->id == 0) {
112
    if (CPU->id == 0) {
121
        secfrag += 1000000/HZ;
113
        secfrag += 1000000 / HZ;
122
        if (secfrag >= 1000000) {
114
        if (secfrag >= 1000000) {
123
            secfrag -= 1000000;
115
            secfrag -= 1000000;
124
            public_time->seconds1++;
116
            uptime->seconds1++;
125
            write_barrier();
117
            write_barrier();
126
            public_time->useconds = secfrag;
118
            uptime->useconds = secfrag;
127
            write_barrier();
119
            write_barrier();
128
            public_time->seconds2 = public_time->seconds1;
120
            uptime->seconds2 = uptime->seconds1;
129
        } else
121
        } else
130
            public_time->useconds += 1000000/HZ;
122
            uptime->useconds += 1000000 / HZ;
131
    }
123
    }
132
}
124
}
133
 
125
 
134
/** Clock routine
126
/** Clock routine
135
 *
127
 *