Changeset 3118355 in mainline for kernel/generic/src/proc/scheduler.c


Ignore:
Timestamp:
2023-03-21T17:41:48Z (21 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c680333
Parents:
72ac106
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-26 17:56:29)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-03-21 17:41:48)
Message:

Optimize relink_rq()

Iterate backwards and only lock each runqueue once instead of twice.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/scheduler.c

    r72ac106 r3118355  
    275275        CPU->relink_deadline = CPU->current_clock_tick + NEEDS_RELINK_MAX;
    276276
     277        /* Temporary cache for lists we are moving. */
    277278        list_t list;
    278279        list_initialize(&list);
    279280
     281        size_t n = 0;
     282
    280283        irq_spinlock_lock(&CPU->lock, false);
    281284
    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 
     285        /* Move every list (except the one with highest priority) one level up. */
     286        for (int i = RQ_COUNT - 1; i > start; i--) {
    293287                irq_spinlock_lock(&CPU->rq[i].lock, false);
    294                 list_concat(&CPU->rq[i].rq, &list);
    295                 CPU->rq[i].n += n;
     288
     289                /* Swap lists. */
     290                list_swap(&CPU->rq[i].rq, &list);
     291
     292                /* Swap number of items. */
     293                size_t tmpn = CPU->rq[i].n;
     294                CPU->rq[i].n = n;
     295                n = tmpn;
     296
    296297                irq_spinlock_unlock(&CPU->rq[i].lock, false);
     298        }
     299
     300        /* Append the contents of rq[start + 1]  to rq[start]. */
     301        if (n != 0) {
     302                irq_spinlock_lock(&CPU->rq[start].lock, false);
     303                list_concat(&CPU->rq[start].rq, &list);
     304                CPU->rq[start].n += n;
     305                irq_spinlock_unlock(&CPU->rq[start].lock, false);
    297306        }
    298307
Note: See TracChangeset for help on using the changeset viewer.