Jake Badlands
Jake Badlands

Reputation: 1026

Suspend the program execution until interrupt is handled - how to achieve that?

I have created a kernel module, which handles interrupts. Also, there is a C program.

This program causes interrupts during its execution. When the interrupt is coming, the program should be suspended, and stay suspended - until the interrupt handler in kernel module will finish handling this interrupt.

Please tell me, how to achieve that?

Upvotes: 3

Views: 546

Answers (2)

Barath Ravikumar
Barath Ravikumar

Reputation: 5836

This program causes interrupts during its execution

I assume the User Space program is doing a soft interrupt/system call , and you have edited the kernel system call table , and assigned the number of your custom system call and recompiled and installed the kernel with your custom system call/soft interrupt.

When the interrupt is coming, the program should be suspended, and stay suspended - until the interrupt handler in kernel module will finish handling this interrupt.

For this to happen when your program calls the soft interrupt , you must make your irq , to run atomically , this way , before your program calls another soft interrupt , the previous interrupt would have been handled at a go , without being preempted by any other , higher priority interrupt. To achieve this atomicity , you can use spinlocks in your irq handler.

Example

spinlock_t mLock = SPIN_LOCK_UNLOCK;
unsigned long flags;

spin_lock_irqsave(&mLock, flags); // save the state, if locked already it is saved in flags
// IRQ Handler Code here
spin_unlock_irqsave(&mLock, flags); // return to the formally state specified in flags

Upvotes: 1

Tony The Lion
Tony The Lion

Reputation: 63200

You could wait on a mutex with attribute PTHREAD_PROCESS_SHARED set while your kernel module is doing it's thing, when the kernel module is done, you can signal the mutex so that your process can continue.

To set this you can use pthread_mutexattr_setpshared

There is also this:

For inter-process synchronization, a mutex needs to be allo- cated
in memory shared between these processes. Since the memory for such a mutex must be allocated dynamically, the mutex needs to be explicitly initialized using mutex_init().

Upvotes: 1

Related Questions