Skip to content

Instantly share code, notes, and snippets.

@zoranzaric
Created March 28, 2010 09:41
Show Gist options
  • Save zoranzaric/346677 to your computer and use it in GitHub Desktop.
Save zoranzaric/346677 to your computer and use it in GitHub Desktop.
GDI3 Kram
T - CPU-Zeit in Sekunden
f - Taktfrequenz in Zyklen pro Sekunde
t - Taktzykluszeit in Sekunden pro Zyklus
MIPS - Millionen von Instruktionen pro Sekunde
CPI - mittlere Anzahl Zyklen pro Instruktion
B - Anzahl Instruktionen
Z - CPU-Zeit in Zyklen
T = Z * t
CPI = Z / (T * MIPS * 10^6)
T = B * CPI / f
B = T * MIPS * 10^6
Z = T * CPI * MIPS * 10^6
Alle Priester saufen Tequila nach der Prädigt
7. Application
6. Presentation
5. Session
4. Transport
3. Network
2. Data
1. Physical
// Andrew S. Tanenbaum: Modern Operating Systems 3e p. 164
#define N 5
#define LEFT (i+N-1)%N
#define RIGHT (i+1)%N
#define THINKING 0
#define HUNGRY 1
#define EATING 2
typedf int semaphore;
int state[N];
semaphore mutex = 1;
semaphore s[N];
void philosopher(int i)
{
while (TRUE) {
think();
take_forks(i);
eat();
put_forks(i);
}
}
void take_forks(int i)
{
down(&mutex);
state[i] = HUNGRY;
test(i);
up(&mutex);
down(&s[i]);
}
void put_forks(i)
{
down(&mutes);
state[i] = THINKING;
test(LEFT);
test(RIGHT);
up(&mutex);
}
void test(i)
{
if (state[i] == HUNGRY && state[LEFT] != EATING && state[RIGHT] != EATING) {
state[i] = EATING;
up(&s[i]);
}
}
josephus:
sub $sp, $sp, 12
sw $ra, 8($sp) #sichere ruecksprungadresse
sw $a1, 4($sp) #sichere K
sw $a0, 0($sp) #sichere N
seq $t0, $a0, 1
beqz $t0, rekursion #N ist != 1, also rekursion
li $v0, 0
jr $ra
rekursion:
sub $a0, $a0, 1 #dekrementiere N um 1
jal josephus
lw $a0, 0($sp) #hole N
lw $a1, 4($sp) #hole K
lw $ra, 8($sp) #hole ruecksprungadresse
add $sp, $sp, 12
2^3 - 8
2^4 - 16
2^5 - 32
2^6 - 64
2^7 - 128
2^8 - 256
2^9 - 512
2^10 - 1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment