/arch/ppc64/lib/locks.c

https://bitbucket.org/evzijst/gittest · C · 95 lines · 68 code · 8 blank · 19 comment · 14 complexity · c8b2f678b680f784ec52ed60545a8a77 MD5 · raw file

  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/config.h>
  15. #include <linux/kernel.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/module.h>
  18. #include <linux/stringify.h>
  19. #include <asm/hvcall.h>
  20. #include <asm/iSeries/HvCall.h>
  21. /* waiting for a spinlock... */
  22. #if defined(CONFIG_PPC_SPLPAR) || defined(CONFIG_PPC_ISERIES)
  23. void __spin_yield(spinlock_t *lock)
  24. {
  25. unsigned int lock_value, holder_cpu, yield_count;
  26. struct paca_struct *holder_paca;
  27. lock_value = lock->lock;
  28. if (lock_value == 0)
  29. return;
  30. holder_cpu = lock_value & 0xffff;
  31. BUG_ON(holder_cpu >= NR_CPUS);
  32. holder_paca = &paca[holder_cpu];
  33. yield_count = holder_paca->lppaca.yield_count;
  34. if ((yield_count & 1) == 0)
  35. return; /* virtual cpu is currently running */
  36. rmb();
  37. if (lock->lock != lock_value)
  38. return; /* something has changed */
  39. #ifdef CONFIG_PPC_ISERIES
  40. HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc,
  41. ((u64)holder_cpu << 32) | yield_count);
  42. #else
  43. plpar_hcall_norets(H_CONFER, get_hard_smp_processor_id(holder_cpu),
  44. yield_count);
  45. #endif
  46. }
  47. /*
  48. * Waiting for a read lock or a write lock on a rwlock...
  49. * This turns out to be the same for read and write locks, since
  50. * we only know the holder if it is write-locked.
  51. */
  52. void __rw_yield(rwlock_t *rw)
  53. {
  54. int lock_value;
  55. unsigned int holder_cpu, yield_count;
  56. struct paca_struct *holder_paca;
  57. lock_value = rw->lock;
  58. if (lock_value >= 0)
  59. return; /* no write lock at present */
  60. holder_cpu = lock_value & 0xffff;
  61. BUG_ON(holder_cpu >= NR_CPUS);
  62. holder_paca = &paca[holder_cpu];
  63. yield_count = holder_paca->lppaca.yield_count;
  64. if ((yield_count & 1) == 0)
  65. return; /* virtual cpu is currently running */
  66. rmb();
  67. if (rw->lock != lock_value)
  68. return; /* something has changed */
  69. #ifdef CONFIG_PPC_ISERIES
  70. HvCall2(HvCallBaseYieldProcessor, HvCall_YieldToProc,
  71. ((u64)holder_cpu << 32) | yield_count);
  72. #else
  73. plpar_hcall_norets(H_CONFER, get_hard_smp_processor_id(holder_cpu),
  74. yield_count);
  75. #endif
  76. }
  77. #endif
  78. void spin_unlock_wait(spinlock_t *lock)
  79. {
  80. while (lock->lock) {
  81. HMT_low();
  82. if (SHARED_PROCESSOR)
  83. __spin_yield(lock);
  84. }
  85. HMT_medium();
  86. }
  87. EXPORT_SYMBOL(spin_unlock_wait);