AW: [can-utils][PATCH 2/3] canbusload: support busload statistic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Marc,

> -----Ursprüngliche Nachricht-----
> Von: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> Gesendet: Montag, 20. Januar 2025 18:11
> An: Jonas Mark (BT-FS/ENG1-Mue) <mark.jonas@xxxxxxxxxxxx>
> Cc: linux-can@xxxxxxxxxxxxxxx; Zhu Yi <yi.zhu5@xxxxxxxxxxxx>; Streidl
> Hubert (BT-FS/ENG1-Mue) <hubert.streidl@xxxxxxxxxxxx>
> Betreff: Re: [can-utils][PATCH 2/3] canbusload: support busload
> statistic
> 
> 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/tr
> > +ee/
> > + * 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.

Thank you for your feedback. We'll have a look it by the end of the week.

We compiled and tested with Ubuntu 22.04 on amd64 (standard PC). That is, we used gcc 11.4 and ld (binutils) 2.38. For us it linked flawlessly and compiled without warnings. Which version of gcc and ld did you use?

Thanks,
Mark




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux