lkml.org 
[lkml]   [2023]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v2 17/24] selftests/resctrl: Replace count_bits with count_consecutive_bits()
Date
Hi Ilpo,

> On Wed, 31 May 2023, Shaopeng Tan (Fujitsu) wrote:
>
> > Hi Ilpo,
> >
> > > CAT and CMT tests depends on masks being continuous.
> > >
> > > Replace count_bits with more appropriate variant that counts consecutive
> bits.
> > >
> > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > ---
>
> > > @@ -218,6 +220,34 @@ static int get_bit_mask(char *filename,
> > > unsigned long
> > > *mask)
> > > return 0;
> > > }
> > >
> > > +/*
> > > + * count_consecutive_bits - Returns the longest train of bits in a bit mask
> > > + * @val A bit mask
> > > + * @start The location of the least-significant bit of the longest train
> > > + *
> > > + * Return: The length of the consecutive bits in the longest train of bits
> > > + */
> > > +unsigned int count_consecutive_bits(unsigned long val, unsigned int
> > > +*start) {
> > > + unsigned long last_val;
> > > + int count = 0;
> > > +
> > > + while (val) {
> > > + last_val = val;
> > > + val &= (val >> 1);
> > > + count++;
> > > + }
> >
> > There may not be a case that the most-significant bit is 1 at present,
> > but if this case exists, it cannot count correctly.
>
> Can you please rephrase what is your concern here please?
>
> I test 0U, 1U, ~0U, and a few more complex combinations of bits, and all
> returned correct count so I might not have understood what case you meant
> with your description.
>
> This function does not count nor calculate the most-significant bit in any
> phase but the longest train of bits using the count variable (and the
> least-significant bit of the longest train in the code that is not included into this
> partial snippet).

Thanks for your explanation.
I'm sorry, it was my mistake.
No problem here.

Best regards
Shaopeng TAN
\
 
 \ /
  Last update: 2023-06-01 08:21    [W:0.107 / U:0.424 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site