Changeset d9dda26 in mainline


Ignore:
Timestamp:
2022-08-15T13:33:01Z (21 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
742f95ec
Parents:
0d59ea7e
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 13:31:57)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 13:33:01)
Message:

Update uptime using absolute count of clock ticks

Location:
kernel/generic
Files:
2 edited

Legend:

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

    r0d59ea7e rd9dda26  
    7474        size_t missed_clock_ticks;
    7575
     76        uint64_t current_clock_tick;
     77
    7678        /**
    7779         * Processor cycle accounting.
  • kernel/generic/src/time/clock.c

    r0d59ea7e rd9dda26  
    6565static parea_t clock_parea;
    6666
    67 /** Fragment of second
    68  *
    69  * For updating  seconds correctly.
    70  *
    71  */
    72 static sysarg_t secfrag = 0;
    73 
    7467/** Initialize realtime clock counter
    7568 *
     
    109102 *
    110103 * Update it only on first processor
    111  * TODO: Do we really need so many write barriers?
    112  *
    113  */
    114 static void clock_update_counters(void)
     104 */
     105static void clock_update_counters(uint64_t current_tick)
    115106{
    116107        if (CPU->id == 0) {
    117                 secfrag += 1000000 / HZ;
    118                 if (secfrag >= 1000000) {
    119                         secfrag -= 1000000;
    120                         uptime->seconds1++;
    121                         write_barrier();
    122                         uptime->useconds = secfrag;
    123                         write_barrier();
    124                         uptime->seconds2 = uptime->seconds1;
    125                 } else
    126                         uptime->useconds += 1000000 / HZ;
     108                uint64_t usec = (1000000 / HZ) * current_tick;
     109
     110                sysarg_t secs = usec / 1000000;
     111                sysarg_t usecs = usec % 1000000;
     112
     113                uptime->seconds1 = secs;
     114                write_barrier();
     115                uptime->useconds = usecs;
     116                write_barrier();
     117                uptime->seconds2 = secs;
    127118        }
    128119}
     
    147138{
    148139        size_t missed_clock_ticks = CPU->missed_clock_ticks;
     140        CPU->current_clock_tick += missed_clock_ticks + 1;
     141        uint64_t current_clock_tick = CPU->current_clock_tick;
     142        clock_update_counters(current_clock_tick);
    149143
    150144        /* Account CPU usage */
     
    159153        for (i = 0; i <= missed_clock_ticks; i++) {
    160154                /* Update counters and accounting */
    161                 clock_update_counters();
     155
    162156                cpu_update_accounting();
    163157
Note: See TracChangeset for help on using the changeset viewer.