/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12* This file is included into spinlock_32.c or _64.c.13*/1415/*16* The mfspr in __spinlock_relax() is 5 or 6 cycles plus 2 for loop17* overhead.18*/19#ifdef __tilegx__20#define CYCLES_PER_RELAX_LOOP 721#else22#define CYCLES_PER_RELAX_LOOP 823#endif2425/*26* Idle the core for CYCLES_PER_RELAX_LOOP * iterations cycles.27*/28static inline void29relax(int iterations)30{31for (/*above*/; iterations > 0; iterations--)32__insn_mfspr(SPR_PASS);33barrier();34}3536/* Perform bounded exponential backoff.*/37static void delay_backoff(int iterations)38{39u32 exponent, loops;4041/*42* 2^exponent is how many times we go around the loop,43* which takes 8 cycles. We want to start with a 16- to 31-cycle44* loop, so we need to go around minimum 2 = 2^1 times, so we45* bias the original value up by 1.46*/47exponent = iterations + 1;4849/*50* Don't allow exponent to exceed 7, so we have 128 loops,51* or 1,024 (to 2,047) cycles, as our maximum.52*/53if (exponent > 8)54exponent = 8;5556loops = 1 << exponent;5758/* Add a randomness factor so two cpus never get in lock step. */59loops += __insn_crc32_32(stack_pointer, get_cycles_low()) &60(loops - 1);6162relax(1 << exponent);63}646566