Subversion Repositories HelenOS

Rev

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

Rev 906 Rev 907
Line 94... Line 94...
94
}
94
}
95
 
95
 
96
#ifdef CONFIG_FPU_LAZY
96
#ifdef CONFIG_FPU_LAZY
97
void scheduler_fpu_lazy_request(void)
97
void scheduler_fpu_lazy_request(void)
98
{
98
{
-
 
99
restart:
99
    fpu_enable();
100
    fpu_enable();
100
    spinlock_lock(&CPU->lock);
101
    spinlock_lock(&CPU->lock);
101
 
102
 
102
    /* Save old context */
103
    /* Save old context */
103
    if (CPU->fpu_owner != NULL) {  
104
    if (CPU->fpu_owner != NULL) {  
104
        spinlock_lock(&CPU->fpu_owner->lock);
105
        spinlock_lock(&CPU->fpu_owner->lock);
105
        fpu_context_save(CPU->fpu_owner->saved_fpu_context);
106
        fpu_context_save(CPU->fpu_owner->saved_fpu_context);
106
        /* don't prevent migration */
107
        /* don't prevent migration */
107
        CPU->fpu_owner->fpu_context_engaged=0;
108
        CPU->fpu_owner->fpu_context_engaged=0;
108
        spinlock_unlock(&CPU->fpu_owner->lock);
109
        spinlock_unlock(&CPU->fpu_owner->lock);
-
 
110
        CPU->fpu_owner = NULL;
109
    }
111
    }
110
 
112
 
111
    spinlock_lock(&THREAD->lock);
113
    spinlock_lock(&THREAD->lock);
112
    if (THREAD->fpu_context_exists) {
114
    if (THREAD->fpu_context_exists) {
113
        fpu_context_restore(THREAD->saved_fpu_context);
115
        fpu_context_restore(THREAD->saved_fpu_context);
114
    } else {
116
    } else {
115
        /* Allocate FPU context */
117
        /* Allocate FPU context */
116
        if (!THREAD->saved_fpu_context) {
118
        if (!THREAD->saved_fpu_context) {
117
            /* Might sleep */
119
            /* Might sleep */
118
            spinlock_unlock(&THREAD->lock);
120
            spinlock_unlock(&THREAD->lock);
-
 
121
            spinlock_unlock(&CPU->lock);
119
            THREAD->saved_fpu_context = slab_alloc(fpu_context_slab,
122
            THREAD->saved_fpu_context = slab_alloc(fpu_context_slab,
120
                                   0);
123
                                   0);
121
            spinlock_lock(&THREAD->lock);
124
            /* We may have switched CPUs during slab_alloc */
-
 
125
            goto restart;
122
        }
126
        }
123
        fpu_init();
127
        fpu_init();
124
        THREAD->fpu_context_exists=1;
128
        THREAD->fpu_context_exists=1;
125
    }
129
    }
126
    CPU->fpu_owner=THREAD;
130
    CPU->fpu_owner=THREAD;