Vcore timers are stored in ticks (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 15 May 2014 00:03:26 +0000 (17:03 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 15 May 2014 00:03:26 +0000 (17:03 -0700)
Convert only when we actually care about the value.  Also renames
vcore_{resume,total}.

Reinstall your kernel headers.

kern/include/ros/procinfo.h
kern/src/process.c
tests/prof_test.c
user/parlib/include/vcore.h

index 65cfd4f..a34e7f2 100644 (file)
@@ -32,15 +32,10 @@ struct vcore {
        uint32_t                        nr_preempts_sent;       /* these two differ when a preempt*/
        uint32_t                        nr_preempts_done;       /* is in flight. */
        uint64_t                        preempt_pending;
-       /* for profiling. Store nsecs into 'resume' each time we start.
-        * Each time we stop, subtract resume from current nsecs and add it to total.
-        * This way, a process can see cumulative runtime as of the last
-        * resume, and can also calculate runtime in this interval, by adding
-        * (ns - resume) + total. This assumes we have an easy way to get
-        * ns at the application level.
-        */
-       uint64_t                        resume; 
-       uint64_t                        total;
+       /* A process can see cumulative runtime as of the last resume, and can also
+        * calculate runtime in this interval, by adding (ns - resume) + total. */
+       uint64_t                        resume_ticks;           /* TSC at resume time */
+       uint64_t                        total_ticks;            /* ticks up to last offlining */
 };
 
 struct pcore {
index cdeede6..e4aa091 100644 (file)
@@ -82,8 +82,8 @@ static void put_free_pid(pid_t pid)
        spin_unlock(&pid_bmask_lock);
 }
 
-/* 'resume' is the time of the most recent onlining.  'total' is the amount of
- * time consumed up to and including the current offlining.
+/* 'resume' is the time int ticks of the most recent onlining.  'total' is the
+ * amount of time in ticks consumed up to and including the current offlining.
  *
  * We could move these to the map and unmap of vcores, though not every place
  * uses that (SCPs, in particular).  However, maps/unmaps happen remotely;
@@ -93,19 +93,19 @@ static void put_free_pid(pid_t pid)
 void vcore_account_online(struct proc *p, uint32_t vcoreid)
 {
        struct vcore *vc = &p->procinfo->vcoremap[vcoreid];
-       vc->resume = nsec();
+       vc->resume_ticks = read_tsc();
 }
 
 void vcore_account_offline(struct proc *p, uint32_t vcoreid)
 {
        struct vcore *vc = &p->procinfo->vcoremap[vcoreid];
-       vc->total += nsec() - vc->resume;
+       vc->total_ticks += read_tsc() - vc->resume_ticks;
 }
 
 uint64_t vcore_account_gettotal(struct proc *p, uint32_t vcoreid)
 {
        struct vcore *vc = &p->procinfo->vcoremap[vcoreid];
-       return vc->total;
+       return vc->total_ticks;
 }
 
 /* While this could be done with just an assignment, this gives us the
@@ -2244,7 +2244,7 @@ void print_proc_info(pid_t pid)
                printk("\tVcore %d\n", vcore2vcoreid(p, vc_i));
        printk("Nsec Online, up to the last offlining:\n------------------------");
        for (int i = 0; i < p->procinfo->max_vcores; i++) {
-               uint64_t vc_time = vcore_account_gettotal(p, i);
+               uint64_t vc_time = tsc2nsec(vcore_account_gettotal(p, i));
                if (i % 4 == 0)
                        printk("\n");
                printk("  VC %3d: %14llu", i, vc_time);
index d39cbe4..77deb2c 100644 (file)
@@ -30,18 +30,18 @@ int main(int argc, char** argv)
        uint64_t ns;
 
        uint64_t resume, total;
-       resume = vcore_resume(vcore_id());
-       total = vcore_total(vcore_id());
+       resume = vcore_account_resume_nsec(vcore_id());
+       total = vcore_account_total_nsec(vcore_id());
        for(i = 0; i < 1048576*1024; i++)
                ;
        ns = tsc2nsec(read_tsc());
        printf("resume 0x%llx total 0x%llx ns 0x%llx\n", resume, total, ns);
-       resume = vcore_resume(vcore_id());
-       total = vcore_total(vcore_id());
+       resume = vcore_account_resume_nsec(vcore_id());
+       total = vcore_account_total_nsec(vcore_id());
        ns = tsc2nsec(read_tsc());
        printf("resume 0x%llx total 0x%llx ns 0x%llx\n", resume, total, ns);
-       resume = vcore_resume(vcore_id());
-       total = vcore_total(vcore_id());
+       resume = vcore_account_resume_nsec(vcore_id());
+       total = vcore_account_total_nsec(vcore_id());
        for(i = 0; i < 1048576*1024; i++)
                ;
        ns = tsc2nsec(read_tsc());
index 4cc2d97..8141c24 100644 (file)
@@ -9,6 +9,7 @@ extern "C" {
 #include <arch/atomic.h>
 #include <sys/param.h>
 #include <string.h>
+#include <timing.h>
 
 /*****************************************************************************/
 /* TODO: This is a complete hack, but necessary for vcore stuff to work for now
@@ -52,6 +53,8 @@ static inline bool preempt_is_pending(uint32_t vcoreid);
 static inline bool __preempt_is_pending(uint32_t vcoreid);
 static inline void *get_vcpd_tls_desc(uint32_t vcoreid);
 static inline void set_vcpd_tls_desc(uint32_t vcoreid, void *tls_desc);
+static inline uint64_t vcore_account_resume_nsec(uint32_t vcoreid);
+static inline uint64_t vcore_account_total_nsec(uint32_t vcoreid);
 void vcore_init(void);
 void vcore_event_init(void);
 void vcore_change_to_m(void);
@@ -157,14 +160,14 @@ static inline void set_vcpd_tls_desc(uint32_t vcoreid, void *tls_desc)
        __procdata.vcore_preempt_data[vcoreid].vcore_tls_desc = (uintptr_t)tls_desc;
 }
 
-static inline uint64_t vcore_resume(int vcore)
+static inline uint64_t vcore_account_resume_nsec(uint32_t vcoreid)
 {
-       return __procinfo.vcoremap[vcore].resume;
+       return tsc2nsec(__procinfo.vcoremap[vcoreid].resume_ticks);
 }
 
-static inline uint64_t vcore_total(int vcore)
+static inline uint64_t vcore_account_total_nsec(uint32_t vcoreid)
 {
-       return __procinfo.vcoremap[vcore].total;
+       return tsc2nsec(__procinfo.vcoremap[vcoreid].total_ticks);
 }
 
 #ifndef __PIC__