Skip to content

Commit d09f298

Browse files
author
Michael Haberler
committed
hal_lib: change .time item from parameter to pin
tmax is still a _parameter_ so that it can be reset (HAL_RW) Signed-off-by: Dewey Garrett <[email protected]> Conflicts: src/hal/lib/hal_lib.c src/hal/lib/hal_priv.h
1 parent 10e369f commit d09f298

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

src/hal/lib/hal_lib.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -1694,18 +1694,31 @@ int hal_export_funct(const char *name, void (*funct) (void *, long),
16941694
new->runtime = 0;
16951695
new->maxtime = 0;
16961696
new->maxtime_increased = 0;
1697+
1698+
/* at this point we have a new function and can yield the mutex */
1699+
rtapi_mutex_give(&(hal_data->mutex));
1700+
1701+
/* create a pin with the function's runtime in it */
1702+
if (hal_pin_s32_newf(HAL_OUT, &(new->runtime), comp_id,"%s.time",name)) {
1703+
rtapi_print_msg(RTAPI_MSG_ERR,
1704+
"HAL: ERROR: fail to create pin '%s.time'\n", name);
1705+
return -EINVAL;
1706+
}
1707+
*(new->runtime) = 0;
1708+
16971709
/* note that failure to successfully create the following params
16981710
does not cause the "export_funct()" call to fail - they are
16991711
for debugging and testing use only */
1700-
/* create a parameter with the function's runtime in it */
1701-
rtapi_snprintf(buf, sizeof(buf), "%s.time", name);
1702-
hal_param_s32_new(buf, HAL_RO, &(new->runtime), comp_id);
17031712
/* create a parameter with the function's maximum runtime in it */
17041713
rtapi_snprintf(buf, sizeof(buf), "%s.tmax", name);
1714+
new->maxtime = 0;
17051715
hal_param_s32_new(buf, HAL_RW, &(new->maxtime), comp_id);
1716+
17061717
/* create a parameter with the function's maximum runtime in it */
17071718
rtapi_snprintf(buf, sizeof(buf), "%s.tmax-increased", name);
1719+
new->maxtime_increased = 0;
17081720
hal_param_bit_new(buf, HAL_RO, &(new->maxtime_increased), comp_id);
1721+
17091722
return 0;
17101723
}
17111724

@@ -2831,9 +2844,9 @@ static void thread_task(void *arg)
28312844
/* point to function structure */
28322845
funct = SHMPTR(funct_entry->funct_ptr);
28332846
/* update execution time data */
2834-
funct->runtime = (hal_s32_t)(end_time - start_time);
2835-
if (funct->runtime > funct->maxtime) {
2836-
funct->maxtime = funct->runtime;
2847+
*(funct->runtime) = (hal_s32_t)(end_time - start_time);
2848+
if ( *(funct->runtime) > funct->maxtime) {
2849+
funct->maxtime = *(funct->runtime);
28372850
funct->maxtime_increased = 1;
28382851
} else {
28392852
funct->maxtime_increased = 0;
@@ -3445,6 +3458,7 @@ static void free_funct_struct(hal_funct_t * funct)
34453458
funct->users = 0;
34463459
funct->arg = 0;
34473460
funct->funct = 0;
3461+
funct->runtime = 0;
34483462
funct->name[0] = '\0';
34493463
/* add it to free list */
34503464
funct->next_ptr = hal_data->funct_free_ptr;

src/hal/lib/hal_priv.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ typedef struct {
340340
int users; /* number of threads using function */
341341
void *arg; /* argument for function */
342342
void (*funct) (void *, long); /* ptr to function code */
343-
hal_s32_t runtime; /* duration of last run, in nsec */
344-
hal_s32_t maxtime; /* duration of longest run, in nsec */
345343
int handle; // unique ID
344+
hal_s32_t* runtime; /* (pin) duration of last run, in nsec */
345+
hal_s32_t maxtime; /* duration of longest run, in nsec */
346346
hal_bit_t maxtime_increased; /* on last call, maxtime increased */
347347
char name[HAL_NAME_LEN + 1]; /* function name */
348348
} hal_funct_t;

src/hal/lib/halpb.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int halpr_describe_funct(hal_funct_t *funct, pb::Function *pbfunct)
8888
pbfunct->set_handle(funct->handle);
8989
pbfunct->set_owner_id(owner->comp_id);
9090
pbfunct->set_users(funct->users);
91-
pbfunct->set_runtime(funct->runtime);
91+
pbfunct->set_runtime(*(funct->runtime));
9292
pbfunct->set_maxtime(funct->maxtime);
9393
pbfunct->set_reentrant(funct->reentrant);
9494
return 0;

tests/alias.0/expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
and2.0.in1 and2.0.out something
1+
and2.0.in1 and2.0.out and2.0.time something

tests/loadrt.1/expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
and2.0 m.q m.r or2.0 or2.1 or2.2
2-
and2.0.in0 and2.0.in1 and2.0.out m.q.in0 m.q.in1 m.q.out m.q.sel m.r.in0 m.r.in1 m.r.out m.r.sel or2.0.in0 or2.0.in1 or2.0.out or2.1.in0 or2.1.in1 or2.1.out or2.2.in0 or2.2.in1 or2.2.out
2+
and2.0.in0 and2.0.in1 and2.0.out and2.0.time m.q.in0 m.q.in1 m.q.out m.q.sel m.q.time m.r.in0 m.r.in1 m.r.out m.r.sel m.r.time or2.0.in0 or2.0.in1 or2.0.out or2.0.time or2.1.in0 or2.1.in1 or2.1.out or2.1.time or2.2.in0 or2.2.in1 or2.2.out or2.2.time

0 commit comments

Comments
 (0)