From e67e6784ee0d4c548ddcf846bb76673ef8f8822f Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Sun, 2 Oct 2022 22:50:20 +0000 Subject: [PATCH 1/5] threads comp: fix a copy/paste error in a doc string --- src/hal/components/threads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hal/components/threads.c b/src/hal/components/threads.c index 33c3dc765a9..bbb7e406949 100644 --- a/src/hal/components/threads.c +++ b/src/hal/components/threads.c @@ -72,7 +72,7 @@ RTAPI_MP_LONG(period2, "thread2 period (nsecs)"); static char *name3 = NULL; /* name of thread */ RTAPI_MP_STRING(name3, "name of thread 3"); static int fp3 = 1; /* use floating point? default = yes */ -RTAPI_MP_INT(fp3, "thread1 uses floating point"); +RTAPI_MP_INT(fp3, "thread3 uses floating point"); static long period3 = 0; /* thread period - default = no thread */ RTAPI_MP_LONG(period3, "thread3 period (nsecs)"); From ec19b7066286570ec02370d9ae2568beef3689d5 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Wed, 28 Sep 2022 16:59:17 +0000 Subject: [PATCH 2/5] timedelta comp: document the pins --- src/hal/components/timedelta.comp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/hal/components/timedelta.comp b/src/hal/components/timedelta.comp index 46b0e6054c1..12d918d673d 100644 --- a/src/hal/components/timedelta.comp +++ b/src/hal/components/timedelta.comp @@ -1,11 +1,20 @@ component timedelta "LinuxCNC HAL component that measures thread scheduling timing behavior"; -pin out s32 out; -pin out s32 err=0; -pin out s32 min_=0; -pin out s32 max_=0; -pin out s32 jitter=0; -pin out float avg_err=0; -pin in bit reset; + +pin out s32 jitter=0 "Worst-case scheduling error (in ns). This is the largest discrepancy between ideal thread period, and actual time between sequential runs of this component. This uses the absolute value of the error, so 'got run too early' and 'got run too late' both show up as positive jitter."; + +pin out s32 min_=0 "Minimum time (in ns) between sequential runs of this component."; + +pin out s32 max_=0 "Maximum time (in ns) between sequential runs of this component."; + +pin in bit reset "Set this pin to True, then back to False, to reset some of the statistics."; + +pin out s32 out "Time (in ns) since the previous run of this component. This should ideally be equal to the thread period."; + +pin out s32 err=0 "Cumulative time error (in ns). Probably not useful."; + +pin out float avg_err=0 "The average scheduling error (in ns)."; + + function _ nofp; variable rtapi_s64 last=0; variable int first=1; From ff30083b117a9209980ba537a86a97cf22ea2341 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Wed, 28 Sep 2022 16:59:31 +0000 Subject: [PATCH 3/5] timedelta comp: add a `current-jitter` pin This pin has the scheduling error of the current invocation. This is useful for inspecting the run-to-run scheduling variability, e.g. using halsampler. --- src/hal/components/timedelta.comp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hal/components/timedelta.comp b/src/hal/components/timedelta.comp index 12d918d673d..c0aab13264c 100644 --- a/src/hal/components/timedelta.comp +++ b/src/hal/components/timedelta.comp @@ -2,6 +2,8 @@ component timedelta "LinuxCNC HAL component that measures thread scheduling timi pin out s32 jitter=0 "Worst-case scheduling error (in ns). This is the largest discrepancy between ideal thread period, and actual time between sequential runs of this component. This uses the absolute value of the error, so 'got run too early' and 'got run too late' both show up as positive jitter."; +pin out s32 current_jitter=0 "Scheduling error (in ns) of the current invocation. This is the discrepancy between ideal thread period, and actual time since the previous run of this component. This uses the absolute value of the error, so 'got run too early' and 'got run too late' both show up as positive jitter."; + pin out s32 min_=0 "Minimum time (in ns) between sequential runs of this component."; pin out s32 max_=0 "Maximum time (in ns) between sequential runs of this component."; @@ -39,6 +41,7 @@ if(last != 0) { if(del < min_) min_ = del; if(del > max_) max_ = del; jitter = max(max_ - period, period - min_); + current_jitter = max(del - period, period - del); } count++; avg_err = err / (double)count; From cd56a8c001e25f6fa5e992a8b3d9a56770a916b5 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Tue, 4 Oct 2022 18:33:00 +0000 Subject: [PATCH 4/5] timedelta comp: add a `current-error` pin This is the scheduling error (i.e., time of thread invocation minus expected time of invocation). Unlike `current-jitter` this pin does *not* have the absolute value, so it's useful for catching "under-sleep" conditions. --- src/hal/components/timedelta.comp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hal/components/timedelta.comp b/src/hal/components/timedelta.comp index c0aab13264c..3922e8f71ad 100644 --- a/src/hal/components/timedelta.comp +++ b/src/hal/components/timedelta.comp @@ -4,6 +4,8 @@ pin out s32 jitter=0 "Worst-case scheduling error (in ns). This is the largest pin out s32 current_jitter=0 "Scheduling error (in ns) of the current invocation. This is the discrepancy between ideal thread period, and actual time since the previous run of this component. This uses the absolute value of the error, so 'got run too early' and 'got run too late' both show up as positive jitter."; +pin out s32 current_error=0 "Scheduling error (in ns) of the current invocation. This is the discrepancy between ideal thread period, and actual time since the previous run of this component. This does not use the absolute value of the error, so 'got run too early' shows up as negative error and 'got run too late' shows up as positive error."; + pin out s32 min_=0 "Minimum time (in ns) between sequential runs of this component."; pin out s32 max_=0 "Maximum time (in ns) between sequential runs of this component."; @@ -42,6 +44,7 @@ if(last != 0) { if(del > max_) max_ = del; jitter = max(max_ - period, period - min_); current_jitter = max(del - period, period - del); + current_error = del - period; } count++; avg_err = err / (double)count; From 1abc0ac7cec4a85d285cd8feb8df34e40c13580c Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 3 Oct 2022 19:14:45 +0000 Subject: [PATCH 5/5] rtapi_app: fix a harmless but confusing whitespace error --- src/rtapi/uspace_rtapi_app.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rtapi/uspace_rtapi_app.cc b/src/rtapi/uspace_rtapi_app.cc index 86198c56403..e5f870c8ac7 100644 --- a/src/rtapi/uspace_rtapi_app.cc +++ b/src/rtapi/uspace_rtapi_app.cc @@ -458,7 +458,8 @@ static int master(int fd, vector args) { perror("pthread_create (queue function)"); return -1; } - do_load_cmd("hal_lib", vector()); instance_count = 0; + do_load_cmd("hal_lib", vector()); + instance_count = 0; App(); // force rtapi_app to be created int result=0; if(args.size()) {