waste prints memory bandwidth

old-commit-hash: d341fe0240
commatwo_master
Comma Device 4 years ago
parent 66aba30092
commit 5aa898ef30
  1. 21
      scripts/waste.c

@ -3,6 +3,7 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <sched.h> #include <sched.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -11,6 +12,7 @@
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include "../selfdrive/common/timing.h" #include "../selfdrive/common/timing.h"
int get_nprocs(void);
double *ttime, *oout; double *ttime, *oout;
void waste(int pid) { void waste(int pid) {
@ -21,12 +23,12 @@ void waste(int pid) {
printf("set affinity to %d: %d\n", pid, ret); printf("set affinity to %d: %d\n", pid, ret);
// 256 MB // 256 MB
float32x4_t *tmp = (float32x4_t *)malloc(0x1000001*sizeof(float32x4_t)); float32x4_t *tmp = (float32x4_t *)malloc(0x1000000*sizeof(float32x4_t));
// comment out the memset for CPU only and not RAM // comment out the memset for CPU only and not RAM
// otherwise we need this to avoid the zero page // otherwise we need this to avoid the zero page
#ifdef MEM #ifdef MEM
memset(tmp, 0xaa, 0x1000001*sizeof(float32x4_t)); memset(tmp, 0xaa, 0x1000000*sizeof(float32x4_t));
#endif #endif
float32x4_t out; float32x4_t out;
@ -34,7 +36,7 @@ void waste(int pid) {
double sec = seconds_since_boot(); double sec = seconds_since_boot();
while (1) { while (1) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
for (int j = 0; j < 0x1000000; j++) { for (int j = 0; j < 0x1000000; j+=2) {
out = vmlaq_f32(out, tmp[j], tmp[j+1]); out = vmlaq_f32(out, tmp[j], tmp[j+1]);
} }
} }
@ -51,16 +53,19 @@ int main() {
oout = (double *)malloc(CORES*sizeof(double)); oout = (double *)malloc(CORES*sizeof(double));
pthread_t waster[CORES]; pthread_t waster[CORES];
for (int i = 0 ; i < CORES; i++) { for (long i = 0; i < CORES; i++) {
pthread_create(&waster[i], NULL, waste, (void*)i); ttime[i] = NAN;
pthread_create(&waster[i], NULL, (void *(*)(void *))waste, (void*)i);
} }
while (1) { while (1) {
double avg = 0.0; double avg = 0.0;
for (int i = 0 ; i < CORES; i++) { for (int i = 0; i < CORES; i++) {
avg += ttime[i]; avg += ttime[i];
printf("%.2f ", ttime[i]); printf("%4.2f ", ttime[i]);
} }
printf("-- %.2f\n", avg/CORES); avg /= CORES;
double mb_per_sec = (8.*0x1000000/(1024*1024))*sizeof(float32x4_t)*CORES*(1/avg);
printf("-- %4.2f -- %.2f MB/s \n", avg, mb_per_sec);
sleep(1); sleep(1);
} }
} }

Loading…
Cancel
Save