atomic system calls
atomic system calls
hi
all system calls must be executed atomically. but how can i do this in multiprocessor system?
(in single processor systems I do it whit disabling interrupts) but what can i do for multiprocessor systems?
all system calls must be executed atomically. but how can i do this in multiprocessor system?
(in single processor systems I do it whit disabling interrupts) but what can i do for multiprocessor systems?
Re: atomic system calls
yes
i implement spin-locks in my OS.
using same lock for all system calls and scheduler or spreate spinlocks for any system call?
sorry for my bad english
i implement spin-locks in my OS.
using same lock for all system calls and scheduler or spreate spinlocks for any system call?
sorry for my bad english
Re: atomic system calls
No. Neither is correct. Spinlocks should be used to protect data, not code. Therefore you should be protecting the kernel data structures, not kernel code paths. You need a spinlock for each piece of data that might be shared. You need to design your kernel data structures so that sharing is minimised because, in practice, contended spinlocks kill performance.Megan65 wrote:yes
i implement spin-locks in my OS.
using same lock for all system calls and scheduler or spreate spinlocks for any system call?
sorry for my bad english
If a trainstation is where trains stop, what is a workstation ?
Re: atomic system calls
my problem is in implementing semaphores and mutexes
this my code for semaphore:
semaphore_down function muse be atomic and i protect it with a spinlocks but i must unlock spinlock before switching task and this is wrong. what can i do for this function. how can i guarantee that this system call dose not interrupted by scheduler?
this my code for semaphore:
Code: Select all
// semaphore_down
void semaphore_down( semaphore_t* _sem )
{
spin_lock( &_sem->lock );
_sem->res_count--;
if ( _sem->res_count < 0 )
{
queue_push( _sem->queue, (void*)g_pCurTask );
spin_unlock( &_sem->lock );
change_task_state( g_pCurTask, ETS_BLOCKED );
switch_task();
return;
}
spin_unlock( &_sem->lock );
}
Re: atomic system calls
Why did you waste time (of Berkus and I) by not saying that in the first post ?my problem is in implementing semaphores and mutexes
If a trainstation is where trains stop, what is a workstation ?
Re: atomic system calls
problem is in implementing atomic semaphore down and up and atomic system calls.
sorryWhy did you waste time (of Berkus and I) by not saying that in the first post ?
Re: atomic system calls
The code looks okay to me. I'm not sure I understand your problem.
If a trainstation is where trains stop, what is a workstation ?
Re: atomic system calls
my semaphores implementation can not protect critical regions. i don't understand where is problem. can u check my code (about two months i work on it but i cant find problem):The code looks okay to me. I'm not sure I understand your problem.
http://arax.svn.sourceforge.net
Re: atomic system calls
I reckon it might be useful to actually explain the problem, before you expect people to read through your source code...
Re: atomic system calls
Hi,
The problem:
One solution:
Another solution:
These probably aren't the only possible solutions.
Cheers,
Brendan
The problem:
Code: Select all
// semaphore_down
void semaphore_down( semaphore_t* _sem )
{
spin_lock( &_sem->lock );
_sem->res_count--;
if ( _sem->res_count < 0 )
{
queue_push( _sem->queue, (void*)g_pCurTask );
spin_unlock( &_sem->lock );
/*** Another CPU could unblock this task here, before it has blocked. This ***/
/*** would lead to deadlock (tasks waiting for something that they already have) ***/
change_task_state( g_pCurTask, ETS_BLOCKED );
switch_task();
return;
}
spin_unlock( &_sem->lock );
}
Code: Select all
// semaphore_down
void semaphore_down( semaphore_t* _sem )
{
spin_lock( &_sem->lock );
_sem->res_count--;
if ( _sem->res_count < 0 )
{
queue_push( _sem->queue, (void*)g_pCurTask );
spin_lock( &scheduler_lock );
spin_unlock( &_sem->lock );
change_task_state( g_pCurTask, ETS_BLOCKED );
switch_task_and_unlock_scheduler_lock();
return;
}
spin_unlock( &_sem->lock );
}
Code: Select all
// semaphore_down
void semaphore_down( semaphore_t* _sem )
{
spin_lock( &_sem->lock );
_sem->res_count--;
if ( _sem->res_count < 0 )
{
queue_push( _sem->queue, (void*)g_pCurTask );
change_task_state( g_pCurTask, ETS_BLOCKED );
switch_task_and_unlock( &_sem->lock );
return;
}
spin_unlock( &_sem->lock );
}
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: atomic system calls
@Brendan:
thank you problem solved
thank you problem solved