linux/arch/arm64/include/asm/simd.h

52 lines
1.4 KiB
C
Raw Normal View History

/*
* Copyright (C) 2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#ifndef __ASM_SIMD_H
#define __ASM_SIMD_H
2017-08-03 16:23:23 +00:00
#include <linux/compiler.h>
#include <linux/irqflags.h>
2017-08-03 16:23:23 +00:00
#include <linux/percpu.h>
#include <linux/preempt.h>
#include <linux/types.h>
2017-08-03 16:23:23 +00:00
#ifdef CONFIG_KERNEL_MODE_NEON
DECLARE_PER_CPU(bool, kernel_neon_busy);
/*
* may_use_simd - whether it is allowable at this time to issue SIMD
* instructions or access the SIMD register file
2017-08-03 16:23:23 +00:00
*
* Callers must not assume that the result remains true beyond the next
* preempt_enable() or return from softirq context.
*/
static __must_check inline bool may_use_simd(void)
{
2017-08-03 16:23:23 +00:00
/*
* kernel_neon_busy is only set while preemption is disabled,
* and is clear whenever preemption is enabled. Since
* this_cpu_read() is atomic w.r.t. preemption, kernel_neon_busy
* cannot change under our feet -- if it's set we cannot be
* migrated, and if it's clear we cannot be migrated to a CPU
* where it is set.
2017-08-03 16:23:23 +00:00
*/
return !in_irq() && !irqs_disabled() && !in_nmi() &&
!this_cpu_read(kernel_neon_busy);
}
2017-08-03 16:23:23 +00:00
#else /* ! CONFIG_KERNEL_MODE_NEON */
static __must_check inline bool may_use_simd(void) {
return false;
}
#endif /* ! CONFIG_KERNEL_MODE_NEON */
#endif