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

[xen staging-4.17] tools/xentop: Fix cpu% sort order



commit cd3f405b68ff99f14a8b9424665059c2447a4756
Author:     Leigh Brown <leigh@xxxxxxxxxxxxx>
AuthorDate: Tue May 21 12:02:03 2024 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue May 21 12:02:03 2024 +0200

    tools/xentop: Fix cpu% sort order
    
    In compare_cpu_pct(), there is a double -> unsigned long long converion when
    calling compare().  In C, this discards the fractional part, resulting in an
    out-of order sorting such as:
    
            NAME  STATE   CPU(sec) CPU(%)
           xendd --b---       4020    5.7
        icecream --b---       2600    3.8
        Domain-0 -----r       1060    1.5
            neon --b---        827    1.1
          cheese --b---        225    0.7
           pizza --b---        359    0.5
         cassini --b---        490    0.4
         fusilli --b---        159    0.2
             bob --b---        502    0.2
         blender --b---        121    0.2
           bread --b---         69    0.1
        chickpea --b---         67    0.1
          lentil --b---         67    0.1
    
    Introduce compare_dbl() function and update compare_cpu_pct() to call it.
    
    Fixes: 49839b535b78 ("Add xenstat framework.")
    Signed-off-by: Leigh Brown <leigh@xxxxxxxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    master commit: e27fc7d15eab79e604e8b8728778594accc23cf1
    master date: 2024-05-15 19:59:52 +0100
---
 tools/xentop/xentop.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c
index 545bd5e96d..c2a311befe 100644
--- a/tools/xentop/xentop.c
+++ b/tools/xentop/xentop.c
@@ -85,6 +85,7 @@ static void set_delay(const char *value);
 static void set_prompt(const char *new_prompt, void (*func)(const char *));
 static int handle_key(int);
 static int compare(unsigned long long, unsigned long long);
+static int compare_dbl(double, double);
 static int compare_domains(xenstat_domain **, xenstat_domain **);
 static unsigned long long tot_net_bytes( xenstat_domain *, int);
 static bool tot_vbd_reqs(xenstat_domain *, int, unsigned long long *);
@@ -422,6 +423,16 @@ static int compare(unsigned long long i1, unsigned long 
long i2)
        return 0;
 }
 
+/* Compares two double precision numbers, returning -1,0,1 for <,=,> */
+static int compare_dbl(double d1, double d2)
+{
+       if (d1 < d2)
+               return -1;
+       if (d1 > d2)
+               return 1;
+       return 0;
+}
+
 /* Comparison function for use with qsort.  Compares two domains using the
  * current sort field. */
 static int compare_domains(xenstat_domain **domain1, xenstat_domain **domain2)
@@ -523,7 +534,7 @@ static double get_cpu_pct(xenstat_domain *domain)
 
 static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2)
 {
-       return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2));
+       return -compare_dbl(get_cpu_pct(domain1), get_cpu_pct(domain2));
 }
 
 /* Prints cpu percentage statistic */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.17



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.