A4MCAR - Dummy graph to demonstrate partitioning features added. Tracing features are also updated.
(Models will soon be updated)
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/a4mcar/high_level_applications/apps/dummy_loads/dummy_graph.py b/a4mcar/high_level_applications/apps/dummy_loads/dummy_graph.py
new file mode 100644
index 0000000..e05dbe5
--- /dev/null
+++ b/a4mcar/high_level_applications/apps/dummy_loads/dummy_graph.py
@@ -0,0 +1,193 @@
+#!/usr/bin/python
+
+# Copyright (c) 2017 Eclipse Foundation and FH Dortmund.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# A4MCAR Project - Application that creates a dummy graph using threads
+#
+# Author:
+# M. Ozcelikors <mozcelikors@gmail.com>
+
+import sys
+import os
+import string
+import math
+import datetime
+import time
+import threading
+from threading import Lock
+from time import localtime, strftime
+import prctl
+import numpy
+import imp
+import string
+import signal
+
+aprocessSrc = imp.load_source('aprocess','../touchscreen_display/aprocess.py')
+
+# Set-up
+matrix_size = 190
+periods = 0.5
+thread_names = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
+instruction_size_scales = [ 1, 3, 4, 9, 1, 2, 5, 3, 2, 4 ]
+#mapped_cores = ["3","3","3","3","3","3","3","3","3","3"]
+mapped_cores = ["0-3","0-3","0-3","0-3","0-3","0-3","0-3","0-3","0-3","0-3"]
+threads = [None] * 10
+
+# 1-byte Labels
+BF = "0"
+BG = "0"
+BJ = "0"
+CH = "0"
+AE = "0"
+EH = "0"
+DJ = "0"
+HI = "0"
+GI = "0"
+FI = "0"
+
+def StopAllThreads():
+ global thread_names
+ global threads
+ for i in range (0, len(thread_names)):
+ try:
+ threads[i].join(0)
+ except Exception as inst:
+ print inst
+
+# Join all threads gracefully when SIGINT received, (Ctrl+C)
+def Signal_Handler (signal, frame):
+ StopAllThreads()
+ sys.exit(0)
+
+
+# Worker function
+def Worker(name, instruction_size_scale, core_affinity):
+ global aprocessSrc
+
+ # Set-up parameters
+ global matrix_size
+ global periods
+
+ # Labels
+ global BF
+ global BG
+ global BJ
+ global CH
+ global AE
+ global EH
+ global DJ
+ global HI
+ global GI
+ global FI
+ read_label = "n"
+
+ #Timing Related ---start
+ _thr_DEADLINE = periods
+ _thr_START_TIME = 0
+ _thr_END_TIME = 0
+ _thr_EXECUTION_TIME = 0
+ _thr_PREV_SLACK_TIME = 0
+ _thr_PERIOD = periods
+ #Timing Related ---end
+
+ #Initialize thread and append it to the global process list
+ this_thread = aprocessSrc.aprocess(name, 1, "../../logs/timing/"+name+".inc", 0, name, "None", 1)
+ this_thread.UpdateThreadIDAndRunning()
+ this_thread.SetCoreAffinityOfThread(core_affinity)
+ prctl.set_name(name) #Sets the thread title for linux kernel
+
+ while True:
+ #Timing Related
+ _thr_START_TIME = time.time()
+ _thr_PREV_SLACK_TIME = _thr_START_TIME - _thr_END_TIME
+
+ #TASK CONTENT starts here
+ # Dummy read label
+ if (name == "F"):
+ read_label = BF
+ elif (name == "G"):
+ read_label = BG
+ elif (name == "E"):
+ read_label = AE
+ elif (name == "H"):
+ read_label = EH
+ read_label = read_label + CH
+ elif (name == "I"):
+ read_label = FI
+ read_label = read_label + GI
+ read_label = read_label + HI
+ elif (name == "J"):
+ read_label = BJ
+ read_label = read_label + DJ
+
+ # Dummy work
+ for i in range(0,instruction_size_scale):
+ a=numpy.random.random([matrix_size, matrix_size])
+ b=numpy.random.random([matrix_size, matrix_size])
+ c=numpy.mean(a*b)
+
+ # Dummy write label
+ if (name == "B"):
+ BF = "w"
+ BG = "w"
+ BJ = "w"
+ elif (name == "F"):
+ FI = "w"
+ elif (name == "C"):
+ CH = "w"
+ elif (name == "G"):
+ GI = "w"
+ elif (name == "A"):
+ AE = "w"
+ elif (name == "E"):
+ EH = "w"
+ elif (name == "H"):
+ HI = "w"
+ elif (name == "D"):
+ DJ = "w"
+
+ #Create timing log
+ try:
+ file_obj = open(str(this_thread.aplogfilepath), "w+r")
+ except Exception as inst:
+ print inst
+ #dbg = 1
+ _thr_END_TIME = time.time()
+ _thr_EXECUTION_TIME = _thr_END_TIME - _thr_START_TIME
+ try:
+ file_obj.write(str(_thr_PREV_SLACK_TIME)+' '+str(_thr_EXECUTION_TIME)+' '+str(_thr_PERIOD)+' '+str(_thr_DEADLINE))
+ file_obj.close()
+ except Exception as inst:
+ #print inst
+ dbg = 1
+
+ # Delay
+ if (_thr_PERIOD > _thr_EXECUTION_TIME):
+ time.sleep(_thr_PERIOD - _thr_EXECUTION_TIME)
+
+#Main
+#Threads start
+for i in range (0, len(thread_names)):
+ try:
+ threads[i] = threading.Thread(target=Worker, args=(thread_names[i], instruction_size_scales[i], mapped_cores[i]), name=thread_names[i])
+ threads[i].setDaemon(True)
+ threads[i].start()
+ except Exception as inst:
+ print inst
+
+done = False
+signal.signal(signal.SIGINT, Signal_Handler)
+signal.pause()
+
+while not done:
+ # Main thread doing nothing.
+ try:
+ time.sleep(1)
+ except (KeyboardInterrupt, SystemExit):
+ StopAllThreads()
+ sys.exit(0)
\ No newline at end of file
diff --git a/a4mcar/high_level_applications/apps/touchscreen_display/aprocess.py b/a4mcar/high_level_applications/apps/touchscreen_display/aprocess.py
index dc8e4c8..01f442e 100644
--- a/a4mcar/high_level_applications/apps/touchscreen_display/aprocess.py
+++ b/a4mcar/high_level_applications/apps/touchscreen_display/aprocess.py
@@ -98,4 +98,10 @@
except Exception as inst:
debug = 1
print inst
+
+ def OverrideAProcessAttributes(self, running, core_affinity, aplogfilepath):
+ self.aprunning = running
+ self.aaffinity = core_affinity
+ self.aplogfilepath = aplogfilepath
+ return 1
\ No newline at end of file
diff --git a/a4mcar/high_level_applications/apps/touchscreen_display/touchscreen_display.py b/a4mcar/high_level_applications/apps/touchscreen_display/touchscreen_display.py
index e584f71..a29c3af 100644
--- a/a4mcar/high_level_applications/apps/touchscreen_display/touchscreen_display.py
+++ b/a4mcar/high_level_applications/apps/touchscreen_display/touchscreen_display.py
@@ -70,14 +70,26 @@
aprocess_list.append(aprocess.aprocess("touchscreen_display", 1, "../../logs/timing/touchscreen_display_timing.inc", 1, "Display", "None", 0))
aprocess_list.append(aprocess.aprocess("ethernet_client", 1, "../../logs/timing/ethernet_client_timing.inc", 1, "Ethernet App", "cd ../ethernet_client/ && sudo ./ethernet_client.py &", 0))
aprocess_list.append(aprocess.aprocess("core_recorder", 1, "../../logs/timing/core_recorder_timing.inc", 1, "Core Recorder", "cd ../core_recorder/ && sudo ./core_recorder.py &", 0))
-aprocess_list.append(aprocess.aprocess("dummy_load25_1", 1, "../../logs/timing/dummy_load25_1_timing.inc", 1, "Cycler25_1", "cd ../dummy_loads/ && sudo ./dummy_load25_1.py &", 0))
-aprocess_list.append(aprocess.aprocess("dummy_load25_2", 1, "../../logs/timing/dummy_load25_2_timing.inc", 1, "Cycler25_2", "cd ../dummy_loads/ && sudo ./dummy_load25_2.py &", 0))
-aprocess_list.append(aprocess.aprocess("dummy_load25_3", 1, "../../logs/timing/dummy_load25_3_timing.inc", 1, "Cycler25_3", "cd ../dummy_loads/ && sudo ./dummy_load25_3.py &", 0))
-aprocess_list.append(aprocess.aprocess("dummy_load25_4", 1, "../../logs/timing/dummy_load25_4_timing.inc", 1, "Cycler25_4", "cd ../dummy_loads/ && sudo ./dummy_load25_4.py &", 0))
+#aprocess_list.append(aprocess.aprocess("dummy_load25_1", 1, "../../logs/timing/dummy_load25_1_timing.inc", 1, "Cycler25_1", "cd ../dummy_loads/ && sudo ./dummy_load25_1.py &", 0))
+#aprocess_list.append(aprocess.aprocess("dummy_load25_2", 1, "../../logs/timing/dummy_load25_2_timing.inc", 1, "Cycler25_2", "cd ../dummy_loads/ && sudo ./dummy_load25_2.py &", 0))
+#aprocess_list.append(aprocess.aprocess("dummy_load25_3", 1, "../../logs/timing/dummy_load25_3_timing.inc", 1, "Cycler25_3", "cd ../dummy_loads/ && sudo ./dummy_load25_3.py &", 0))
+#aprocess_list.append(aprocess.aprocess("dummy_load25_4", 1, "../../logs/timing/dummy_load25_4_timing.inc", 1, "Cycler25_4", "cd ../dummy_loads/ && sudo ./dummy_load25_4.py &", 0))
#aprocess_list.append(aprocess.aprocess("dummy_load25_5", 1, "../../logs/timing/dummy_load25_5_timing.inc", 1, "Cycler25_5", "cd ../dummy_loads/ && sudo ./dummy_load25_5.py &", 0))
#aprocess_list.append(aprocess.aprocess("dummy_load100", 1, "../../logs/timing/dummy_load100_timing.inc", 1, "Cycler100", "cd ../dummy_loads/ && sudo ./dummy_load100.py &", 0))
aprocess_list.append(aprocess.aprocess("apache2", 0, "None", 1, "Apache Server", "sudo service apache2 start", 0))
aprocess_list.append(aprocess.aprocess("image_processing", 1, "../../logs/timing/image_processing_timing.inc", 1, "ImageProcess", "cd ../image_processing/ && sudo -E ./image_processing &", 0))
+
+#Add dummy graph's main process
+aprocess_list.append(aprocess.aprocess("dummy_graph", 0, "None", 1, "Dummy Graph", "cd ../dummy_loads/ && sudo ./dummy_graph.py &", 0))
+
+#Add dummy_graph threads
+thread_names = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
+thread_objs = [None] * len(thread_names)
+for i in range (0, len(thread_names)):
+ thread_objs[i] = aprocess.aprocess(thread_names[i], 1, "../../logs/timing/"+thread_names[i]+".inc", 0, thread_names[i], "None", 1)
+ aprocess_list.append(thread_objs[i])
+
+#Find out aprocess list length
aprocess_list_len = len(aprocess_list)
#Software Distribution Type
@@ -110,6 +122,9 @@
#Locks for mutual exclusion
lock_aprocess_list = Lock()
+#Maximum number of processes to display
+no_of_proc_to_display = 14
+
#For timing calculations, missed deadlines, total processes, and slack time sum
missed=0
total=0
@@ -617,6 +632,7 @@
global aprocess_list_len
global coord_x
global coord_y
+ global no_of_proc_to_display
#Red and green color
color_red = ((255,0,0))
@@ -628,18 +644,27 @@
#UpdateProcessInfo() #Not needed now since the Thread_TimingCalculation updates this constantly
lock_aprocess_list.acquire() #----
+ k = 0
for i in range(0,aprocess_list_len):
- if (aprocess_list[i].aprunning == 1):
- colorc = color_green
- else:
- colorc = color_red
- text = font.render (str(aprocess_list[i].display_name), True, colorc)
- screen.blit(text,(coord_x[i],coord_y[i]))
+ if (k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+
+ if (aprocess_list[i].aprunning == 1):
+ colorc = color_green
+ else:
+ colorc = color_red
+ text = font.render (str(aprocess_list[i].display_name), True, colorc)
+ screen.blit(text,(coord_x[k],coord_y[k]))
+ k = k + 1
lock_aprocess_list.release() #----
def KillProcess(process_name):
pid = GetProcessIDFromProcessName(process_name)
+ if (process_name == "dummy_graph"):
+ for i in range(0,aprocess_list_len):
+ if (len(aprocess_list[i].apname) < 2):
+ aprocess_list[i].aprunning = 0
+
if (process_name == "apache2"):
try:
os.system("sudo service apache2 stop &")
@@ -687,6 +712,10 @@
global aprocess_list
global aprocess_list_len
+ if (process_name == "dummy_graph"):
+ for i in range(0,aprocess_list_len):
+ if (len(aprocess_list[i].apname) < 2):
+ aprocess_list[i].aprunning = 1
for i in range(0,aprocess_list_len):
if (process_name == aprocess_list[i].apname):
@@ -694,13 +723,13 @@
os.system(str(aprocess_list[i].apstartcommand))
except Exception as inst:
print "Err-StartProcess"
-
def AllocationPage():
global aprocess_list
global aprocess_list_len
global coord_x
global coord_y
+ global no_of_proc_to_display
Clear_Variables()
@@ -719,22 +748,25 @@
#UpdateProcessInfo() #Not needed now since the Thread_TimingCalculation updates this constantly
lock_aprocess_list.acquire() #----
+ k = 0
for i in range(0,aprocess_list_len):
- font = pygame.font.SysFont("Roboto Condensed", 30)
- text = font.render (str(aprocess_list[i].display_name), True, (0, 0, 0))
- screen.blit(text,(coord_x[i],coord_y[i]))
- font = pygame.font.SysFont("Roboto Condensed", 20)
+ if (k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+ font = pygame.font.SysFont("Roboto Condensed", 30)
+ text = font.render (str(aprocess_list[i].display_name), True, (0, 0, 0))
+ screen.blit(text,(coord_x[k],coord_y[k]))
+ font = pygame.font.SysFont("Roboto Condensed", 20)
- if (aprocess_list[i].isthread == 0):
- AddPromptBox_Passive(coord_x[i]+180, coord_y[i], 60, 40)
- text = font.render ("Start", True, (255, 0, 0))
- screen.blit(text,(coord_x[i]+190,coord_y[i]+10))
- AddPromptBox_Passive(coord_x[i]+250, coord_y[i], 50, 40)
- text = font.render ("Kill", True, (255, 0, 0))
- screen.blit(text,(coord_x[i]+260,coord_y[i]+10))
- else:
- text = font.render ("[Thread]", True, (0, 0, 255))
- screen.blit(text,(coord_x[i]+180,coord_y[i]+10))
+ if (aprocess_list[i].isthread == 0):
+ AddPromptBox_Passive(coord_x[k]+180, coord_y[k], 60, 40)
+ text = font.render ("Start", True, (255, 0, 0))
+ screen.blit(text,(coord_x[k]+190,coord_y[k]+10))
+ AddPromptBox_Passive(coord_x[k]+250, coord_y[k], 50, 40)
+ text = font.render ("Kill", True, (255, 0, 0))
+ screen.blit(text,(coord_x[k]+260,coord_y[k]+10))
+ else:
+ text = font.render ("[Thread]", True, (0, 0, 255))
+ screen.blit(text,(coord_x[k]+180,coord_y[k]+10))
+ k = k + 1
lock_aprocess_list.release() #----
return 1
@@ -751,6 +783,7 @@
global aprocess_list_len
global coord_x
global coord_y
+ global no_of_proc_to_display
#UpdateProcessInfo()
#GetCoreInfoRpi()
@@ -760,19 +793,22 @@
color_green = ((34,139,34))
lock_aprocess_list.acquire()#----
+ k = 0
for i in range(0,aprocess_list_len):
- if (aprocess_list[i].aprunning == 1):
- colorc = color_green
- else:
- colorc = color_red
-
- font = pygame.font.SysFont("Roboto Condensed", 30)
- text = font.render (str(aprocess_list[i].display_name), True, colorc)
- screen.blit(text,(coord_x[i], coord_y[i]))
- font = pygame.font.SysFont("Roboto Condensed", 20)
- AddPromptBox_Passive(coord_x[i]+180, coord_y[i], 60, 40)
- text = font.render (str(aprocess_list[i].aaffinity), True, (0, 0, 0))
- screen.blit(text,(coord_x[i]+190,coord_y[i]+10))
+ if (k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+ if (aprocess_list[i].aprunning == 1):
+ colorc = color_green
+ else:
+ colorc = color_red
+
+ font = pygame.font.SysFont("Roboto Condensed", 30)
+ text = font.render (str(aprocess_list[i].display_name), True, colorc)
+ screen.blit(text,(coord_x[k], coord_y[k]))
+ font = pygame.font.SysFont("Roboto Condensed", 20)
+ AddPromptBox_Passive(coord_x[k]+180, coord_y[k], 60, 40)
+ text = font.render (str(aprocess_list[i].aaffinity), True, (0, 0, 0))
+ screen.blit(text,(coord_x[k]+190,coord_y[k]+10))
+ k = k + 1
lock_aprocess_list.release()#----
def CoreAllocationPage():
@@ -780,6 +816,7 @@
global aprocess_list_len
global coord_x
global coord_y
+ global no_of_proc_to_display
Clear_Variables()
@@ -796,17 +833,20 @@
screen.blit(text,(30,30))
lock_aprocess_list.acquire() #----
+ k = 0
for i in range(0,aprocess_list_len):
- font = pygame.font.SysFont("Roboto Condensed", 30)
- text = font.render (str(aprocess_list[i].display_name), True, (0, 0, 0))
- screen.blit(text,(coord_x[i],coord_y[i]))
- font = pygame.font.SysFont("Roboto Condensed", 20)
- AddPromptBox_Passive(coord_x[i]+180, coord_y[i], 60, 40)
- text = font.render ("", True, (0, 0, 0))
- screen.blit(text,(coord_x[i]+190,coord_y[i]+10))
- AddPromptBox_Passive(coord_x[i]+250, coord_y[i], 80, 40)
- text = font.render ("Allocate", True, (255, 0, 0))
- screen.blit(text,(coord_x[i]+260,coord_y[i]+10))
+ if (k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+ font = pygame.font.SysFont("Roboto Condensed", 30)
+ text = font.render (str(aprocess_list[i].display_name), True, (0, 0, 0))
+ screen.blit(text,(coord_x[k],coord_y[k]))
+ font = pygame.font.SysFont("Roboto Condensed", 20)
+ AddPromptBox_Passive(coord_x[k]+180, coord_y[k], 60, 40)
+ text = font.render ("", True, (0, 0, 0))
+ screen.blit(text,(coord_x[k]+190,coord_y[k]+10))
+ AddPromptBox_Passive(coord_x[k]+250, coord_y[k], 80, 40)
+ text = font.render ("Allocate", True, (255, 0, 0))
+ screen.blit(text,(coord_x[k]+260,coord_y[k]+10))
+ k = k + 1
lock_aprocess_list.release() #----
return 1
@@ -1117,7 +1157,7 @@
aprocess_list.append(this_thread)
lock_aprocess_list.release() #----
aprocess_list_len = len(aprocess_list)
- prctl.set_name("Thread_TimingCalculation")
+ prctl.set_name("Thread_TimingCalculation") #Sets the thread title for linux kernel
while True:
@@ -1225,7 +1265,7 @@
aprocess_list.append(this_thread)
lock_aprocess_list.release() #----
aprocess_list_len = len(aprocess_list)
- prctl.set_name("Thread_TouchscreenEvents")
+ prctl.set_name("Thread_TouchscreenEvents") #Sets the thread title for linux kernel
while True:
#Timing Related
@@ -1311,12 +1351,14 @@
kill_w = 50
h=40
+ k=0
for i in range(0,aprocess_list_len):
- if (aprocess_list[i].isthread == 0):
- if ((mouseX>180+coord_x[i] and mouseX<180+coord_x[i]+start_w) and (mouseY>coord_y[i] and mouseY < coord_y[i]+h)):
+ if (aprocess_list[i].isthread == 0 and k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+ if ((mouseX>180+coord_x[k] and mouseX<180+coord_x[k]+start_w) and (mouseY>coord_y[k] and mouseY < coord_y[k]+h)):
StartProcess(aprocess_list[i].apname)
- if ((mouseX>250+coord_x[i] and mouseX<250+coord_x[i]+kill_w) and (mouseY>coord_y[i] and mouseY < coord_y[i]+h)):
+ if ((mouseX>250+coord_x[k] and mouseX<250+coord_x[k]+kill_w) and (mouseY>coord_y[k] and mouseY < coord_y[k]+h)):
KillProcess(aprocess_list[i].apname)
+ k = k + 1
if (Current_Page == 5 ):
#CoreAllocationPage
@@ -1324,9 +1366,12 @@
kill_w = 80
h=40
+ k = 0
for i in range(0,aprocess_list_len):
- if ((mouseX>250+coord_x[i] and mouseX<250+coord_x[i]+kill_w) and (mouseY>coord_y[i] and mouseY < coord_y[i]+h)):
- AllocateProcessInMainThread(aprocess_list[i].apname)
+ if (k < no_of_proc_to_display and aprocess_list[i].displayed == 1):
+ if ((mouseX>250+coord_x[k] and mouseX<250+coord_x[k]+kill_w) and (mouseY>coord_y[k] and mouseY < coord_y[k]+h)):
+ AllocateProcessInMainThread(aprocess_list[i].apname)
+ k = k + 1
if (Current_Page == 8):
if ((mouseX>320 and mouseX<387) and (mouseY>302 and mouseY<332)):
@@ -1387,7 +1432,7 @@
aprocess_list.append(this_thread)
lock_aprocess_list.release() #----
aprocess_list_len = len(aprocess_list)
- prctl.set_name("Thread_UpdateCoreUsageInfo")
+ prctl.set_name("Thread_UpdateCoreUsageInfo") #Sets the thread title for linux kernel
while True:
#Timing Related