aports/main/util-linux/irq-sort.patch
2023-11-24 03:20:07 +00:00

50 lines
1.3 KiB
Diff

From 65ca5080159444e25b13e092678bf84164f9de6e Mon Sep 17 00:00:00 2001
From: Valery Ushakov <uwe@stderr.spb.ru>
Date: Wed, 22 Nov 2023 03:56:19 +0300
Subject: [PATCH] irqtop: fix numeric sorting
qsort(3) requires three-way result like that from strcmp(3),
not an std::less like boolean.
---
sys-utils/irq-common.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/sys-utils/irq-common.c b/sys-utils/irq-common.c
index 725a132814..f36ed693c8 100644
--- a/sys-utils/irq-common.c
+++ b/sys-utils/irq-common.c
@@ -369,18 +369,29 @@ static inline int cmp_name(const struct irq_info *a,
return strcoll(a->name, b->name);
}
+static inline int cmp_ulong_descending(unsigned long a,
+ unsigned long b)
+{
+ if (a == b)
+ return 0;
+ if (a < b)
+ return 1;
+ else
+ return -1;
+}
+
static inline int cmp_total(const struct irq_info *a,
const struct irq_info *b)
{
- return a->total < b->total;
+ int cmp = cmp_ulong_descending(a->total, b->total);
+ return cmp ? cmp : cmp_name(a, b);
}
static inline int cmp_delta(const struct irq_info *a,
const struct irq_info *b)
{
- if (a->delta != b->delta)
- return a->delta < b->delta;
- return cmp_name(a, b);
+ int cmp = cmp_ulong_descending(a->delta, b->delta);
+ return cmp ? cmp : cmp_name(a, b);
}
static inline int cmp_interrupts(const struct irq_info *a,