1 /* 2 * Copyright (C) 2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <iostream> 8 #include <unordered_map> 9 #include <string> 10 11 #include <semaphore.h> 12 #include <fcntl.h> 13 #include <signal.h> 14 15 #include <sys/ipc.h> 16 #include <sys/shm.h> 17 #include <sys/mman.h> 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 21 #include "ivshmemlib.h" 22 23 using namespace std; 24 25 class LatencyCounter 26 { 27 public: 28 29 //A total count of the latencies 30 unsigned int latenciesCount; 31 32 /*Used for sending the data needed for the histogram to python 33 First value is the latency data point, second value is the count*/ 34 unordered_map<int,int> *latencyValues; 35 LatencyCounter()36 LatencyCounter() 37 { 38 latenciesCount = 0; 39 latencyValues = new unordered_map<int,int>(); 40 } 41 ~LatencyCounter()42 ~LatencyCounter() 43 { 44 45 latenciesCount = 0; 46 delete latencyValues; 47 48 } 49 50 /* 51 void clear(void) 52 53 This method clears the latency counter 54 */ clear(void)55 void clear(void) 56 { 57 58 latenciesCount = 0; 59 latencyValues->clear(); 60 61 } 62 63 }; 64 65 #define SHM_KEY "/pyservershm" 66 #define SHM_ID 1337 67 #define SHM_SIZE 1048576 68 69 #define SEM_KEY "/pyserversem" 70 71 #define BUFFERSIZE 256 72 73 //Used for synchronizing between the webserver and the data 74 sem_t *web_sem; 75 76 //Shared memory region between userapp and webapp 77 char *shm_addr; 78 79 //Used for holding the data from cyclictest 80 char data_buffer[BUFFERSIZE] = {0}; 81 char *search_str; 82 83 char *setup_ipcomms(void); 84 char *setup_shm_region(void); 85 int remove_shm_region(void *); 86 87 int process_data(LatencyCounter&); 88 int dump_data(LatencyCounter&, char *); 89 90 void sig_handler(int); 91