1
0

simd.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published
  6. * by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_SIMD_H
  9. #define __ASM_SIMD_H
  10. #include <linux/compiler.h>
  11. #include <linux/irqflags.h>
  12. #include <linux/percpu.h>
  13. #include <linux/preempt.h>
  14. #include <linux/types.h>
  15. #ifdef CONFIG_KERNEL_MODE_NEON
  16. DECLARE_PER_CPU(bool, kernel_neon_busy);
  17. /*
  18. * may_use_simd - whether it is allowable at this time to issue SIMD
  19. * instructions or access the SIMD register file
  20. *
  21. * Callers must not assume that the result remains true beyond the next
  22. * preempt_enable() or return from softirq context.
  23. */
  24. static __must_check inline bool may_use_simd(void)
  25. {
  26. /*
  27. * kernel_neon_busy is only set while preemption is disabled,
  28. * and is clear whenever preemption is enabled. Since
  29. * this_cpu_read() is atomic w.r.t. preemption, kernel_neon_busy
  30. * cannot change under our feet -- if it's set we cannot be
  31. * migrated, and if it's clear we cannot be migrated to a CPU
  32. * where it is set.
  33. */
  34. return !in_irq() && !irqs_disabled() && !in_nmi() &&
  35. !this_cpu_read(kernel_neon_busy);
  36. }
  37. #else /* ! CONFIG_KERNEL_MODE_NEON */
  38. static __must_check inline bool may_use_simd(void) {
  39. return false;
  40. }
  41. #endif /* ! CONFIG_KERNEL_MODE_NEON */
  42. #endif