On Sat, Apr 22, 2023 at 12:00:44AM +0000, Klemens Nanni wrote:
> On Fri, Apr 21, 2023 at 11:29:11PM +0000, Koakuma wrote:
> > I noticed that when using `ldomctl status` the utilization value of
> > stopped ldoms is always a copy of the previous entry's value,
> > which is probably incorrect?

Right, it sticks to the value of the last running guest, that's wrong.

> > 
> > Zeroing utilization value in `ldomctl status` at the start of the loop
> > makes it so that stopped ldoms' utilization appear as a zero, which
> > I believe is a more appropriate value in this context.
> > 
> > Before:
> > primary          -        running          OpenBSD running                  
> >  11%
> > gentoo           ttyV0    running          Linux running                    
> >   0%
> > openbsd          ttyV1    running          OpenBSD running                  
> >   5%
> > solaris          ttyV2    stopped          -                                
> >   5%
> > 
> > After:
> > primary          -        running          OpenBSD running                  
> >   1%
> > gentoo           ttyV0    running          Linux running                    
> >   0%
> > openbsd          ttyV1    running          OpenBSD running                  
> >   8%
> > solaris          ttyV2    stopped          -                                
> >   0%
> > 
> > Any comments?
> 
> That explains why I saw >0% after i stopped a guest that caused problems...
> thought it was a bug nastier than this, but didn't look and forgot.
> 
> Makes sense, I'll test in a few days and come back.

Works as expected, thanks!

> 
> > 
> > diff --git usr.sbin/ldomctl/ldomctl.c usr.sbin/ldomctl/ldomctl.c
> > index e48a560f7db..3a1b47cc1dc 100644
> > --- usr.sbin/ldomctl/ldomctl.c
> > +++ usr.sbin/ldomctl/ldomctl.c
> > @@ -574,6 +574,8 @@ guest_status(int argc, char **argv)
> >                 if (gid != -1 && guest->gid != gid)
> >                         continue;
> >  
> > +               utilisation = 0.0;
> > +
> >                 /*
> >                  * Request status.
> >                  */

I'd reset after the comment and struct msg setup,
closer to the switch block which may set the value.

Feedback? OK?

> > @@ -644,8 +646,6 @@ guest_status(int argc, char **argv)
> >                         if (yielded_cycles <= total_cycles)
> >                                 utilisation = (100.0 * (total_cycles
> >                                     - yielded_cycles)) / total_cycles;
> > -                       else
> > -                               utilisation = 0.0;
> >  
> >                         break;
> >                 case GUEST_STATE_SUSPENDED:
> > 
> 


Index: ldomctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.c,v
retrieving revision 1.40
diff -u -p -r1.40 ldomctl.c
--- ldomctl.c   24 Oct 2021 21:24:18 -0000      1.40
+++ ldomctl.c   7 Aug 2023 14:15:08 -0000
@@ -592,6 +592,8 @@ guest_status(int argc, char **argv)
                if (nbytes != sizeof(msg))
                        err(1, "read");
 
+               utilisation = 0.0;
+
                memcpy(&state, msg.msg.resstat.data, sizeof(state));
                switch (state.state) {
                case GUEST_STATE_STOPPED:
@@ -644,8 +646,6 @@ guest_status(int argc, char **argv)
                        if (yielded_cycles <= total_cycles)
                                utilisation = (100.0 * (total_cycles
                                    - yielded_cycles)) / total_cycles;
-                       else
-                               utilisation = 0.0;
 
                        break;
                case GUEST_STATE_SUSPENDED:

Reply via email to