Commit d0cc5089 authored by Christoph Gerum's avatar Christoph Gerum

Adding config

parent 81404cdc
dcec9ee72f99eac5f7ffea6ff92a5b68dcf49868 8
dcec9ee72f99eac5f7ffea6ff92a5b68dcf49868 default
data/LICENSE.i
data/Makefile.i
data/README.i
data/profiling_hooks.h.i
data/pthread.c.i
data/pthread_defs.h.i
data/spinlock_alpha.h.i
data/spinlock_arm.h.i
data/spinlock_sparc.h.i
data/spinlock_x86.h.i
data/profiling_hooks.h.i
data/tests/Makefile.i
data/tests/test___thread.cpp.i
data/tests/test_atomic.cpp.i
data/tests/test_stackgrow.cpp.i
data/tests/test_barrier.cpp.i
data/tests/test_lock.cpp.i
data/Makefile.i
data/tls_defs.h.i
data/tests/test_malloc.cpp.i
data/tests/test_omp.cpp.i
data/tests/test_pthread.cpp.i
data/tests/test_atomic.cpp.i
data/pthread.c.i
data/LICENSE.i
data/spinlock_x86.h.i
data/tests/test_pthreadbasic.cpp.i
data/tests/test___thread.cpp.i
data/spinlock_arm.h.i
data/spinlock_alpha.h.i
data/README.i
data/tests/test_pthread.cpp.i
data/spinlock_sparc.h.i
data/tests/test_sieve.cpp.i
data/tests/test_stackgrow.cpp.i
data/tls_defs.h.i
8 dcec9ee72f99eac5f7ffea6ff92a5b68dcf49868
......@@ -18,9 +18,9 @@ ARM_FLAGS := -march=armv7-a -marm
#CFLAGS := -ggdb3 -O3 -D__DEBUG
#CFLAGS := -g -O3 -DM5_PROFILING
CFLAGS := -g -O3 $(ARM_FLAGS) -std=c99
CFLAGS := -g -O3 $(ARM_FLAGS)
CPPFLAGS := -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
......@@ -39,24 +39,21 @@ clean:
$(RM) $(TEST_OBJS) $(TEST_PROGS) $(TEST_OBJS:.o=_p) ../pthread.o
$(TEST_PROGS): $(TEST_OBJS) ../pthread.o
$(CC) -static -o $@ $@.o ../pthread.o
$(CC) -static -o $@_p $@.o -lpthread
%.o: %.c Makefile
$(CC) $(CFLAGS) -c -o $@ $*.c
$(CPP) -static -o $@ $@.o ../pthread.o
$(CPP) -static -o $@_p $@.o -lpthread
%.o: %.cpp Makefile
$(CPP) $(CPPFLAGS) -c -o $@ $*.cpp
#Special rules for OpenMP programs
test_omp: test_omp.o
$(CC) -static -o $@ $@.o -lgomp ../pthread.o -lgomp
$(CC) -static -o $@_p $@.o -lgomp -lpthread
$(CPP) -static -o $@ $@.o -lgomp ../pthread.o -lgomp
$(CPP) -static -o $@_p $@.o -lgomp -lpthread
test_omp.o: test_omp.cpp ../pthread.o
$(CC) $(CFLAGS) -fopenmp -c -o $@ $*.cpp
$(CPP) $(CPPFLAGS) -fopenmp -c -o $@ $*.cpp
../pthread.o: ../pthread.c ../pthread_defs.h ../tls_defs.h Makefile
$(CC) -g -O3 $(ARM_FLAGS) -c ../pthread.c -o ../pthread.o
$(CC) $(CFLAGS) -c ../pthread.c -o ../pthread.o
/*
m5threads, a pthread library for the M5 simulator
Copyright (C) 2009, Stanford University
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
// without volatile, simulator test works even if __thread support is broken
__thread volatile int local = 7;
volatile long long int jjjs = 0;
static const int count = 1024;
void* run (void* arg)
{
long long int id = (long long int)arg;
int i;
printf("&local[%lld]=%p\n", id, &local);
local += id;
for (i = 0; i < count; i++) {
local++;
}
//Some calculations to delay last read
long long int jjj = 0;
for (i = 0; i < 10000; i++) {
jjj = 2*jjj +4 -i/5 + local;
}
jjjs = jjj;
//assert(local == count +id);
return (void*)local;
}
int main (int argc, char** argv)
{
if (argc != 2) {
printf("usage: %s <thread_count>\n", argv[0]);
exit(1);
}
int thread_count = atoi(argv[1]);
printf("Starting %d threads...\n", thread_count);
//struct timeval startTime;
//int startResult = gettimeofday(&startTime, NULL);
//assert(startResult == 0);
int i;
pthread_t* threads = (pthread_t*)calloc(thread_count, sizeof(pthread_t));
assert(threads != NULL);
for (i = 1 ; i < thread_count; i++) {
int createResult = pthread_create(&threads[i],
NULL,
run,
(void*)i);
assert(createResult == 0);
}
long long int local = (long long int)run((void*)0);
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] = %lld\n", i, local);
}
/*struct timeval endTime;
int endResult = gettimeofday(&endTime, NULL);
assert(endResult == 0);
long startMillis = (((long)startTime.tv_sec)*1000) + (((long)startTime.tv_usec)/1000);
long endMillis = (((long)endTime.tv_sec)*1000) + (((long)endTime.tv_usec)/1000);
*/
/*printf("End Time (s) = %d\n", (int)endTime.tv_sec);
printf("Start Time (s) = %d\n", (int)startTime.tv_sec);
printf("Time (s) = %d\n", (int)(endTime.tv_sec-startTime.tv_sec));
printf("\n");
printf("End Time (us) = %d\n", (int)endTime.tv_usec);
printf("Start Time (us) = %d\n", (int)startTime.tv_usec);
printf("Time (us) = %d\n", (int)(endTime.tv_usec-startTime.tv_usec));
printf("\n");
printf("End Time (ms) = %d\n", (int)endMillis);
printf("Start Time (ms) = %d\n", (int)startMillis);
printf("Time (ms) = %d\n", (int)(endMillis-startMillis));
printf("\n");*/
/*double difference=(double)(endTime.tv_sec-startTime.tv_sec)+(double)(endTime.tv_usec-startTime.tv_usec)*1e-6;
printf("Time (s) = %f\n", difference);
printf("\n");*/
return 0;
}
......@@ -37,7 +37,7 @@ void* run1(void* arglist)
printf("[run1] thread id : %d \n", (int)run1th);
pthread_exit(0);
assert(0);
assert(false);
return NULL;
}
......
/*
m5threads, a pthread library for the M5 simulator
Copyright (C) 2009, Stanford University
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author: Daniel Sanchez
*/
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* run (void* arg) {
printf("Hello from a child thread! (thread ID: %d).\n", (int)pthread_self());
return NULL;
}
int main(int argc, const char** argv) {
pthread_t pth;
pthread_attr_t attr;
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");
result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
assert(result == 0);
printf("Main thread called pthread_attr_setscope\n");
printf("Main thread creating 1st thread...\n");
result = pthread_create(&pth, &attr, run, NULL);
pthread_t pth2;
printf("Main thread creating 2nd thread...\n");
result = pthread_create(&pth2, &attr, run, NULL);
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=%lx)... (self=%lx)\n", pth2, pthread_self());
pthread_join(pth2, NULL);
printf("Main thread has self=%d\n", (int)pthread_self());
printf("Main thread done.\n");
}
/*
m5threads, a pthread library for the M5 simulator
Copyright (C) 2009, Stanford University
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
g++ -O3 -o ./sieve -lm -lpthread sieve.cpp && time sieve 1 && time sieve 2
*/
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
static int max_limit;
static int sqrt_max_limit;
static int* not_prime;
static const int print = 1;
static const int start = 2;
static int sqrt_limit;
static int limit;
static void* run (void*);
#ifdef SIMULATOR
void mainX(int argc, const char **argv, const char **envp)
#else
int main (int argc, char** argv)
#endif
{
#ifdef SIMULATOR
if (argc != 1) {
printf("usage: %s\n", argv[0]);
exit(1);
}
int thread_count = Sim_GetNumCpus();
#else
if (argc != 2) {
printf("usage: %s <thread_count>\n", argv[0]);
exit(1);
}
int thread_count = atoi(argv[1]);
#endif
#ifdef SIMULATOR
max_limit = 10000;
#else
max_limit = 10000;//0000;
#endif
sqrt_max_limit = (int)ceil(sqrt(max_limit));
not_prime = (int*)calloc(max_limit, sizeof(int));
assert(not_prime != NULL);
sqrt_limit = (int)ceil(sqrt(sqrt_max_limit));
limit = sqrt_max_limit;
if (1) {
not_prime[0] = 1;
not_prime[1] = 1;
run(NULL);
}
sqrt_limit = (int)ceil(sqrt(max_limit));
limit = max_limit;
printf("sqrt_max_limit %d\n", sqrt_max_limit);
printf("max_limit %d\n", max_limit);
#ifdef SIMULATOR
printf("Starting threads...\n");
#else
printf("Starting %d threads...\n", thread_count);
#endif
#ifndef SIMULATOR
struct timeval startTime;
int startResult = gettimeofday(&startTime, NULL);
assert(startResult == 0);
#endif
pthread_t* threads = (pthread_t*)calloc(thread_count, sizeof(pthread_t));
assert(threads != NULL);
for (int i = 1 ; i < thread_count; i++) {
int createResult = pthread_create(&threads[i],
NULL,
run,
NULL);
assert(createResult == 0);
}
run(NULL);
for (int i = 1 ; i < thread_count; i++) {
int joinResult = pthread_join(threads[i],
NULL);
assert(joinResult == 0);
}
#ifndef SIMULATOR
struct timeval endTime;
int endResult = gettimeofday(&endTime, NULL);
assert(endResult == 0);
long startMillis = (((long)startTime.tv_sec)*1000) + (((long)startTime.tv_usec)/1000);
long endMillis = (((long)endTime.tv_sec)*1000) + (((long)endTime.tv_usec)/1000);
printf("%d\n", (int)endTime.tv_sec);
printf("%d\n", (int)startTime.tv_sec);
printf("%d\n", (int)(endTime.tv_sec-startTime.tv_sec));
printf("\n");
printf("%d\n", (int)endTime.tv_usec);
printf("%d\n", (int)startTime.tv_usec);
printf("%d\n", (int)(endTime.tv_usec-startTime.tv_usec));
printf("\n");
printf("%d\n", (int)endMillis);
printf("%d\n", (int)startMillis);
printf("%d\n", (int)(endMillis-startMillis));
printf("\n");
double difference=(double)(endTime.tv_sec-startTime.tv_sec)+(double)(endTime.tv_usec-startTime.tv_usec)*1e-6;
printf("%f\n", difference);
printf("\n");
#endif
if (print) {
printf("Primes less than 100:\n");
for (int i = 0; i < 100; i++) {
if (!not_prime[i]) {
printf("%d\n",i);
}
}
}
#ifndef SIMULATOR
return 0;
#endif
}
void* run (void* arg)
{
if (0 /*Sim_GetMode() == MODE_TM*/) {
#ifdef WITH_TM
for (int my_prime = start; my_prime < sqrt_limit; ++my_prime) {
if (!not_prime[my_prime]) {
TM_BeginClosed(); {
not_prime[my_prime] = true;
}
TM_EndClosed();
for (int multiple = my_prime*2; multiple < limit; multiple += my_prime) {
not_prime[multiple] = true;
}
TM_BeginClosed(); {
not_prime[my_prime] = false;
}
TM_EndClosed();
}
}
#else
printf("Somehow mode is MODE_TM but WITH_TM was not defined.");
exit(1);
#endif
}
else {
for (int my_prime = start; my_prime < sqrt_limit; ++my_prime) {
if (!not_prime[my_prime]) {
// Sim_Print1("Found prime: %d\n", my_prime);
not_prime[my_prime] = 1;
for (int multiple = my_prime*2; multiple < limit; multiple += my_prime) {
not_prime[multiple] = 1;
}
not_prime[my_prime] = 0;
} else {
// Sim_Print1("not prime: %d\n", my_prime);
}
}
}
return NULL;
}
/*
m5threads, a pthread library for the M5 simulator
Copyright (C) 2009, Stanford University
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author: Daniel Sanchez
*/
/* Just test which direction the stack grows in this arch/ABI
Kind of a big deal when deciding which end of the stack to
pass as a pointer to clone :-)
*/
#include <stdio.h>
void func (int* f1) {
int 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 {
printf("Stack grows down\n");
}
}
int main (int argc, char**argv) {
int f1;
func(&f1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment