Moved timing parameters into proc_global_info (XCC)
authorGanShun <ganshun@gmail.com>
Tue, 29 Mar 2016 18:26:31 +0000 (11:26 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 31 Mar 2016 20:46:47 +0000 (16:46 -0400)
Moved tsc_freq, timing_overhead and bus freq into __proc_global_info.
PIT stuff is now in k/a/x/time.c as a static. timing_overhead has been
renamed to tsc_overhead.

Reinstall your kernel headers.

Signed-off-by: GanShun <ganshun@gmail.com>
[kernel headers warning, removed extraneous comment]
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
14 files changed:
kern/arch/riscv/time.c
kern/arch/riscv/time.h
kern/arch/x86/apic.c
kern/arch/x86/rdtsc_test.c
kern/arch/x86/time.c
kern/arch/x86/time.h
kern/drivers/dev/cons.c
kern/drivers/dev/kprof.c
kern/drivers/net/udrvr/compat.c
kern/include/ros/procinfo.h
kern/include/time.h
kern/src/process.c
kern/src/syscall.c
kern/src/time.c

index ba7654c..cd5c403 100644 (file)
@@ -4,14 +4,13 @@
 #include <arch/arch.h>
 #include <stdio.h>
 #include <assert.h>
-
-system_timing_t system_timing = {0};
+#include <ros/procinfo.h>
 
 void
 timer_init(void)
 {
-       system_timing.tsc_freq = TSC_HZ;
-       cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
+       __proc_global_info.tsc_freq = TSC_HZ;
+       cprintf("TSC Frequency: %llu\n", __proc_global_info.tsc_freq);
 }
 
 void
@@ -43,12 +42,12 @@ set_core_timer(uint32_t usec, bool periodic)
 void
 udelay(uint64_t usec)
 {
-       if (system_timing.tsc_freq != 0)
+       if (__proc_global_info.tsc_freq != 0)
        {
                uint64_t start, end, now;
-        
+
                start = read_tsc();
-               end = start + (system_timing.tsc_freq * usec) / 1000000;
+               end = start + (__proc_global_info.tsc_freq * usec) / 1000000;
 
                do
                {
index 8c57604..b237219 100644 (file)
@@ -4,12 +4,5 @@
 
 #include <ros/common.h>
 
-typedef struct system_timing {
-       uint64_t tsc_freq;
-       uint64_t timing_overhead;
-} system_timing_t;
-
-extern system_timing_t system_timing;
-
 void timer_init(void);
 void set_timer(uint32_t usec);
index e212843..e030647 100644 (file)
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <bitmask.h>
 #include <arch/topology.h>
+#include <ros/procinfo.h>
 
 bool lapic_check_spurious(int trap_nr)
 {
@@ -139,8 +140,8 @@ void lapic_set_timer(uint32_t usec, bool periodic)
         * then, we might not be able to match 4000 sec (based on the bus speed).
         * The kernel alarm code can handle spurious timer interrupts, so we just
         * set the timer for as close as we can get to the desired time. */
-       uint64_t ticks64 = (usec * system_timing.bus_freq) / LAPIC_TIMER_DIVISOR_VAL
-                           / 1000000;
+       uint64_t ticks64 = (usec * __proc_global_info.bus_freq)
+                          / LAPIC_TIMER_DIVISOR_VAL / 1000000;
        uint32_t ticks32 = ((ticks64 >> 32) ? 0xffffffff : ticks64);
        assert(ticks32 > 0);
        __lapic_set_timer(ticks32, IdtLAPIC_TIMER, periodic,
index c22c0b1..7d2f1ee 100644 (file)
 #include <stdio.h>
 #include <kmalloc.h>
 #include <time.h>
+#include <ros/procinfo.h>
 
 #define STAT_SIZE_DEF 10000
 #define LOOP_BOUND_DEF 1000
@@ -755,7 +756,7 @@ void test_tsc_cycles(void)
                                      : : : "eax", "cc");
        }
        end = read_tsc_serialized();
-       end = end - start - system_timing.timing_overhead;
+       end = end - start - __proc_global_info.tsc_overhead;
        printk("%llu (100,000) ticks passed, run twice to load the icache\n", end);
 
        enable_irqsave(&irq_state);
index 547251c..d08d589 100644 (file)
 #include <trap.h>
 #include <assert.h>
 #include <stdio.h>
+#include <ros/procinfo.h>
 
-system_timing_t system_timing = {0, 0, 0xffff, 0};
+static uint16_t pit_divisor;
+static uint8_t pit_mode;
 
 // timer init calibrates both tsc timer and lapic timer using PIT
 void timer_init(void){
@@ -26,8 +28,8 @@ void timer_init(void){
        tscval[0] = read_tsc();
        udelay_pit(1000000);
        tscval[1] = read_tsc();
-       system_timing.tsc_freq = tscval[1] - tscval[0];
-       cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
+       __proc_global_info.tsc_freq = tscval[1] - tscval[0];
+       cprintf("TSC Frequency: %llu\n", __proc_global_info.tsc_freq);
        __lapic_set_timer(0xffffffff, IdtLAPIC_TIMER, FALSE,
                          LAPIC_TIMER_DIVISOR_BITS);
        // Mask the LAPIC Timer, so we never receive this interrupt (minor race)
@@ -35,13 +37,13 @@ void timer_init(void){
        timercount[0] = apicrget(MSR_LAPIC_CURRENT_COUNT);
        udelay_pit(1000000);
        timercount[1] = apicrget(MSR_LAPIC_CURRENT_COUNT);
-       system_timing.bus_freq = (timercount[0] - timercount[1])
+       __proc_global_info.bus_freq = (timercount[0] - timercount[1])
                                 * LAPIC_TIMER_DIVISOR_VAL;
        /* The time base for the timer is derived from the processor's bus clock,
         * divided by the value specified in the divide configuration register.
         * Note we mult and div by the divisor, saving the actual freq (even though
         * we don't use it yet). */
-       cprintf("Bus Frequency: %llu\n", system_timing.bus_freq);
+       cprintf("Bus Frequency: %llu\n", __proc_global_info.bus_freq);
 }
 
 void pit_set_timer(uint32_t divisor, uint32_t mode)
@@ -52,8 +54,8 @@ void pit_set_timer(uint32_t divisor, uint32_t mode)
        outb(TIMER_MODE, mode);
        outb(TIMER_CNTR0, divisor & 0xff);
        outb(TIMER_CNTR0, (divisor >> 8) );
-       system_timing.pit_mode = mode;
-       system_timing.pit_divisor = divisor;
+       pit_mode = mode;
+       pit_divisor = divisor;
        // cprintf("timer mode set to %d, divisor %d\n",mode, divisor);
 }
 
@@ -75,7 +77,7 @@ static int getpit()
 void udelay(uint64_t usec)
 {
        #if !defined(__BOCHS__)
-       if (system_timing.tsc_freq != 0)
+       if (__proc_global_info.tsc_freq != 0)
        {
                uint64_t start, end, now;
 
@@ -126,7 +128,7 @@ void udelay_pit(uint64_t usec)
                prev_tick = tick;
                if (delta < 0) {
                        // counter looped around during the delta time period
-                       delta += system_timing.pit_divisor; // maximum count
+                       delta += pit_divisor; // maximum count
                        if (delta < 0)
                                delta = 0;
                }
@@ -141,7 +143,7 @@ uint64_t gettimer(void)
 
 uint64_t getfreq(void)
 {
-       return system_timing.tsc_freq;
+       return __proc_global_info.tsc_freq;
 }
 
 void set_core_timer(uint32_t usec, bool periodic)
index 6d48313..da74b1e 100644 (file)
 #define TIMER_CNTR2 (IO_TIMER1 + TIMER_REG_CNTR2)
 #define TIMER_MODE  (IO_TIMER1 + TIMER_REG_MODE)
 
-typedef struct system_timing {
-       uint64_t tsc_freq;
-       uint64_t bus_freq;
-       uint64_t timing_overhead;
-       uint16_t pit_divisor;
-       uint8_t pit_mode;
-} system_timing_t;
-
-extern system_timing_t system_timing;
-
 // PIT related
 void pit_set_timer(uint32_t freq, uint32_t mode);
 void timer_init(void);
index 2718449..0b84c71 100644 (file)
@@ -19,6 +19,7 @@
 #include <error.h>
 #include <sys/queue.h>
 #include <event.h>
+#include <ros/procinfo.h>
 
 #if 0
 void (*consdebug) (void) = NULL;
@@ -1289,7 +1290,7 @@ static int readtime(uint32_t off, char *buf, int n)
        char str[7 * NUMSIZE];
 
        if (fasthz == 0LL)
-               fasthz = system_timing.tsc_freq;
+               fasthz = __proc_global_info.tsc_freq;
 #if 0
        fastticks((uint64_t *) & fasthz);
        nsec = todget(&ticks);
@@ -1338,7 +1339,7 @@ static int readbintime(char *buf, int n)
 
        i = 0;
        if (fasthz == 0LL)
-               fasthz = system_timing.tsc_freq;
+               fasthz = __proc_global_info.tsc_freq;
 #if 0
        fastticks((uint64_t *) & fasthz);
        nsec = todget(&ticks);
index bc3fe08..f07a0e9 100644 (file)
@@ -26,6 +26,7 @@
 #include <umem.h>
 #include <profiler.h>
 #include <kprof.h>
+#include <ros/procinfo.h>
 
 #define KTRACE_BUFFER_SIZE (128 * 1024)
 #define TRACE_PRINTK_BUFFER_SIZE (8 * 1024)
@@ -371,7 +372,7 @@ static long mpstatraw_read(void *va, long n, int64_t off)
 
        /* header line: version, num_cores, tsc freq, state names */
        len += snprintf(buf + len, bufsz - len, "v%03d %5d %16llu", 1, num_cores,
-                       system_timing.tsc_freq);
+                       __proc_global_info.tsc_freq);
        for (int j = 0; j < NR_CPU_STATES; j++)
                len += snprintf(buf + len, bufsz - len, " %6s", cpu_state_names[j]);
        len += snprintf(buf + len, bufsz - len, "\n");
@@ -623,7 +624,7 @@ void trace_vprintk(bool btrace, const char *fmt, va_list args)
 
        if (!atomic_cas(&tpb->in_use, 0, 1))
                return;
-       if (likely(system_timing.tsc_freq))
+       if (likely(__proc_global_info.tsc_freq))
                tsc2timespec(read_tsc(), &ts_now);
        snprintf(hdr, sizeof(hdr), "[%lu.%09lu]:cpu%d: ", ts_now.tv_sec,
                 ts_now.tv_nsec, core_id_early());
index 1d3a015..2f3935e 100644 (file)
@@ -16,6 +16,7 @@
 #include <devfs.h>
 #include <linux/rdma/ib_user_verbs.h>
 #include "uverbs.h"
+#include <ros/procinfo.h>
 
 static unsigned long pgprot_val(int vmprot)
 {
@@ -275,7 +276,7 @@ static ssize_t cpu_read(struct file *filp, char __user *buf,
     size_t count, loff_t *pos)
 {
        char cpu_info_str[128];
-       long freq = system_timing.tsc_freq, idx;
+       long freq = __proc_global_info.tsc_freq, idx;
 
        strncpy(cpu_info_str, "cpu MHz\t\t: ", 16);
        idx = strlen(cpu_info_str);
index 2a56c69..d5fe58d 100644 (file)
@@ -68,6 +68,9 @@ typedef struct procinfo {
 struct proc_global_info {
        unsigned long cpu_feats[__NR_CPU_FEAT_BITS];
        uint64_t x86_default_xcr0;
+       uint64_t tsc_freq;
+       uint64_t tsc_overhead;
+       uint64_t bus_freq;
 } __attribute__((aligned(PGSIZE)));
 #define PROCGINFO_NUM_PAGES  (sizeof(struct proc_global_info) / PGSIZE)
 
index b3b9c13..909742c 100644 (file)
@@ -3,6 +3,7 @@
 #include <ros/common.h>
 #include <ros/time.h>
 #include <arch/time.h>
+#include <ros/procinfo.h>
 
 void train_timing();
 void udelay(uint64_t usec);    /* done in arch-specific files */
@@ -37,7 +38,7 @@ uint64_t stop_timing(uint64_t start_time)
 {
     uint64_t diff = read_tsc_serialized();
     diff -= start_time;
-    diff -= system_timing.timing_overhead;
+    diff -= __proc_global_info.tsc_overhead;
        if ((int64_t) diff < 0) {
                return 1;
        }
index c428a8d..3f7b38c 100644 (file)
@@ -25,6 +25,7 @@
 #include <arsc_server.h>
 #include <devfs.h>
 #include <kmalloc.h>
+#include <ros/procinfo.h>
 
 struct kmem_cache *proc_cache;
 
@@ -275,8 +276,8 @@ void proc_init_procinfo(struct proc* p)
        p->procinfo->pid = p->pid;
        p->procinfo->ppid = p->ppid;
        p->procinfo->max_vcores = max_vcores(p);
-       p->procinfo->tsc_freq = system_timing.tsc_freq;
-       p->procinfo->timing_overhead = system_timing.timing_overhead;
+       p->procinfo->tsc_freq = __proc_global_info.tsc_freq;
+       p->procinfo->timing_overhead = __proc_global_info.tsc_overhead;
        p->procinfo->heap_bottom = 0;
        /* 0'ing the arguments.  Some higher function will need to set them */
        memset(p->procinfo->res_grant, 0, sizeof(p->procinfo->res_grant));
index d8a6b20..f09893e 100644 (file)
@@ -35,6 +35,7 @@
 #include <kprof.h>
 #include <termios.h>
 #include <manager.h>
+#include <ros/procinfo.h>
 
 /* Tracing Globals */
 int systrace_flags = 0;
@@ -2077,8 +2078,8 @@ intreg_t sys_gettimeofday(struct proc *p, int *buf)
 
        long long dt = read_tsc();
        /* TODO: This probably wants its own function, using a struct timeval */
-       long kbuf[2] = {t0+dt/system_timing.tsc_freq,
-           (dt%system_timing.tsc_freq)*1000000/system_timing.tsc_freq};
+       long kbuf[2] = {t0+dt/__proc_global_info.tsc_freq,
+           (dt%__proc_global_info.tsc_freq)*1000000/__proc_global_info.tsc_freq};
 
        return memcpy_to_user_errno(p,buf,kbuf,sizeof(kbuf));
 }
index 654416d..a18578c 100644 (file)
@@ -5,6 +5,7 @@
 #include <multiboot.h>
 #include <pmap.h>
 #include <smp.h>
+#include <ros/procinfo.h>
 
 /* Determines the overhead of tsc timing.  Note the start/stop calls are
  * inlined, so we're trying to determine the lowest amount of overhead
@@ -20,7 +21,7 @@ void train_timing()
 
        /* Reset this, in case we run it again.  The use of start/stop to determine
         * the overhead relies on timing_overhead being 0. */
-       system_timing.timing_overhead = 0;
+       __proc_global_info.tsc_overhead = 0;
        /* timing might use cpuid, in which case we warm it up to avoid some extra
         * variance */
        time = start_timing();
@@ -37,7 +38,7 @@ void train_timing()
                max_overhead = MAX(max_overhead, diff);
        }
        enable_irqsave(&irq_state);
-       system_timing.timing_overhead = min_overhead;
+       __proc_global_info.tsc_overhead = min_overhead;
        printk("TSC overhead (Min: %llu, Max: %llu)\n", min_overhead, max_overhead);
 }
 
@@ -56,15 +57,15 @@ void timer_interrupt(struct hw_trapframe *hw_tf, void *data)
  * called something that scaled down the tsc_time by more than 1000. */
 uint64_t tsc2sec(uint64_t tsc_time)
 {
-       return tsc_time / system_timing.tsc_freq;
+       return tsc_time / __proc_global_info.tsc_freq;
 }
 
 uint64_t tsc2msec(uint64_t tsc_time)
 {
        if (mult_will_overflow_u64(tsc_time, 1000))
                return tsc2sec(tsc_time) * 1000;
-       else 
-               return (tsc_time * 1000) / system_timing.tsc_freq;
+       else
+               return (tsc_time * 1000) / __proc_global_info.tsc_freq;
 }
 
 uint64_t tsc2usec(uint64_t tsc_time)
@@ -72,7 +73,7 @@ uint64_t tsc2usec(uint64_t tsc_time)
        if (mult_will_overflow_u64(tsc_time, 1000000))
                return tsc2msec(tsc_time) * 1000;
        else
-               return (tsc_time * 1000000) / system_timing.tsc_freq;
+               return (tsc_time * 1000000) / __proc_global_info.tsc_freq;
 }
 
 uint64_t tsc2nsec(uint64_t tsc_time)
@@ -80,42 +81,42 @@ uint64_t tsc2nsec(uint64_t tsc_time)
        if (mult_will_overflow_u64(tsc_time, 1000000000))
                return tsc2usec(tsc_time) * 1000;
        else
-               return (tsc_time * 1000000000) / system_timing.tsc_freq;
+               return (tsc_time * 1000000000) / __proc_global_info.tsc_freq;
 }
 
 uint64_t sec2tsc(uint64_t sec)
 {
-       if (mult_will_overflow_u64(sec, system_timing.tsc_freq)) {
+       if (mult_will_overflow_u64(sec, __proc_global_info.tsc_freq)) {
                /* in this case, we simply can't express the number of ticks */
                warn("Wraparound in sec2tsc(), rounding up");
                return (uint64_t)(-1);
        } else {
-               return sec * system_timing.tsc_freq;
+               return sec * __proc_global_info.tsc_freq;
        }
 }
 
 uint64_t msec2tsc(uint64_t msec)
 {
-       if (mult_will_overflow_u64(msec, system_timing.tsc_freq))
+       if (mult_will_overflow_u64(msec, __proc_global_info.tsc_freq))
                return sec2tsc(msec / 1000);
        else
-               return (msec * system_timing.tsc_freq) / 1000;
+               return (msec * __proc_global_info.tsc_freq) / 1000;
 }
 
 uint64_t usec2tsc(uint64_t usec)
 {
-       if (mult_will_overflow_u64(usec, system_timing.tsc_freq))
+       if (mult_will_overflow_u64(usec, __proc_global_info.tsc_freq))
                return msec2tsc(usec / 1000);
        else
-               return (usec * system_timing.tsc_freq) / 1000000;
+               return (usec * __proc_global_info.tsc_freq) / 1000000;
 }
 
 uint64_t nsec2tsc(uint64_t nsec)
 {
-       if (mult_will_overflow_u64(nsec, system_timing.tsc_freq))
+       if (mult_will_overflow_u64(nsec, __proc_global_info.tsc_freq))
                return usec2tsc(nsec / 1000);
        else
-               return (nsec * system_timing.tsc_freq) / 1000000000;
+               return (nsec * __proc_global_info.tsc_freq) / 1000000000;
 }
 
 /* TODO: figure out what epoch time TSC == 0 is and store that as boot_tsc */