当前位置:网站首页>Test memory read rate
Test memory read rate
2022-06-30 10:22:00 【Yangxiangrui】
1. Ideas
At ordinary times CPU Read data from cache Or read data from memory . If you want to simply read data from memory , So you need to take cache close . Then read the array sequentially from memory . Read rate bandwidth、 Array size arraysize、 Read time time The calculation formula between is as follows :
b a n d w i d t h = a r r a y s i z e t i m e bandwidth = \frac{arraysize}{time} bandwidth=timearraysize
2. close cache
First, in the Linux System shutdown cache, Use the following code to cache close .( Code reference 1, Code reference 2)
#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 rax,cr0\n\t"
"or rax,(1 << 30)\n\t"
"mov cr0,rax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "rax" );
return 0;
}
static void disableCache_exit(void)
{
printk(KERN_ALERT "Enabling L1 and L2 caches.\n");
__asm__(".intel_syntax noprefix\n\t"
"mov rax,cr0\n\t"
"and rax,~(1 << 30)\n\t"
"mov cr0,rax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "rax" );
}
module_init(disableCache_init);
module_exit(disableCache_exit);
makefile as follows
EXTRA_CFLAGS = -m64
obj-m += disableCache.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Use the following Linux Command to compile source code
$ make
After compilation, use the command insmod Load the program into kernel module in , And use dmesg Check whether the load is successful
$ insmod disableCache.ko
$ dmesg
Post load system log The following output will appear in
3. Start testing bandwidth
Closing cache Use the following code to test bandwidth
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
// Test read BIG_ARR How long does it take , And then calculate bandwidth
#define BIG_ARR 999999
int main()
{
int *block = (int *)calloc(BIG_ARR, sizeof(int));
int i, temp;
clock_t start = clock(), total_time;
for(i = 0; i < BIG_ARR; ++i)
temp += block[i];
total_time = clock() - start;
double sec = (double)total_time / (double) CLOCKS_PER_SEC;
printf("read %d times from main memory need %lf sec\n\ The bandwidth is %lfbyte/sec\n",\
BIG_ARR, sec, BIG_ARR / sec);
return 0;
}
The running results are as follows ( Here the code output forgets to multiply the number of bytes sizeof(int), So the final result needs to be multiplied by 4)
obtain b a n d w i d t h = 359453271 i n t / s e c ≈ 1.44 M / s e c bandwidth = 359453271 \ int/sec \approx 1.44M/sec bandwidth=359453271 int/sec≈1.44M/sec
4. Enable cache
Will actually close cache load kernel module Just uninstall the module , Use the following instructions
$ rmmod disableCache.ko
$ dmesg
Output in the system log You can see the following output in , Explain that you have cache Enable .
notes : This test is in Intel i3 The complete ,AMD Need to be right cr0 Register for other operations , Code reference 2.
边栏推荐
- train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- Jump table introduction
- Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
- Dyson design award, changing the world with sustainable design
- 逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展
- Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
- AttributeError: ‘Version‘ object has no attribute ‘major‘
- GD32 RT-Thread OTA/Bootloader驱动函数
- 6. Redis new data type
- Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
猜你喜欢
MySQL advanced SQL statement of database (1)
Robot system dynamics - inertia parameters
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
机械臂速成小指南(五):末端执行器
文章内容无法复制复制不了
Rider does not prompt after opening unity script
Dyson design award, changing the world with sustainable design
JS obtient la chaîne spécifiée spécifiant la position du caractère & sous - chaîne spécifiant la plage de position du caractère 【 détails simples 】
Brève description du collecteur d'ordures G1
“昆明城市咖啡地图”活动再度开启
随机推荐
unable to convert expression into double array
AttributeError: ‘Version‘ object has no attribute ‘major‘
Brève description du collecteur d'ordures G1
Installation and use
Applying applet container technology to IOT ecological construction
Compare the maximum computing power of the Cenozoic top ant s19xp and the existing s19pro in bitland
OSError: [Errno 28] No space left on device
Rider does not prompt after opening unity script
MySQL index, transaction and storage engine of database (2)
1033 To Fill or Not to Fill
Koreano essential creates a professional style
6. Redis new data type
Use and description of event delegation
Theme Studio
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
MIT-6874-Deep Learning in the Life Sciences Week5
Robot system dynamics - inertia parameters
Article content cannot be copied
Koreano essential creates a professional style
Jump table introduction