Linux-rt-users archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] rt-tests: queuelat: Fix storing unsigned long long in int
@ 2020-05-12 15:16 John Kacur
  0 siblings, 0 replies; only message in thread
From: John Kacur @ 2020-05-12 15:16 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, Marcelo Tosatti, John Kacur

queuelat can occassionally hang because of overflow mixing
unsigned long long and int

Attaching to process 173912
Reading symbols from /root/rt-tests/queuelat...done.
Reading symbols from /lib64/librt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/librt-2.28.so.debug...done.
done.
Reading symbols from /lib64/libpthread.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libpthread-2.28.so.debug...done.
done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Reading symbols from /lib64/libc.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libc-2.28.so.debug...done.
done.
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.28.so.debug...done.
done.
__memmove_avx_unaligned_erms ()
    at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:254
254		rep movsb
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400c02 in account (val=18446744071562067968)
    at src/queuelat/queuelat.c:93
93		buckets[bucket_nr]++;
(gdb) bt full
    at src/queuelat/queuelat.c:93
        bucket_nr = -193273529
        a = 825932047802952
        b = 825925371232340
        dest = 0xf322b0
        src = 0xf4e3f0
        i = 45749
        delta = -2147483648
        loops = 50000
        time = 6500
        bucket_nr = 65
        n = 115000
        delta = 3500
    at src/queuelat/queuelat.c:671
        tsc_freq_mhz = 2398.5039999999999
        max_queue_len_f = 159.900284
        mvalue = 0x7ffc99d3021c "20000"
        cvalue = 0x7ffc99d30225 "300"
        pvalue = 0x7ffc99d30238 "6.1"
        fvalue = 0x7ffc99d3022c "2398.504"
        tvalue = 0x7ffc99d3023f "30"
        qvalue = 0x0
        index = 0
        c = -1

Fix the above by declaring delta as an unsigned long long

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/queuelat/queuelat.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/queuelat/queuelat.c b/src/queuelat/queuelat.c
index 7e5e35768a8b..22b68a84d6ae 100644
--- a/src/queuelat/queuelat.c
+++ b/src/queuelat/queuelat.c
@@ -354,9 +354,9 @@ static void trace_write(char *buf, int len)
 
 static void run_n(int n)
 {
-	u64 a, b;
+	u64 a, b, delta;
 	void *dest, *src;
-	int i, delta, loops = 50000;
+	int i, loops = 50000;
 
 	init_buckets();
 
@@ -445,9 +445,8 @@ static void print_exit_info(void)
 
 void main_loop(void)
 {
-	u64 a, b;
+	u64 a, b, delta;
 	void *dest, *src;
-	int delta;
 	int queue_size = 0;
 
 	trace_open();
@@ -500,7 +499,7 @@ void main_loop(void)
 			continue;
 
 		ret = sprintf(buf, "memmove block queue_size=%d queue_dec=%d"
-			           " queue_inc=%d delta=%d ns\n", queue_size,
+			           " queue_inc=%d delta=%llu ns\n", queue_size,
 				   nr_packets_drain_per_block,
 				   nr_packets_fill, delta);
 		trace_write(buf, ret);
@@ -536,7 +535,7 @@ static void install_signals(void)
 
 int calculate_nr_packets_drain_per_block(void)
 {
-	int maxcount;
+	unsigned long long maxcount;
 	int i, time;
 	int found = 0;
 	int bucket_nr = find_highest_count_bucket();
-- 
2.21.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 15:16 [PATCH] rt-tests: queuelat: Fix storing unsigned long long in int John Kacur

Linux-rt-users archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rt-users/0 linux-rt-users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rt-users linux-rt-users/ https://lore.kernel.org/linux-rt-users \
		linux-rt-users@vger.kernel.org
	public-inbox-index linux-rt-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rt-users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git