Changeset 78a580d for libcfa/src
- Timestamp:
- Mar 22, 2022, 3:28:29 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- ff7b2de
- Parents:
- 8f01ad71
- Location:
- libcfa/src/concurrency
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/io.cfa
r8f01ad71 r78a580d 42 42 #include "kernel/fwd.hfa" 43 43 #include "kernel/private.hfa" 44 #include "kernel/cluster.hfa" 44 45 #include "io/types.hfa" 45 46 … … 93 94 extern void __kernel_unpark( thread$ * thrd, unpark_hint ); 94 95 95 bool __cfa_io_drain( $io_context * ctx ) {96 bool __cfa_io_drain( $io_context * ctx, cluster * cltr ) { 96 97 /* paranoid */ verify( ! __preemption_enabled() ); 97 98 /* paranoid */ verify( ready_schedule_islocked() ); … … 112 113 } 113 114 115 unsigned long long ts_prev = ctx->cq.ts; 116 114 117 for(i; count) { 115 118 unsigned idx = (head + i) & mask; … … 125 128 126 129 __cfadbg_print_safe(io, "Kernel I/O : %u completed\n", count); 130 unsigned long long ts_next = ctx->cq.ts = rdtscl(); 127 131 128 132 // Mark to the kernel that the cqe has been seen … … 134 138 135 139 __atomic_unlock(&ctx->cq.lock); 140 141 touch_tsc( cltr->sched.io.tscs, ctx->cq.id, ts_prev, ts_next ); 136 142 137 143 return true; … … 143 149 /* paranoid */ verify( proc->io.ctx ); 144 150 145 __attribute__((unused))cluster * cltr = proc->cltr;151 cluster * cltr = proc->cltr; 146 152 $io_context & ctx = *proc->io.ctx; 147 153 … … 183 189 184 190 ready_schedule_lock(); 185 bool ret = __cfa_io_drain( &ctx );191 bool ret = __cfa_io_drain( &ctx, cltr ); 186 192 ready_schedule_unlock(); 187 193 return ret; -
libcfa/src/concurrency/io/setup.cfa
r8f01ad71 r78a580d 60 60 #include "fstream.hfa" 61 61 #include "kernel/private.hfa" 62 #include "limits.hfa" 62 63 #include "thread.hfa" 63 64 #pragma GCC diagnostic pop … … 215 216 // completion queue 216 217 cq.lock = 0; 218 cq.id = MAX; 219 cq.ts = rdtscl(); 217 220 cq.head = (volatile __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.head); 218 221 cq.tail = (volatile __u32 *)(((intptr_t)cq.ring_ptr) + params.cq_off.tail); -
libcfa/src/concurrency/io/types.hfa
r8f01ad71 r78a580d 79 79 struct __cmp_ring_t { 80 80 volatile bool lock; 81 82 unsigned id; 83 84 unsigned long long ts; 81 85 82 86 // Head and tail of the ring -
libcfa/src/concurrency/kernel.cfa
r8f01ad71 r78a580d 136 136 static void mark_awake(__cluster_proc_list & idles, processor & proc); 137 137 138 extern bool __cfa_io_drain( $io_context * );138 extern bool __cfa_io_drain( $io_context *, cluster * cltr ); 139 139 extern bool __cfa_io_flush( processor *, int min_comp ); 140 140 static inline bool __maybe_io_drain( processor * ); … … 839 839 if(head == tail) return false; 840 840 ready_schedule_lock(); 841 ret = __cfa_io_drain( ctx );841 ret = __cfa_io_drain( ctx, proc->cltr ); 842 842 ready_schedule_unlock(); 843 843 #endif -
libcfa/src/concurrency/kernel.hfa
r8f01ad71 r78a580d 108 108 struct { 109 109 $io_context * ctx; 110 unsigned id;111 110 unsigned target; 112 111 volatile bool pending; -
libcfa/src/concurrency/kernel/cluster.cfa
r8f01ad71 r78a580d 27 27 28 28 #include "ready_subqueue.hfa" 29 #include "io/types.hfa" 29 30 30 31 #include <errno.h> … … 259 260 it->rdq.id = valrq; 260 261 it->rdq.target = MAX; 261 it->io. id = valio;262 it->io.ctx->cq.id = valio; 262 263 it->io.target = MAX; 263 264 valrq += __shard_factor.readyq; … … 278 279 while(it) { 279 280 /* paranoid */ verifyf( it, "Unexpected null iterator\n"); 280 /* paranoid */ verifyf( it->io. id < count, "Processor %p has id %u above count %zu\n", it, it->rdq.id, count);281 data[it->io. id] = it->io.ctx;281 /* paranoid */ verifyf( it->io.ctx->cq.id < count, "Processor %p has id %u above count %zu\n", it, it->rdq.id, count); 282 data[it->io.ctx->cq.id] = it->io.ctx; 282 283 it = &(*it)`next; 283 284 } -
libcfa/src/concurrency/kernel/cluster.hfa
r8f01ad71 r78a580d 16 16 #pragma once 17 17 18 #include "device/cpu.hfa" 18 19 #include "kernel/private.hfa" 20 21 #include "limits.hfa" 19 22 20 23 //----------------------------------------------------------------------- … … 31 34 const unsigned long long ret = ((new_weight * new_val) + (old_weight * old_avg)) / total_weight; 32 35 return ret; 36 } 37 38 static inline void touch_tsc(__timestamp_t * tscs, size_t idx, unsigned long long ts_prev, unsigned long long ts_next) { 39 if (ts_next == MAX) return; 40 unsigned long long now = rdtscl(); 41 unsigned long long pma = __atomic_load_n(&tscs[ idx ].ma, __ATOMIC_RELAXED); 42 __atomic_store_n(&tscs[ idx ].tv, ts_next, __ATOMIC_RELAXED); 43 __atomic_store_n(&tscs[ idx ].ma, moving_average(now, ts_prev, pma), __ATOMIC_RELAXED); 33 44 } 34 45 -
libcfa/src/concurrency/kernel/startup.cfa
r8f01ad71 r78a580d 233 233 /* paranoid */ verify( sizeof(storage_mainIdleEventFd) == sizeof(eventfd_t) ); 234 234 235 __cfa_io_start( mainProcessor ); 235 236 register_tls( mainProcessor ); 236 __cfa_io_start( mainProcessor );237 237 238 238 // Start by initializing the main thread … … 314 314 mainProcessor->local_data = 0p; 315 315 316 unregister_tls( mainProcessor ); 316 317 __cfa_io_stop( mainProcessor ); 317 unregister_tls( mainProcessor );318 318 319 319 // Destroy the main processor and its context in reverse order of construction … … 364 364 proc->local_data = &__cfaabi_tls; 365 365 366 __cfa_io_start( proc ); 366 367 register_tls( proc ); 367 368 __cfa_io_start( proc );369 368 370 369 // used for idle sleep when io_uring is present … … 401 400 // Main routine of the core returned, the core is now fully terminated 402 401 __cfadbg_print_safe(runtime_core, "Kernel : core %p main ended (%p)\n", proc, &proc->runner); 403 404 __cfa_io_stop( proc );405 402 406 403 #if !defined(__CFA_NO_STATISTICS__) … … 417 414 418 415 unregister_tls( proc ); 416 __cfa_io_stop( proc ); 419 417 420 418 return 0p; -
libcfa/src/concurrency/ready_queue.cfa
r8f01ad71 r78a580d 26 26 #include "kernel/cluster.hfa" 27 27 #include "kernel/private.hfa" 28 29 #include "limits.hfa"30 28 31 29 // #include <errno.h> … … 202 200 // Actually pop the list 203 201 struct thread$ * thrd; 204 unsigned long long ts c_before= ts(lane);205 unsigned long long ts v;206 [thrd, ts v] = pop(lane);202 unsigned long long ts_prev = ts(lane); 203 unsigned long long ts_next; 204 [thrd, ts_next] = pop(lane); 207 205 208 206 /* paranoid */ verify(thrd); 209 /* paranoid */ verify(ts v);207 /* paranoid */ verify(ts_next); 210 208 /* paranoid */ verify(lane.lock); 211 209 … … 216 214 __STATS( stats.success++; ) 217 215 218 if (tsv != MAX) { 219 unsigned long long now = rdtscl(); 220 unsigned long long pma = __atomic_load_n(&readyQ.tscs[w].ma, __ATOMIC_RELAXED); 221 __atomic_store_n(&readyQ.tscs[w].tv, tsv, __ATOMIC_RELAXED); 222 __atomic_store_n(&readyQ.tscs[w].ma, moving_average(now, tsc_before, pma), __ATOMIC_RELAXED); 223 } 216 touch_tsc(readyQ.tscs, w, ts_prev, ts_next); 224 217 225 218 thrd->preferred = w / __shard_factor.readyq;
Note: See TracChangeset
for help on using the changeset viewer.