lwkt_thread.c (3824f392) | lwkt_thread.c (ae8e83e6) |
---|---|
1/* 2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@backplane.com> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 1181 unchanged lines hidden (view full) --- 1190/* 1191 * Thread migration using a 'Pull' method. The thread may or may not be 1192 * the current thread. It MUST be descheduled and in a stable state. 1193 * lwkt_giveaway() must be called on the cpu owning the thread. 1194 * 1195 * At any point after lwkt_giveaway() is called, the target cpu may 1196 * 'pull' the thread by calling lwkt_acquire(). 1197 * | 1/* 2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@backplane.com> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 1181 unchanged lines hidden (view full) --- 1190/* 1191 * Thread migration using a 'Pull' method. The thread may or may not be 1192 * the current thread. It MUST be descheduled and in a stable state. 1193 * lwkt_giveaway() must be called on the cpu owning the thread. 1194 * 1195 * At any point after lwkt_giveaway() is called, the target cpu may 1196 * 'pull' the thread by calling lwkt_acquire(). 1197 * |
1198 * We have to make sure the thread is not sitting on a per-cpu tsleep 1199 * queue or it will blow up when it moves to another cpu. 1200 * |
|
1198 * MPSAFE - must be called under very specific conditions. 1199 */ 1200void 1201lwkt_giveaway(thread_t td) 1202{ 1203 globaldata_t gd = mycpu; 1204 1205 crit_enter_gd(gd); | 1201 * MPSAFE - must be called under very specific conditions. 1202 */ 1203void 1204lwkt_giveaway(thread_t td) 1205{ 1206 globaldata_t gd = mycpu; 1207 1208 crit_enter_gd(gd); |
1209 if (td->td_flags & TDF_TSLEEPQ) 1210 tsleep_remove(td); |
|
1206 KKASSERT(td->td_gd == gd); 1207 TAILQ_REMOVE(&gd->gd_tdallq, td, td_allq); 1208 td->td_flags |= TDF_MIGRATING; 1209 crit_exit_gd(gd); 1210} 1211 1212void 1213lwkt_acquire(thread_t td) --- 103 unchanged lines hidden (view full) --- 1317 1318/* 1319 * Migrate the current thread to the specified cpu. 1320 * 1321 * This is accomplished by descheduling ourselves from the current cpu, 1322 * moving our thread to the tdallq of the target cpu, IPI messaging the 1323 * target cpu, and switching out. TDF_MIGRATING prevents scheduling 1324 * races while the thread is being migrated. | 1211 KKASSERT(td->td_gd == gd); 1212 TAILQ_REMOVE(&gd->gd_tdallq, td, td_allq); 1213 td->td_flags |= TDF_MIGRATING; 1214 crit_exit_gd(gd); 1215} 1216 1217void 1218lwkt_acquire(thread_t td) --- 103 unchanged lines hidden (view full) --- 1322 1323/* 1324 * Migrate the current thread to the specified cpu. 1325 * 1326 * This is accomplished by descheduling ourselves from the current cpu, 1327 * moving our thread to the tdallq of the target cpu, IPI messaging the 1328 * target cpu, and switching out. TDF_MIGRATING prevents scheduling 1329 * races while the thread is being migrated. |
1330 * 1331 * We must be sure to remove ourselves from the current cpu's tsleepq 1332 * before potentially moving to another queue. The thread can be on 1333 * a tsleepq due to a left-over tsleep_interlock(). |
|
1325 */ 1326#ifdef SMP 1327static void lwkt_setcpu_remote(void *arg); 1328#endif 1329 1330void 1331lwkt_setcpu_self(globaldata_t rgd) 1332{ 1333#ifdef SMP 1334 thread_t td = curthread; 1335 1336 if (td->td_gd != rgd) { 1337 crit_enter_quick(td); | 1334 */ 1335#ifdef SMP 1336static void lwkt_setcpu_remote(void *arg); 1337#endif 1338 1339void 1340lwkt_setcpu_self(globaldata_t rgd) 1341{ 1342#ifdef SMP 1343 thread_t td = curthread; 1344 1345 if (td->td_gd != rgd) { 1346 crit_enter_quick(td); |
1347 if (td->td_flags & TDF_TSLEEPQ) 1348 tsleep_remove(td); |
|
1338 td->td_flags |= TDF_MIGRATING; 1339 lwkt_deschedule_self(td); 1340 TAILQ_REMOVE(&td->td_gd->gd_tdallq, td, td_allq); 1341 lwkt_send_ipiq(rgd, (ipifunc1_t)lwkt_setcpu_remote, td); 1342 lwkt_switch(); 1343 /* we are now on the target cpu */ 1344 TAILQ_INSERT_TAIL(&rgd->gd_tdallq, td, td_allq); 1345 crit_exit_quick(td); --- 245 unchanged lines hidden --- | 1349 td->td_flags |= TDF_MIGRATING; 1350 lwkt_deschedule_self(td); 1351 TAILQ_REMOVE(&td->td_gd->gd_tdallq, td, td_allq); 1352 lwkt_send_ipiq(rgd, (ipifunc1_t)lwkt_setcpu_remote, td); 1353 lwkt_switch(); 1354 /* we are now on the target cpu */ 1355 TAILQ_INSERT_TAIL(&rgd->gd_tdallq, td, td_allq); 1356 crit_exit_quick(td); --- 245 unchanged lines hidden --- |