diff --git a/misc/sample_application/README.rst b/misc/sample_application/README.rst index ccc4bcf4a..df301b842 100644 --- a/misc/sample_application/README.rst +++ b/misc/sample_application/README.rst @@ -1,11 +1,11 @@ ACRN Sample Application ####################### -This directory contains the software that is necessary to run a real-time application between a real-time VM and a standard VM using the acrn-hypervisor. +This directory contains a software application that runs a real-time application between a real-time VM and a standard VM using the acrn-hypervisor. -The ``rtvm`` directory contains the code required to pipe data from ``cyclictest`` to the User VM using the inter-vm shared memory feature that acrn-hypervisor exposes to its VMs. +The ``rtvm`` directory contains the code that reads and pipes data from ``cyclictest`` to the User VM using the inter-vm shared memory feature that acrn-hypervisor exposes to its VMs. -The ``uservm`` directory contains the code required to read the piped data from the RTVM, process the data, and display that data over a web application that can be accessed from the hypervisor's Service VM. +The ``uservm`` directory contains the code that reads the piped data from the RTVM, processes the data, and displays the data over a web application that can be accessed from the hypervisor's Service VM. To build and run the applications, copy this repo to your VMs, run make in the directory that corresponds to the VM that you are running, and then follow the sample app guide in the acrn-hypervisor documentation. diff --git a/misc/sample_application/rtvm/ivshmemlib.c b/misc/sample_application/rtvm/ivshmemlib.c index 05d621994..4aa3e5080 100644 --- a/misc/sample_application/rtvm/ivshmemlib.c +++ b/misc/sample_application/rtvm/ivshmemlib.c @@ -20,7 +20,7 @@ On failure it returns -1 */ int setup_ivshmem_region(const char *f_path) { - + //Open the file so we can map it into memory int pci_file = open(f_path, O_RDWR | O_SYNC); if (pci_file == failure) { @@ -29,18 +29,18 @@ int setup_ivshmem_region(const char *f_path) return failure; } - + //Map the file into memory ivshmem_ptr = (char *)mmap(0, REGION_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, pci_file , 0); close(pci_file); if (!ivshmem_ptr) { perror("Failed to map the shared memory region into our address space\n"); - return failure; + return failure; } - return success; + return success; } /* @@ -61,9 +61,9 @@ int close_ivshmem_region(void) ret_val = munmap(ivshmem_ptr, REGION_SIZE); ivshmem_ptr = NULL; - + } - + else printf("Ivshmem region is not set up."); @@ -92,16 +92,18 @@ size_t read_ivshmem_region(char *user_ptr, size_t size) return ret; //Determine if ivshmem region is set up - if (ivshmem_ptr) { - + if ((ivshmem_ptr) && (size < REGION_SIZE - 1)) { + //Do the copy and zero out the ivshmem region - strncpy(user_ptr, ivshmem_ptr, size - 1); - user_ptr[size] = 0; + bzero(user_ptr, size); + strncpy(user_ptr, ivshmem_ptr, size); + ivshmem_ptr[size] = '\0'; + user_ptr[size] = '\0'; ret = strlen(user_ptr); - bzero(ivshmem_ptr, ret); + bzero(ivshmem_ptr, size); } - + else printf("Ivshmem region is not set up."); @@ -126,20 +128,22 @@ size_t write_ivshmem_region(char *user_ptr, size_t size) //Make sure that we need to actually write something if (size == 0) - + return ret; //Determine if ivshmem region is set up - if (ivshmem_ptr) { + if ((ivshmem_ptr) && (size < REGION_SIZE - 1)) { //Do the copy and zero out the user_ptr - strncpy(ivshmem_ptr, user_ptr, size - 1); - user_ptr[size] = 0; + bzero(ivshmem_ptr, size); + strncpy(ivshmem_ptr, user_ptr, size); + user_ptr[size] = '\0'; + ivshmem_ptr[size] = '\0'; ret = strlen(ivshmem_ptr); - bzero(user_ptr, ret); - + bzero(user_ptr, size); + } - + else printf("Ivshmem region is not set up."); diff --git a/misc/sample_application/rtvm/rtApp.c b/misc/sample_application/rtvm/rtApp.c index a50dc1788..26d275bd4 100644 --- a/misc/sample_application/rtvm/rtApp.c +++ b/misc/sample_application/rtvm/rtApp.c @@ -64,7 +64,7 @@ int main(void) //Read the data bzero(data_buffer, BUFFERSIZE); - read(data_pipe, data_buffer, BUFFERSIZE); + read(data_pipe, data_buffer, BUFFERSIZE - 1); //Get the sample stat start_stat = strstr(data_buffer, "T:"); diff --git a/misc/sample_application/uservm/histapp.py b/misc/sample_application/uservm/histapp.py index 118a94ad9..dc4044e3e 100644 --- a/misc/sample_application/uservm/histapp.py +++ b/misc/sample_application/uservm/histapp.py @@ -27,7 +27,7 @@ def histapp(): #Send the histogram as a webpage to the user return send_file("hist.png", mimetype='image/png') - + #Creates the user histogram and saves to hist.png def create_hist(): @@ -41,7 +41,7 @@ def create_hist(): #Transform the data into an array that matplotlib can understand dataset = transform_data(data) - + #Clear the figure and recreate from the new data plt.clf() @@ -57,8 +57,10 @@ def create_hist(): return figure def transform_data(data_string): + + #Holds the transformed data transformed_data_values = [] - + str_data = data_string.decode("utf-8") str_data = str_data.replace('\n',"") @@ -66,7 +68,7 @@ def transform_data(data_string): #Holds the count of latencies that we have total_count = data_values[0] - + #Used for transforming the data values data_percentages = data_values[1:] if (len(data_percentages) % 2 != 0): @@ -90,4 +92,4 @@ if __name__ == '__main__': web_sem = ipc.Semaphore("/pyserversem", 0, 0o0774) #Run the webserver - app.run(host="0.0.0.0", port=80, debug=True) + app.run(host="0.0.0.0", port=80, debug=False) diff --git a/misc/sample_application/uservm/ivshmemlib.c b/misc/sample_application/uservm/ivshmemlib.c index 05d621994..713b6be0d 100644 --- a/misc/sample_application/uservm/ivshmemlib.c +++ b/misc/sample_application/uservm/ivshmemlib.c @@ -20,7 +20,7 @@ On failure it returns -1 */ int setup_ivshmem_region(const char *f_path) { - + //Open the file so we can map it into memory int pci_file = open(f_path, O_RDWR | O_SYNC); if (pci_file == failure) { @@ -29,18 +29,18 @@ int setup_ivshmem_region(const char *f_path) return failure; } - + //Map the file into memory ivshmem_ptr = (char *)mmap(0, REGION_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, pci_file , 0); close(pci_file); if (!ivshmem_ptr) { perror("Failed to map the shared memory region into our address space\n"); - return failure; + return failure; } - return success; + return success; } /* @@ -61,9 +61,9 @@ int close_ivshmem_region(void) ret_val = munmap(ivshmem_ptr, REGION_SIZE); ivshmem_ptr = NULL; - + } - + else printf("Ivshmem region is not set up."); @@ -92,16 +92,18 @@ size_t read_ivshmem_region(char *user_ptr, size_t size) return ret; //Determine if ivshmem region is set up - if (ivshmem_ptr) { - + if ((ivshmem_ptr) && (size < REGION_SIZE - 1)) { + //Do the copy and zero out the ivshmem region - strncpy(user_ptr, ivshmem_ptr, size - 1); - user_ptr[size] = 0; + bzero(user_ptr, size); + strncpy(user_ptr, ivshmem_ptr, size); + ivshmem_ptr[size] = '\0'; + user_ptr[size] = '\0'; ret = strlen(user_ptr); - bzero(ivshmem_ptr, ret); + bzero(ivshmem_ptr, size); } - + else printf("Ivshmem region is not set up."); @@ -126,20 +128,22 @@ size_t write_ivshmem_region(char *user_ptr, size_t size) //Make sure that we need to actually write something if (size == 0) - + return ret; //Determine if ivshmem region is set up - if (ivshmem_ptr) { + if ((ivshmem_ptr) && (size < REGION_SIZE - 1)){ //Do the copy and zero out the user_ptr - strncpy(ivshmem_ptr, user_ptr, size - 1); - user_ptr[size] = 0; + bzero(ivshmem_ptr, size); + strncpy(ivshmem_ptr, user_ptr, size); + user_ptr[size] = '\0'; + ivshmem_ptr[size] = '\0'; ret = strlen(ivshmem_ptr); - bzero(user_ptr, ret); - + bzero(user_ptr, size); + } - + else printf("Ivshmem region is not set up."); diff --git a/misc/sample_application/uservm/userApp.cpp b/misc/sample_application/uservm/userApp.cpp index 59105b69a..7737db65e 100644 --- a/misc/sample_application/uservm/userApp.cpp +++ b/misc/sample_application/uservm/userApp.cpp @@ -44,7 +44,7 @@ int main(void) latencies.latenciesCount++; //Dump the data if we have enough data points - if (latencies.latenciesCount % 100 == 0) { + if ((latencies.latenciesCount > 0) && (latencies.latenciesCount % 100 == 0)) { dump_data(latencies, shm_addr);