#include <stdbool.h>
#include <pthread.h>
#include <stdlib.h>
+#include <error.h>
#ifndef SYS_prem_memguard_check
#define SYS_prem_memguard_check 793
flags & MGF_MASK_INT ? 'I' : '-'
);
struct mg_ret r = mgret(retval);
- printf("Testing \"%-40s %-25s ⇒ time:%8u%c mem:%8u%c\" in %s:\n",
- call, code,
+ printf("Testing \"CPU%d: %-40s %-25s ⇒ time:%8u%c mem:%8u%c\" in %s:\n",
+ sched_getcpu(), call, code,
r.time, r.time_ovf ? '!' : ' ',
r.mem, r.mem_ovf ? '!' : ' ',
__FILE__);
void *test_thread(void *ptr)
{
- cpu_set_t set;
- int *cpu;
- cpu = (int *) ptr;
-
+ cpu_set_t set;
+ int cpu = (intptr_t)ptr;
+
/* Ensure that memory phase starts and ends on the same CPU */
CPU_ZERO(&set);
- CPU_SET(*cpu, &set);
- if (sched_setaffinity(getpid(), sizeof(set), &set) < 0)
+ CPU_SET(cpu, &set);
+ if (sched_setaffinity(0, sizeof(set), &set) < 0)
err(1, "sched_setaffinity");
- printf("Pinned to CPU %d\n", *cpu);
-
- pthread_barrier_wait(&barrier);
-
+
+ pthread_barrier_wait(&barrier);
+
struct mg_ret r;
for (uint64_t flags = 0; flags < 4; flags++) {
compute_kernel(1); /* warm up */
printf("\n");
}
-
- return NULL;
+
+ return NULL;
}
int main(int argc, char *argv[])
{
- int cpu_mask = 0;
-
- int cpu_count = 0;
- pthread_t threads[MAX_CORES];
- int cores[MAX_CORES];
- int retvals[MAX_CORES];
-
- /* TODO: currently shared memory */
+ int cpu_mask = 1;
+ int cpu_count = 0;
+ pthread_t threads[MAX_CORES];
+
+ /* TODO: currently shared memory */
for (int i = 0; i < sizeof(memory); i += 64)
memory[i] = 1;
if (argc > 1)
cpu_mask = strtol(argv[1], NULL, 16);
- for(int i=0; i<MAX_CORES; i++){
- if(cpu_mask & (1 << i)){
- cpu_count++;
- }
- }
-
- int s = pthread_barrier_init(&barrier, NULL, cpu_count);
- if (s != 0)
- err(1, "pthread_barrier_init");
-
- for(int i=0; i<MAX_CORES; i++){
- if(cpu_mask & (1 << i)){
- cores[i] = i;
- retvals[i] = pthread_create(&threads[i], NULL, test_thread, (void*) &cores[i]);
- }
- }
-
- for(int i=0; i<MAX_CORES; i++){
- if(cpu_mask & (1 << i)){
- pthread_join(threads[i], NULL);
- }
- }
-
+ for (int i = 0; i < MAX_CORES; i++) {
+ if (cpu_mask & (1 << i)) {
+ cpu_count++;
+ }
+ }
+
+ printf("CPU count:%d CPU mask:%#x\n", cpu_count, cpu_mask);
+ int s = pthread_barrier_init(&barrier, NULL, cpu_count);
+ if (s != 0)
+ error(1, s, "pthread_barrier_init");
+
+ for (intptr_t i = 0; i < MAX_CORES; i++) {
+ if (cpu_mask & (1 << i))
+ pthread_create(&threads[i], NULL, test_thread, (void *)i);
+ }
+
+ for (int i = 0; i < MAX_CORES; i++) {
+ if (cpu_mask & (1 << i)) {
+ pthread_join(threads[i], NULL);
+ }
+ }
+
return 0;
}