Changeset b2ec5cf in mainline for kernel/generic/src/sysinfo/stats.c


Ignore:
Timestamp:
2023-04-15T16:47:54Z (2 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
169815e
Parents:
dd218ea
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-15 11:54:58)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-15 16:47:54)
Message:

Implement atomic_time_stat_t for lockless timekeeping

We keep monotonically increasing temporal statistics in several places.
They are frequently written from the thread that owns them, and rarely
read from other threads in certain syscalls. This new code serves the
purpose of avoiding the need for synchronization on the writer side.
On 64b system, we can simply assume that 64b writes are indivisible,
and relaxed atomic read/writes simply serve to formally prevent C
undefined behavior from data races (they translate to regular memory
reads/writes in assembly).

On 32b systems, we use the same algorithm that's been used for userspace
clock access, using three fields and some memory barriers to maintain
consistency of reads when the upper half changes. Only readers always
synchronize though. For writers, barriers are avoided in the common case
when the upper half remains unchanged.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/sysinfo/stats.c

    rdd218ea rb2ec5cf  
    124124                stats_cpus[i].active = cpus[i].active;
    125125                stats_cpus[i].frequency_mhz = cpus[i].frequency_mhz;
    126                 stats_cpus[i].busy_cycles = cpus[i].busy_cycles;
    127                 stats_cpus[i].idle_cycles = cpus[i].idle_cycles;
     126
     127                stats_cpus[i].busy_cycles = atomic_time_read(&cpus[i].busy_cycles);
     128                stats_cpus[i].idle_cycles = atomic_time_read(&cpus[i].idle_cycles);
    128129
    129130                irq_spinlock_unlock(&cpus[i].lock, true);
Note: See TracChangeset for help on using the changeset viewer.