Skip to content

Commit

Permalink
hal_lib: change .time item from parameter to pin
Browse files Browse the repository at this point in the history
tmax is still a _parameter_ so that it can be reset (HAL_RW)

Signed-off-by: Dewey Garrett <[email protected]>
  • Loading branch information
dngarrett committed Feb 17, 2015
1 parent 7c1427a commit 9516669
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,22 +1687,28 @@ int hal_export_funct(const char *name, void (*funct) (void *, long),
}
/* at this point we have a new function and can yield the mutex */
rtapi_mutex_give(&(hal_data->mutex));
/* init time logging variables */
new->runtime = 0;
new->maxtime = 0;
new->maxtime_increased = 0;

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

/* 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 runtime in it */
rtapi_snprintf(buf, sizeof(buf), "%s.time", name);
hal_param_s32_new(buf, HAL_RO, &(new->runtime), comp_id);
/* create a parameter with the function's maximum runtime in it */
rtapi_snprintf(buf, sizeof(buf), "%s.tmax", name);
new->maxtime = 0;
hal_param_s32_new(buf, HAL_RW, &(new->maxtime), comp_id);

/* create a parameter with the function's maximum runtime in it */
rtapi_snprintf(buf, sizeof(buf), "%s.tmax-increased", name);
new->maxtime_increased = 0;
hal_param_bit_new(buf, HAL_RO, &(new->maxtime_increased), comp_id);

return 0;
}

Expand Down Expand Up @@ -2689,9 +2695,9 @@ static void thread_task(void *arg)
/* point to function structure */
funct = SHMPTR(funct_entry->funct_ptr);
/* update execution time data */
funct->runtime = (hal_s32_t)(end_time - start_time);
if (funct->runtime > funct->maxtime) {
funct->maxtime = funct->runtime;
*(funct->runtime) = (hal_s32_t)(end_time - start_time);
if ( *(funct->runtime) > funct->maxtime) {
funct->maxtime = *(funct->runtime);
funct->maxtime_increased = 1;
} else {
funct->maxtime_increased = 0;
Expand Down Expand Up @@ -3266,6 +3272,7 @@ static void free_funct_struct(hal_funct_t * funct)
funct->users = 0;
funct->arg = 0;
funct->funct = 0;
funct->runtime = 0;
funct->name[0] = '\0';
/* add it to free list */
funct->next_ptr = hal_data->funct_free_ptr;
Expand Down
4 changes: 2 additions & 2 deletions src/hal/hal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ typedef struct {
int users; /* number of threads using function */
void *arg; /* argument for function */
void (*funct) (void *, long); /* ptr to function code */
hal_s32_t runtime; /* duration of last run, in nsec */
hal_s32_t maxtime; /* duration of longest run, in nsec */
hal_s32_t* runtime; /* (pin) duration of last run, in nsec */
hal_s32_t maxtime; /* (param) duration of longest run, in nsec */
hal_bit_t maxtime_increased; /* on last call, maxtime increased */
char name[HAL_NAME_LEN + 1]; /* function name */
} hal_funct_t;
Expand Down

0 comments on commit 9516669

Please sign in to comment.