Changeset a35b458 in mainline for kernel/generic/src/time
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- kernel/generic/src/time
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/time/clock.c
r3061bc1 ra35b458 84 84 if (faddr == 0) 85 85 panic("Cannot allocate page for clock."); 86 86 87 87 uptime = (uptime_t *) PA2KA(faddr); 88 88 89 89 uptime->seconds1 = 0; 90 90 uptime->seconds2 = 0; 91 91 uptime->useconds = 0; 92 92 93 93 clock_parea.pbase = faddr; 94 94 clock_parea.frames = 1; … … 96 96 clock_parea.mapped = false; 97 97 ddi_parea_register(&clock_parea); 98 98 99 99 /* 100 100 * Prepare information for the userspace so that it can successfully … … 146 146 { 147 147 size_t missed_clock_ticks = CPU->missed_clock_ticks; 148 148 149 149 /* Account CPU usage */ 150 150 cpu_update_accounting(); 151 151 152 152 /* 153 153 * To avoid lock ordering problems, … … 160 160 clock_update_counters(); 161 161 cpu_update_accounting(); 162 162 163 163 irq_spinlock_lock(&CPU->timeoutlock, false); 164 164 165 165 link_t *cur; 166 166 while ((cur = list_first(&CPU->timeout_active_list)) != NULL) { 167 167 timeout_t *timeout = list_get_instance(cur, timeout_t, 168 168 link); 169 169 170 170 irq_spinlock_lock(&timeout->lock, false); 171 171 if (timeout->ticks-- != 0) { … … 173 173 break; 174 174 } 175 175 176 176 list_remove(cur); 177 177 timeout_handler_t handler = timeout->handler; 178 178 void *arg = timeout->arg; 179 179 timeout_reinitialize(timeout); 180 180 181 181 irq_spinlock_unlock(&timeout->lock, false); 182 182 irq_spinlock_unlock(&CPU->timeoutlock, false); 183 183 184 184 handler(arg); 185 185 186 186 irq_spinlock_lock(&CPU->timeoutlock, false); 187 187 } 188 188 189 189 irq_spinlock_unlock(&CPU->timeoutlock, false); 190 190 } 191 191 CPU->missed_clock_ticks = 0; 192 192 193 193 /* 194 194 * Do CPU usage accounting and find out whether to preempt THREAD. 195 195 * 196 196 */ 197 197 198 198 if (THREAD) { 199 199 uint64_t ticks; 200 200 201 201 irq_spinlock_lock(&CPU->lock, false); 202 202 CPU->needs_relink += 1 + missed_clock_ticks; 203 203 irq_spinlock_unlock(&CPU->lock, false); 204 204 205 205 irq_spinlock_lock(&THREAD->lock, false); 206 206 if ((ticks = THREAD->ticks)) { … … 211 211 } 212 212 irq_spinlock_unlock(&THREAD->lock, false); 213 213 214 214 if (ticks == 0 && PREEMPTION_ENABLED) { 215 215 scheduler(); -
kernel/generic/src/time/delay.c
r3061bc1 ra35b458 35 35 * @brief Active delay function. 36 36 */ 37 37 38 38 #include <time/delay.h> 39 39 #include <proc/thread.h> -
kernel/generic/src/time/timeout.c
r3061bc1 ra35b458 103 103 irq_spinlock_lock(&CPU->timeoutlock, true); 104 104 irq_spinlock_lock(&timeout->lock, false); 105 105 106 106 if (timeout->cpu) 107 107 panic("Unexpected: timeout->cpu != 0."); 108 108 109 109 timeout->cpu = CPU; 110 110 timeout->ticks = us2ticks(time); 111 111 112 112 timeout->handler = handler; 113 113 timeout->arg = arg; 114 114 115 115 /* 116 116 * Insert timeout into the active timeouts list according to timeout->ticks. … … 123 123 target = list_get_instance(cur, timeout_t, link); 124 124 irq_spinlock_lock(&target->lock, false); 125 125 126 126 if (timeout->ticks < sum + target->ticks) { 127 127 irq_spinlock_unlock(&target->lock, false); 128 128 break; 129 129 } 130 130 131 131 sum += target->ticks; 132 132 irq_spinlock_unlock(&target->lock, false); 133 133 } 134 134 135 135 /* Avoid using cur->prev directly */ 136 136 link_t *prev = cur->prev; 137 137 list_insert_after(&timeout->link, prev); 138 138 139 139 /* 140 140 * Adjust timeout->ticks according to ticks … … 142 142 */ 143 143 timeout->ticks -= sum; 144 144 145 145 /* 146 146 * Decrease ticks of timeout's immediate succesor by timeout->ticks. … … 151 151 irq_spinlock_unlock(&target->lock, false); 152 152 } 153 153 154 154 irq_spinlock_unlock(&timeout->lock, false); 155 155 irq_spinlock_unlock(&CPU->timeoutlock, true); … … 168 168 { 169 169 DEADLOCK_PROBE_INIT(p_tolock); 170 170 171 171 grab_locks: 172 172 irq_spinlock_lock(&timeout->lock, true); … … 175 175 return false; 176 176 } 177 177 178 178 if (!irq_spinlock_trylock(&timeout->cpu->timeoutlock)) { 179 179 irq_spinlock_unlock(&timeout->lock, true); … … 181 181 goto grab_locks; 182 182 } 183 183 184 184 /* 185 185 * Now we know for sure that timeout hasn't been activated yet 186 186 * and is lurking in timeout->cpu->timeout_active_list. 187 187 */ 188 188 189 189 link_t *cur = timeout->link.next; 190 190 if (cur != &timeout->cpu->timeout_active_list.head) { … … 194 194 irq_spinlock_unlock(&tmp->lock, false); 195 195 } 196 196 197 197 list_remove(&timeout->link); 198 198 irq_spinlock_unlock(&timeout->cpu->timeoutlock, false); 199 199 200 200 timeout_reinitialize(timeout); 201 201 irq_spinlock_unlock(&timeout->lock, true); 202 202 203 203 return true; 204 204 }
Note:
See TracChangeset
for help on using the changeset viewer.