当前位置:网站首页>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.
边栏推荐
- Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
- Article content cannot be copied
- 《锦绣中华》中老年公益文旅游-走进佛山敬老院
- unable to convert expression into double array
- 跳跃表介绍
- How to seize the opportunity of NFT's "chaos"?
- [JVM] brief introduction to CMS
- KOREANO ESSENTIAL打造气质职场范
- MIT-6874-Deep Learning in the Life Sciences Week4
- Nlopt -- Nonlinear Optimization -- principle introduction and application method
猜你喜欢

Great Wall digital art digital collection platform releases the creation Badge

逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展

UAV project tracking record 83 -- PCB diagram completion

Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home

Deployment of efficient and versatile clusters lvs+kept highly available clusters

6.Redis新数据类型

Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

Jump table introduction

MIT-6874-Deep Learning in the Life Sciences Week5
随机推荐
Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
磁悬浮3D灯
Theme Studio
Rider does not prompt after opening unity script
Basic MySQL operation commands of database
KOREANO ESSENTIAL打造气质职场范
The URL copied by the browser and pasted into the document is a hyperlink
Enter the world of helium (hNT) hotspot servers to bring you different benefits
Appium automation test foundation - 12 Introduction to appium automated testing framework
Some domestic image sources
移植完整版RT-Thread到GD32F4XX(详细)
GD32 RT-Thread flash驱动函数
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
Force buckle 428 Serialize and deserialize n-tree DFS
Robot system dynamics - inertia parameters
GD32 RT-Thread OTA/Bootloader驱动函数
长城数艺数字藏品平台发布创世徽章
Deployment of efficient and versatile clusters lvs+kept highly available clusters
The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art