changeset d53e38d5fc76 in /z/repo/m5threads
details: http://repo.gem5.org/m5threads?cmd=changeset;node=d53e38d5fc76
description:
        Add ARM support to m5threads.

diffstat:

 pthread.c                   |  60 +++++++++++++++++++++++++++++++++++---------
 tests/Makefile              |  15 ++++++++---
 tests/test___thread.cpp     |   6 ++--
 tests/test_atomic.cpp       |   4 +-
 tests/test_barrier.cpp      |   4 +-
 tests/test_lock.cpp         |   2 +-
 tests/test_malloc.cpp       |   4 +-
 tests/test_pthreadbasic.cpp |   8 +++---
 tests/test_stackgrow.cpp    |   2 +-
 tls_defs.h                  |  54 +++++++++++++++++++++++++++++++++++++++-
 10 files changed, 126 insertions(+), 33 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r 3f8d39a1afa1 -r d53e38d5fc76 pthread.c
--- a/pthread.c Mon Feb 16 13:29:55 2009 -0800
+++ b/pthread.c Wed Sep 26 16:36:57 2012 -0500
@@ -39,6 +39,8 @@
   #include "spinlock_alpha.h"
 #elif defined(__sparc)
   #include "spinlock_sparc.h"
+#elif defined (__arm__)
+  #include "spinlock_arm.h"
 #else
   #error "spinlock routines not available for your arch!\n"
 #endif
@@ -61,9 +63,9 @@
 #endif
 
 //Size and alignment requirements of "real" (NPTL/LinuxThreads) thread control 
block
-#define TCB_SIZE 512
-#define TCB_ALIGN sizeof(double)
-//TODO: Figure out real (NPTL/LinuxThreads) TCB space. 512 bytes should be 
enough.
+#define NPTL_TCB_SIZE 1184 // sizeof (struct pthread)
+#define NPTL_TCB_ALIGN sizeof(double)
+#define NPTL_TCBHEAD_T_SIZE (sizeof(tcbhead_t))
 
 //Thread control structure
 typedef struct {
@@ -133,26 +135,52 @@
   thread_block_info.stack_guard_size = 2048;
 
   //Total thread block size -- this is what we'll request to mmap
-  size_t sz = sizeof(pthread_tcb_t) + thread_block_info.tls_memsz + TCB_SIZE + 
thread_block_info.stack_guard_size + CHILD_STACK_SIZE;
+  #if TLS_TCB_AT_TP
+  size_t sz = sizeof(pthread_tcb_t) + thread_block_info.tls_memsz + 
NPTL_TCBHEAD_T_SIZE + thread_block_info.stack_guard_size + CHILD_STACK_SIZE;
+  #elif TLS_DTV_AT_TP
+  size_t sz = sizeof(pthread_tcb_t) + thread_block_info.tls_memsz + 
NPTL_TCB_SIZE + NPTL_TCBHEAD_T_SIZE + thread_block_info.stack_guard_size + 
CHILD_STACK_SIZE;
+  #else
+  #error "TLS_TCB_AT_TP xor TLS_DTV_AT_TP must be defined"
+  #endif
   //Note that TCB_SIZE is the "real" TCB size, not ours, which we leave zeroed 
(but some variables, notably errno, are somewhere inside there)
 
   //Align to multiple of CHILD_STACK_SIZE
   sz += CHILD_STACK_SIZE - 1;  
   thread_block_info.total_size = (sz>>CHILD_STACK_BITS)<<CHILD_STACK_BITS;
-
 }
 
+//Set up TLS block in current thread
+// @param th_block_addr:  beginning of entire thread memory space
+static void setup_thread_tls(void* th_block_addr) {
+  size_t tcb_offset = 0;
+  void *tlsblock = NULL;
+  char *tls_start_ptr = NULL;
 
-//Set up TLS block in current thread
-static void setup_thread_tls(void* th_block_addr) {
+  #if TLS_DTV_AT_TP
+  th_block_addr += NPTL_TCB_SIZE;
+  #endif
+
   /* Compute the (real) TCB offset */
-  size_t tcb_offset = roundup(thread_block_info.tls_memsz, TCB_ALIGN);
+  #if TLS_DTV_AT_TP
+  tcb_offset = roundup(NPTL_TCBHEAD_T_SIZE, NPTL_TCB_ALIGN);
+  #elif TLS_TCB_AT_TP
+  tcb_offset = roundup(thread_block_info.tls_memsz, NPTL_TCB_ALIGN);
+  #else
+  #error "TLS_TCB_AT_TP xor TLS_DTV_AT_TP must be defined"
+  #endif
+
   /* Align the TLS block.  */
-  void* tlsblock = (void *) (((uintptr_t) th_block_addr + 
thread_block_info.tls_align - 1)
+  tlsblock = (void *) (((uintptr_t) th_block_addr + 
thread_block_info.tls_align - 1)
                        & ~(thread_block_info.tls_align - 1));
   /* Initialize the TLS block.  */
-  char* tls_start_ptr = ((char *) tlsblock + tcb_offset
-                           - roundup (thread_block_info.tls_memsz, 
thread_block_info.tls_align ?: 1));
+  #if TLS_DTV_AT_TP
+  tls_start_ptr = ((char *) tlsblock + tcb_offset);
+  #elif TLS_TCB_AT_TP
+  tls_start_ptr = ((char *) tlsblock + tcb_offset
+                       - roundup (thread_block_info.tls_memsz, 
thread_block_info.tls_align ?: 1));
+  #else
+  #error "TLS_TCB_AT_TP xor TLS_DTV_AT_TP must be defined"
+  #endif
 
   //DEBUG("Init TLS: Copying %d bytes from 0x%llx to 0x%llx\n", filesz, 
(uint64_t) initimage, (uint64_t) tls_start_ptr);
   memcpy (tls_start_ptr, thread_block_info.tls_initimage, 
thread_block_info.tls_filesz);
@@ -161,7 +189,13 @@
 
   //Note: We don't care about DTV pointers for x86/SPARC -- they're never used 
in static mode
   /* Initialize the thread pointer.  */
+  #if TLS_DTV_AT_TP
+  TLS_INIT_TP (tlsblock, 0);
+  #elif TLS_TCB_AT_TP
   TLS_INIT_TP ((char *) tlsblock + tcb_offset, 0);
+  #else
+  #error "TLS_TCB_AT_TP xor TLS_DTV_AT_TP must be defined"
+  #endif
 }
 
 //Some NPTL definitions
@@ -174,7 +208,7 @@
   __libc_multiple_threads = 1; //tell libc we're multithreaded (NPTL-specific)
   populate_thread_block_info();
   void* ptr = mmap(0, thread_block_info.total_size, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-  setup_thread_tls(ptr);
+  setup_thread_tls(ptr + sizeof(pthread_tcb_t));
 }
 
 
@@ -211,7 +245,7 @@
   tcb->child_finished = 0;
   tcb->start_routine = start_routine;
   tcb->arg = arg;
-  tcb->tls_start_addr = (void*)(((char*)thread_block) + 
sizeof(pthread_tcb_t)); //right after tcb
+  tcb->tls_start_addr = (void*)(((char*)thread_block) + 
sizeof(pthread_tcb_t)); //right after m5's tcb
   tcb->stack_start_addr = (void*) (((char*) thread_block) + thread_block_size 
- thread_block_info.stack_guard_size); //end of thread_block
   
   *thread=(pthread_t) thread_block;
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/Makefile
--- a/tests/Makefile    Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/Makefile    Wed Sep 26 16:36:57 2012 -0500
@@ -4,20 +4,27 @@
 
 # 64-bit compiles
 #Uncomment to use sparc/alpha cross-compilers
-CC := sparc64-unknown-linux-gnu-gcc
-CPP := sparc64-unknown-linux-gnu-g++
+#CC := sparc64-unknown-linux-gnu-gcc
+#CPP := sparc64-unknown-linux-gnu-g++
 #CC := alpha-unknown-linux-gnu-gcc
 #CPP := alpha-unknown-linux-gnu-g++
-
+CC := arm-linux-gnueabi-gcc
+CPP := arm-linux-gnueabi-g++
 #CC := gcc
 #CPP := g++
 
+# Needed for support of v7 assembly instructions on ARM architecture
+ARM_FLAGS := -march=armv7-a -marm
+
 #CFLAGS := -ggdb3 -O3 -D__DEBUG
-CFLAGS := -g -O3 -DM5_PROFILING
+#CFLAGS := -g -O3 -DM5_PROFILING
+CFLAGS := -g -O3 $(ARM_FLAGS)
 
 CPPFLAGS := $(CFLAGS)
 
+# ARM support for OpenMP not tested (test_omp.o)
 TEST_OBJS := test_stackgrow.o test_pthreadbasic.o test_pthread.o test_atomic.o 
test_barrier.o test_lock.o test_malloc.o test_sieve.o  test___thread.o 
test_omp.o
+#TEST_OBJS := test_stackgrow.o test_pthreadbasic.o test_pthread.o 
test_atomic.o test_barrier.o test_lock.o test_malloc.o test_sieve.o  
test___thread.o
 
 TEST_PROGS := $(TEST_OBJS:.o=)
 
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test___thread.cpp
--- a/tests/test___thread.cpp   Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test___thread.cpp   Wed Sep 26 16:36:57 2012 -0500
@@ -37,7 +37,7 @@
 {
     long long int id = (long long int)arg;
     int i;
-    printf("&local[%d]=%p\n", id, &local);
+    printf("&local[%lld]=%p\n", id, &local);
     local += id;
     for (i = 0; i < count; i++) {
         local++;
@@ -79,13 +79,13 @@
     }
 
     long long int local = (long long int)run((void*)0);
-    printf("local[0] = %d\n", local);
+    printf("local[0] = %lld\n", local);
 
     for (i = 1 ; i < thread_count; i++) {
         int joinResult = pthread_join(threads[i], 
                                       (void**)&local);
         assert(joinResult == 0);
-        printf("local[%d] = %d\n", i, local);
+        printf("local[%d] = %lld\n", i, local);
     }
     
     /*struct timeval endTime;
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_atomic.cpp
--- a/tests/test_atomic.cpp     Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_atomic.cpp     Wed Sep 26 16:36:57 2012 -0500
@@ -48,7 +48,7 @@
     pthread_mutex_lock(&lock);
 
     int current = next;
-    printf("[Iteration %d, Thread %d] Got lock\n", iteration, id);
+    printf("[Iteration %d, Thread %lld] Got lock\n", iteration, id);
     intArray[current]++;
 
     //Uncomment this snip for longer-running critical section
@@ -60,7 +60,7 @@
 
     next = id;
 
-    printf("[Iteration %d, Thread %d] Critical section done, previously 
next=%d, now next=%d\n", iteration, id, current, next);
+    printf("[Iteration %d, Thread %lld] Critical section done, previously 
next=%d, now next=%d\n", iteration, id, current, next);
     pthread_mutex_unlock(&lock);
 
     pthread_barrier_wait(&barrier);
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_barrier.cpp
--- a/tests/test_barrier.cpp    Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_barrier.cpp    Wed Sep 26 16:36:57 2012 -0500
@@ -29,9 +29,9 @@
 void* run (void* arg) {
     long long int my_id = (long long int) arg;
     //A[my_id][0]++;
-    printf("%i BEFORE\n", my_id);
+    printf("%lli BEFORE\n", my_id);
     pthread_barrier_wait(&barrier);
-    printf("%i AFTER\n", my_id);
+    printf("%lli AFTER\n", my_id);
     //A[my_id][0]++;
     return NULL;
 }
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_lock.cpp
--- a/tests/test_lock.cpp       Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_lock.cpp       Wed Sep 26 16:36:57 2012 -0500
@@ -27,7 +27,7 @@
 void* run1(void* arglist)
 {
     pthread_t id = pthread_self();
-    printf("[run1] TID=%d\n", id);
+    printf("[run1] TID=%d\n", (int)id);
 
     printf("[run1] started\n");
 
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_malloc.cpp
--- a/tests/test_malloc.cpp     Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_malloc.cpp     Wed Sep 26 16:36:57 2012 -0500
@@ -50,12 +50,12 @@
     int bytes = iteration*(id +1);
     void* ptr = malloc(bytes);
     ptr_matrix[iteration][id] = ptr;
-    printf("[ALLOC %d, Thread %d] Allocated %d bytes, from %x to %x\n", 
iteration, id, bytes, (uint32)ptr, (uint32)(((char*)ptr) + bytes - 1));
+    printf("[ALLOC %d, Thread %lld] Allocated %d bytes, from %p to %p\n", 
iteration, id, bytes, ptr, ((char*)ptr) + bytes - 1);
 
     pthread_barrier_wait(&barrier);
     int target = (id + iteration) % nthreads;
     free(ptr_matrix[iteration][target]);
-    printf("[ALLOC %d, Thread %d] Freed %d's allocation, %x\n", iteration, id, 
target, (uint32)ptr_matrix[iteration][target]);
+    printf("[ALLOC %d, Thread %lld] Freed %d's allocation, %p\n", iteration, 
id, target, ptr_matrix[iteration][target]);
     //free(ptr_matrix[iteration][target]);
     return NULL;
 }
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_pthreadbasic.cpp
--- a/tests/test_pthreadbasic.cpp       Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_pthreadbasic.cpp       Wed Sep 26 16:36:57 2012 -0500
@@ -35,7 +35,7 @@
     pthread_t pth;
     pthread_attr_t attr;
 
-    printf("Main thread initialized. TID=%d\n", pthread_self());
+    printf("Main thread initialized. TID=%d\n", (int)pthread_self());
     int result = pthread_attr_init(&attr);
     assert(result == 0);
     printf("Main thread called pthread_attr_init\n");
@@ -52,11 +52,11 @@
     printf("Main thread creating 2nd thread...\n");
     result = pthread_create(&pth2, &attr, run, NULL);
 
-    printf("Main thread calling join w/ 1st thread (id=%llx)... 
(self=%llx)\n", pth, pthread_self());
+    printf("Main thread calling join w/ 1st thread (id=%lx)... (self=%lx)\n", 
pth, pthread_self());
     pthread_join(pth, NULL);
-    printf("Main thread calling join w/ 2nd thread (id=%llx)... 
(self=%llx)\n", pth2, pthread_self());
+    printf("Main thread calling join w/ 2nd thread (id=%lx)... (self=%lx)\n", 
pth2, pthread_self());
     pthread_join(pth2, NULL);
-    printf("Main thread has self=%d\n", pthread_self());
+    printf("Main thread has self=%d\n", (int)pthread_self());
 
     printf("Main thread done.\n");
 }
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tests/test_stackgrow.cpp
--- a/tests/test_stackgrow.cpp  Mon Feb 16 13:29:55 2009 -0800
+++ b/tests/test_stackgrow.cpp  Wed Sep 26 16:36:57 2012 -0500
@@ -31,7 +31,7 @@
 
 void func (int* f1) {
   int f2;
-  printf("Addr frame 1 = %llx, Addr frame 2 = %llx\n", f1, &f2);
+  printf("Addr frame 1 = %p, Addr frame 2 = %p\n", f1, &f2);
   if (&f2 > f1) {
     printf("Stack grows up (and this threading library needs to be fixed for 
your arch...)\n");
   } else {
diff -r 3f8d39a1afa1 -r d53e38d5fc76 tls_defs.h
--- a/tls_defs.h        Mon Feb 16 13:29:55 2009 -0800
+++ b/tls_defs.h        Wed Sep 26 16:36:57 2012 -0500
@@ -28,8 +28,19 @@
 //These are mostly taken verbatim from glibc 2.3.6
 
 //32 for ELF32 binaries, 64 for ELF64
-//TODO: Macro it
+#if defined(__LP64__)
 #define __ELF_NATIVE_CLASS 64
+#else
+#define __ELF_NATIVE_CLASS 32
+#endif
+
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to