On 20.01.2025 17:23:31, mark.jonas@xxxxxxxxxxxx wrote: > From: Zhu Yi <yi.zhu5@xxxxxxxxxxxx> > > Add '-s' option for display busload statistic, the output contains > minimal, maximum and exponentially-damped moving sums of one second > average (borrowed from Linux load average algorithm) since start or > reset (press 'r' while running). > > canbusload 2024-09-23 17:15:18 (exact bitstuffing) > can0@500k 942 107535 60168 0 18% min: 0%, max: 21%, load: 16% 6% 2% |XXX.................| > > Signed-off-by: Zhu Yi <yi.zhu5@xxxxxxxxxxxx> > Signed-off-by: Hubert Streidl <hubert.streidl@xxxxxxxxxxxx> > Signed-off-by: Mark Jonas <mark.jonas@xxxxxxxxxxxx> > --- > canbusload.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 91 insertions(+), 1 deletion(-) > > diff --git a/canbusload.c b/canbusload.c > index 753d658..577d99c 100644 > --- a/canbusload.c > +++ b/canbusload.c > @@ -48,11 +48,13 @@ > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > +#include <termios.h> > #include <time.h> > #include <unistd.h> > > #include <net/if.h> > #include <sys/ioctl.h> > +#include <sys/param.h> > #include <sys/socket.h> > #include <sys/time.h> > #include <sys/types.h> > @@ -72,6 +74,34 @@ > #define NUMBAR (100 / PERCENTRES) /* number of bargraph elements */ > #define BRSTRLEN 20 > > +/* > + * Inspired from > + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/ > + * include/linux/sched/loadavg.h > + * > + * Following are the fixed-point math constants and the exponential-damping > + * factors for: > + * - 1 samples/s in 1 minute > + * - 1 samples/s in 5 minutes > + * - 1 samples/s in 15 minutes > + * in fixed-point representation. > + */ > +#define FP_SHIFT 12 /* bits of precision */ > +#define FP_ONE (1 << FP_SHIFT) /* 1.0 fixed-point representation */ > +#define EXP_1 4028 /* (1 / e ^ (1 / 60)) * FP_ONE */ > +#define EXP_5 4082 /* (1 / e ^ (1 / 300)) * FP_ONE */ > +#define EXP_15 4091 /* (1 / e ^ (1 / 900)) * FP_ONE */ > + > +inline unsigned int calc_load(unsigned int load_fp, > + unsigned int exp_fp, > + unsigned int sample) > +{ > + unsigned int sample_fp = sample << FP_SHIFT; > + unsigned int damped_sum = (load_fp * exp_fp) + > + (sample_fp * (FP_ONE - exp_fp)); > + return damped_sum >> FP_SHIFT; > +} > + Had to make this a "static" function, otherwise it fails to link. Some singed/unsigned changes were also needed. Can you check if this still works for you: | https://github.com/linux-can/can-utils/pull/571 So far compile tested only. regards, Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Attachment:
signature.asc
Description: PGP signature