]> Zhao Yanbai Git Server - minix.git/commitdiff
SMP - CPU local cycles accounting
authorTomas Hruby <tom@minix3.org>
Wed, 15 Sep 2010 14:10:27 +0000 (14:10 +0000)
committerTomas Hruby <tom@minix3.org>
Wed, 15 Sep 2010 14:10:27 +0000 (14:10 +0000)
- tsc_ctr_switch is made cpu local

- although an x86 specific variable it must be declared globaly as the
  cpulocal implementation does not allow otherwise

kernel/arch/i386/arch_clock.c
kernel/arch/i386/arch_smp.c
kernel/cpulocals.h

index 7c2309573355cde9f1d8ed3ab4a545726133ed0c..27483fccff76ec1ef7d55da58c90ebbeb1d55155 100644 (file)
@@ -27,9 +27,6 @@
 #define TIMER_FREQ  1193182    /* clock frequency for timer in PC and AT */
 #define TIMER_COUNT(freq) (TIMER_FREQ/(freq)) /* initial value for counter*/
 
-/* FIXME make it cpu local! */
-PRIVATE u64_t tsc_ctr_switch; /* when did we switched time accounting */
-
 PRIVATE irq_hook_t pic_timer_hook;             /* interrupt handler hook */
 
 PRIVATE unsigned probe_ticks;
@@ -175,17 +172,17 @@ PUBLIC int arch_register_local_timer_handler(const irq_handler_t handler)
 
 PUBLIC void cycles_accounting_init(void)
 {
-       read_tsc_64(&tsc_ctr_switch);
+       read_tsc_64(get_cpulocal_var_ptr(tsc_ctr_switch));
 }
 
 PUBLIC void context_stop(struct proc * p)
 {
        u64_t tsc, tsc_delta;
+       u64_t * __tsc_ctr_switch = get_cpulocal_var_ptr(tsc_ctr_switch);
 
        read_tsc_64(&tsc);
-       tsc_delta = sub64(tsc, tsc_ctr_switch);
+       tsc_delta = sub64(tsc, *__tsc_ctr_switch);
        p->p_cycles = add64(p->p_cycles, tsc_delta);
-       tsc_ctr_switch = tsc;
 
        /*
         * deduct the just consumed cpu cycles from the cpu time left for this
@@ -215,10 +212,17 @@ PUBLIC void context_stop(struct proc * p)
         * If we stop accounting for KERNEL we must unlock the BKL. If account
         * for IDLE we must not hold the lock
         */
-       if (p == proc_addr(KERNEL))
+       if (p == proc_addr(KERNEL)) {
+               read_tsc_64(&tsc);
+               p->p_cycles = add64(p->p_cycles, sub64(tsc, *__tsc_ctr_switch));
                BKL_UNLOCK();
-       else
+       } else {
                BKL_LOCK();
+               read_tsc_64(&tsc);
+               p->p_cycles = add64(p->p_cycles, sub64(tsc, *__tsc_ctr_switch));
+       }
+       
+       *__tsc_ctr_switch = tsc;
 }
 
 PUBLIC void context_stop_idle(void)
index 88b20a7ccddfd84b6686034088cb3a3190d2fb0f..e45d0439aa8b0ca7689acf834db96ffe6528d987 100644 (file)
@@ -211,7 +211,7 @@ PRIVATE void ap_finish_booting(void)
 
        if (app_cpu_init_timer(system_hz)) {
                panic("FATAL : failed to initialize timer interrupts CPU %d, "
-                               "cannot continue without any clock source!", cpuid);
+                               "cannot continue without any clock source!", cpu);
        }
        printf("CPU %d local APIC timer is ticking\n", cpu);
 
index f9faefa9a25056806168140848ccba890e7502ac..fad9ede5cfa29a4de04e209771a36f0213e17832 100644 (file)
@@ -30,6 +30,7 @@
 #define get_cpulocal_var(name)         CPULOCAL_STRUCT.name
 #define get_cpulocal_var_ptr(name)     &(get_cpulocal_var(name))
 #define get_cpu_var(cpu, name)         get_cpulocal_var(name)
+#define get_cpu_var_ptr(cpu, name)     get_cpulocal_var_ptr(name)
 
 #endif
 
@@ -74,6 +75,8 @@ DECLARE_CPULOCAL(struct proc *, ptproc);
 DECLARE_CPULOCAL(struct proc *, run_q_head[NR_SCHED_QUEUES]); /* ptrs to ready list headers */
 DECLARE_CPULOCAL(struct proc *, run_q_tail[NR_SCHED_QUEUES]); /* ptrs to ready list tails */
 
+DECLARE_CPULOCAL(u64_t ,tsc_ctr_switch); /* when did we switched time accounting */
+
 DECLARE_CPULOCAL_END
 
 #endif /* __ASSEMBLY__ */