Rev 2307 | Rev 2421 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2307 | Rev 2336 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
Line 121... | Line 121... | ||
121 | } else |
121 | } else |
122 | uptime->useconds += 1000000 / HZ; |
122 | uptime->useconds += 1000000 / HZ; |
123 | } |
123 | } |
124 | } |
124 | } |
125 | 125 | ||
- | 126 | #ifdef CONFIG_TIMEOUT_EXTAVL_TREE |
|
- | 127 | ||
- | 128 | /** Clock routine |
|
- | 129 | * |
|
- | 130 | * Clock routine executed from clock interrupt handler |
|
- | 131 | * (assuming interrupts_disable()'d). Runs expired timeouts |
|
- | 132 | * and preemptive scheduling. |
|
- | 133 | * |
|
- | 134 | */ |
|
- | 135 | void clock(void) |
|
- | 136 | { |
|
- | 137 | timeout_t *h; |
|
- | 138 | timeout_handler_t f; |
|
- | 139 | void *arg; |
|
- | 140 | count_t missed_clock_ticks = CPU->missed_clock_ticks; |
|
- | 141 | uint64_t *i = &(CPU->timeout_active_tree.basetime); |
|
- | 142 | uint64_t absolute_clock_ticks = *i + |
|
- | 143 | missed_clock_ticks; |
|
- | 144 | extavltree_node_t *head = &(CPU->timeout_active_tree.head); |
|
- | 145 | extavltree_node_t *expnode = head->next; |
|
- | 146 | ||
- | 147 | /* |
|
- | 148 | * To avoid lock ordering problems, |
|
- | 149 | * run all expired timeouts as you visit them. |
|
- | 150 | */ |
|
- | 151 | ||
- | 152 | for (; *i <= absolute_clock_ticks; (*i)++) { |
|
- | 153 | clock_update_counters(); |
|
- | 154 | spinlock_lock(&CPU->timeoutlock); |
|
- | 155 | ||
- | 156 | while ((expnode = head->next) != head) { |
|
- | 157 | h = extavltree_get_instance(expnode,timeout_t,node); |
|
- | 158 | spinlock_lock(&h->lock); |
|
- | 159 | if (expnode->key != *i) { |
|
- | 160 | spinlock_unlock(&h->lock); |
|
- | 161 | break; |
|
- | 162 | } |
|
- | 163 | ||
- | 164 | extavltree_delete_min(&CPU->timeout_active_tree); |
|
- | 165 | ||
- | 166 | f = h->handler; |
|
- | 167 | arg = h->arg; |
|
- | 168 | timeout_reinitialize(h); |
|
- | 169 | spinlock_unlock(&h->lock); |
|
- | 170 | spinlock_unlock(&CPU->timeoutlock); |
|
- | 171 | ||
- | 172 | f(arg); |
|
- | 173 | ||
- | 174 | spinlock_lock(&CPU->timeoutlock); |
|
- | 175 | } |
|
- | 176 | spinlock_unlock(&CPU->timeoutlock); |
|
- | 177 | } |
|
- | 178 | ||
- | 179 | CPU->missed_clock_ticks = 0; |
|
- | 180 | ||
- | 181 | /* |
|
- | 182 | * Do CPU usage accounting and find out whether to preempt THREAD. |
|
- | 183 | */ |
|
- | 184 | if (THREAD) { |
|
- | 185 | uint64_t ticks; |
|
- | 186 | ||
- | 187 | spinlock_lock(&CPU->lock); |
|
- | 188 | CPU->needs_relink += 1 + missed_clock_ticks; |
|
- | 189 | spinlock_unlock(&CPU->lock); |
|
- | 190 | ||
- | 191 | spinlock_lock(&THREAD->lock); |
|
- | 192 | if ((ticks = THREAD->ticks)) { |
|
- | 193 | if (ticks >= 1 + missed_clock_ticks) |
|
- | 194 | THREAD->ticks -= 1 + missed_clock_ticks; |
|
- | 195 | else |
|
- | 196 | THREAD->ticks = 0; |
|
- | 197 | } |
|
- | 198 | spinlock_unlock(&THREAD->lock); |
|
- | 199 | ||
- | 200 | if (!ticks && !PREEMPTION_DISABLED) { |
|
- | 201 | scheduler(); |
|
- | 202 | } |
|
- | 203 | } |
|
- | 204 | } |
|
- | 205 | ||
- | 206 | ||
- | 207 | #else |
|
- | 208 | ||
- | 209 | ||
126 | /** Clock routine |
210 | /** Clock routine |
127 | * |
211 | * |
128 | * Clock routine executed from clock interrupt handler |
212 | * Clock routine executed from clock interrupt handler |
129 | * (assuming interrupts_disable()'d). Runs expired timeouts |
213 | * (assuming interrupts_disable()'d). Runs expired timeouts |
130 | * and preemptive scheduling. |
214 | * and preemptive scheduling. |
Line 193... | Line 277... | ||
193 | } |
277 | } |
194 | } |
278 | } |
195 | 279 | ||
196 | } |
280 | } |
197 | 281 | ||
- | 282 | #endif |
|
198 | /** @} |
283 | /** @} |
199 | */ |
284 | */ |