forked from Imagelibrary/rtems
smplock01: Convert to JSON data
This avoids a dependency on the non-standard libxml2 module.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2013, 2016 embedded brains GmbH & Co. KG
|
* Copyright (C) 2013, 2024 embedded brains GmbH & Co. KG
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -47,6 +47,8 @@ const char rtems_test_name[] = "SMPLOCK 1";
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
rtems_test_parallel_context base;
|
rtems_test_parallel_context base;
|
||||||
|
const char *test_sep;
|
||||||
|
const char *counter_sep;
|
||||||
unsigned long counter[TEST_COUNT];
|
unsigned long counter[TEST_COUNT];
|
||||||
unsigned long local_counter[CPU_COUNT][TEST_COUNT][CPU_COUNT];
|
unsigned long local_counter[CPU_COUNT][TEST_COUNT][CPU_COUNT];
|
||||||
SMP_lock_Control lock RTEMS_ALIGNED(CPU_CACHE_LINE_BYTES);
|
SMP_lock_Control lock RTEMS_ALIGNED(CPU_CACHE_LINE_BYTES);
|
||||||
@@ -84,40 +86,69 @@ static rtems_interval test_init(
|
|||||||
return test_duration();
|
return test_duration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const rtems_test_parallel_job test_jobs[TEST_COUNT];
|
||||||
|
|
||||||
static void test_fini(
|
static void test_fini(
|
||||||
test_context *ctx,
|
test_context *ctx,
|
||||||
const char *name,
|
const char *lock_type,
|
||||||
|
bool global_lock,
|
||||||
|
const char *section_type,
|
||||||
size_t test,
|
size_t test,
|
||||||
size_t active_workers
|
size_t active_workers
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
bool cascade = test_jobs[test].cascade;
|
||||||
unsigned long sum = 0;
|
unsigned long sum = 0;
|
||||||
unsigned long n = active_workers;
|
const char *value_sep;
|
||||||
unsigned long i;
|
size_t i;
|
||||||
|
|
||||||
printf(" <%s activeWorker=\"%lu\">\n", name, n);
|
if (active_workers == 1 || !cascade) {
|
||||||
|
printf(
|
||||||
|
"%s{\n"
|
||||||
|
" \"lock-type\": \"%s\",\n"
|
||||||
|
" \"lock-object\": \"%s\",\n"
|
||||||
|
" \"section-type\": \"%s\",\n"
|
||||||
|
" \"results\": [",
|
||||||
|
ctx->test_sep,
|
||||||
|
lock_type,
|
||||||
|
global_lock ? "global" : "local",
|
||||||
|
section_type
|
||||||
|
);
|
||||||
|
ctx->test_sep = ", ";
|
||||||
|
ctx->counter_sep = "\n ";
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
printf(
|
||||||
|
"%s{\n"
|
||||||
|
" \"counter\": [", ctx->counter_sep);
|
||||||
|
ctx->counter_sep = "\n }, ";
|
||||||
|
value_sep = "";
|
||||||
|
|
||||||
|
for (i = 0; i < active_workers; ++i) {
|
||||||
unsigned long local_counter =
|
unsigned long local_counter =
|
||||||
ctx->local_counter[active_workers - 1][test][i];
|
ctx->local_counter[active_workers - 1][test][i];
|
||||||
|
|
||||||
sum += local_counter;
|
sum += local_counter;
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
" <LocalCounter worker=\"%lu\">%lu</LocalCounter>\n",
|
"%s%lu",
|
||||||
i,
|
value_sep,
|
||||||
local_counter
|
local_counter
|
||||||
);
|
);
|
||||||
|
value_sep = ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
" <GlobalCounter>%lu</GlobalCounter>\n"
|
"],\n"
|
||||||
" <SumOfLocalCounter>%lu</SumOfLocalCounter>\n"
|
" \"global-counter\": %lu,\n"
|
||||||
" </%s>\n",
|
" \"sum-of-local-counter\": %lu",
|
||||||
ctx->counter[test],
|
ctx->counter[test],
|
||||||
sum,
|
sum
|
||||||
name
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (active_workers == rtems_scheduler_get_processor_maximum() || !cascade) {
|
||||||
|
printf("\n }\n ]\n }");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_0_body(
|
static void test_0_body(
|
||||||
@@ -151,7 +182,9 @@ static void test_0_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalTicketLockWithLocalCounter",
|
"Ticket Lock",
|
||||||
|
true,
|
||||||
|
"local counter",
|
||||||
0,
|
0,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -188,7 +221,9 @@ static void test_1_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalMCSLockWithLocalCounter",
|
"MCS Lock",
|
||||||
|
true,
|
||||||
|
"local counter",
|
||||||
1,
|
1,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -226,7 +261,9 @@ static void test_2_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalTicketLockWithGlobalCounter",
|
"Ticket Lock",
|
||||||
|
true,
|
||||||
|
"global counter",
|
||||||
2,
|
2,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -264,7 +301,9 @@ static void test_3_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalMCSLockWithGlobalCounter",
|
"MCS Lock",
|
||||||
|
true,
|
||||||
|
"global counter",
|
||||||
3,
|
3,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -306,7 +345,9 @@ static void test_4_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"LocalTicketLockWithLocalCounter",
|
"Ticket Lock",
|
||||||
|
false,
|
||||||
|
"local counter",
|
||||||
4,
|
4,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -353,7 +394,9 @@ static void test_5_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"LocalMCSLockWithLocalCounter",
|
"MCS Lock",
|
||||||
|
false,
|
||||||
|
"local counter",
|
||||||
5,
|
5,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -399,7 +442,9 @@ static void test_6_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"LocalTicketLockWithGlobalCounter",
|
"Ticket Lock",
|
||||||
|
false,
|
||||||
|
"global counter",
|
||||||
6,
|
6,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -450,7 +495,9 @@ static void test_7_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"LocalMCSLockWithGlobalCounter",
|
"MCS Lock",
|
||||||
|
false,
|
||||||
|
"global counter",
|
||||||
7,
|
7,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -497,7 +544,9 @@ static void test_8_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalTicketLockWithBusySection",
|
"Ticket Lock",
|
||||||
|
true,
|
||||||
|
"busy loop",
|
||||||
8,
|
8,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -535,7 +584,9 @@ static void test_9_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalMCSLockWithBusySection",
|
"MCS Lock",
|
||||||
|
true,
|
||||||
|
"busy loop",
|
||||||
9,
|
9,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -595,7 +646,9 @@ static void test_10_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"SequenceLock",
|
"Sequence Lock",
|
||||||
|
true,
|
||||||
|
"two global counter",
|
||||||
10,
|
10,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -634,7 +687,9 @@ static void test_11_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalTASLockWithLocalCounter",
|
"TAS Lock",
|
||||||
|
true,
|
||||||
|
"local counter",
|
||||||
11,
|
11,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -675,7 +730,9 @@ static void test_12_fini(
|
|||||||
|
|
||||||
test_fini(
|
test_fini(
|
||||||
ctx,
|
ctx,
|
||||||
"GlobalTTASLockWithLocalCounter",
|
"TTAS Lock",
|
||||||
|
true,
|
||||||
|
"local counter",
|
||||||
12,
|
12,
|
||||||
active_workers
|
active_workers
|
||||||
);
|
);
|
||||||
@@ -753,11 +810,11 @@ static const rtems_test_parallel_job test_jobs[TEST_COUNT] = {
|
|||||||
static void test(void)
|
static void test(void)
|
||||||
{
|
{
|
||||||
test_context *ctx = &test_instance;
|
test_context *ctx = &test_instance;
|
||||||
const char *test = "SMPLock01";
|
|
||||||
|
|
||||||
printf("<%s>\n", test);
|
printf("*** BEGIN OF JSON DATA ***\n[\n ");
|
||||||
|
ctx->test_sep = "";
|
||||||
rtems_test_parallel(&ctx->base, NULL, &test_jobs[0], TEST_COUNT);
|
rtems_test_parallel(&ctx->base, NULL, &test_jobs[0], TEST_COUNT);
|
||||||
printf("</%s>\n", test);
|
printf("\n]\n*** END OF JSON DATA ***\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Init(rtems_task_argument arg)
|
static void Init(rtems_task_argument arg)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# SPDX-License-Identifier: BSD-2-Clause
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
#
|
# Copyright (C) 2016, 2024 embedded brains GmbH & Co. KG
|
||||||
# Copyright (c) 2016 embedded brains GmbH & Co. KG
|
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions
|
# modification, are permitted provided that the following conditions
|
||||||
@@ -25,54 +22,50 @@
|
|||||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
|
||||||
|
|
||||||
import re
|
import json
|
||||||
import libxml2
|
|
||||||
import math
|
import math
|
||||||
|
import re
|
||||||
import statistics
|
import statistics
|
||||||
from libxml2 import xmlNode
|
import matplotlib.pyplot as plt # type: ignore
|
||||||
import matplotlib.pyplot as plt
|
from matplotlib import ticker # type: ignore
|
||||||
data = open('smplock01.scn').read()
|
|
||||||
data = re.sub(r'\*\*\*.*\*\*\*', '', data)
|
|
||||||
doc = libxml2.parseDoc(data)
|
|
||||||
ctx = doc.xpathNewContext()
|
|
||||||
|
|
||||||
plt.title('SMP Lock Fairness')
|
|
||||||
plt.xlabel('Active Workers')
|
|
||||||
plt.ylabel('Normed Coefficient of Variation')
|
|
||||||
|
|
||||||
i = 1
|
def _normed_coefficient_of_variation(counter: list[int]) -> float:
|
||||||
ticket = []
|
return (statistics.stdev(counter) / statistics.mean(counter)) / math.sqrt(
|
||||||
mcs = []
|
len(counter))
|
||||||
tas = []
|
|
||||||
ttas = []
|
|
||||||
|
|
||||||
def m(n):
|
|
||||||
return int(xmlNode.getContent(n))
|
|
||||||
|
|
||||||
def normedCoefficientOfVariation(name, i):
|
def _plot(data: dict) -> None:
|
||||||
y = map(m, ctx.xpathEval('/SMPLock01/' + name + '[@activeWorker=' + str(i) + ']/LocalCounter'))
|
_, axes = plt.subplots()
|
||||||
if len(y) == 0:
|
axes.set_title("SMP Lock Fairness")
|
||||||
raise
|
axes.set_xlabel("Active Workers")
|
||||||
return (statistics.stdev(y) / statistics.mean(y)) / math.sqrt(len(y))
|
axes.set_ylabel("Normed Coefficient of Variation")
|
||||||
|
axes.set_yscale("symlog", linthresh=1e-6)
|
||||||
|
x = list(range(2, len(data[0]["results"]) + 1))
|
||||||
|
axes.xaxis.set_major_locator(ticker.FixedLocator(x))
|
||||||
|
for samples in data:
|
||||||
|
if samples["lock-object"] != "global":
|
||||||
|
continue
|
||||||
|
if samples["section-type"] != "local counter":
|
||||||
|
continue
|
||||||
|
y = [
|
||||||
|
_normed_coefficient_of_variation(results["counter"])
|
||||||
|
for results in samples["results"][1:]
|
||||||
|
]
|
||||||
|
axes.plot(x, y, label=samples["lock-type"], marker="o")
|
||||||
|
axes.legend(loc="best")
|
||||||
|
plt.savefig("smplock01fair.png")
|
||||||
|
plt.savefig("smplock01fair.pdf")
|
||||||
|
plt.close()
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
i = i + 1
|
|
||||||
ticket.append(normedCoefficientOfVariation('GlobalTicketLockWithLocalCounter', i))
|
|
||||||
mcs.append(normedCoefficientOfVariation('GlobalMCSLockWithLocalCounter', i))
|
|
||||||
tas.append(normedCoefficientOfVariation('GlobalTASLockWithLocalCounter', i))
|
|
||||||
ttas.append(normedCoefficientOfVariation('GlobalTTASLockWithLocalCounter', i))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
x = range(2, len(ticket) + 2)
|
_JSON_DATA = re.compile(
|
||||||
plt.xticks(x)
|
r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
|
||||||
plt.yscale('symlog', linthreshy = 1e-6)
|
r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
|
||||||
plt.plot(x, ticket, label = 'Ticket Lock', marker = 'o')
|
|
||||||
plt.plot(x, mcs, label = 'MCS Lock', marker = 'o')
|
with open("smplock01.scn", "r", encoding="utf-8") as src:
|
||||||
plt.plot(x, tas, label = 'TAS Lock', marker = 'o')
|
match = _JSON_DATA.search(src.read())
|
||||||
plt.plot(x, ttas, label = 'TTAS Lock', marker = 'o')
|
data = json.loads(match.group(1))
|
||||||
plt.legend(loc = 'best')
|
|
||||||
plt.show()
|
_plot(data)
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# SPDX-License-Identifier: BSD-2-Clause
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
#
|
# Copyright (C) 2016, 2024 embedded brains GmbH & Co. KG
|
||||||
# Copyright (c) 2016 embedded brains GmbH & Co. KG
|
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions
|
# modification, are permitted provided that the following conditions
|
||||||
@@ -25,34 +22,39 @@
|
|||||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import libxml2
|
import matplotlib.pyplot as plt # type: ignore
|
||||||
from libxml2 import xmlNode
|
from matplotlib import ticker # type: ignore
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
data = open('smplock01.scn').read()
|
|
||||||
data = re.sub(r'\*\*\*.*\*\*\*', '', data)
|
|
||||||
doc = libxml2.parseDoc(data)
|
|
||||||
ctx = doc.xpathNewContext()
|
|
||||||
|
|
||||||
plt.title('SMP Lock Performance')
|
|
||||||
plt.xlabel('Active Workers')
|
|
||||||
plt.ylabel('Operation Count')
|
|
||||||
|
|
||||||
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalTicketLockWithLocalCounter/SumOfLocalCounter'))
|
def _plot(data: dict) -> None:
|
||||||
x = range(1, len(y) + 1)
|
_, axes = plt.subplots()
|
||||||
plt.xticks(x)
|
axes.set_title("SMP Lock Performance")
|
||||||
plt.plot(x, y, label = 'Ticket Lock', marker = 'o')
|
axes.set_xlabel("Active Workers")
|
||||||
|
axes.set_ylabel("Operation Count")
|
||||||
|
x = list(range(1, len(data[0]["results"]) + 1))
|
||||||
|
axes.xaxis.set_major_locator(ticker.FixedLocator(x))
|
||||||
|
for samples in data:
|
||||||
|
if samples["lock-object"] != "global":
|
||||||
|
continue
|
||||||
|
if samples["section-type"] != "local counter":
|
||||||
|
continue
|
||||||
|
y = [sum(results["counter"]) for results in samples["results"]]
|
||||||
|
axes.plot(x, y, label=samples["lock-type"], marker="o")
|
||||||
|
axes.legend(loc="best")
|
||||||
|
plt.savefig("smplock01perf.png")
|
||||||
|
plt.savefig("smplock01perf.pdf")
|
||||||
|
plt.close()
|
||||||
|
|
||||||
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalMCSLockWithLocalCounter/SumOfLocalCounter'))
|
|
||||||
plt.plot(x, y, label = 'MCS Lock', marker = 'o')
|
|
||||||
|
|
||||||
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalTASLockWithLocalCounter/SumOfLocalCounter'))
|
_JSON_DATA = re.compile(
|
||||||
plt.plot(x, y, label = 'TAS Lock', marker = 'o')
|
r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
|
||||||
|
r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
|
||||||
|
|
||||||
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalTTASLockWithLocalCounter/SumOfLocalCounter'))
|
with open("smplock01.scn", "r", encoding="utf-8") as src:
|
||||||
plt.plot(x, y, label = 'TTAS Lock', marker = 'o')
|
match = _JSON_DATA.search(src.read())
|
||||||
|
data = json.loads(match.group(1))
|
||||||
|
|
||||||
plt.legend(loc = 'best')
|
_plot(data)
|
||||||
plt.show()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user