Fixed a bug in memory idle calculation

The python script was not correctly calculating the idle times for
traces with long pause times due to refreshes. Also out of order
scheduling would screw up this calculation.
This commit is contained in:
Matthias Jung
2020-11-25 22:03:02 +01:00
parent 09eed96338
commit f008c0f4f6

View File

@@ -77,11 +77,45 @@ def memory_total(connection):
clk, unit = getClock(connection)
return (total[0]/clk)
@metric
def memory_idle(connection):
# This complex query identifies idle times where the DRAM is not used.
# The code works also if schedulers are used.
subquery = """ -- The subquery selects all TLM phases and sorts them according to BEGIN_RESP
SELECT
ROW_NUMBER () OVER (
ORDER BY q.PhaseBegin
) RowNum,
p.PhaseBegin AS BeginRequest,
p.PhaseEnd AS EndRequest,
q.PhaseBegin AS BeginResponse,
q.PhaseEnd AS EndResponse
FROM
Phases p,
Phases q
WHERE
p.PhaseName = "REQ"
AND q.PhaseName = "RESP"
AND p.Transact = q.Transact
"""
query = """
SELECT sum(b.BeginRequest - a.EndResponse) as idle FROM
(
{}
) AS a,
(
{}
) AS b
WHERE
(a.RowNum)=(b.RowNum-1) -- In the list of ordered transactions always compare two adjacent
AND b.BeginRequest > a.EndResponse; -- This makes sure that no negative summands exists
""".format(subquery, subquery)
cursor = connection.cursor()
cursor.execute(""" SELECT sum(p1.PhaseEnd - p2.PhaseBegin) FROM Phases p1, Phases p2 Where p1.PhaseName = "REQ" and p2.PhaseName = "RESP" and ((p1.Transact-1) = (p2.Transact)) and (p1.PhaseEnd > p2.PhaseBegin) """)
cursor.execute(query)
idle = cursor.fetchone()
if (idle[0] is None):
return 0
@@ -89,7 +123,6 @@ def memory_idle(connection):
clk, unit = getClock(connection)
return (idle[0]/clk)
@metric
def memory_delayed(connection):
total = memory_total(connection)
@@ -98,7 +131,29 @@ def memory_delayed(connection):
return total - active - idle
@metric
def memory_utilisation_percent_new(connection):
def memory_idle_in_percent(connection):
total = memory_total(connection)
idle = memory_idle(connection)
return (idle/total)*100
@metric
def memory_active_in_percent(connection):
total = memory_total(connection)
active = memory_active(connection)
return (active/total)*100
@metric
def memory_delayed_in_percent(connection):
total = memory_total(connection)
delayed = memory_delayed(connection)
return (delayed/total)*100
@metric
def memory_idle_active_delayed_check(connection):
return memory_idle_in_percent(connection) + memory_active_in_percent(connection) + memory_delayed_in_percent(connection)
@metric
def memory_utilisation_percent_without_idle(connection):
total = memory_total(connection)
active = memory_active(connection)
idle = memory_idle(connection)
@@ -106,15 +161,14 @@ def memory_utilisation_percent_new(connection):
@metric
def memory_utilisation_in_Gibps(connection):
def memory_utilisation_in_Gibps_without_idle(connection):
# This function calculates the memory utilisation in Gibit/s considering the memory_utilisation_percent_new function result.
maxDataRate = maximum_data_rate(connection)
memoryPercent = memory_utilisation_percent_new(connection)
memoryPercent = memory_utilisation_percent_without_idle(connection)
return (memoryPercent/100)*(maxDataRate/1024)
@metric
def memory_utilisation_percent_old(connection):
def memory_utilisation_percent_including_idle(connection):
cursor = connection.cursor()
cursor.execute(""" SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions """)
active = cursor.fetchone()
@@ -123,7 +177,6 @@ def memory_utilisation_percent_old(connection):
total = cursor.fetchone()
return (active[0]/total[0])*100
def refreshMissDecision(connection, calculatedMetrics):
cursor = connection.cursor()
cursor.execute("""SELECT phases.ID,PhaseBegin,PhaseEnd,TBank FROM Phases INNER JOIN transactions on transactions.id = phases.transact WHERE PhaseName IN ('REFA')' """)