This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 8d9c18833 testing/sched/timerjitter: Fix the default run and the
results.
8d9c18833 is described below
commit 8d9c18833ffb3c516b9795fbdfb7ffe5c7f118bb
Author: Max Kriegleder <[email protected]>
AuthorDate: Mon Oct 26 23:58:00 2026 +0100
testing/sched/timerjitter: Fix the default run and the results.
With USEC_PER_TICK above 1000 the default interval (1000 ticks) is
longer than a second, so DEFAULT_ITERATION was 0: no samples, avg
0/0 = nan and min printed as ULONG_MAX. Run at least one iteration
and don't divide by zero.
min and max were unsigned long while the latency is a signed int64_t,
so an early wakeup was stored and shown as a huge value (2^32 - 851).
Keep them as int64_t and print them with PRId64.
Count an iteration only after sigwait() returns, so a failed wait
isn't taken as a sample.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Max Kriegleder <[email protected]>
---
testing/sched/timerjitter/timerjitter.c | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/testing/sched/timerjitter/timerjitter.c
b/testing/sched/timerjitter/timerjitter.c
index 2f7cea37f..536391804 100644
--- a/testing/sched/timerjitter/timerjitter.c
+++ b/testing/sched/timerjitter/timerjitter.c
@@ -24,6 +24,7 @@
* Included Files
****************************************************************************/
+#include <inttypes.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
@@ -37,7 +38,8 @@
#define DEFAULT_CLOCKID CLOCK_REALTIME
#define DEFAULT_INTERVAL (1000 * USEC_PER_TICK)
-#define DEFAULT_ITERATION (USEC_PER_SEC / DEFAULT_INTERVAL)
+#define DEFAULT_ITERATION (USEC_PER_SEC / DEFAULT_INTERVAL > 0 ? \
+ USEC_PER_SEC / DEFAULT_INTERVAL : 1)
/* Fix compilation error for Non-NuttX OS */
#ifndef FAR
@@ -63,8 +65,8 @@ struct timerjitter_param_s
unsigned long max_cnt;
unsigned long cur_cnt;
double avg;
- unsigned long max;
- unsigned long min;
+ int64_t max;
+ int64_t min;
int print;
unsigned int missed;
};
@@ -192,13 +194,11 @@ static FAR void *timerjitter(FAR void *arg)
}
param->avg = 0;
- param->max = 0;
- param->min = (unsigned long)-1;
+ param->max = INT64_MIN;
+ param->min = INT64_MAX;
while (param->cur_cnt < param->max_cnt)
{
- param->cur_cnt++;
-
/* Wait for SIGALRM */
if (sigwait(&sigset, &sigs) < 0)
@@ -207,6 +207,8 @@ static FAR void *timerjitter(FAR void *arg)
break;
}
+ param->cur_cnt++;
+
ret = clock_gettime(param->clockid, &now);
if (ret)
{
@@ -246,7 +248,11 @@ static FAR void *timerjitter(FAR void *arg)
}
timer_delete(timer);
- param->avg = param->avg / param->cur_cnt;
+ if (param->cur_cnt > 0)
+ {
+ param->avg = param->avg / param->cur_cnt;
+ }
+
return NULL;
}
@@ -359,8 +365,15 @@ int main(int argc, FAR char *argv[])
}
printf("timer jitter in %lu run:\n", param.max_cnt);
- printf("(latency/us) min: %lu, avg: %.0lf, max %lu\n",
- param.min, param.avg, param.max);
+ if (param.cur_cnt == 0)
+ {
+ printf("(latency/us) no samples\n");
+ }
+ else
+ {
+ printf("(latency/us) min: %" PRId64 ", avg: %.0lf, max %" PRId64 "\n",
+ param.min, param.avg, param.max);
+ }
return 0;
}