blog 文章

2020/12/15

test

arm64_test.cpp
  1 
  2 #include "stdlib.h"
  3 #include "stdio.h"
  4 #include "string.h"
  5 #include "unistd.h"
  6 #include "fcntl.h"
  7 #include "pthread.h"
  8 #include "malloc.h"
  9 #include <sys/mman.h> // Needed for mlockall() 
 10 #include "stdint.h"
 11 #include <sched.h>
 12 #include <time.h>
 13 
 14 #define SYSFS_GPIO_EXPORT           "/sys/class/gpio/export"
 15 #define SYSFS_GPIO_RST_PIN_VAL      "136"
 16 #define SYSFS_GPIaO_RST_DIR          "/sys/class/gpio/gpio136/direction"
 17 #define SYSFS_GPIO_RST_DIR_VAL      "OUT"
 18 #define SYSFS_GPIO_RST_VAL          "/sys/class/gpio/gpio136/value"
 19 #define SYSFS_GPIO_RST_VAL_H        "1"
 20 #define SYSFS_GPIO_RST_VAL_L        "0"
 21 
 22 #define NSEC_PER_SEC		1000000000
 23 
 24 unsigned int  raw_read_cntfrq_el0(void)
 25 {
 26     unsigned int cntfrq_el0;
 27 
 28     __asm__ __volatile__("mrs %0, CNTFRQ_EL0\n\t" : "=r" (cntfrq_el0) : : "memory");
 29     return cntfrq_el0;
 30 }
 31 
 32 
 33 static long long armv8_read_CNTPCT_EL0(void)
 34 {
 35     long long val;
 36     asm volatile("mrs %0, CNTVCT_EL0" : "=r" (val));
 37     return val;
 38 } 
 39 
 40 
 41 pthread_t m_thread;
 42 void *MainThread(void *param)
 43 {
 44 	struct timespec t, t_start,t_end;  
 45     long long int tt,t_max=0,loop_count=0,t_execmax=0;
 46     
 47     
 48     int fd = 0, i, size=10*1024*1024;
 49     //int fd = 0, i, size=128*1024;
 50 	char *buf;
 51 
 52 	struct sched_param schedp;
 53 	memset(&schedp, 0, sizeof(schedp));
 54 	schedp.sched_priority = 90;
 55 	sched_setscheduler(0, SCHED_FIFO, &schedp);
 56 
 57     long long t1 = 0, t2 = 0;
 58 	cpu_set_t cpuset;
 59 	int cpu = 2;
 60      
 61 	CPU_ZERO(&cpuset);
 62 	CPU_SET(cpu, &cpuset);
 63 	sched_setaffinity(0, sizeof(cpuset), &cpuset);
 64 	pthread_detach(pthread_self());
 65 
 66 
 67 	buf = (char *) malloc(size);
 68 
 69     clock_gettime(CLOCK_MONOTONIC, &t);
 70     
 71 	while (1)
 72 	{
 73  clock_gettime(CLOCK_MONOTONIC, &t_end);		
 74  loop_count++;
 75  
 76         t1 = armv8_read_CNTPCT_EL0();
 77 
 78         if( loop_count > 5000 ) 
 79         { 
 80             if((tt=(t_end.tv_sec-t.tv_sec)*NSEC_PER_SEC+(t_end.tv_nsec-t.tv_nsec)) > t_max) 
 81                 t_max=tt;
 82         }    
 83         
 84 		for (i = 0; i < size; i = i + 1500)
 85 		{
 86 			buf[i]++;
 87 			//buf[0]++;
 88 		}
 89         t2 = armv8_read_CNTPCT_EL0();
 90             
 91 /* calculate next shot */
 92         t.tv_nsec += 1000000;  // 1000us
 93        
 94         while (t.tv_nsec >= NSEC_PER_SEC) {
 95 			t.tv_nsec -= NSEC_PER_SEC;
 96             t.tv_sec++;
 97             
 98         }
 99         
100         if( (t2-t1) > t_execmax  )
101             t_execmax = t2-t1;
102         
103         if( !(loop_count % 5000) ) 
104         {
105             printf("total:%lldus jitter:%lldus exec:%lldus\n", (t2-t1)/(raw_read_cntfrq_el0()/1000000),t_max/1000,t_execmax/(raw_read_cntfrq_el0()/1000000));
106             t_max=0;
107             t_execmax=0;
108         }
109             
110         clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
111          
112 	}
113 
114 	return (void*)0;
115 }
116 
117 int main()
118 {
119 	int fd = 0;
120 
121     if (mlockall(MCL_CURRENT | MCL_FUTURE))
122         perror("mlockall failed:");	// Turn off malloc trimming.
123     mallopt (M_TRIM_THRESHOLD, -1);	// Turn off mmap usage.	mallopt (M_MMAP_MAX, 0);
124 
125 
126 	pthread_create(&m_thread, NULL, MainThread, NULL);
127 	pthread_join(m_thread, NULL);
128 
129 	printf("INFO: Radio hard reset pin value open error.\n");
130 	return 0;
131 
132 }

1 則留言:

  1. 8 Casinos Near Hollywood, MD - Mapyro
    With 2,500 slots and 300 과천 출장샵 table 진주 출장샵 games, including 200 속초 출장안마 table games, the casino is located in South Maryland and is 울산광역 출장샵 open daily 청주 출장마사지 24 hours.

    回覆刪除