public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mru@inprovide.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] SysRq-n changes RT tasks to normal
Date: Fri, 29 Oct 2004 13:25:48 +0200	[thread overview]
Message-ID: <yw1xy8hpix4z.fsf@inprovide.com> (raw)

This makes SysRq-n change all RT tasks into normal tasks.  Useful for
regaining control if an RT task is behaving badly.

Signed-off-by: Måns Rullgård <mru@inprovide.com>

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/10/09 12:44:26+02:00 mru@ford.(none) 
#   sysrq-n changes all RT tasks into normally scheduled tasks
#   this is useful in case an RT task is misbehaving
# 
# kernel/sched.c
#   2004/10/09 12:44:13+02:00 mru@ford.(none) +32 -0
#   normalize_rt_tasks() converts all RT tasks into normal tasks
# 
# include/linux/sched.h
#   2004/10/09 12:44:13+02:00 mru@ford.(none) +6 -0
#   prototype for normalize_rt_tasks()
# 
# drivers/char/sysrq.c
#   2004/10/09 12:44:13+02:00 mru@ford.(none) +11 -1
#   sysrq-n calls normalize_rt_tasks()
# 
diff -Nru a/drivers/char/sysrq.c b/drivers/char/sysrq.c
--- a/drivers/char/sysrq.c	2004-10-29 13:19:05 +02:00
+++ b/drivers/char/sysrq.c	2004-10-29 13:19:05 +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,
diff -Nru a/include/linux/sched.h b/include/linux/sched.h
--- a/include/linux/sched.h	2004-10-29 13:19:05 +02:00
+++ b/include/linux/sched.h	2004-10-29 13:19:05 +02:00
@@ -1027,6 +1027,12 @@
 extern long sched_setaffinity(pid_t pid, cpumask_t new_mask);
 extern long sched_getaffinity(pid_t pid, cpumask_t *mask);
 
+#ifdef CONFIG_MAGIC_SYSRQ
+
+extern void normalize_rt_tasks(void);
+
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif
diff -Nru a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c	2004-10-29 13:19:05 +02:00
+++ b/kernel/sched.c	2004-10-29 13:19:05 +02:00
@@ -4767,3 +4767,35 @@
 }
 EXPORT_SYMBOL(__might_sleep);
 #endif
+
+#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@inprovide.com

             reply	other threads:[~2004-10-29 11:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-29 11:25 Måns Rullgård [this message]
2004-10-29 11:34 ` [PATCH] SysRq-n changes RT tasks to normal Ingo Molnar
2004-10-29 11:51   ` Måns Rullgård
2004-10-29 12:30     ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xy8hpix4z.fsf@inprovide.com \
    --to=mru@inprovide.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox