Subversion Repositories HelenOS

Rev

Rev 2131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2422
Line 205... Line 205...
205
         goto loop;
205
         goto loop;
206
    }
206
    }
207
 
207
 
208
    interrupts_disable();
208
    interrupts_disable();
209
   
209
   
210
    for (i = 0; i<RQ_COUNT; i++) {
210
    for (i = 0; i < RQ_COUNT; i++) {
211
        r = &CPU->rq[i];
211
        r = &CPU->rq[i];
212
        spinlock_lock(&r->lock);
212
        spinlock_lock(&r->lock);
213
        if (r->n == 0) {
213
        if (r->n == 0) {
214
            /*
214
            /*
215
             * If this queue is empty, try a lower-priority queue.
215
             * If this queue is empty, try a lower-priority queue.
Line 375... Line 375...
375
 * Assume THREAD->lock is held.
375
 * Assume THREAD->lock is held.
376
 */
376
 */
377
void scheduler_separated_stack(void)
377
void scheduler_separated_stack(void)
378
{
378
{
379
    int priority;
379
    int priority;
-
 
380
    DEADLOCK_PROBE_INIT(p_joinwq);
380
   
381
 
381
    ASSERT(CPU != NULL);
382
    ASSERT(CPU != NULL);
382
   
383
   
383
    if (THREAD) {
384
    if (THREAD) {
384
        /* must be run after the switch to scheduler stack */
385
        /* must be run after the switch to scheduler stack */
385
        after_thread_ran();
386
        after_thread_ran();
Line 404... Line 405...
404
                     * Avoid deadlock.
405
                     * Avoid deadlock.
405
                     */
406
                     */
406
                    spinlock_unlock(&THREAD->lock);
407
                    spinlock_unlock(&THREAD->lock);
407
                    delay(10);
408
                    delay(10);
408
                    spinlock_lock(&THREAD->lock);
409
                    spinlock_lock(&THREAD->lock);
-
 
410
                    DEADLOCK_PROBE(p_joinwq,
-
 
411
                        DEADLOCK_THRESHOLD);
409
                    goto repeat;
412
                    goto repeat;
410
                }
413
                }
411
                _waitq_wakeup_unsafe(&THREAD->join_wq, false);
414
                _waitq_wakeup_unsafe(&THREAD->join_wq,
-
 
415
                    WAKEUP_FIRST);
412
                spinlock_unlock(&THREAD->join_wq.lock);
416
                spinlock_unlock(&THREAD->join_wq.lock);
413
               
417
               
414
                THREAD->state = Undead;
418
                THREAD->state = Undead;
415
                spinlock_unlock(&THREAD->lock);
419
                spinlock_unlock(&THREAD->lock);
416
            }
420
            }
Line 445... Line 449...
445
 
449
 
446
        default:
450
        default:
447
            /*
451
            /*
448
             * Entering state is unexpected.
452
             * Entering state is unexpected.
449
             */
453
             */
450
            panic("tid%d: unexpected state %s\n", THREAD->tid,
454
            panic("tid%llu: unexpected state %s\n", THREAD->tid,
451
                thread_states[THREAD->state]);
455
                thread_states[THREAD->state]);
452
            break;
456
            break;
453
        }
457
        }
454
 
458
 
455
        THREAD = NULL;
459
        THREAD = NULL;
456
    }
460
    }
Line 498... Line 502...
498
 
502
 
499
    spinlock_lock(&THREAD->lock);  
503
    spinlock_lock(&THREAD->lock);  
500
    THREAD->state = Running;
504
    THREAD->state = Running;
501
 
505
 
502
#ifdef SCHEDULER_VERBOSE
506
#ifdef SCHEDULER_VERBOSE
503
    printf("cpu%d: tid %d (priority=%d, ticks=%lld, nrdy=%ld)\n",
507
    printf("cpu%d: tid %llu (priority=%d, ticks=%llu, nrdy=%ld)\n",
504
        CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks,
508
        CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks,
505
        atomic_get(&CPU->nrdy));
509
        atomic_get(&CPU->nrdy));
506
#endif  
510
#endif  
507
 
511
 
508
    /*
512
    /*
Line 566... Line 570...
566
 
570
 
567
    /*
571
    /*
568
     * Searching least priority queues on all CPU's first and most priority
572
     * Searching least priority queues on all CPU's first and most priority
569
     * queues on all CPU's last.
573
     * queues on all CPU's last.
570
     */
574
     */
571
    for (j= RQ_COUNT - 1; j >= 0; j--) {
575
    for (j = RQ_COUNT - 1; j >= 0; j--) {
572
        for (i = 0; i < config.cpu_active; i++) {
576
        for (i = 0; i < config.cpu_active; i++) {
573
            link_t *l;
577
            link_t *l;
574
            runq_t *r;
578
            runq_t *r;
575
            cpu_t *cpu;
579
            cpu_t *cpu;
576
 
580
 
Line 607... Line 611...
607
                 * steal threads whose FPU context is still in
611
                 * steal threads whose FPU context is still in
608
                 * CPU.
612
                 * CPU.
609
                 */
613
                 */
610
                spinlock_lock(&t->lock);
614
                spinlock_lock(&t->lock);
611
                if ((!(t->flags & (THREAD_FLAG_WIRED |
615
                if ((!(t->flags & (THREAD_FLAG_WIRED |
612
                    THREAD_FLAG_STOLEN))) &&
616
                    THREAD_FLAG_STOLEN))) &&
613
                    (!(t->fpu_context_engaged)) ) {
617
                    (!(t->fpu_context_engaged))) {
614
                    /*
618
                    /*
615
                     * Remove t from r.
619
                     * Remove t from r.
616
                     */
620
                     */
617
                    spinlock_unlock(&t->lock);
621
                    spinlock_unlock(&t->lock);
618
                   
622
                   
Line 634... Line 638...
634
                /*
638
                /*
635
                 * Ready t on local CPU
639
                 * Ready t on local CPU
636
                 */
640
                 */
637
                spinlock_lock(&t->lock);
641
                spinlock_lock(&t->lock);
638
#ifdef KCPULB_VERBOSE
642
#ifdef KCPULB_VERBOSE
639
                printf("kcpulb%d: TID %d -> cpu%d, nrdy=%ld, "
643
                printf("kcpulb%d: TID %llu -> cpu%d, nrdy=%ld, "
640
                    "avg=%nd\n", CPU->id, t->tid, CPU->id,
644
                    "avg=%nd\n", CPU->id, t->tid, CPU->id,
641
                    atomic_get(&CPU->nrdy),
645
                    atomic_get(&CPU->nrdy),
642
                    atomic_get(&nrdy) / config.cpu_active);
646
                    atomic_get(&nrdy) / config.cpu_active);
643
#endif
647
#endif
644
                t->flags |= THREAD_FLAG_STOLEN;
648
                t->flags |= THREAD_FLAG_STOLEN;
Line 717... Line 721...
717
            }
721
            }
718
            printf("\trq[%d]: ", i);
722
            printf("\trq[%d]: ", i);
719
            for (cur = r->rq_head.next; cur != &r->rq_head;
723
            for (cur = r->rq_head.next; cur != &r->rq_head;
720
                cur = cur->next) {
724
                cur = cur->next) {
721
                t = list_get_instance(cur, thread_t, rq_link);
725
                t = list_get_instance(cur, thread_t, rq_link);
722
                printf("%d(%s) ", t->tid,
726
                printf("%llu(%s) ", t->tid,
723
                    thread_states[t->state]);
727
                    thread_states[t->state]);
724
            }
728
            }
725
            printf("\n");
729
            printf("\n");
726
            spinlock_unlock(&r->lock);
730
            spinlock_unlock(&r->lock);
727
        }
731
        }