locks.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Spin and read/write lock operations.
  3. *
  4. * Copyright (C) 2001-2004 Paul Mackerras <paulus@au.ibm.com>, IBM
  5. * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
  6. * Copyright (C) 2002 Dave Engebretsen <engebret@us.ibm.com>, IBM
  7. * Rework to support virtual processors
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/export.h>
  17. #include <linux/smp.h>
  18. /* waiting for a spinlock... */
  19. #if defined(CONFIG_PPC_SPLPAR)
  20. #include <asm/hvcall.h>
  21. #include <asm/smp.h>
  22. void __spin_yield(arch_spinlock_t *lock)
  23. {
  24. unsigned int lock_value, holder_cpu, yield_count;
  25. lock_value = lock->slock;
  26. if (lock_value == 0)
  27. return;
  28. holder_cpu = lock_value & 0xffff;
  29. BUG_ON(holder_cpu >= NR_CPUS);
  30. yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count);
  31. if ((yield_count & 1) == 0)
  32. return; /* virtual cpu is currently running */
  33. rmb();
  34. if (lock->slock != lock_value)
  35. return; /* something has changed */
  36. plpar_hcall_norets(H_CONFER,
  37. get_hard_smp_processor_id(holder_cpu), yield_count);
  38. }
  39. EXPORT_SYMBOL_GPL(__spin_yield);
  40. /*
  41. * Waiting for a read lock or a write lock on a rwlock...
  42. * This turns out to be the same for read and write locks, since
  43. * we only know the holder if it is write-locked.
  44. */
  45. void __rw_yield(arch_rwlock_t *rw)
  46. {
  47. int lock_value;
  48. unsigned int holder_cpu, yield_count;
  49. lock_value = rw->lock;
  50. if (lock_value >= 0)
  51. return; /* no write lock at present */
  52. holder_cpu = lock_value & 0xffff;
  53. BUG_ON(holder_cpu >= NR_CPUS);
  54. yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count);
  55. if ((yield_count & 1) == 0)
  56. return; /* virtual cpu is currently running */
  57. rmb();
  58. if (rw->lock != lock_value)
  59. return; /* something has changed */
  60. plpar_hcall_norets(H_CONFER,
  61. get_hard_smp_processor_id(holder_cpu), yield_count);
  62. }
  63. #endif