Changeset aae2869 in mainline


Ignore:
Timestamp:
2023-02-04T16:19:21Z (15 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
011c79a
Parents:
8addb24a
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-16 11:03:29)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-04 16:19:21)
Message:

Replace THREAD→ticks with CPU→preempt_deadline

This removes a bit of unnecessary locking in clock().

Location:
kernel/generic
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/cpu.h

    r8addb24a raae2869  
    7676        /** Can only be accessed when interrupts are disabled. */
    7777        uint64_t current_clock_tick;
     78        uint64_t preempt_deadline;  /* < when should the currently running thread be preempted */
    7879
    7980        /**
  • kernel/generic/include/proc/thread.h

    r8addb24a raae2869  
    177177        bool uspace;
    178178
    179         /** Ticks before preemption. */
    180         uint64_t ticks;
    181 
    182179        /** Thread accounting. */
    183180        uint64_t ucycles;
  • kernel/generic/src/proc/scheduler.c

    r8addb24a raae2869  
    236236
    237237                thread->cpu = CPU;
    238                 thread->ticks = us2ticks((i + 1) * 10000);
    239238                thread->priority = i;  /* Correct rq index */
     239
     240                /* Time allocation in microseconds. */
     241                uint64_t time_to_run = (i + 1) * 10000;
     242
     243                /* This is safe because interrupts are disabled. */
     244                CPU->preempt_deadline = CPU->current_clock_tick + us2ticks(time_to_run);
    240245
    241246                /*
  • kernel/generic/src/proc/thread.c

    r8addb24a raae2869  
    372372        thread->thread_code = func;
    373373        thread->thread_arg = arg;
    374         thread->ticks = -1;
    375374        thread->ucycles = 0;
    376375        thread->kcycles = 0;
  • kernel/generic/src/time/clock.c

    r8addb24a raae2869  
    184184
    185185        if (THREAD) {
    186                 uint64_t ticks;
    187 
    188186                irq_spinlock_lock(&CPU->lock, false);
    189187                CPU->needs_relink += 1 + missed_clock_ticks;
    190188                irq_spinlock_unlock(&CPU->lock, false);
    191189
    192                 irq_spinlock_lock(&THREAD->lock, false);
    193                 if ((ticks = THREAD->ticks)) {
    194                         if (ticks >= 1 + missed_clock_ticks)
    195                                 THREAD->ticks -= 1 + missed_clock_ticks;
    196                         else
    197                                 THREAD->ticks = 0;
    198                 }
    199                 irq_spinlock_unlock(&THREAD->lock, false);
    200 
    201                 if (ticks == 0 && PREEMPTION_ENABLED) {
     190                if (current_clock_tick >= CPU->preempt_deadline && PREEMPTION_ENABLED) {
    202191                        scheduler();
    203192#ifdef CONFIG_UDEBUG
Note: See TracChangeset for help on using the changeset viewer.