taskqueue.cpp revision 546
0N/A * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 0N/A const int a =
16807;
0N/A const int m =
2147483647;
0N/A const int q =
127773;
/* m div a */ 0N/A const int r =
2836;
/* m mod a */ 0N/A assert(
sizeof(
int) ==
4,
"I think this relies on that");
0N/A // Number of hard spin loops done since last yield 0N/A // Number of iterations in the hard spin loop. 0N/A // If WorkStealingSpinToYieldRatio is 0, no hard spinning is done. 0N/A // If it is greater than 0, then start with a small number 0N/A // of spins and increase number with each turn at spinning until 0N/A // the count of hard spins exceeds WorkStealingSpinToYieldRatio. 0N/A // Then do a yield() call and start spinning afresh. 0N/A // Remember the initial spin limit. 0N/A // Loop waiting for all threads to offer termination or 0N/A // Are all threads offering termination? 0N/A // Look for more work. 0N/A // Periodically sleep() instead of yield() to give threads 0N/A // waiting on the cores the chance to grab this code 0N/A // Do a yield or hardspin. For purposes of deciding whether 0N/A // to sleep, count this as a yield. 0N/A // Periodically call yield() instead spinning 0N/A // After WorkStealingSpinToYieldRatio spins, do a yield() call 0N/A // and reset the counts and starting limit. 0N/A // Hard spin this time 0N/A // Increase the hard spinning period but only up to a limit. 0N/A "thread %d sleeps after %d yields",
0N/A // A sleep will cause this processor to seek work on another processor's 0N/A // runqueue, if it has nothing else to run (as opposed to the yield 0N/A // which may only move the thread to the end of the this processor's 0N/A "Total spins: %lld Total peeks: %lld",
0N/A "Terminator may still be in use");
0N/A// Note that using this method will retrieve all regions 0N/A// that have been saved but that it will always check 222N/A// the overflow stack. It may be more efficient to 0N/A// check the stealable queue and the overflow stack