Rev 3539 | Rev 3617 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3539 | Rev 3615 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 3539 $ |
8 | $Revision: 3615 $ |
9 | 9 | ||
10 | 10 | ||
Line 29... | Line 29... | ||
29 | .nocounter: |
29 | .nocounter: |
30 | xor ecx, ecx ; send End Of Interrupt signal |
30 | xor ecx, ecx ; send End Of Interrupt signal |
31 | call irq_eoi |
31 | call irq_eoi |
32 | ; btr dword[DONT_SWITCH], 0 |
32 | ; btr dword[DONT_SWITCH], 0 |
33 | ; jc .return |
33 | ; jc .return |
- | 34 | mov bl, SCHEDULE_ANY_PRIORITY |
|
34 | call find_next_task |
35 | call find_next_task |
35 | jz .return ; if there is only one running process |
36 | jz .return ; if there is only one running process |
36 | call do_change_task |
37 | call do_change_task |
37 | .return: |
38 | .return: |
38 | popad |
39 | popad |
Line 56... | Line 57... | ||
56 | mov [TASK_BASE], edi |
57 | mov [TASK_BASE], edi |
57 | jmp @f |
58 | jmp @f |
58 | .find_next_task: |
59 | .find_next_task: |
59 | ; \end{Mario79} |
60 | ; \end{Mario79} |
60 | end if |
61 | end if |
- | 62 | mov bl, SCHEDULE_ANY_PRIORITY |
|
61 | call find_next_task |
63 | call find_next_task |
62 | jz .return ; the same task -> skip switch |
64 | jz .return ; the same task -> skip switch |
63 | @@: |
65 | @@: |
64 | ; mov byte[DONT_SWITCH], 1 |
66 | ; mov byte[DONT_SWITCH], 1 |
65 | call do_change_task |
67 | call do_change_task |
Line 322... | Line 324... | ||
322 | ; 4. Release the lock and return. |
324 | ; 4. Release the lock and return. |
323 | spin_unlock_irqrestore SchedulerLock |
325 | spin_unlock_irqrestore SchedulerLock |
324 | ret |
326 | ret |
325 | endp |
327 | endp |
Line -... | Line 328... | ||
- | 328 | ||
- | 329 | SCHEDULE_ANY_PRIORITY = 0 |
|
326 | 330 | SCHEDULE_HIGHER_PRIORITY = 1 |
|
327 | ;info: |
331 | ;info: |
- | 332 | ; Find next task to execute |
|
- | 333 | ;in: |
|
- | 334 | ; bl = SCHEDULE_ANY_PRIORITY: |
|
- | 335 | ; consider threads with any priority |
|
- | 336 | ; bl = SCHEDULE_HIGHER_PRIORITY: |
|
- | 337 | ; consider only threads with strictly higher priority than the current one, |
|
328 | ; Find next task to execute |
338 | ; keep running the current thread if other ready threads have the same or lower priority |
329 | ;retval: |
339 | ;retval: |
330 | ; ebx = address of the APPDATA for the selected task (slot-base) |
340 | ; ebx = address of the APPDATA for the selected task (slot-base) |
331 | ; edi = address of the TASKDATA for the selected task |
341 | ; edi = address of the TASKDATA for the selected task |
332 | ; ZF = 1 if the task is the same |
342 | ; ZF = 1 if the task is the same |
Line 335... | Line 345... | ||
335 | ; [current_slot] is not set to new value (ebx)!!! |
345 | ; [current_slot] is not set to new value (ebx)!!! |
336 | ;scratched: eax,ecx |
346 | ;scratched: eax,ecx |
337 | proc find_next_task |
347 | proc find_next_task |
338 | call update_counters |
348 | call update_counters |
339 | spin_lock_irqsave SchedulerLock |
349 | spin_lock_irqsave SchedulerLock |
- | 350 | push NR_SCHED_QUEUES |
|
- | 351 | ; If bl == SCHEDULE_ANY_PRIORITY = 0, loop over all NR_SCHED lists. |
|
- | 352 | ; Otherwise, loop over first [APPDATA.priority] lists. |
|
- | 353 | test bl, bl |
|
- | 354 | jz .start |
|
- | 355 | mov ebx, [current_slot] |
|
- | 356 | mov edi, [TASK_BASE] |
|
- | 357 | mov eax, [ebx+APPDATA.priority] |
|
- | 358 | test eax, eax |
|
- | 359 | jz .unlock_found |
|
- | 360 | mov [esp], eax |
|
- | 361 | .start: |
|
340 | xor ecx, ecx |
362 | xor ecx, ecx |
341 | .priority_loop: |
363 | .priority_loop: |
342 | mov ebx, [scheduler_current+ecx*4] |
364 | mov ebx, [scheduler_current+ecx*4] |
343 | test ebx, ebx |
365 | test ebx, ebx |
344 | jz .priority_next |
366 | jz .priority_next |
Line 368... | Line 390... | ||
368 | @@: |
390 | @@: |
369 | mov [ebx+APPDATA.wait_param], eax ; retval for wait |
391 | mov [ebx+APPDATA.wait_param], eax ; retval for wait |
370 | mov [edi+TASKDATA.state], 0 |
392 | mov [edi+TASKDATA.state], 0 |
371 | .task_found: |
393 | .task_found: |
372 | mov [scheduler_current+ecx*4], ebx |
394 | mov [scheduler_current+ecx*4], ebx |
- | 395 | .unlock_found: |
|
- | 396 | pop ecx |
|
373 | spin_unlock_irqrestore SchedulerLock |
397 | spin_unlock_irqrestore SchedulerLock |
374 | .found: |
398 | .found: |
375 | mov [CURRENT_TASK], bh |
399 | mov [CURRENT_TASK], bh |
376 | mov [TASK_BASE], edi |
400 | mov [TASK_BASE], edi |
377 | rdtsc ;call _rdtsc |
401 | rdtsc ;call _rdtsc |
Line 381... | Line 405... | ||
381 | .task_next: |
405 | .task_next: |
382 | cmp ebx, [scheduler_current+ecx*4] |
406 | cmp ebx, [scheduler_current+ecx*4] |
383 | jnz .task_loop |
407 | jnz .task_loop |
384 | .priority_next: |
408 | .priority_next: |
385 | inc ecx |
409 | inc ecx |
386 | cmp ecx, NR_SCHED_QUEUES |
410 | cmp ecx, [esp] |
387 | jb .priority_loop |
411 | jb .priority_loop |
388 | hlt |
412 | mov ebx, [current_slot] |
- | 413 | mov edi, [TASK_BASE] |
|
389 | jmp $-1 |
414 | jmp .unlock_found |
390 | endp |
415 | endp |
Line 391... | Line 416... | ||
391 | 416 | ||
Line 392... | Line 417... | ||
392 | if 0 |
417 | if 0 |