[sched] [patch] migration-fixes-2.5.3-pre2-A1

Ingo Molnar (mingo@elte.hu)
Sun, 20 Jan 2002 14:36:55 +0100 (CET)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--8323328-338135374-1011533815=:7972
Content-Type: TEXT/PLAIN; charset=US-ASCII

the attached patch solves an SMP task migration bug in the O(1) scheduler.

the bug is triggered all the time on an 8-way CPU i tested, and there are
some bugreports from dual boxes as well that lock up during bootups.

task migration is a subtle issue. The basic task is to 'send' the
currently executing task over to another CPU, where it continues
execution. The current code in 2.5.3-pre2 is broken, as it has a window in
which it's possible for a ksoftirqd thread to run on two CPUs at once -
causing a lockup.

my solution is to send the task to the other CPU using the
smp_migrate_task() lowlevel-SMP method defined by the SMP architecture,
where it will call back the scheduler via sched_task_migrated(new_task).

it's also possible to move a task from one runqueue to another one without
using cross-CPU messaging, but this increases the overhead of the
scheduler hot-path, schedule_tail() needs to check for some sort of
prev->state == TASK_MIGRATED flag, at least. The patch solves this without
adding overhead to the hot-path.

the patch is also an optimization: the set_cpus_allowed() function used to
switch the current idle thread manually, to initiate a reschedule (due to
locking issues). This 'manual context switching' code is gone now, and
set_cpus_allowed() calls schedule() directly now. This simplifies
set_cpus_allowed() greatly, reducing sched.c's line count by 10.

Ingo

--8323328-338135374-1011533815=:7972
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="migration-fixes-2.5.3-pre2-A1"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.33.0201201436550.7972@localhost.localdomain>
Content-Description:
Content-Disposition: attachment; filename="migration-fixes-2.5.3-pre2-A1"

LS0tIGxpbnV4L2tlcm5lbC9zY2hlZC5jLm9yaWcJU3VuIEphbiAyMCAxMToz
ODo1OSAyMDAyDQorKysgbGludXgva2VybmVsL3NjaGVkLmMJU3VuIEphbiAy
MCAxMTozOToxNiAyMDAyDQpAQCAtMTkxLDYgKzE5MSwyMCBAQA0KIH0NCi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Bmcm9tIHN5
c2NhbGwgY29udGV4dHMsIHdpdGggaW50ZXJydXB0cyAqZW5hYmxlZCouDQor
ICovDQordm9pZCBzbXBfbWlncmF0ZV90YXNrKGludCBjcHUsIHRhc2tfdCAq
cCkNCit7DQorCS8qDQorCSAqIFRoZSB0YXJnZXQgQ1BVIHdpbGwgdW5sb2Nr
IHRoZSBtaWdyYXRpb24gc3BpbmxvY2s6DQorCSAqLw0KKwlzcGluX2xvY2so
Jm1pZ3JhdGlvbl9sb2NrKTsNCisJbmV3X3Rhc2sgPSBwOw0KKwlzZW5kX0lQ
SV9tYXNrKDEgPDwgY3B1LCBUQVNLX01JR1JBVElPTl9WRUNUT1IpOw0KK30N
CisNCisvKg0KKyAqIFRhc2sgbWlncmF0aW9uIGNhbGxiYWNrLg0KKyAqLw0K
K2FzbWxpbmthZ2Ugdm9pZCBzbXBfdGFza19taWdyYXRpb25faW50ZXJydXB0
KHZvaWQpDQorew0KKwl0YXNrX3QgKnA7DQorDQorCWFja19BUElDX2lycSgp
Ow0KKwlwID0gbmV3X3Rhc2s7DQorCXNwaW5fdW5sb2NrKCZtaWdyYXRpb25f
bG9jayk7DQorCXNjaGVkX3Rhc2tfbWlncmF0ZWQocCk7DQorfQ0KIC8qDQog
ICogdGhpcyBmdW5jdGlvbiBzZW5kcyBhICdyZXNjaGVkdWxlJyBJUEkgdG8g
YW5vdGhlciBDUFUuDQogICogaXQgZ29lcyBzdHJhaWdodCB0aHJvdWdoIGFu
ZCB3YXN0ZXMgbm8gdGltZSBzZXJpYWxpemluZw0K
--8323328-338135374-1011533815=:7972--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/