mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 17:12:06 +00:00
0bdf525f04
This patch is meant to improve overall system performance when making use of the __phys_addr call. To do this I have implemented several changes. First if CONFIG_DEBUG_VIRTUAL is not defined __phys_addr is made an inline, similar to how this is currently handled in 32 bit. However in order to do this it is required to export phys_base so that it is available if __phys_addr is used in kernel modules. The second change was to streamline the code by making use of the carry flag on an add operation instead of performing a compare on a 64 bit value. The advantage to this is that it allows us to significantly reduce the overall size of the call. On my Xeon E5 system the entire __phys_addr inline call consumes a little less than 32 bytes and 5 instructions. I also applied similar logic to the debug version of the function. My testing shows that the debug version of the function with this patch applied is slightly faster than the non-debug version without the patch. Finally I also applied the same logic changes to __virt_addr_valid since it used the same general code flow as __phys_addr and could achieve similar gains though these changes. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Link: http://lkml.kernel.org/r/20121116215315.8521.46270.stgit@ahduyck-cp1.jf.intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
81 lines
1.7 KiB
C
81 lines
1.7 KiB
C
#include <linux/mmdebug.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include "physaddr.h"
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#ifdef CONFIG_DEBUG_VIRTUAL
|
|
unsigned long __phys_addr(unsigned long x)
|
|
{
|
|
unsigned long y = x - __START_KERNEL_map;
|
|
|
|
/* use the carry flag to determine if x was < __START_KERNEL_map */
|
|
if (unlikely(x > y)) {
|
|
x = y + phys_base;
|
|
|
|
VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE);
|
|
} else {
|
|
x = y + (__START_KERNEL_map - PAGE_OFFSET);
|
|
|
|
/* carry flag will be set if starting x was >= PAGE_OFFSET */
|
|
VIRTUAL_BUG_ON((x > y) || !phys_addr_valid(x));
|
|
}
|
|
|
|
return x;
|
|
}
|
|
EXPORT_SYMBOL(__phys_addr);
|
|
#endif
|
|
|
|
bool __virt_addr_valid(unsigned long x)
|
|
{
|
|
unsigned long y = x - __START_KERNEL_map;
|
|
|
|
/* use the carry flag to determine if x was < __START_KERNEL_map */
|
|
if (unlikely(x > y)) {
|
|
x = y + phys_base;
|
|
|
|
if (y >= KERNEL_IMAGE_SIZE)
|
|
return false;
|
|
} else {
|
|
x = y + (__START_KERNEL_map - PAGE_OFFSET);
|
|
|
|
/* carry flag will be set if starting x was >= PAGE_OFFSET */
|
|
if ((x > y) || !phys_addr_valid(x))
|
|
return false;
|
|
}
|
|
|
|
return pfn_valid(x >> PAGE_SHIFT);
|
|
}
|
|
EXPORT_SYMBOL(__virt_addr_valid);
|
|
|
|
#else
|
|
|
|
#ifdef CONFIG_DEBUG_VIRTUAL
|
|
unsigned long __phys_addr(unsigned long x)
|
|
{
|
|
/* VMALLOC_* aren't constants */
|
|
VIRTUAL_BUG_ON(x < PAGE_OFFSET);
|
|
VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x));
|
|
return x - PAGE_OFFSET;
|
|
}
|
|
EXPORT_SYMBOL(__phys_addr);
|
|
#endif
|
|
|
|
bool __virt_addr_valid(unsigned long x)
|
|
{
|
|
if (x < PAGE_OFFSET)
|
|
return false;
|
|
if (__vmalloc_start_set && is_vmalloc_addr((void *) x))
|
|
return false;
|
|
if (x >= FIXADDR_START)
|
|
return false;
|
|
return pfn_valid((x - PAGE_OFFSET) >> PAGE_SHIFT);
|
|
}
|
|
EXPORT_SYMBOL(__virt_addr_valid);
|
|
|
|
#endif /* CONFIG_X86_64 */
|