smplock01: Convert to JSON data

This avoids a dependency on the non-standard libxml2 module.
This commit is contained in:
Sebastian Huber
2024-01-09 10:27:39 +01:00
parent 8e26f7ef02
commit 4f6f5f4643
4 changed files with 391 additions and 2676 deletions

View File

@@ -1,7 +1,7 @@
/* 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
* modification, are permitted provided that the following conditions
@@ -47,6 +47,8 @@ const char rtems_test_name[] = "SMPLOCK 1";
typedef struct {
rtems_test_parallel_context base;
const char *test_sep;
const char *counter_sep;
unsigned long counter[TEST_COUNT];
unsigned long local_counter[CPU_COUNT][TEST_COUNT][CPU_COUNT];
SMP_lock_Control lock RTEMS_ALIGNED(CPU_CACHE_LINE_BYTES);
@@ -84,40 +86,69 @@ static rtems_interval test_init(
return test_duration();
}
static const rtems_test_parallel_job test_jobs[TEST_COUNT];
static void test_fini(
test_context *ctx,
const char *name,
const char *lock_type,
bool global_lock,
const char *section_type,
size_t test,
size_t active_workers
)
{
bool cascade = test_jobs[test].cascade;
unsigned long sum = 0;
unsigned long n = active_workers;
unsigned long i;
const char *value_sep;
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 =
ctx->local_counter[active_workers - 1][test][i];
sum += local_counter;
printf(
" <LocalCounter worker=\"%lu\">%lu</LocalCounter>\n",
i,
"%s%lu",
value_sep,
local_counter
);
value_sep = ", ";
}
printf(
" <GlobalCounter>%lu</GlobalCounter>\n"
" <SumOfLocalCounter>%lu</SumOfLocalCounter>\n"
" </%s>\n",
"],\n"
" \"global-counter\": %lu,\n"
" \"sum-of-local-counter\": %lu",
ctx->counter[test],
sum,
name
sum
);
if (active_workers == rtems_scheduler_get_processor_maximum() || !cascade) {
printf("\n }\n ]\n }");
}
}
static void test_0_body(
@@ -151,7 +182,9 @@ static void test_0_fini(
test_fini(
ctx,
"GlobalTicketLockWithLocalCounter",
"Ticket Lock",
true,
"local counter",
0,
active_workers
);
@@ -188,7 +221,9 @@ static void test_1_fini(
test_fini(
ctx,
"GlobalMCSLockWithLocalCounter",
"MCS Lock",
true,
"local counter",
1,
active_workers
);
@@ -226,7 +261,9 @@ static void test_2_fini(
test_fini(
ctx,
"GlobalTicketLockWithGlobalCounter",
"Ticket Lock",
true,
"global counter",
2,
active_workers
);
@@ -264,7 +301,9 @@ static void test_3_fini(
test_fini(
ctx,
"GlobalMCSLockWithGlobalCounter",
"MCS Lock",
true,
"global counter",
3,
active_workers
);
@@ -306,7 +345,9 @@ static void test_4_fini(
test_fini(
ctx,
"LocalTicketLockWithLocalCounter",
"Ticket Lock",
false,
"local counter",
4,
active_workers
);
@@ -353,7 +394,9 @@ static void test_5_fini(
test_fini(
ctx,
"LocalMCSLockWithLocalCounter",
"MCS Lock",
false,
"local counter",
5,
active_workers
);
@@ -399,7 +442,9 @@ static void test_6_fini(
test_fini(
ctx,
"LocalTicketLockWithGlobalCounter",
"Ticket Lock",
false,
"global counter",
6,
active_workers
);
@@ -450,7 +495,9 @@ static void test_7_fini(
test_fini(
ctx,
"LocalMCSLockWithGlobalCounter",
"MCS Lock",
false,
"global counter",
7,
active_workers
);
@@ -497,7 +544,9 @@ static void test_8_fini(
test_fini(
ctx,
"GlobalTicketLockWithBusySection",
"Ticket Lock",
true,
"busy loop",
8,
active_workers
);
@@ -535,7 +584,9 @@ static void test_9_fini(
test_fini(
ctx,
"GlobalMCSLockWithBusySection",
"MCS Lock",
true,
"busy loop",
9,
active_workers
);
@@ -595,7 +646,9 @@ static void test_10_fini(
test_fini(
ctx,
"SequenceLock",
"Sequence Lock",
true,
"two global counter",
10,
active_workers
);
@@ -634,7 +687,9 @@ static void test_11_fini(
test_fini(
ctx,
"GlobalTASLockWithLocalCounter",
"TAS Lock",
true,
"local counter",
11,
active_workers
);
@@ -675,7 +730,9 @@ static void test_12_fini(
test_fini(
ctx,
"GlobalTTASLockWithLocalCounter",
"TTAS Lock",
true,
"local counter",
12,
active_workers
);
@@ -753,11 +810,11 @@ static const rtems_test_parallel_job test_jobs[TEST_COUNT] = {
static void test(void)
{
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);
printf("</%s>\n", test);
printf("\n]\n*** END OF JSON DATA ***\n");
}
static void Init(rtems_task_argument arg)

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,6 @@
#!/usr/bin/env python
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2016 embedded brains GmbH & Co. KG
# Copyright (C) 2016, 2024 embedded brains GmbH & Co. KG
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -25,54 +22,50 @@
# 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
# POSSIBILITY OF SUCH DAMAGE.
#
import re
import libxml2
import json
import math
import re
import statistics
from libxml2 import xmlNode
import matplotlib.pyplot as plt
data = open('smplock01.scn').read()
data = re.sub(r'\*\*\*.*\*\*\*', '', data)
doc = libxml2.parseDoc(data)
ctx = doc.xpathNewContext()
import matplotlib.pyplot as plt # type: ignore
from matplotlib import ticker # type: ignore
plt.title('SMP Lock Fairness')
plt.xlabel('Active Workers')
plt.ylabel('Normed Coefficient of Variation')
i = 1
ticket = []
mcs = []
tas = []
ttas = []
def _normed_coefficient_of_variation(counter: list[int]) -> float:
return (statistics.stdev(counter) / statistics.mean(counter)) / math.sqrt(
len(counter))
def m(n):
return int(xmlNode.getContent(n))
def normedCoefficientOfVariation(name, i):
y = map(m, ctx.xpathEval('/SMPLock01/' + name + '[@activeWorker=' + str(i) + ']/LocalCounter'))
if len(y) == 0:
raise
return (statistics.stdev(y) / statistics.mean(y)) / math.sqrt(len(y))
def _plot(data: dict) -> None:
_, axes = plt.subplots()
axes.set_title("SMP Lock Fairness")
axes.set_xlabel("Active Workers")
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)
plt.xticks(x)
plt.yscale('symlog', linthreshy = 1e-6)
plt.plot(x, ticket, label = 'Ticket Lock', marker = 'o')
plt.plot(x, mcs, label = 'MCS Lock', marker = 'o')
plt.plot(x, tas, label = 'TAS Lock', marker = 'o')
plt.plot(x, ttas, label = 'TTAS Lock', marker = 'o')
plt.legend(loc = 'best')
plt.show()
_JSON_DATA = re.compile(
r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
with open("smplock01.scn", "r", encoding="utf-8") as src:
match = _JSON_DATA.search(src.read())
data = json.loads(match.group(1))
_plot(data)

View File

@@ -1,9 +1,6 @@
#!/usr/bin/env python
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2016 embedded brains GmbH & Co. KG
# Copyright (C) 2016, 2024 embedded brains GmbH & Co. KG
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -25,34 +22,39 @@
# 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
# POSSIBILITY OF SUCH DAMAGE.
#
import json
import re
import libxml2
from libxml2 import xmlNode
import matplotlib.pyplot as plt
data = open('smplock01.scn').read()
data = re.sub(r'\*\*\*.*\*\*\*', '', data)
doc = libxml2.parseDoc(data)
ctx = doc.xpathNewContext()
import matplotlib.pyplot as plt # type: ignore
from matplotlib import ticker # type: ignore
plt.title('SMP Lock Performance')
plt.xlabel('Active Workers')
plt.ylabel('Operation Count')
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalTicketLockWithLocalCounter/SumOfLocalCounter'))
x = range(1, len(y) + 1)
plt.xticks(x)
plt.plot(x, y, label = 'Ticket Lock', marker = 'o')
def _plot(data: dict) -> None:
_, axes = plt.subplots()
axes.set_title("SMP Lock Performance")
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'))
plt.plot(x, y, label = 'TAS Lock', marker = 'o')
_JSON_DATA = re.compile(
r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
y = map(xmlNode.getContent, ctx.xpathEval('/SMPLock01/GlobalTTASLockWithLocalCounter/SumOfLocalCounter'))
plt.plot(x, y, label = 'TTAS Lock', marker = 'o')
with open("smplock01.scn", "r", encoding="utf-8") as src:
match = _JSON_DATA.search(src.read())
data = json.loads(match.group(1))
plt.legend(loc = 'best')
plt.show()
_plot(data)