Changeset 4760793 in mainline for kernel/generic/include/cpu.h


Ignore:
Timestamp:
2024-01-14T18:23:40Z (17 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
5663872, c7ceacf
Parents:
3b68542
Message:

Add CPU_LOCAL alongside CPU and segregate fields that are only used locally

This makes it more clear which fields can be used without synchronization
and which need more care.

File:
1 edited

Legend:

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

    r3b68542 r4760793  
    4444#include <arch.h>
    4545
    46 #define CPU                  CURRENT->cpu
     46#define CPU                  (CURRENT->cpu)
     47#define CPU_LOCAL            (&CPU->local)
     48
     49/**
     50 * Contents of CPU_LOCAL. These are variables that are only ever accessed by
     51 * the CPU they belong to, so they don't need any synchronization,
     52 * just locally disabled interrupts.
     53 */
     54typedef struct cpu_local {
     55        /**
     56         * When system clock loses a tick, it is
     57         * recorded here so that clock() can react.
     58         */
     59        size_t missed_clock_ticks;
     60
     61        uint64_t current_clock_tick;
     62        uint64_t preempt_deadline;  /* < when should the currently running thread be preempted */
     63        uint64_t relink_deadline;
     64
     65        /**
     66         * Stack used by scheduler when there is no running thread.
     67         * This field is unchanged after initialization.
     68         */
     69        uint8_t *stack;
     70
     71        /**
     72         * Processor cycle accounting.
     73         */
     74        bool idle;
     75        uint64_t last_cycle;
     76} cpu_local_t;
    4777
    4878/** CPU structure.
     
    6393
    6494        /**
    65          * When system clock loses a tick, it is
    66          * recorded here so that clock() can react.
    67          * This variable is CPU-local and can be
    68          * only accessed when interrupts are
    69          * disabled.
    70          */
    71         size_t missed_clock_ticks;
    72 
    73         /** Can only be accessed by the CPU represented by this structure when interrupts are disabled. */
    74         uint64_t current_clock_tick;
    75         uint64_t preempt_deadline;  /* < when should the currently running thread be preempted */
    76         uint64_t relink_deadline;
    77 
    78         /**
    7995         * Processor cycle accounting.
    8096         */
    81         bool idle;
    82         uint64_t last_cycle;
    8397        atomic_time_stat_t idle_cycles;
    8498        atomic_time_stat_t busy_cycles;
     
    103117        _Atomic(struct thread *) fpu_owner;
    104118
    105         /**
    106          * Stack used by scheduler when there is no running thread.
    107          */
    108         uint8_t *stack;
     119        cpu_local_t local;
    109120} cpu_t;
    110121
Note: See TracChangeset for help on using the changeset viewer.