Hi all,

I am trying to use m5thread library according to the instruction at
http://lacasa.uah.edu/portal/Upload/tutorials/gem5/GettingStarted-m5threads.txt,
since I would like to build a multi-thread program for GEM5 simulator.

However, when I run the `./test_malloc n` (n > 1) in it's own tests/
folder, it will cause segmentation fault. I searched but found that no one
had encountered this problem before?

OS:
  Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-91-generic x86_64)

Compiler:
  gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)

===================Start the test case=====================
./test_malloc 2
Init done
[ALLOC 1, Thread 0] Allocated 1 bytes, from 0x21e8cd0 to 0x21e8cd0
[ALLOC 1, Thread 1] Allocated 2 bytes, from 0x7f69e40008c0 to 0x7f69e40008c1
[ALLOC 1, Thread 1] Freed 0's allocation, 0x21e8cd0
[ALLOC 1, Thread 0] Freed 1's allocation, 0x7f69e40008c0
Iteration 1 completed
[ALLOC 2, Thread 0] Allocated 2 bytes, from 0x21e8cd0 to 0x21e8cd1
[ALLOC 2, Thread 1] Allocated 4 bytes, from 0x7f69dc0008c0 to 0x7f69dc0008c3
[ALLOC 2, Thread 1] Freed 1's allocation, 0x7f69dc0008c0
[ALLOC 2, Thread 0] Freed 0's allocation, 0x21e8cd0
Iteration 2 completed
[ALLOC 3, Thread 0] Allocated 3 bytes, from 0x21e8cd0 to 0x21e8cd2
[ALLOC 3, Thread 1] Allocated 6 bytes, from 0x7f69e00008c0 to 0x7f69e00008c5
[ALLOC 3, Thread 1] Freed 0's allocation, 0x21e8cd0
[ALLOC 3, Thread 0] Freed 1's allocation, 0x7f69e00008c0
Iteration 3 completed
[ALLOC 4, Thread 0] Allocated 4 bytes, from 0x21e8cd0 to 0x21e8cd3
[ALLOC 4, Thread 1] Allocated 8 bytes, from 0x7f69d40008c0 to 0x7f69d40008c7
[ALLOC 4, Thread 1] Freed 1's allocation, 0x7f69d40008c0
[ALLOC 4, Thread 0] Freed 0's allocation, 0x21e8cd0
Iteration 4 completed
[ALLOC 5, Thread 0] Allocated 5 bytes, from 0x21e8cd0 to 0x21e8cd4
[ALLOC 5, Thread 1] Allocated 10 bytes, from 0x7f69d80008c0 to
0x7f69d80008c9
[ALLOC 5, Thread 1] Freed 0's allocation, 0x21e8cd0
[ALLOC 5, Thread 0] Freed 1's allocation, 0x7f69d80008c0
Iteration 5 completed
[ALLOC 6, Thread 0] Allocated 6 bytes, from 0x21e8cd0 to 0x21e8cd5
[ALLOC 6, Thread 1] Allocated 12 bytes, from 0x7f69cc0008c0 to
0x7f69cc0008cb
[ALLOC 6, Thread 1] Freed 1's allocation, 0x7f69cc0008c0
[ALLOC 6, Thread 0] Freed 0's allocation, 0x21e8cd0
Iteration 6 completed
[ALLOC 7, Thread 0] Allocated 7 bytes, from 0x21e8cd0 to 0x21e8cd6
[ALLOC 7, Thread 1] Allocated 14 bytes, from 0x7f69d00008c0 to
0x7f69d00008cd
[ALLOC 7, Thread 1] Freed 0's allocation, 0x21e8cd0
[ALLOC 7, Thread 0] Freed 1's allocation, 0x7f69d00008c0
Iteration 7 completed
[ALLOC 8, Thread 0] Allocated 8 bytes, from 0x21e8cd0 to 0x21e8cd7
[ALLOC 8, Thread 1] Allocated 16 bytes, from 0x7f69c40008c0 to
0x7f69c40008cf
[ALLOC 8, Thread 1] Freed 1's allocation, 0x7f69c40008c0
[ALLOC 8, Thread 0] Freed 0's allocation, 0x21e8cd0
Iteration 8 completed
[ALLOC 9, Thread 0] Allocated 9 bytes, from 0x21e8cd0 to 0x21e8cd8
Job 1, './test_malloc 2' terminated by signal SIGSEGV (Address boundary
error)

===================End the test case=====================


One interesting thing is that the test will stop at exactly the same
position (with `./test_malloc 2`, right at the ALLOC 9, thread 1 malloc() ).
I used some debug tools and here is the stack:

Thread #1 [test_malloc] [core: 3] (Suspended : Container)
  pthread_barrier_wait() at pthread.c:699 0x40201b
  alloc() at test_malloc.cpp:55 0x401112
  main() at test_malloc.cpp:91 0x40130b
Thread #2 [test_malloc] [core: 4] (Suspended : Signal :
SIGSEGV:Segmentation fault)
  get_nprocs() at 0x43886c
  arena_get2.isra() at 0x411f90
  malloc() at 0x416297
  alloc() at test_malloc.cpp:51 0x40109f
  __pthread_trampoline() at pthread.c:226 0x401714
  clone() at 0x438bb9

But every iteration seems identical (create new threads then malloc() and
free()), why could it happen exactly at the 9th iteration? I even ran the
same code on another Ubuntu 14.04 with gcc-4.8 machine, and the same thing
just happened again.

I suppose that it may partially due to the `mmap()` function when
allocating a new thread. I changed mmap() to malloc() in pthread_create()
function and then it could pass `./test_malloc n <= 3` but not n > 3 cases
(still segfault).

Hope someone could help me! I am sincerely looking forward to your response.

Best Regards,
Qian
_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

Reply via email to