2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
13 * This file is included into spinlock_32.c or _64.c.
17 * The mfspr in __spinlock_relax() is 5 or 6 cycles plus 2 for loop
21 #define CYCLES_PER_RELAX_LOOP 7
23 #define CYCLES_PER_RELAX_LOOP 8
27 * Idle the core for CYCLES_PER_RELAX_LOOP * iterations cycles.
32 for (/*above*/; iterations
> 0; iterations
--)
33 __insn_mfspr(SPR_PASS
);
37 /* Perform bounded exponential backoff.*/
38 static void delay_backoff(int iterations
)
43 * 2^exponent is how many times we go around the loop,
44 * which takes 8 cycles. We want to start with a 16- to 31-cycle
45 * loop, so we need to go around minimum 2 = 2^1 times, so we
46 * bias the original value up by 1.
48 exponent
= iterations
+ 1;
51 * Don't allow exponent to exceed 7, so we have 128 loops,
52 * or 1,024 (to 2,047) cycles, as our maximum.
57 loops
= 1 << exponent
;
59 /* Add a randomness factor so two cpus never get in lock step. */
60 loops
+= __insn_crc32_32(stack_pointer
, get_cycles_low()) &