Skip to contentSkip to conversation

Porting intLock()

DISCUSSION Morten Mossige 4 participants 5 messages Oct 4, 2007 – Oct 10, 2007

lore
Share & tools
lore
#0 lore raw

Hi
I'm porting an application from another realtime-os to Linux. This application makes use of intLock() from time to time. I still need the the application to be compilable on both Linux and my old os, so I need a portabel intLock()
I have tried the following approach:
When a thread needs to do intLock, I boost the thread-pri to max, and when the thread does intUnLock() I set the thread-pri back. This woorks quite ok, but by using this approach, I will also lock other threads in other applications running on Linux.
What I really need is a way of blocking all other threads in my application, without affecting other applications.
I know I can use mutex'es and semaphores, but that will require a major rewriting of the application, and that is somthing I dont want to do. Can someone come up with an idea how this is done best?
Morten

#1 lore raw

--

Quoted 8 lines · Morten Mossige

Hi
I'm porting an application from another realtime-os to Linux. This application makes use of intLock() from time to time. I still need the the application to be compilable on both Linux and my old os, so I need a portabel intLock()
I have tried the following approach:
When a thread needs to do intLock, I boost the thread-pri to max, and when the thread does intUnLock() I set the thread-pri back. This woorks quite ok,

Quoted 8 lines

but by using this approach, I will also lock other threads in other applications running on Linux.
What I really need is a way of blocking all other threads in my application, without affecting other applications.
I know I can use mutex'es and semaphores, but that will require a major rewriting of the application, and that is somthing I dont want to do. Can someone come up with an idea how this is done best?
Morten

Upping the prio is basically what intLock does really. That is upping it over the priority of interrupts, which would also mean that you would not be preempted. So by increasing the prio to max, you have in essence locked out all interrupts from that CPU, as well as other tasks. So just doing for you application doesn't make sense. Note, the timer interrupt will still go off.

Without knowing more about you application, we really cant give much more advice.

#2 lore raw
In reply to Morten Mossige

Hello Morten,

Quoted 8 lines · Morten Mossige

Hi
I'm porting an application from another realtime-os to Linux. This application makes use of intLock() from time to time. I still need the the application to be compilable on both Linux and my old os, so I need a portabel intLock()
I have tried the following approach:
When a thread needs to do intLock, I boost the thread-pri to max, and when the thread does intUnLock() I set the thread-pri back. This woorks quite ok,

I think your approach is good if it is working.

Quoted 2 lines

but by using this approach, I will also lock other threads in other applications running on Linux.

Someone has to pay. If you are boosting someone on the same time you are also suppressing others, this is how real-time works.

Quoted 2 lines

What I really need is a way of blocking all other threads in my application, without affecting other applications.

If you block other applications they will be affected. No solution for this.

Jaswinder Singh.

Quoted 12 lines

I know I can use mutex'es and semaphores, but that will require a major rewriting of the application, and that is somthing I dont want to do. Can someone come up with an idea how this is done best? Morten

-
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Morten Mossige
Quoted 8 lines · Morten Mossige

Hi
I'm porting an application from another realtime-os to Linux. This application makes use of intLock() from time to time. I still need the the application to be compilable on both Linux and my old os, so I need a portabel intLock()
I have tried the following approach:
When a thread needs to do intLock, I boost the thread-pri to max, and when the thread does intUnLock() I set the thread-pri back. This woorks quite ok,

but only on UP machines. On SMP machines you get into trouble.

Quoted 2 lines

but by using this approach, I will also lock other threads in other applications running on Linux.

That is a side effect of intLock(), too.
But intLock/intUnlock are relatively cheap operations. pthread_setschedprio() is expensive because it involves a system call.

Quoted 2 lines

What I really need is a way of blocking all other threads in my application, without affecting other applications.

Are you sure you need to prevent all other threads from preempting the current one? Isn't it just a cheap way of implementing a mutex?

Quoted 3 lines

I know I can use mutex'es and semaphores, but that will require a major rewriting of the application, and that is somthing I dont want to do. Can someone come up with an idea how this is done best?

The code paths sharing the data you need to protect via intLock should also have intLock/intUnlock around them or being interrupthandlers in the original application. What about having a global "interrupt_mutex" and make two functions

int intLock()
{
pthread_mutex_lock(&interrupt_mutex);
return 0;
}

void intUnlock(int level)
{
pthread_mutex_unlock(&interrupt_mutex);
return 0;
}

and put in extra intLock/intUnlock around the original interrupthandlers.

Esben

Quoted 9 lines

Morten

-
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

"Esben Nielsen" <[email protected]> skrev i melding news:[email protected]...

Quoted 51 lines · Morten Mossige
Quoted 12 lines

Hi
I'm porting an application from another realtime-os to Linux. This application makes use of intLock() from time to time. I still need the the
application to be compilable on both Linux and my old os, so I need a portabel intLock()
I have tried the following approach:
When a thread needs to do intLock, I boost the thread-pri to max, and when
the thread does intUnLock() I set the thread-pri back. This woorks quite ok,

but only on UP machines. On SMP machines you get into trouble.

Quoted 2 lines

but by using this approach, I will also lock other threads in other applications running on Linux.

That is a side effect of intLock(), too.
But intLock/intUnlock are relatively cheap operations. pthread_setschedprio() is expensive because it involves a system call.

Quoted 3 lines

What I really need is a way of blocking all other threads in my application,
without affecting other applications.

Are you sure you need to prevent all other threads from preempting the current one? Isn't it just a cheap way of implementing a mutex?

Quoted 3 lines

I know I can use mutex'es and semaphores, but that will require a major rewriting of the application, and that is somthing I dont want to do. Can someone come up with an idea how this is done best?

The code paths sharing the data you need to protect via intLock should also have intLock/intUnlock around them or being interrupthandlers in the original application. What about having a global "interrupt_mutex" and make two functions

int intLock()
{
pthread_mutex_lock(&interrupt_mutex);
return 0;
}

void intUnlock(int level)
{
pthread_mutex_unlock(&interrupt_mutex);
return 0;
}

Quoted 15 lines

and put in extra intLock/intUnlock around the original interrupthandlers.

Esben

Quoted 10 lines

Morten

-
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Tnx for many good recommendations about porting intLock/unLock. Currently I'm using priboost, and that works for my application, but I will look into implementing the lock with a mutex later.

Morten