Combuster:
Thank you soo much. You have given me enough a ton of excellent information! Ill be busy for weeks!
Thanks again,
Rich
Mutex Implementation.
My fetch and increment:
Looks ok right?
It seems to be working.
If I do:
Thanks,
Rich
Code: Select all
unsigned long fetch_and_increment(volatile unsigned long *mem)
{
unsigned long val = 1;
asm volatile ("lock; xadd %1, (%2)"
: "=r"(val)
: "r"(val), "r"(mem)
: "%1","memory");
return val;
}
It seems to be working.
If I do:
Code: Select all
int a =0;
fetch_and_increment(&a); // Returns 0
fetch_and_increment(&a); // Returns 1
fetch_and_increment(&a); // Returns 2
Rich
So... no... there not working...
At first I tried to use a struct per mutex... and failed miserably...
Now I am try something much simpler:
It runs for a brief while giving and closing tickets... but it usually locks up pretty quick...
After about 10 - 100 tickets...
However, I actually think that the tickets are all on the same thread and after the switch the switch it blows up. Ignore the function headers the volatile mutex_t mt was for something else I was testing and failed... Also if I turn entries and exits volatile, I get two grabs for ticket 1 and no exits...
If you think it matters, I post my scheduler code... but I am attaching screen shots of the output.
Thanks,
Rich
At first I tried to use a struct per mutex... and failed miserably...
Now I am try something much simpler:
Code: Select all
unsigned long fetch_and_increment(volatile unsigned long *mem)
{
unsigned long val = 1;
asm volatile ("lock; xadd %1, (%2)"
: "=r"(val)
: "r"(val), "r"(mem)
: "%1","memory");
return val;
}
int entries = 0;
int exits = 0;
void mutex_lock(volatile mutex_t mt)
{
int ticket = fetch_and_increment(&entries);
kprintf("GOT TICKET: %d\n",ticket);
while (ticket != exits)
{
//schedule(); // or anything else you can do while waiting for your turn
}
}
void mutex_unlock(volatile mutex_t mt)
{
exits = exits + 1;
kprintf("MADE EXIT: %d\n",exits);
}
After about 10 - 100 tickets...
However, I actually think that the tickets are all on the same thread and after the switch the switch it blows up. Ignore the function headers the volatile mutex_t mt was for something else I was testing and failed... Also if I turn entries and exits volatile, I get two grabs for ticket 1 and no exits...
If you think it matters, I post my scheduler code... but I am attaching screen shots of the output.
Thanks,
Rich
- Attachments
-
- Tickets with out volatile.
- crazy tickets.jpg (47.36 KiB) Viewed 4715 times
-
- Tickets WITH volatile.
- volatile tickets.jpg (69.93 KiB) Viewed 4714 times