Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/config/core-components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ These pins, parameters, and functions are created by the realtime 'motmod' modul
Many of these parameters serve as debugging aids, and are subject to
change or removal at any time.

* 'motion-command-handler.time' - (s32, RO)
* 'motion-command-handler.tmax' - (s32, RW)
* 'motion-controller.time' - (s32, RO)
* 'motion-controller.tmax' - (s32, RW)
* 'motion-command-handler.time' - (float, RO) runtime in seconds
* 'motion-command-handler.tmax' - (float, RW) max runtime in seconds
* 'motion-controller.time' - (float, RO) runtime in seconds
* 'motion-controller.tmax' - (float, RW) max runtime in seconds
* 'motion.debug-bit-0' - (bit, RO) This is used for debugging purposes.
* 'motion.debug-bit-1' - (bit, RO) This is used for debugging purposes.
* 'motion.debug-float-0' - (float, RO) This is used for debugging purposes.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/hal/basic-hal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ One pin and two parameters are automatically added to each HAL component when it
These allow you to scope the execution time of a component.

[horizontal]
`.time`(((HAL time))):: Pin time shows in ns how long it took to execute the function.
`.tmax`(((HAL tmax))):: Parameter tmax is the maximum time in ns it took to execute the function.
`.time`(((HAL time))):: Pin time is a float showing in seconds how long it took to execute the function.
`.tmax`(((HAL tmax))):: Parameter tmax is a float holding the maximum time in seconds it took to execute the function.
`.tmax-increased`(((HAL tmax-increased))):: This parameter is set to true for one cycle if tmax increased.

`tmax` is a read/write parameter so the user can set it to 0 to get rid of the first time initialization on the function's execution time.
Expand Down
8 changes: 4 additions & 4 deletions docs/src/hal/rtcomps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ halcmd: unloadrt encoder

=== Parameters

* `encoder._<chan>_.capture-position.time` (s32, RO)
* `encoder._<chan>_.capture-position.tmax` (s32, RW)
* `encoder._<chan>_.update-counters.time` (s32, RO)
* `encoder._<chan>_.update-counter.tmax` (s32, RW)
* `encoder._<chan>_.capture-position.time` (float, RO) runtime in seconds
* `encoder._<chan>_.capture-position.tmax` (float, RW) max runtime in seconds
* `encoder._<chan>_.update-counters.time` (float, RO) runtime in seconds
* `encoder._<chan>_.update-counter.tmax` (float, RW) max runtime in seconds

=== Functions

Expand Down
2 changes: 1 addition & 1 deletion docs/src/hal/tools.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ or
|===
|Option |Value |Description
|--minvalue |minvalue |minimum bin, default: 0
|--binsize |binsize |binsize, default: 100
|--binsize |binsize |binsize, default: 1e-07 (suits the default pin, a runtime in seconds)
|--nbins |nbins |number of bins, default: 50
| | |
|--logscale |0/1 |y axis log scale, default: 1
Expand Down
26 changes: 13 additions & 13 deletions docs/src/hal/tutorial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ halcmd: show param

Parameters:
Owner Type Dir Value Name
3 s32 RO 0 siggen.0.update.time
3 s32 RW 0 siggen.0.update.tmax
3 float RO 0 siggen.0.update.time
3 float RW 0 siggen.0.update.tmax
----

The 'show param' command shows all the parameters in the HAL.
Expand Down Expand Up @@ -328,8 +328,8 @@ halcmd: show param

Parameters:
Owner Type Dir Value Name
3 s32 RO 1754 siggen.0.update.time
3 s32 RW 16997 siggen.0.update.tmax
3 float RO 1.754e-06 siggen.0.update.time
3 float RW 1.6997e-05 siggen.0.update.tmax

halcmd: show pin

Expand Down Expand Up @@ -369,7 +369,7 @@ loadrt siggen
# signals
# nets
# parameter values
setp siggen.0.update.tmax 14687
setp siggen.0.update.tmax 1.4687e-05
# realtime thread/function links
addf siggen.0.update test-thread
----
Expand Down Expand Up @@ -495,8 +495,8 @@ halcmd: show param

Parameters:
Owner Type Dir Value Name
4 s32 RO 0 siggen.0.update.time
4 s32 RW 0 siggen.0.update.tmax
4 float RO 0 siggen.0.update.time
4 float RW 0 siggen.0.update.tmax
3 u32 RW 0x00000001 stepgen.0.dirhold
3 u32 RW 0x00000001 stepgen.0.dirsetup
3 float RO 0 stepgen.0.frequency
Expand All @@ -515,12 +515,12 @@ Owner Type Dir Value Name
3 s32 RO 0 stepgen.1.rawcounts
3 u32 RW 0x00000001 stepgen.1.steplen
3 u32 RW 0x00000001 stepgen.1.stepspace
3 s32 RO 0 stepgen.capture-position.time
3 s32 RW 0 stepgen.capture-position.tmax
3 s32 RO 0 stepgen.make-pulses.time
3 s32 RW 0 stepgen.make-pulses.tmax
3 s32 RO 0 stepgen.update-freq.time
3 s32 RW 0 stepgen.update-freq.tmax
3 float RO 0 stepgen.capture-position.time
3 float RW 0 stepgen.capture-position.tmax
3 float RO 0 stepgen.make-pulses.time
3 float RW 0 stepgen.make-pulses.tmax
3 float RO 0 stepgen.update-freq.time
3 float RW 0 stepgen.update-freq.tmax
----

=== Connecting pins with signals
Expand Down
8 changes: 4 additions & 4 deletions docs/src/man/man9/classicladder.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ the outputs.

== PARAMETERS

*classicladder.0.refresh.time* RO s32::
Tells you how long the last refresh took.
*classicladder.0.refresh.tmax* RW s32::
Tells you how long the longest refresh took.
*classicladder.0.refresh.time* RO float::
Tells you how long the last refresh took, in seconds.
*classicladder.0.refresh.tmax* RW float::
Tells you how long the longest refresh took, in seconds.
*classicladder.0.ladder-state* RO s32::
Tells you if the program is running or not

Expand Down
4 changes: 2 additions & 2 deletions docs/src/man/man9/encoder.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ The *encoder*.__N__. format is shown in the following descriptions.
of the phase-A input, ignoring the value on phase-B. This is useful
for counting the output of a single channel (non-quadrature) sensor.
When false (the default), it counts in quadrature mode.
**encoder**.__N__.**capture-position.tmax** s32 rw::
Maximum time in ns it took to execute this function.
**encoder**.__N__.**capture-position.tmax** float rw::
Maximum time in seconds it took to execute this function.

== PARAMETERS

Expand Down
16 changes: 8 additions & 8 deletions docs/src/man/man9/motion.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ digital pins and two analog pins.

== MOTION PINS

*motion-command-handler.time* OUT S32::
Time (in ns) for the motion module motion-command-handler
*motion-controller.time* OUT S32::
Time (in ns) for the motion module motion-controller
*motion-command-handler.time* OUT FLOAT::
Time (in seconds) for the motion module motion-command-handler
*motion-controller.time* OUT FLOAT::
Time (in seconds) for the motion module motion-controller
*motion.adaptive-feed* IN FLOAT::
When adaptive feed is enabled with M52 P1, the commanded velocity is
multiplied by this value. This effect is multiplicative with the
Expand Down Expand Up @@ -543,13 +543,13 @@ the M19 command fails with an error message.

Many of the parameters serve as debugging aids, and are subject to change or removal at any time.

*motion-command-handler.tmax* RW S32::
Show information about the execution time of these HAL functions in ns.
*motion-command-handler.tmax* RW FLOAT::
Show information about the execution time of these HAL functions in seconds.

*motion-command-handler.tmax-increased* RO S32::

*motion-controller.tmax* RW S32::
Show information about the execution time of these HAL functions in ns.
*motion-controller.tmax* RW FLOAT::
Show information about the execution time of these HAL functions in seconds.

*motion-controller.tmax-increased* RO BIT::
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="adj_read_tmax">
<property name="upper">1000000000000</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
<property name="upper">1000</property>
<property name="step-increment">0.000001</property>
<property name="page-increment">0.00001</property>
</object>
<object class="GtkAdjustment" id="adj_servo_thread_period">
<property name="upper">1000000000000</property>
Expand All @@ -18,14 +18,14 @@
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="adj_servo_thread_tmax">
<property name="upper">1000000000000</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
<property name="upper">1000</property>
<property name="step-increment">0.000001</property>
<property name="page-increment">0.00001</property>
</object>
<object class="GtkAdjustment" id="adj_write_tmax">
<property name="upper">1000000000000</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
<property name="upper">1000</property>
<property name="step-increment">0.000001</property>
<property name="page-increment">0.00001</property>
</object>
<object class="GtkWindow" id="window1">
<property name="can-focus">False</property>
Expand Down Expand Up @@ -85,6 +85,7 @@
<property name="width-chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">adj_servo_thread_tmax</property>
<property name="digits">9</property>
</object>
<packing>
<property name="left-attach">1</property>
Expand Down Expand Up @@ -452,6 +453,7 @@ try increasing the thread period.</property>
<property name="width-chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">adj_read_tmax</property>
<property name="digits">9</property>
</object>
<packing>
<property name="left-attach">1</property>
Expand All @@ -468,6 +470,7 @@ try increasing the thread period.</property>
<property name="width-chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">adj_write_tmax</property>
<property name="digits">9</property>
</object>
<packing>
<property name="left-attach">1</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def on_btn_servo_thread_tmax_released(self, gtkbutton):
line = line.strip()
if line.endswith("servo-thread.tmax"):
parts = line.split()
value = int(parts[3]) # 4. column is Value
value = float(parts[3]) # 4. column is Value, in seconds
break

spin_thread_tmax = self.builder.get_object("sbtn_servo_thread_tmax")
Expand Down Expand Up @@ -253,8 +253,8 @@ def on_btn_calc_servo_released(self, gtkbutton):
buffer.insert(buffer.get_end_iter(), "Servo Thread period must be greater than 0")
return

# Calculation
result = t_max / period * 100
# Calculation; t_max is in seconds, period in ns
result = t_max / (period * 1e-9) * 100
label_result.set_text(f'{result:.0f}%')


Expand All @@ -279,7 +279,7 @@ def on_btn_read_tmax_released(self, gtkbutton):
line = line.strip()
if "read.tmax" in line:
parts = line.split()
value = int(parts[3]) # 4. column is Value
value = float(parts[3]) # 4. column is Value, in seconds
break

spin_thread_period = self.builder.get_object("sbtn_read_tmax")
Expand All @@ -306,7 +306,7 @@ def on_btn_write_tmax_released(self, gtkbutton):
line = line.strip()
if "write.tmax" in line:
parts = line.split()
value = int(parts[3]) # 4. column is Value
value = float(parts[3]) # 4. column is Value, in seconds
break

spin_thread_period = self.builder.get_object("sbtn_write_tmax")
Expand Down Expand Up @@ -376,7 +376,8 @@ def on_btn_nic_calculate_released(self, gtkbutton):

# Calculation
rw_tmax = read_tmax + write_tmax
result = rw_tmax / period * 100
# rw_tmax is in seconds, period in ns
result = rw_tmax / (period * 1e-9) * 100
label_result.set_text(f'{result:.0f}%')

def on_btn_packet_error_released(self, gtkbutton):
Expand Down
4 changes: 3 additions & 1 deletion scripts/hal-histogram
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ proc set_defaults {} {
set ::HH(y,logscale) 1
set ::HH(nbins) 50
set ::HH(minvalue) 0
set ::HH(binsize) 100
# the default pin is a function runtime pin, which is a float in seconds,
# so the default binsize is 100ns expressed in seconds
set ::HH(binsize) 1e-07
set ::HH(maxvalue) 0
set ::HH(pinname) motion-command-handler.time

Expand Down
31 changes: 17 additions & 14 deletions src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2499,17 +2499,17 @@ int hal_export_funct(const char *name, void (*funct) (void *, long),
/* at this point we have a new function and can yield the mutex */
halpr_mutex_release();

/* create a pin with the function's runtime in it */
if (hal_pin_new_si32(comp_id, HAL_OUT, &(new->runtime), 0, "%s.time", name) < 0) {
/* create a pin with the function's runtime (in seconds) in it */
if (hal_pin_new_real(comp_id, HAL_OUT, &(new->runtime), 0.0, "%s.time", name) < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: fail to create pin '%s.time'\n", name);
return -EINVAL;
}

/* note that failure to successfully create the following params
does not cause the "export_funct()" call to fail - they are
for debugging and testing use only */
/* create a parameter with the function's maximum runtime in it */
if(hal_param_new_si32(comp_id, HAL_RW, &(new->maxtime), 0, "%s.tmax", name) < 0) {
/* create a parameter with the function's maximum runtime (in seconds) in it */
if(hal_param_new_real(comp_id, HAL_RW, &(new->maxtime), 0.0, "%s.tmax", name) < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: fail to create param '%s.tmax'\n", name);
return -EINVAL;
}
Expand Down Expand Up @@ -2684,13 +2684,13 @@ int hal_create_thread(const char *name, unsigned long period_nsec, int uses_fp)
return new->comp_id;
}

if ((retval = hal_param_new_si32(new->comp_id, HAL_RW, &(new->maxtime), 0, "%s.tmax", new->name)) < 0) {
if ((retval = hal_param_new_real(new->comp_id, HAL_RW, &(new->maxtime), 0.0, "%s.tmax", new->name)) < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"HAL: ERROR: fail to create param '%s.tmax'\n", new->name);
return retval;
}

if ((retval = hal_pin_new_si32(new->comp_id, HAL_OUT, &(new->runtime), 0, "%s.time", new->name)) < 0) {
if ((retval = hal_pin_new_real(new->comp_id, HAL_OUT, &(new->runtime), 0.0, "%s.time", new->name)) < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"HAL: ERROR: fail to create pin '%s.time'\n", new->name);
return retval;
Expand Down Expand Up @@ -3673,10 +3673,12 @@ static void thread_task(void *arg)
end_time = rtapi_get_time();
/* point to function structure */
funct = SHMPTR(funct_entry->funct_ptr);
/* update execution time data */
rtapi_s32 runtime = hal_set_si32(funct->runtime, end_time - start_time);
if ( runtime > hal_get_si32(funct->maxtime)) {
hal_set_si32(funct->maxtime, runtime);
/* update execution time data; rtapi_get_time() counts ns,
the .time pin and .tmax param report seconds */
rtapi_real runtime = hal_set_real(funct->runtime,
(rtapi_real)(end_time - start_time) * 1e-9);
if ( runtime > hal_get_real(funct->maxtime)) {
hal_set_real(funct->maxtime, runtime);
hal_set_bool(funct->maxtime_increased, 1);
} else {
hal_set_bool(funct->maxtime_increased, 0);
Expand All @@ -3686,10 +3688,11 @@ static void thread_task(void *arg)
/* prepare to measure time for next funct */
start_time = end_time;
}
/* update thread execution time */
rtapi_s32 runtime = hal_set_si32(thread->runtime, end_time - thread_start_time);
if ( runtime > hal_get_si32(thread->maxtime)) {
hal_set_si32(thread->maxtime, runtime);
/* update thread execution time, in seconds */
rtapi_real runtime = hal_set_real(thread->runtime,
(rtapi_real)(end_time - thread_start_time) * 1e-9);
if ( runtime > hal_get_real(thread->maxtime)) {
hal_set_real(thread->maxtime, runtime);
}
hal_set_sint(thread->threadbeat, ++thread->beatcnt);
}
Expand Down
8 changes: 4 additions & 4 deletions src/hal/hal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ struct hal_funct_t {
// IMPORTANT: The pins and params are valid as seen from the context that
// created them. For uspace that is rtapi_app and in the kernel it is the
// kernel's module context.
hal_sint_t runtime; /* (pin) duration of last run, in CPU cycles */
hal_sint_t maxtime; /* (param) duration of longest run, in CPU cycles */
hal_real_t runtime; /* (pin) duration of last run, in seconds */
hal_real_t maxtime; /* (param) duration of longest run, in seconds */
hal_bool_t maxtime_increased; /* (param) on last call, maxtime increased */
char name[HAL_NAME_LEN + 1]; /* function name */
};
Expand All @@ -429,8 +429,8 @@ struct hal_thread_t {
// IMPORTANT: The pins and params are valid as seen from the context that
// created them. For uspace that is rtapi_app and in the kernel it is the
// kernel's module context.
hal_sint_t runtime; /* (pin) duration of last run, in ns */
hal_sint_t maxtime; /* (param) duration of longest run, in ns */
hal_real_t runtime; /* (pin) duration of last run, in seconds */
hal_real_t maxtime; /* (param) duration of longest run, in seconds */
hal_sint_t threadbeat; /* (pin) visible monotonic loop beat counter */
rtapi_sint beatcnt; /* Thread monotonic increasing loop beat counter (so we don't need to read/write volatile) */
hal_list_t funct_list; /* list of functions to run */
Expand Down
Loading