# # Lock test -- multiple threads that acquire and release a single lock in # loops. An additional thread does not acquire any locks and outputs a # message per yield. The output of this thread should be interleaved with # those of the others. Should run to completion. # TEST_LOCK_SIZE=256 DRVR_THR_STK_SZ=2048 .data bsy_t0tick: .asciiz "t0 tick\n" .text .globl bsy_t0main bsy_t0main: sub $sp, $sp, 8 sw $ra, 4($sp) move $t0, $zero sw $t0, 8($sp) b bsy_t0test bsy_t0body: la $a0, bsy_t0tick li $v0, 4 syscall jal thr_yield lw $t0, 8($sp) add $t0, $t0, 1 sw $t0, 8($sp) bsy_t0test: blt $t0, 1600, bsy_t0body lw $ra, 4($sp) add $sp, $sp, 8 jr $ra .data .align 2 bsy_lck0: .space TEST_LOCK_SIZE .align 2 bsy_lck1: .space TEST_LOCK_SIZE .text .globl bsy_t1main bsy_t1main: sub $sp, $sp, 8 sw $ra, 4($sp) move $t0, $zero sw $zero, 8($sp) b bsy_t1test bsy_t1body: .data bsy_t1msg1: .asciiz "t1: acquiring 0\n" bsy_t1msg2: .asciiz "t1: got 0, yielding\n" bsy_t1msg3: .asciiz "t1: releasing 0\n" bsy_t1msg4: .asciiz "t1: released 0, yielding\n" .text la $a0, bsy_t1msg1 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_acquire la $a0, bsy_t1msg2 li $v0, 4 syscall jal thr_yield la $a0, bsy_t1msg3 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_release la $a0, bsy_t1msg4 li $v0, 4 syscall jal thr_yield .data bsy_t1msg11: .asciiz "t1: acquiring 1\n" bsy_t1msg21: .asciiz "t1: got 1, yielding\n" bsy_t1msg31: .asciiz "t1: releasing 1\n" bsy_t1msg41: .asciiz "t1: released 1, yielding\n" .text la $a0, bsy_t1msg11 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_acquire la $a0, bsy_t1msg21 li $v0, 4 syscall jal thr_yield la $a0, bsy_t1msg31 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_release la $a0, bsy_t1msg41 li $v0, 4 syscall jal thr_yield lw $t0, 8($sp) add $t0, $t0, 1 sw $t0, 8($sp) bsy_t1test: blt $t0, 256, bsy_t1body lw $ra, 4($sp) add $sp, $sp, 8 jr $ra .globl bsy_t2main bsy_t2main: sub $sp, $sp, 8 sw $ra, 4($sp) move $t0, $zero sw $zero, 8($sp) b bsy_t2test bsy_t2body: .data bsy_t2msg1: .asciiz "t2: acquiring 0\n" bsy_t2msg2: .asciiz "t2: got 0, yielding\n" bsy_t2msg3: .asciiz "t2: releasing 0\n" bsy_t2msg4: .asciiz "t2: released 0, yielding\n" .text jal thr_yield la $a0, bsy_t2msg1 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_acquire la $a0, bsy_t2msg2 li $v0, 4 syscall jal thr_yield la $a0, bsy_t2msg3 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_release la $a0, bsy_t2msg4 li $v0, 4 syscall .data bsy_t2msg11: .asciiz "t2: acquiring 1\n" bsy_t2msg21: .asciiz "t2: got 1, yielding\n" bsy_t2msg31: .asciiz "t2: releasing 1\n" bsy_t2msg41: .asciiz "t2: released 1, yielding\n" .text jal thr_yield la $a0, bsy_t2msg11 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_acquire la $a0, bsy_t2msg21 li $v0, 4 syscall jal thr_yield la $a0, bsy_t2msg31 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_release la $a0, bsy_t2msg41 li $v0, 4 syscall lw $t0, 8($sp) add $t0, $t0, 1 sw $t0, 8($sp) bsy_t2test: blt $t0, 256, bsy_t2body lw $ra, 4($sp) add $sp, $sp, 8 jr $ra .globl bsy_t3main bsy_t3main: sub $sp, $sp, 8 sw $ra, 4($sp) move $t0, $zero sw $zero, 8($sp) b bsy_t3test bsy_t3body: .data bsy_t3msg1: .asciiz "t3: acquiring 0\n" bsy_t3msg2: .asciiz "t3: got 0, yielding\n" bsy_t3msg3: .asciiz "t3: releasing 0\n" bsy_t3msg4: .asciiz "t3: released 0, yielding\n" .text la $a0, bsy_t3msg1 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_acquire la $a0, bsy_t3msg2 li $v0, 4 syscall jal thr_yield jal thr_yield la $a0, bsy_t3msg3 li $v0, 4 syscall la $a0, bsy_lck0 jal lock_release la $a0, bsy_t3msg4 li $v0, 4 syscall jal thr_yield .data bsy_t3msg11: .asciiz "t3: acquiring 1\n" bsy_t3msg21: .asciiz "t3: got 1, yielding\n" bsy_t3msg31: .asciiz "t3: releasing 1\n" bsy_t3msg41: .asciiz "t3: released 1, yielding\n" .text la $a0, bsy_t3msg11 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_acquire la $a0, bsy_t3msg21 li $v0, 4 syscall jal thr_yield jal thr_yield la $a0, bsy_t3msg31 li $v0, 4 syscall la $a0, bsy_lck1 jal lock_release la $a0, bsy_t3msg41 li $v0, 4 syscall jal thr_yield lw $t0, 8($sp) add $t0, $t0, 1 sw $t0, 8($sp) bsy_t3test: blt $t0, 256, bsy_t3body lw $ra, 4($sp) add $sp, $sp, 8 jr $ra # # 8 + 4 * THR_STATE_SIZE + 4 * 4 * 512 # = 8 + 4 * 68 + 4 * 2048 # = 8 + 272 + 8192 # = 8472 # # fp -> t3stk -2044($fp) # t2stk -4092($fp) # t1stk -6140($fp) # t0stk -8188($fp) # t3 -8488($fp) 300 byte states # t2 -8788($fp) # t1 -9088($fp) # t0 -9388($fp) # old-ra -9392($fp) # old-fp -9396($fp) # sp -> main: subu $sp, $sp, 9400 sw $fp, 4($sp) sw $ra, 8($sp) addu $fp, $sp, 9400 li $t0, 2048 subu $sp, $sp, 4 sw $t0, 4($sp) # push shared 4th arg la $a3, -8188($fp) li $a2, 0 la $a1, bsy_t0main la $a0, -9388($fp) jal thr_init la $a3, -6140($fp) li $a2, 0 la $a1, bsy_t1main la $a0, -9088($fp) jal thr_init la $a3, -4092($fp) li $a2, 1 la $a1, bsy_t2main la $a0, -8788($fp) jal thr_init la $a3, -2044($fp) li $a2, 2 la $a1, bsy_t3main la $a0, -8488($fp) jal thr_init addu $sp, $sp, 4 # pop shared 4th arg la $a0, bsy_lck0 jal lock_init la $a0, bsy_lck1 jal lock_init jal thr_go .data bsy_done_msg: .asciiz "All done!\n" .text la $a0, bsy_done_msg li $v0, 4 syscall lw $ra, -9392($fp) lw $fp, -9396($fp) addu $sp, $sp, 9400 jr $ra