Anonymous avatar Anonymous committed 000db46

Add sembench, not work yet

Comments (0)

Files changed (7)

sembench/Makefile

+CC=gcc
+CFLAGS=-O2 -Wall -pthread
+
+default: sembench pingpong
+
+sembench: sembench.o config.h
+	$(CC) -o $@ $^ $(CFLAGS)
+
+pingpong: pingpong.o config.h
+	$(CC) -o $@ $^ $(CFLAGS)
+
+clean:
+	rm -rf *.o
+	rm -rf sembench pingpong
+#ifndef _BENCH_H_
+#define _BENCH_H_
+
+#include <sched.h>
+
+static int
+affinity_set(int cpu)
+{
+    cpu_set_t cpuset;
+    CPU_ZERO(&cpuset);
+    CPU_SET(cpu, &cpuset);
+    return sched_setaffinity(0, sizeof(cpuset), &cpuset);
+}
+
+static uint64_t
+get_cpu_freq(void)
+{
+    FILE *fd;
+    uint64_t freq = 0;
+    float freqf = 0;
+    char *line = NULL;
+    size_t len = 0;
+
+    fd = fopen("/proc/cpuinfo", "r");
+    if (!fd) {
+	fprintf(stderr, "failed to get cpu frequecy\n");
+	perror(NULL);
+	return freq;
+    }
+
+    while (getline(&line, &len, fd) != EOF) {
+	if (sscanf(line, "cpu MHz\t: %f", &freqf) == 1) {
+	    freqf = freqf * 1000000UL;
+	    freq = (uint64_t)freqf;
+	    break;
+	}
+    }
+
+    fclose(fd);
+    return freq;
+}
+
+static uint64_t
+read_tsc(void)
+{
+    uint32_t a, d;
+    __asm __volatile("rdtsc" : "=a" (a), "=d" (d));
+    return ((uint64_t) a) | (((uint64_t) d) << 32);
+}
+
+typedef uint64_t atomic_t;
+
+#define LOCK_PREFIX \
+		".section .smp_locks,\"a\"\n"	\
+		"  .align 4\n"			\
+		"  .long 661f\n" /* address */	\
+		".previous\n"			\
+	       	"661:\n\tlock; "
+
+static __inline__ void
+atomic_add(int i, uint64_t *v)
+{
+	__asm__ __volatile__(
+		LOCK_PREFIX "addl %1,%0"
+		:"+m" (v)
+		:"ir" (i));
+}
+
+#endif /* _BENCH_H_ */

sembench/config.h

+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+#define NR_PINGPONGS 10
+
+#endif /* _CONFIG_H_ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.