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

switch back to rdtsc

- no all emulators supports rdtscp
This commit is contained in:
Stefan Lankes 2015-08-28 22:45:38 +02:00
parent a6e81226d2
commit 5e3d7a81da
5 changed files with 26 additions and 23 deletions

View file

@ -316,11 +316,11 @@ static inline void clts(void)
*/
inline static uint64_t rdtsc(void)
{
uint64_t lo, hi;
uint32_t lo, hi;
asm volatile ("rdtsc" : "=a"(lo), "=d"(hi) );
return (hi << 32 | lo);
return ((uint64_t)hi << 32ULL | (uint64_t)lo);
}
/** @brief Read time stamp counter and processor id
@ -332,14 +332,14 @@ inline static uint64_t rdtsc(void)
*/
inline static unsigned long long rdtscp(uint32_t* cpu_id)
{
uint64_t lo, hi;
uint32_t lo, hi;
uint32_t id;
asm volatile ("rdtscp" : "=a"(lo), "=c"(id), "=d"(hi) :: "memory");
if (cpu_id)
*cpu_id = id;
return (hi << 32 | lo);
return ((uint64_t)hi << 32ULL | (uint64_t)lo);
}
/** @brief Read MSR

View file

@ -704,7 +704,7 @@ static void apic_shutdown(struct state *s)
static void apic_lint0(struct state * s)
{
// Currently nothing to do
//kputs("Receive LINT0 interrupt\n");
kputs("Receive LINT0 interrupt\n");
}
int apic_init(void)

View file

@ -43,8 +43,13 @@ extern uint64_t base;
static inline void enter_user_task(size_t ep, size_t stack)
{
asm volatile ("swapgs");
// don't interrupt the jump to user-level code
irq_disable();
asm volatile ("swapgs" ::: "memory");
kprintf("AAAA fs 0x%llx\n", readfs());
// the jump also enable interrupts
jump_to_user_code(ep, stack);
}
@ -90,7 +95,7 @@ static int thread_entry(void* arg, size_t ep)
if (curr_task->tls_addr && curr_task->tls_size) {
// set fs register to the TLS segment
writefs(stack+offset);
kprintf("Task %d set fs to 0x%llx\n", curr_task->id, stack+offset);
kprintf("Task %d set fs to 0x%llx\n", curr_task->id, readfs());
// copy default TLS segment to stack
offset -= curr_task->tls_size;
@ -389,7 +394,7 @@ static int load_task(load_args_t* largs)
// set fs register to the TLS segment
writefs(stack+offset);
kprintf("Task %d set fs to 0x%zx\n", curr_task->id, stack+offset);
kprintf("Task %d set fs to 0x%zx\n", curr_task->id, readfs());
// copy default TLS segment to stack
offset -= curr_task->tls_size;

View file

@ -140,7 +140,7 @@ static int initd(void* arg)
//create_kernel_task(NULL, foo, "foo1", NORMAL_PRIO);
//create_kernel_task(NULL, foo, "foo2", NORMAL_PRIO);
//create_user_task(NULL, "/bin/hello", argv1, NORMAL_PRIO);
create_user_task(NULL, "/bin/hello", argv1, NORMAL_PRIO);
//create_user_task(NULL, "/bin/jacobi", argv2, NORMAL_PRIO);
//create_user_task(NULL, "/bin/jacobi", argv2, NORMAL_PRIO);
create_user_task(NULL, "/bin/stream", argv3, NORMAL_PRIO);

View file

@ -417,12 +417,18 @@ checktick()
#include <sys/time.h>
extern unsigned int get_cpufreq();
static unsigned long long start_tsc;
inline static unsigned long long rdtscp(void)
inline static unsigned long long rdtsc(void)
{
unsigned long long lo, hi;
asm volatile ("rdtscp; lfence" : "=a"(lo), "=d"(hi) :: "%rcx", "memory");
return (hi << 32 | lo);
unsigned long lo, hi;
asm volatile ("rdtsc; mfence" : "=a"(lo), "=d"(hi) :: "memory");
return ((unsigned long long) hi << 32ULL | (unsigned long long) lo);
}
__attribute__((constructor)) static void timer_init()
{
start_tsc = rdtsc();
}
double mysecond()
@ -435,18 +441,10 @@ double mysecond()
i = gettimeofday(&tp,&tzp);
return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
#else
static unsigned long long start;
static int init = 0;
double ret;
if (init) {
ret = (double) (rdtscp() - start) / ((double) get_cpufreq() * 1000000.0);
} else {
//printf("CPU frequency: %d MHz\n", get_cpufreq());
start = rdtscp();
init = 1;
ret = 0.0;
}
ret = ((double) (rdtsc() - start_tsc)) / ((double) get_cpufreq() * 1000000.0);
//printf("CPU frequency: %d MHz\n", get_cpufreq());
return ret;
#endif