taskqueue.cpp revision 1753
1558N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A#
include "incls/_precompiled.incl" 1585N/A "qpush",
"qpop",
"qpop-s",
"qattempt",
"qsteal",
"opush",
"omax" 1585N/A // Use a width w: 1 <= w <= max_width 1585N/A if (
line == 0) {
// spaces equal in width to the header 1629N/A// Invariants which should hold after a TaskQueue has been emptied and is 1629N/A// quiescent; they do not hold at arbitrary times. 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");
546N/A // Number of hard spin loops done since last yield 546N/A // Number of iterations in the hard spin loop. 546N/A // If WorkStealingSpinToYieldRatio is 0, no hard spinning is done. 546N/A // If it is greater than 0, then start with a small number 546N/A // of spins and increase number with each turn at spinning until 546N/A // the count of hard spins exceeds WorkStealingSpinToYieldRatio. 546N/A // Then do a yield() call and start spinning afresh. 546N/A // Remember the initial spin limit. 546N/A // Loop waiting for all threads to offer termination or 546N/A // Are all threads offering termination? 546N/A // Periodically sleep() instead of yield() to give threads 546N/A // waiting on the cores the chance to grab this code 546N/A // Do a yield or hardspin. For purposes of deciding whether 546N/A // to sleep, count this as a yield. 546N/A // Periodically call yield() instead spinning 546N/A // After WorkStealingSpinToYieldRatio spins, do a yield() call 546N/A // and reset the counts and starting limit. 546N/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 546N/A "Total spins: %lld Total peeks: %lld",
0N/A "Terminator may still be in use");