Changeset 040334e
- Timestamp:
- Jan 27, 2022, 1:16:42 PM (23 months ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- ac6fc48
- Parents:
- 00a8e19
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r00a8e19 r040334e 187 187 MAIN_LOOP: 188 188 for() { 189 #define OLD_MAIN 1190 #if OLD_MAIN191 189 // Check if there is pending io 192 190 __maybe_io_drain( this ); … … 248 246 __cfa_io_flush( this, 0 ); 249 247 } 250 251 #else252 #warning new kernel loop253 SEARCH: {254 /* paranoid */ verify( ! __preemption_enabled() );255 256 // First, lock the scheduler since we are searching for a thread257 ready_schedule_lock();258 259 // Try to get the next thread260 readyThread = pop_fast( this->cltr );261 if(readyThread) { ready_schedule_unlock(); break SEARCH; }262 263 // If we can't find a thread, might as well flush any outstanding I/O264 if(this->io.pending) { __cfa_io_flush( this, 0 ); }265 266 // Spin a little on I/O, just in case267 for(5) {268 __maybe_io_drain( this );269 readyThread = pop_fast( this->cltr );270 if(readyThread) { ready_schedule_unlock(); break SEARCH; }271 }272 273 // no luck, try stealing a few times274 for(5) {275 if( __maybe_io_drain( this ) ) {276 readyThread = pop_fast( this->cltr );277 } else {278 readyThread = pop_slow( this->cltr );279 }280 if(readyThread) { ready_schedule_unlock(); break SEARCH; }281 }282 283 // still no luck, search for a thread284 readyThread = pop_search( this->cltr );285 if(readyThread) { ready_schedule_unlock(); break SEARCH; }286 287 // Don't block if we are done288 if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) {289 ready_schedule_unlock();290 break MAIN_LOOP;291 }292 293 __STATS( __tls_stats()->ready.sleep.halts++; )294 295 // Push self to idle stack296 ready_schedule_unlock();297 if(!mark_idle(this->cltr->procs, * this)) goto SEARCH;298 ready_schedule_lock();299 300 // Confirm the ready-queue is empty301 __maybe_io_drain( this );302 readyThread = pop_search( this->cltr );303 ready_schedule_unlock();304 305 if( readyThread ) {306 // A thread was found, cancel the halt307 mark_awake(this->cltr->procs, * this);308 309 __STATS( __tls_stats()->ready.sleep.cancels++; )310 311 // continue the main loop312 break SEARCH;313 }314 315 __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )316 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle_fd);317 318 {319 eventfd_t val;320 ssize_t ret = read( this->idle_fd, &val, sizeof(val) );321 if(ret < 0) {322 switch((int)errno) {323 case EAGAIN:324 #if EAGAIN != EWOULDBLOCK325 case EWOULDBLOCK:326 #endif327 case EINTR:328 // No need to do anything special here, just assume it's a legitimate wake-up329 break;330 default:331 abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );332 }333 }334 }335 336 __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )337 338 // We were woken up, remove self from idle339 mark_awake(this->cltr->procs, * this);340 341 // DON'T just proceed, start looking again342 continue MAIN_LOOP;343 }344 345 RUN_THREAD:346 /* paranoid */ verify( ! __preemption_enabled() );347 /* paranoid */ verify( readyThread );348 349 // Reset io dirty bit350 this->io.dirty = false;351 352 // We found a thread run it353 __run_thread(this, readyThread);354 355 // Are we done?356 if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;357 358 if(this->io.pending && !this->io.dirty) {359 __cfa_io_flush( this, 0 );360 }361 362 ready_schedule_lock();363 __maybe_io_drain( this );364 ready_schedule_unlock();365 #endif366 248 } 367 249 … … 951 833 unsigned tail = *ctx->cq.tail; 952 834 if(head == tail) return false; 953 #if OLD_MAIN 954 ready_schedule_lock(); 955 ret = __cfa_io_drain( proc ); 956 ready_schedule_unlock(); 957 #else 958 ret = __cfa_io_drain( proc ); 959 #endif 835 ready_schedule_lock(); 836 ret = __cfa_io_drain( proc ); 837 ready_schedule_unlock(); 960 838 #endif 961 839 return ret;
Note: See TracChangeset
for help on using the changeset viewer.