| Linux - Kernel This forum is for all discussion relating to the Linux kernel. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
03-23-2012, 02:03 PM
|
#1
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Rep:
|
Disabling CPU caches
Hi,
I would like to disable the level 1 and level 2 caches of my CPU. I wrote a kernel module to set the 30th bit of the control register cr0. But when I try to insert the module with insmod, the system freezes. I am using a Thinkpad X41 with a Pentium M and kernel 2.6.32-40-generic #87-Ubuntu SMP. What can I do to determine the reason for the freeze?
Thank you for your help!
The code of the module:
Code:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int disableCache_init(void)
{
printk(KERN_ALERT "Disabling L1 and L2 caches.\n");
__asm__(".intel_syntax noprefix\n\t"
"mov eax,cr0\n\t"
"or eax,(1 << 30)\n\t"
"mov cr0,eax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "eax" );
return 0;
}
static void disableCache_exit(void)
{
printk(KERN_ALERT "Enabling L1 and L2 caches.\n");
__asm__(".intel_syntax noprefix\n\t"
"mov eax,cr0\n\t"
"and eax,~(1 << 30)\n\t"
"mov cr0,eax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "eax" );
}
module_init(disableCache_init);
module_exit(disableCache_exit);
And the Makefile:
Code:
EXTRA_CFLAGS = -m32
obj-m += disableCache.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
insmod command:
Code:
sudo insmod ./disableCache.ko
Edit: Adopted the code of the module, see second post.
Last edited by ulmo; 03-24-2012 at 09:17 AM.
|
|
|
|
03-24-2012, 09:24 AM
|
#2
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
As I just found out, the syntax for the mov instruction with control registers is not as I expected: in Intel syntax, the destination register comes first in cases where control registers are involved. I adopted the code of the module in the first post.
However, the overall result stays the same, the system freezes when the module is inserted. I found out that the module runs without problems with this line commented out:
Code:
"or eax,(1 << 30)\n\t"
(But it also has no effect because cr0 is not altered.)
Any ideas?
|
|
|
|
04-10-2012, 10:56 AM
|
#3
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
Any suggestions about an other forum where I can ask? Any hint is appreciated, thanks.
|
|
|
|
04-10-2012, 02:18 PM
|
#4
|
|
Member
Registered: Apr 2009
Posts: 719
Rep:
|
You can't disable CPU cache in fly.
|
|
|
|
04-10-2012, 02:42 PM
|
#5
|
|
Member
Registered: Mar 2012
Location: Aguascalientes, mx
Distribution: Opensuse 12.1 x86-64
Posts: 34
Rep:
|
Disabling cpu caches gives you a pentium I like processor!!!
The addition of Cache on CPU was one of the best upgrades to cpu architecture and is used to retain temporal data / instructions. as nini09 have said, you cannot disable it at fly, but certain BIOS would give you the option at boot time. Is there any special requirement, or is only homework / test?
|
|
|
|
04-10-2012, 04:12 PM
|
#6
|
|
Member
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 563
Rep: 
|
It can be done this is from memtest
Code:
static inline void cache_off(void)
{
asm(
"push %eax\n\t"
"movl %cr0,%eax\n\t"
"orl $0x40000000,%eax\n\t" /* Set CD */
"movl %eax,%cr0\n\t"
"wbinvd\n\t"
"pop %eax\n\t");
}
but you need to flush the cache that's what wbinvd is for.
|
|
|
1 members found this post helpful.
|
04-11-2012, 01:44 PM
|
#7
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
Thank you for your answers. I want to disable the caches for a research project where we want to measure execution times and want to be sure they are not influenced by the internal caches.
@whizje: I tried your suggestion and apparently, it is working.  But I have to investigate it further tomorrow when I will have more time.
Last edited by ulmo; 04-11-2012 at 01:45 PM.
|
|
|
1 members found this post helpful.
|
04-12-2012, 10:40 AM
|
#8
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
After some investigation, I found out that the module runs fine (with the corrections from my second post). I just didn't wait long enough after fixing the mov cr0, eax bug, misinterpreating the slow behavior of the system with disabled caches as a complete freeze. My apologies for that.
The code posted by whizje is also working, of course. I didn't find an option for cache disabling in the BIOS of my machine.
Thanks for your input.
|
|
|
1 members found this post helpful.
|
07-30-2012, 06:59 AM
|
#9
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Rep: 
|
how to run the above segment of codes....thanks
i am trying to disable the caches ...i want to know how the above code works and how to execute it
|
|
|
|
07-30-2012, 08:26 AM
|
#10
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
@hga Run make and insmod. Source code, makefile and argument for insmod is given in the first post. If you have problems, please ask more specific questions.
|
|
|
|
07-31-2012, 03:28 AM
|
#11
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Rep: 
|
can you be more specfic with the steps...where is to be the code saved and with what extension? thank you.
|
|
|
|
07-31-2012, 03:48 AM
|
#12
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
I would suggest to save the source code (in an arbitrary directory) in a file named and the make file in a file named Then run followed by
Code:
sudo insmod ./disableCache.ko
Last edited by ulmo; 07-31-2012 at 03:53 AM.
|
|
|
|
07-31-2012, 07:41 AM
|
#13
|
|
LQ Newbie
Registered: Jul 2012
Posts: 2
Rep: 
|
i saved the above files and tried the make command. But it displays
make: Nothing to be done for `all'..... Can you help me???
---------- Post added 07-31-12 at 07:42 AM ----------
i saved the above files and tried the make command. But it displays
make: Nothing to be done for `all'..... Can you help me???
|
|
|
|
08-01-2012, 07:58 AM
|
#14
|
|
LQ Newbie
Registered: Jul 2004
Distribution: debian
Posts: 27
Original Poster
Rep:
|
I have no idea, I have only a very basic knowledge of make...
|
|
|
|
08-01-2012, 02:28 PM
|
#15
|
|
Member
Registered: Apr 2009
Posts: 719
Rep:
|
Hi naam,
It look like your makefile has problem. You can make Hello module work at first and then deal with disableCache.c
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:14 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|