Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 742f95ec in mainline


Ignore:
Timestamp:
2022-08-15T14:20:53Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
ad58fd2
Parents:
d9dda26
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 14:08:44)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 14:20:53)
Message:

Replace timeout→ticks with timeout→deadline

Instead of counting down in the structure, use a fixed deadline number.
This simplifies the code significantly.

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/time/timeout.h

    rd9dda26 r742f95ec  
    4747        /** Link to the list of active timeouts on CURRENT->cpu */
    4848        link_t link;
    49         /** Timeout will be activated in this amount of clock() ticks. */
    50         uint64_t ticks;
     49        /** Timeout will be activated when current clock tick reaches this value. */
     50        uint64_t deadline;
    5151        /** Function that will be called on timeout activation. */
    5252        timeout_handler_t handler;
  • kernel/generic/src/time/clock.c

    rd9dda26 r742f95ec  
    164164
    165165                        irq_spinlock_lock(&timeout->lock, false);
    166                         if (timeout->ticks-- != 0) {
     166                        if (current_clock_tick <= timeout->deadline) {
    167167                                irq_spinlock_unlock(&timeout->lock, false);
    168168                                break;
  • kernel/generic/src/time/timeout.c

    rd9dda26 r742f95ec  
    6767{
    6868        timeout->cpu = NULL;
    69         timeout->ticks = 0;
     69        timeout->deadline = 0;
    7070        timeout->handler = NULL;
    7171        timeout->arg = NULL;
     
    108108
    109109        timeout->cpu = CPU;
    110         timeout->ticks = us2ticks(time);
    111 
     110        timeout->deadline = CPU->current_clock_tick + us2ticks(time);
    112111        timeout->handler = handler;
    113112        timeout->arg = arg;
    114113
    115114        /*
    116          * Insert timeout into the active timeouts list according to timeout->ticks.
     115         * Insert timeout into the active timeouts list according to timeout->deadline.
    117116         */
    118         uint64_t sum = 0;
    119117        timeout_t *target = NULL;
    120118        link_t *cur, *prev;
     
    125123                irq_spinlock_lock(&target->lock, false);
    126124
    127                 if (timeout->ticks < sum + target->ticks) {
     125                if (timeout->deadline < target->deadline) {
    128126                        irq_spinlock_unlock(&target->lock, false);
    129127                        break;
    130128                }
    131129
    132                 sum += target->ticks;
    133130                irq_spinlock_unlock(&target->lock, false);
    134131                prev = cur;
     
    139136        else
    140137                list_insert_after(&timeout->link, prev);
    141 
    142         /*
    143          * Adjust timeout->ticks according to ticks
    144          * accumulated in target's predecessors.
    145          */
    146         timeout->ticks -= sum;
    147 
    148         /*
    149          * Decrease ticks of timeout's immediate succesor by timeout->ticks.
    150          */
    151         if (cur != NULL) {
    152                 irq_spinlock_lock(&target->lock, false);
    153                 target->ticks -= timeout->ticks;
    154                 irq_spinlock_unlock(&target->lock, false);
    155         }
    156138
    157139        irq_spinlock_unlock(&timeout->lock, false);
     
    195177                timeout_t *tmp = list_get_instance(cur, timeout_t, link);
    196178                irq_spinlock_lock(&tmp->lock, false);
    197                 tmp->ticks += timeout->ticks;
    198179                irq_spinlock_unlock(&tmp->lock, false);
    199180        }
Note: See TracChangeset for help on using the changeset viewer.