From: Robert Love <rml@tech9.net>
To: jgarzik@pobox.com, hch@infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] set_cpus_allowed() for 2.4
Date: 01 Oct 2002 19:03:28 -0400 [thread overview]
Message-ID: <1033513407.12959.91.camel@phantasy> (raw)
The following patch implements set_cpus_allowed() for stock 2.4 without
the O(1) scheduler.
The calling semantics and behavior remain the same as 2.5's method.
This is to provide a backward-compatible interface, specifically for
those interested in back-porting the new workqueue code to 2.4 -
set_cpus_allowed() seems to be the only nit preventing a straight
drop-in.
Patch is against 2.4.20-pre8 and untested but does compile.
Robert Love
diff -urN linux-2.4.20-pre8/include/linux/sched.h linux/include/linux/sched.h
--- linux-2.4.20-pre8/include/linux/sched.h Mon Sep 30 17:41:22 2002
+++ linux/include/linux/sched.h Tue Oct 1 18:35:28 2002
@@ -163,6 +164,12 @@
extern int start_context_thread(void);
extern int current_is_keventd(void);
+#if CONFIG_SMP
+extern void set_cpus_allowed(struct task_struct *p, unsigned long new_mask);
+#else
+# define set_cpus_allowed(p, new_mask) do { } while (0)
+#endif
+
/*
* The default fd array needs to be at least BITS_PER_LONG,
* as this is the granularity returned by copy_fdset().
diff -urN linux-2.4.20-pre8/kernel/ksyms.c linux/kernel/ksyms.c
--- linux-2.4.20-pre8/kernel/ksyms.c Mon Sep 30 17:41:22 2002
+++ linux/kernel/ksyms.c Tue Oct 1 18:34:41 2002
@@ -451,6 +451,9 @@
EXPORT_SYMBOL(interruptible_sleep_on_timeout);
EXPORT_SYMBOL(schedule);
EXPORT_SYMBOL(schedule_timeout);
+#if CONFIG_SMP
+EXPORT_SYMBOL(set_cpus_allowed);
+#endif
EXPORT_SYMBOL(yield);
EXPORT_SYMBOL(__cond_resched);
EXPORT_SYMBOL(jiffies);
diff -urN linux-2.4.20-pre8/kernel/sched.c linux/kernel/sched.c
--- linux-2.4.20-pre8/kernel/sched.c Mon Sep 30 17:41:22 2002
+++ linux/kernel/sched.c Tue Oct 1 18:54:49 2002
@@ -850,6 +850,46 @@
void scheduling_functions_end_here(void) { }
+#if CONFIG_SMP
+
+/**
+ * set_cpus_allowed() - change a given task's processor affinity
+ * @p: task to bind
+ * @new_mask: bitmask of allowed processors
+ *
+ * Upon return, the task is running on a legal processor. Note the caller
+ * must have a valid reference to the task: it must not exit() prematurely.
+ * This call can sleep; do not hold locks on call.
+ */
+void set_cpus_allowed(struct task_struct *p, unsigned long new_mask)
+{
+ new_mask &= cpu_online_map;
+ BUG_ON(!new_mask);
+
+ p->cpus_allowed = new_mask;
+
+ /*
+ * If the task is on a no-longer-allowed processor, we need to move
+ * it. If the task is not current, then set need_resched and send
+ * its processor an IPI to reschedule.
+ */
+ if (!(p->cpus_runnable & p->cpus_allowed)) {
+ if (p != current) {
+ p->need_resched = 1;
+ smp_send_reschedule(p->processor);
+ }
+ /*
+ * Wait until we are on a legal processor. If the task is
+ * current, then we should be on a legal processor the next
+ * time we reschedule. Otherwise, we need to wait for the IPI.
+ */
+ while (!(p->cpus_runnable & p->cpus_allowed))
+ schedule();
+ }
+}
+
+#endif /* CONFIG_SMP */
+
#ifndef __alpha__
/*
diff -urN linux-2.4.20-pre8/kernel/softirq.c linux/kernel/softirq.c
--- linux-2.4.20-pre8/kernel/softirq.c Mon Sep 30 17:41:22 2002
+++ linux/kernel/softirq.c Tue Oct 1 18:53:01 2002
@@ -368,9 +368,8 @@
sigfillset(¤t->blocked);
/* Migrate to the right CPU */
- current->cpus_allowed = 1UL << cpu;
- while (smp_processor_id() != cpu)
- schedule();
+ set_cpus_allowed(current, 1UL << cpu);
+ BUG_ON(smp_processor_id() != cpu);
sprintf(current->comm, "ksoftirqd_CPU%d", bind_cpu);
next reply other threads:[~2002-10-01 22:58 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-01 23:03 Robert Love [this message]
2002-10-02 13:01 ` [PATCH] set_cpus_allowed() for 2.4 Christoph Hellwig
2002-10-02 15:00 ` Robert Love
2002-11-05 3:37 ` Christoph Hellwig
2002-11-06 15:32 ` Adrian Bunk
2002-11-07 21:42 ` Christoph Hellwig
2002-12-02 17:12 ` Mikael Pettersson
2002-12-03 0:51 ` Christoph Hellwig
2002-12-02 17:47 ` Mikael Pettersson
2002-12-02 19:10 ` Robert Love
-- strict thread matches above, loose matches on Subject: below --
2002-12-03 0:26 Christoph Hellwig
2002-12-02 17:24 ` Jeff Garzik
2002-12-02 18:57 ` Robert Love
2002-12-03 0:51 ` Christoph Hellwig
2002-12-02 17:50 ` Martin J. Bligh
2002-12-02 18:50 ` Adrian Bunk
2002-12-02 19:12 ` Robert Love
2002-12-02 19:30 ` Andrew Morton
2002-12-02 19:50 ` Andrea Arcangeli
2002-12-03 20:49 ` Andrew Morton
2002-12-03 21:09 ` Martin J. Bligh
2002-12-04 0:09 ` Andrea Arcangeli
2002-12-04 0:06 ` Andrea Arcangeli
2002-12-04 0:30 ` Andrew Morton
2002-12-04 0:42 ` Andrea Arcangeli
2002-12-04 1:03 ` William Lee Irwin III
2002-12-04 9:25 ` William Lee Irwin III
2002-12-04 1:14 ` Andrew Morton
2002-12-04 1:21 ` Andrea Arcangeli
2002-12-04 2:14 ` Andrew Morton
2002-12-06 18:11 ` William Lee Irwin III
2002-12-08 13:23 ` Ingo Molnar
2002-12-08 19:56 ` Andrew Morton
2002-12-09 20:13 ` Ingo Molnar
2002-12-03 1:11 ` Christoph Hellwig
2002-12-02 18:59 ` Robert Love
2002-12-02 22:47 ` Alan Cox
2002-12-02 22:38 ` Christoph Hellwig
2002-12-02 22:41 ` Robert Love
2002-12-07 16:55 ` bill davidsen
2002-12-09 3:02 Jim Houston
2002-12-09 20:19 kernel
2002-12-13 23:08 Christoph Hellwig
2002-12-13 21:34 ` Adrian Bunk
2002-12-14 4:55 ` Christoph Hellwig
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=1033513407.12959.91.camel@phantasy \
--to=rml@tech9.net \
--cc=hch@infradead.org \
--cc=jgarzik@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.