Changeset d672350 for libcfa/src/concurrency/io.cfa
- Timestamp:
- Mar 21, 2022, 1:44:06 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- a76202d
- Parents:
- ef3c383 (diff), dbe2533 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/io.cfa
ref3c383 rd672350 41 41 #include "kernel.hfa" 42 42 #include "kernel/fwd.hfa" 43 #include "kernel _private.hfa"43 #include "kernel/private.hfa" 44 44 #include "io/types.hfa" 45 45 … … 93 93 extern void __kernel_unpark( thread$ * thrd, unpark_hint ); 94 94 95 bool __cfa_io_drain( processor * proc) {95 bool __cfa_io_drain( $io_context * ctx ) { 96 96 /* paranoid */ verify( ! __preemption_enabled() ); 97 97 /* paranoid */ verify( ready_schedule_islocked() ); 98 /* paranoid */ verify( proc ); 99 /* paranoid */ verify( proc->io.ctx ); 98 /* paranoid */ verify( ctx ); 100 99 101 100 // Drain the queue 102 $io_context * ctx = proc->io.ctx;103 101 unsigned head = *ctx->cq.head; 104 102 unsigned tail = *ctx->cq.tail; … … 110 108 if(count == 0) return false; 111 109 110 if(!__atomic_try_acquire(&ctx->cq.lock)) { 111 return false; 112 } 113 112 114 for(i; count) { 113 115 unsigned idx = (head + i) & mask; … … 130 132 /* paranoid */ verify( ready_schedule_islocked() ); 131 133 /* paranoid */ verify( ! __preemption_enabled() ); 134 135 __atomic_unlock(&ctx->cq.lock); 132 136 133 137 return true; … … 175 179 /* paranoid */ verify( ! __preemption_enabled() ); 176 180 177 ctx.proc->io.pending = false;181 __atomic_store_n(&ctx.proc->io.pending, false, __ATOMIC_RELAXED); 178 182 } 179 183 180 184 ready_schedule_lock(); 181 bool ret = __cfa_io_drain( proc);185 bool ret = __cfa_io_drain( &ctx ); 182 186 ready_schedule_unlock(); 183 187 return ret; … … 287 291 //============================================================================================= 288 292 // submission 289 static inline void __submit ( struct $io_context * ctx, __u32 idxs[], __u32 have, bool lazy) {293 static inline void __submit_only( struct $io_context * ctx, __u32 idxs[], __u32 have) { 290 294 // We can proceed to the fast path 291 295 // Get the right objects … … 304 308 sq.to_submit += have; 305 309 306 ctx->proc->io.pending = true; 307 ctx->proc->io.dirty = true; 310 __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_RELAXED); 311 __atomic_store_n(&ctx->proc->io.dirty , true, __ATOMIC_RELAXED); 312 } 313 314 static inline void __submit( struct $io_context * ctx, __u32 idxs[], __u32 have, bool lazy) { 315 __sub_ring_t & sq = ctx->sq; 316 __submit_only(ctx, idxs, have); 317 308 318 if(sq.to_submit > 30) { 309 319 __tls_stats()->io.flush.full++; … … 402 412 // I/O Arbiter 403 413 //============================================================================================= 404 static inline void block(__outstanding_io_queue & queue, __outstanding_io & item) { 414 static inline bool enqueue(__outstanding_io_queue & queue, __outstanding_io & item) { 415 bool was_empty; 416 405 417 // Lock the list, it's not thread safe 406 418 lock( queue.lock __cfaabi_dbg_ctx2 ); 407 419 { 420 was_empty = empty(queue.queue); 421 408 422 // Add our request to the list 409 423 add( queue.queue, item ); … … 414 428 unlock( queue.lock ); 415 429 416 wait( item.sem );430 return was_empty; 417 431 } 418 432 … … 432 446 pa.want = want; 433 447 434 block(this.pending, (__outstanding_io&)pa); 448 enqueue(this.pending, (__outstanding_io&)pa); 449 450 wait( pa.sem ); 435 451 436 452 return pa.ctx; … … 485 501 ei.lazy = lazy; 486 502 487 block(ctx->ext_sq, (__outstanding_io&)ei); 503 bool we = enqueue(ctx->ext_sq, (__outstanding_io&)ei); 504 505 __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_SEQ_CST); 506 507 if( we ) { 508 sigval_t value = { PREEMPT_IO }; 509 pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value); 510 } 511 512 wait( ei.sem ); 488 513 489 514 __cfadbg_print_safe(io, "Kernel I/O : %u submitted from arbiter\n", have); … … 501 526 __external_io & ei = (__external_io&)drop( ctx.ext_sq.queue ); 502 527 503 __submit (&ctx, ei.idxs, ei.have, ei.lazy);528 __submit_only(&ctx, ei.idxs, ei.have); 504 529 505 530 post( ei.sem );
Note:
See TracChangeset
for help on using the changeset viewer.