当前位置:网站首页>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.
边栏推荐
- Deployment of efficient and versatile clusters lvs+kept highly available clusters
- 事件流的说明》
- log4j
- Oracle creates a stored procedure successfully, but the compilation fails
- Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
- KOREANO ESSENTIAL打造气质职场范
- 采坑:Didn‘t receive robot state (joint angles) with recent timestamp within 1 seconds.
- NLopt--非线性优化--原理介绍及使用方法
- A brief introduction to database mysql
- “昆明城市咖啡地图”活动再度开启
猜你喜欢

MIT-6874-Deep Learning in the Life Sciences Week4

【JVM】CMS简述

Js獲取指定字符串指定字符比特置&指定字符比特置區間的子串【簡單詳細】

Splendid China: public welfare tourism for the middle-aged and the elderly - entering Foshan nursing home

Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony

“昆明城市咖啡地图”活动再度开启

开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开

MySQL index, transaction and storage engine of database (2)

Brève description du collecteur d'ordures G1

Quick completion guide for mechanical arm (V): end effector
随机推荐
乡村振兴公益基金启动暨古茶树非遗保护公益行发布
【JVM】CMS简述
Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
L'activité "Kunming City coffee map" a rouvert
基于强化学习的股票量化交易Automated-Stock-Trading-Ensemble-Strategy
孙安民作品《莲花净心》数字藏品上线长城数艺
MIT-6874-Deep Learning in the Life Sciences Week4
Questions about cookies and sessions
7. development of mobile login function
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
KOREANO ESSENTIAL打造气质职场范
2022第六季完美童模 托克逊赛区 决赛圆满落幕
100个句子记完7000个雅思词汇,实际只有1043个词汇(包括 I and you 等简单词汇)
一些国内镜像源
华南产业集团发力数字经济,城链科技发布会成功召开
1033 To Fill or Not to Fill
The human agent of kDa, Jinbei kd6, takes you to explore the metauniverse
Appium automation test foundation - ADB shell command
The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art
逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展