Ignore:
Timestamp:
Aug 16, 2022, 4:01:54 PM (19 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
71cf630
Parents:
ee0176b
Message:

Fixed potential false sharing on ready-schedule mutate lock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/private.hfa

    ree0176b r741e22c  
    184184// have been hard-coded to for the ready-queue for
    185185// simplicity and performance
    186 struct __scheduler_RWLock_t {
    187         // total cachelines allocated
    188         unsigned int max;
    189 
    190         // cachelines currently in use
    191         volatile unsigned int alloc;
    192 
    193         // cachelines ready to itereate over
    194         // (!= to alloc when thread is in second half of doregister)
    195         volatile unsigned int ready;
    196 
    197         // writer lock
    198         volatile bool write_lock;
    199 
    200         // data pointer
    201         volatile bool * volatile * data;
     186union __attribute__((aligned(64))) __scheduler_RWLock_t {
     187        struct {
     188                // total cachelines allocated
     189                unsigned int max;
     190
     191                // cachelines currently in use
     192                volatile unsigned int alloc;
     193
     194                // cachelines ready to itereate over
     195                // (!= to alloc when thread is in second half of doregister)
     196                volatile unsigned int ready;
     197
     198                // writer lock
     199                volatile bool write_lock;
     200
     201                // data pointer
     202                volatile bool * volatile * data;
     203        } lock;
     204        char pad[192];
    202205};
    203206
     
    210213// Reader side : acquire when using the ready queue to schedule but not
    211214//  creating/destroying queues
    212 static inline void ready_schedule_lock(void) with(*__scheduler_lock) {
     215static inline void ready_schedule_lock(void) with(__scheduler_lock->lock) {
    213216        /* paranoid */ verify( ! __preemption_enabled() );
    214217        /* paranoid */ verify( ! kernelTLS().in_sched_lock );
     
    235238}
    236239
    237 static inline void ready_schedule_unlock(void) with(*__scheduler_lock) {
     240static inline void ready_schedule_unlock(void) with(__scheduler_lock->lock) {
    238241        /* paranoid */ verify( ! __preemption_enabled() );
    239242        /* paranoid */ verify( data[kernelTLS().sched_id] == &kernelTLS().sched_lock );
     
    256259
    257260        static inline bool ready_mutate_islocked() {
    258                 return __scheduler_lock->write_lock;
     261                return __scheduler_lock->lock.write_lock;
    259262        }
    260263#endif
Note: See TracChangeset for help on using the changeset viewer.