1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

reuse sched_yield from our pthread library

This commit is contained in:
Stefan Lankes 2016-05-04 09:19:26 +02:00
parent b373f207e7
commit 9d0f9bf0a1
2 changed files with 10 additions and 11 deletions

View file

@ -58,9 +58,13 @@ stream: stream.o
$Q$(ELFEDIT_FOR_TARGET) --output-osabi HermitCore $@
$Qchmod a-x $@.sym
basic.o: basic.c
@echo [CC] $@
$Q$(CC_FOR_TARGET) -c $(CFLAGS_FOR_TARGET) -pthread -o $@ $<
basic: basic.o
@echo [LD] $@
$Q$(CC_FOR_TARGET) $(LDFLAGS_FOR_TARGET) $(CFLAGS_FOR_TARGET) -o $@ $<
$Q$(CC_FOR_TARGET) $(LDFLAGS_FOR_TARGET) $(CFLAGS_FOR_TARGET) -pthread -o $@ $<
$Q$(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@
$Q$(ELFEDIT_FOR_TARGET) --output-osabi HermitCore $@

View file

@ -34,26 +34,21 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#ifndef __hermit__
#include <sched.h>
#ifndef __hermit__
#include <sys/syscall.h>
static inline long mygetpid(void)
{
return syscall(__NR_getpid);
}
static inline void reschedule(void)
{
sched_yield();
}
#else
static inline long mygetpid(void)
{
return getpid();
}
void reschedule(void);
int sched_yield(void);
#endif
#define N 10000
@ -93,12 +88,12 @@ int main(int argc, char** argv)
printf("Average time for getpid: %lld cycles, pid %ld\n", (end - start) / N, ret);
// cache warm-up
reschedule();
reschedule();
sched_yield();
sched_yield();
start = rdtsc();
for(i=0; i<N; i++)
reschedule();
sched_yield();
end = rdtsc();
printf("Average time for sched_yield: %lld cycles\n", (end - start) / N);