Ubuntu – How to disable processor’s L1 and L2 caches

armcachelinuxpythonUbuntu

Is it possible to disable L1 and/or L2 cache on Ubuntu 14.04 (preferably in a higher level language like Python)? If so, how?

In addition, will disabling the cache differ significantly between different architectures? If so, I'm more interested in an ARM Cortex-A15.

EDIT

While researching how to disable the cache, I did find out about the "drop_caches" file in /proc/sys/vm/ from the kernel.org documentation

"Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped,
their memory becomes free."

"This file is not a means to control the growth of the various
kernel caches (inodes, dentries, pagecache, etc…) These objects are
automatically reclaimed by the kernel when memory is needed elsewhere
on the system."

This does not seem like what I'm looking for as not only does this not seem like it would disable the cache, I thought that virtual memory resides within the operating system and not on the hardware. My goal is to disable the cache so the desired memory must be sought elsewhere, such as within the RAM.

EDIT

To clarify, I understand what disabling the cache will do to the system. However, it is a common technique used in space applications to increase reliability for safety-critical applications. Here are some resources that document this phenomenon:

Reducing embedded software radiation-induced failures through cache memories

Guideline for Ground Radiation Testing of Microprocessors in the Space Radiation Environment

There are even books on the topic:

Ionizing Radiation Effects in Electronics: From Memories to Imagers

Best Answer

You can not do it directly in Python, as you need a kernel module to do that (and root rights to load that module).

See http://lxr.free-electrons.com/source/arch/arm/mm/cache-v7.S#L21 for what it takes to invalidate the L1 cache (invalidate, not disable).

Different CPU architectures (e.g x86 vs ARM) require different assembly code (CPU instructions) to disable the cache. I'm not sure if the Linux kernel has any possibility to disable the L1/L2/L3/L4 caches and if it would have that, I believe it would be just used internally for a short period of time, as the CPU is slow without these caches.

See Is there a way to disable CPU cache (L1/L2) on a Linux system? for a link on how you can disable the cache on an x86/x64 system (you need to change the register cr0). For ARM check Cache disabled behavior.

I'm not sure that you completely understand what the CPU caches do. Can you please elaborate why you want to cripple the performance of your system?

Related Question