Re: PATCH: cdrecord: avoiding scsi device numbering for ide devices

Måns Rullgård
2004-08-11T00:23:44Z

Lee Revell <rlrevell@joe-job.com> writes:

> On Tue, 2004-08-10 at 04:16, Måns Rullgård wrote:
>> Albert Cahalan <albert@users.sf.net> writes:
>>
>> >> Last time I gave
>> >> superuser privilege to cdrecord it locked my machine - clearly it wasn't
>> >> rt_task safe.
>> >
>> > So, you've been working on the scheduler anyway...
>> > An option to reserve some portion of CPU time for
>> > emergency use (say, 5% after 1 second has passed)
>> > would let somebody get out of this situation.
>>
>> Another option would be an Alt-Sysrq-something that lowered all RT
>> processes to normal levels.
>
> I hate to derail a good flame-fest, but this would be extremely useful,
> for more than burning CDs. Anytime you are dealing with a SCHED_FIFO
> process a bug can lock the machine, this would be useful for hacking
> jackd for example.
>
> If someone wants to code this up I and the other people on jackit-devel
> would gladly test it.

Here you go. Some limited testing suggests that it actually works.
Pressing Alt-Sysrq-N (as in Nice) changes all RT tasks to SCHED_NORMAL
policy.

===== drivers/char/sysrq.c 1.29 vs edited =====
--- 1.29/drivers/char/sysrq.c 2004-01-20 00:38:11 +01:00
+++ edited/drivers/char/sysrq.c 2004-08-11 01:41:38 +02:00
@@ -216,6 +216,16 @@

/* END SIGNAL SYSRQ HANDLERS BLOCK */

+static void sysrq_handle_unrt(int key, struct pt_regs *pt_regs,
+ struct tty_struct *tty)
+{
+ normalize_rt_tasks();
+}
+static struct sysrq_key_op sysrq_unrt_op = {
+ .handler = sysrq_handle_unrt,
+ .help_msg = "Nice",
+ .action_msg = "Nice All RT Tasks"
+};

/* Key Operations table and lock */
static spinlock_t sysrq_key_table_lock = SPIN_LOCK_UNLOCKED;
@@ -250,7 +260,7 @@
#endif
/* l */ NULL,
/* m */ &sysrq_showmem_op,
-/* n */ NULL,
+/* n */ &sysrq_unrt_op,
/* o */ NULL, /* This will often be registered
as 'Off' at init time */
/* p */ &sysrq_showregs_op,
===== include/linux/sched.h 1.197 vs edited =====
--- 1.197/include/linux/sched.h 2004-04-27 07:07:44 +02:00
+++ edited/include/linux/sched.h 2004-08-11 01:45:09 +02:00
@@ -944,6 +944,12 @@

#endif /* CONFIG_SMP */

+#ifdef CONFIG_MAGIC_SYSRQ
+
+extern void normalize_rt_tasks(void);
+
+#endif
+
#endif /* __KERNEL__ */

#endif
===== kernel/sched.c 1.261 vs edited =====
--- 1.261/kernel/sched.c 2004-04-27 07:07:43 +02:00
+++ edited/kernel/sched.c 2004-08-11 01:38:00 +02:00
@@ -3053,3 +3053,35 @@

EXPORT_SYMBOL(__preempt_write_lock);
#endif /* defined(CONFIG_SMP) && defined(CONFIG_PREEMPT) */
+
+#ifdef CONFIG_MAGIC_SYSRQ
+void normalize_rt_tasks(void)
+{
+ struct task_struct *p;
+ prio_array_t *array;
+ unsigned long flags;
+ runqueue_t *rq;
+
+ for_each_process (p) {
+ if (!rt_task(p))
+ continue;
+
+ read_lock_irq(&tasklist_lock);
+ rq = task_rq_lock(p, &flags);
+
+ array = p->array;
+ if (array)
+ deactivate_task(p, task_rq(p));
+ __setscheduler(p, SCHED_NORMAL, 0);
+ if (array) {
+ __activate_task(p, task_rq(p));
+ resched_task(rq->curr);
+ }
+
+ task_rq_unlock(rq, &flags);
+ read_unlock_irq(&tasklist_lock);
+ }
+}
+
+EXPORT_SYMBOL(normalize_rt_tasks);
+#endif /* CONFIG_MAGIC_SYSRQ */

--
Måns Rullgård
mru@kth.se