Subject: [PATCH] preallocate signal queue resource - Posix timers
Reply-to: [email protected]
--text follows this line--
Hi Linus, Everyone,
Please consider applying this patch.
The attached patch adds a new interface to kernel/signal.c which allows signals to be sent using preallocated sigqueue structures. It also modifies kernel/posix-timers.c to use this interface. The patch is against linux-2.5.70.
The current timer code may fail to deliver a timer expiry signal if there are no sigqueue structures available at the time of the expiry. The Posix specification is clear that the signal queuing resource should be allocated at timer_create time. This allows the error to be returned to the application rather than silently losing the signal.
This patch does not change the sigqueue structure allocation policy. I hope to revisit that in another patch.
Here is the definition for the new interface:
struct sigqueue *sigqueue_alloc(void)
Preallocate a sigqueue structure for use with the functions described below.
void sigqueue_free(struct sigqueue *q)
Free a preallocated sigqueue structure. If the sigqueue structure being freed is still queued, it will be removed from the queue. I currently leave the signal pending. It may be delivered without the siginfo structure.
int send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
This function is equivalent to send_sig_info(). It queues a signal to the specified thread using the supplied sigqueue structure. The caller is expected to fill in the siginfo_t which is part of the sigqueue structure.
int send_group_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
This function is equivalent to send_group_sig_info(). It queues the signal to a process allowing the system to select which thread will receive the signal in a multi-threaded process. Again, the sigqueue structure is used to queue the signal.
Both send_sigqueue() and send_group_sigqueue() return 0 if the signal is queued. They return 1 if the signal was not queued because the process is ignoring the signal.
Both versions include code to increment the si_overrun count if the sigqueue entry is for a Posix timer and they are called while the sigqueue entry is still queued. Yes, I know that the current code doesn't rearm the timer until the signal is delivered. Having this extra bit of code doesn't do any harm, and I plan to use it.
These routines do not check if there already is a legacy (non-realtime) signal pending. They always queue the signal. This requires that collect_signal() always checks if there is another matching siginfo before clearing the signal bit.
Jim Houston - Concurrent Computer Corp.
--
include/linux/init_task.h +7 -3
@@ -45,7 +45,9 @@#define INIT_SIGNALS (sig) { \ .count = ATOMIC_INIT(1), \ - .shared_pending = { NULL, &sig.shared_pending.head, {{0}}}, \ + .shared_pending = { \ + .list = LIST_HEAD_INIT(sig.shared_pending.list), \ + .signal = {{0}}}, \ }#define INIT_SIGHAND (sighand) { \
@@ -97,9 +99,11 @@ .files = &init_files, \ .signal = &init_signals, \ .sighand = &init_sighand, \ - .pending = { NULL, &tsk.pending.head, {{0}}}, \ + .pending = { \ + .list = LIST_HEAD_INIT(tsk.pending.list), \ + .signal = {{0}}}, \ .blocked = {{0}}, \ - .posix_timers = LIST_HEAD_INIT(tsk.posix_timers), \ + .posix_timers = LIST_HEAD_INIT(tsk.posix_timers), \ .alloc_lock = SPIN_LOCK_UNLOCKED, \ .proc_lock = SPIN_LOCK_UNLOCKED, \ .switch_lock = SPIN_LOCK_UNLOCKED, \
include/linux/sched.h +5 -0
@@ -317,6 +317,7 @@unsigned long it_incr;/* interval specified in jiffies */ struct task_struct *it_process;/* process to send signal to */ struct timer_list it_timer; +struct sigqueue *sigq;/* signal queue entry. */ };
@@ -571,6 +572,10 @@extern int kill_pg (pid_t ,int ,int );extern int kill_sl (pid_t ,int ,int );extern int kill_proc (pid_t ,int ,int ); +extern struct sigqueue *sigqueue_alloc (void ); +extern void sigqueue_free (struct sigqueue *); +extern int send_sigqueue (int ,struct sigqueue *,struct task_struct *); +extern int send_group_sigqueue (int ,struct sigqueue *,struct task_struct *);extern int do_sigaction (int ,const struct k_sigaction *,struct k_sigaction *);extern int do_sigaltstack (const stack_t __user *,stack_t __user *,unsigned long );
include/linux/signal.h +9 -4
@@ -3,6 +3,7 @@#include <asm/signal.h> #include <asm/siginfo.h> +#include <linux/list.h> #ifdef __KERNEL__/*
@@ -10,12 +11,17 @@*/ struct sigqueue { -struct sigqueue *next; +struct list_head list; +spinlock_t *lock; +int flags;siginfo_t info; }; +/* flags values. */ +#define SIGQUEUE_PREALLOC 1 +struct sigpending { -struct sigqueue *head, **tail; +struct list_head list;sigset_t signal; };
@@ -197,8 +203,7 @@static inline void init_sigpending (struct sigpending *sig) {sigemptyset (&sig->signal); - sig->head =NULL ; - sig->tail = &sig->head; +INIT_LIST_HEAD (&sig->list); }extern long do_sigpending (void __user *,unsigned long );
kernel/posix-timers.c +19 -28
78 lines not on this page · raw message
kernel/signal.c +259 -102
460 lines not on this page · raw message