Changeset 011c79a in mainline


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

Replace CPU→needs_relink with CPU→relink_deadline

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

Location:
kernel/generic
Files:
3 edited

Legend:

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

    raae2869 r011c79a  
    6060        atomic_size_t nrdy;
    6161        runq_t rq[RQ_COUNT];
    62         volatile size_t needs_relink;
    6362
    6463        IRQ_SPINLOCK_DECLARE(timeoutlock);
     
    7473        size_t missed_clock_ticks;
    7574
    76         /** Can only be accessed when interrupts are disabled. */
     75        /** Can only be accessed by the CPU represented by this structure when interrupts are disabled. */
    7776        uint64_t current_clock_tick;
    7877        uint64_t preempt_deadline;  /* < when should the currently running thread be preempted */
     78        uint64_t relink_deadline;
    7979
    8080        /**
  • kernel/generic/src/proc/scheduler.c

    raae2869 r011c79a  
    270270static void relink_rq(int start)
    271271{
     272        if (CPU->current_clock_tick < CPU->relink_deadline)
     273                return;
     274
     275        CPU->relink_deadline = CPU->current_clock_tick + NEEDS_RELINK_MAX;
     276
    272277        list_t list;
    273 
    274278        list_initialize(&list);
     279
    275280        irq_spinlock_lock(&CPU->lock, false);
    276281
    277         if (CPU->needs_relink > NEEDS_RELINK_MAX) {
    278                 int i;
    279                 for (i = start; i < RQ_COUNT - 1; i++) {
    280                         /* Remember and empty rq[i + 1] */
    281 
    282                         irq_spinlock_lock(&CPU->rq[i + 1].lock, false);
    283                         list_concat(&list, &CPU->rq[i + 1].rq);
    284                         size_t n = CPU->rq[i + 1].n;
    285                         CPU->rq[i + 1].n = 0;
    286                         irq_spinlock_unlock(&CPU->rq[i + 1].lock, false);
    287 
    288                         /* Append rq[i + 1] to rq[i] */
    289 
    290                         irq_spinlock_lock(&CPU->rq[i].lock, false);
    291                         list_concat(&CPU->rq[i].rq, &list);
    292                         CPU->rq[i].n += n;
    293                         irq_spinlock_unlock(&CPU->rq[i].lock, false);
    294                 }
    295 
    296                 CPU->needs_relink = 0;
     282        for (int i = start; i < RQ_COUNT - 1; i++) {
     283                /* Remember and empty rq[i + 1] */
     284
     285                irq_spinlock_lock(&CPU->rq[i + 1].lock, false);
     286                list_concat(&list, &CPU->rq[i + 1].rq);
     287                size_t n = CPU->rq[i + 1].n;
     288                CPU->rq[i + 1].n = 0;
     289                irq_spinlock_unlock(&CPU->rq[i + 1].lock, false);
     290
     291                /* Append rq[i + 1] to rq[i] */
     292
     293                irq_spinlock_lock(&CPU->rq[i].lock, false);
     294                list_concat(&CPU->rq[i].rq, &list);
     295                CPU->rq[i].n += n;
     296                irq_spinlock_unlock(&CPU->rq[i].lock, false);
    297297        }
    298298
     
    726726                irq_spinlock_lock(&cpus[cpu].lock, true);
    727727
    728                 printf("cpu%u: address=%p, nrdy=%zu, needs_relink=%zu\n",
     728                /* Technically a data race, but we don't really care in this case. */
     729                int needs_relink = cpus[cpu].relink_deadline - cpus[cpu].current_clock_tick;
     730
     731                printf("cpu%u: address=%p, nrdy=%zu, needs_relink=%d\n",
    729732                    cpus[cpu].id, &cpus[cpu], atomic_load(&cpus[cpu].nrdy),
    730                     cpus[cpu].needs_relink);
     733                    needs_relink);
    731734
    732735                unsigned int i;
  • kernel/generic/src/time/clock.c

    raae2869 r011c79a  
    184184
    185185        if (THREAD) {
    186                 irq_spinlock_lock(&CPU->lock, false);
    187                 CPU->needs_relink += 1 + missed_clock_ticks;
    188                 irq_spinlock_unlock(&CPU->lock, false);
    189 
    190186                if (current_clock_tick >= CPU->preempt_deadline && PREEMPTION_ENABLED) {
    191187                        scheduler();
Note: See TracChangeset for help on using the changeset viewer.