]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/timing/timing.c
timing: segfault removed
[eurobot/public.git] / src / timing / timing.c
index 78a5b7e28cce21536c5c1746a55cfd24342a2a63..9a25924a3bb2e1b0e800fc549d058559c7acd44c 100644 (file)
@@ -42,10 +42,12 @@ timestamp_t ts[TS_SIZE];
 timestamp_t *timestamp_ptr = ts;
 timestamp_t *timestamp_buff_end = &ts[TS_SIZE];
 bool timestamp_enabled = true;
+bool timestamp_finished = false;
 static int cnt=0;
 struct timespec meas_start_ts;
 FILE *file;
 static pid_t pid=-1;
+uint64_t boot_tb;
 
 void timing_statistics_asm(void);
 void timing_output_trace_screen(void);
@@ -70,21 +72,21 @@ long int ns2usec(uint64_t nsec)
 uint64_t mulhdu(uint64_t a, uint64_t b)
 {
        uint64_t ret, ah, al, bh, bl, carry, c1, c2, c3;
+       
        ah = a>>32;
        al = a & 0xffffffff;
        bh = b>>32;
        bl = b & 0xffffffff;
-
+       
        c1 = al*bl;
        c2 = (ah*bl)<<32;
        c3 = (al*bh)<<32;
-
+       
        carry = 0;
        if (~c1 < c2) carry++;
        c1 += c2;
        if (~c1 < c3) carry++;
 
-
        ret = ah*bh + (ah*bl>>32) + (al*bh>>32) + carry;
 
        return ret;
@@ -121,10 +123,11 @@ void print_tstamp_to_schedclock(timestamp_t *ts)
        unsigned long int sec, usec;
 
        tb = restore_tb(ts->tbu, ts->tbl);
-       ns = (uint64_t)((mulhdu(tb - get_boot_tb(), tb_to_ns_scale))<<5);
+
+       ns = mulhdu(tb - boot_tb, tb_to_ns_scale) << 5;
        
        sched_clock = ns2usec(ns);
-
+       
        usec = do_div(&sched_clock, 1000000ULL);
        sec = (uint32_t) (sched_clock);
 
@@ -132,6 +135,7 @@ void print_tstamp_to_schedclock(timestamp_t *ts)
        printf("%d %5lu.%06lu\n", ts->id, sec, usec);
 #endif
 #ifdef CONFIG_TIMING_OUTPUT_FILE
+       printf("%5lu.%06lu\t%d\t%d\tR\t%llu\n", sec, usec, pid, ts->id, tb);
        fprintf(file, "%5lu.%06lu\t%d\t%d\tR\t%llu\n", sec, usec, pid, ts->id, tb);
 #endif
 }
@@ -151,17 +155,23 @@ timestamp_t * timestamp_handle_overflow(void)
        return 0;
 }
 
-void timing_ipoint_dummy(unsigned char id)
+void timing_ipoint_dummy(uint16_t id)
 {
        printf("timing: Instrumentation point type not set!\n");
 }
 
+void timing_ipoint_finished(uint16_t id)
+{
+       printf("timing: Instrumentation point called after timing finish!\n");
+}
+
 #ifdef CONFIG_TIMING_IPOINT_ASM
-void timing_ipoint_asm(unsigned char id)
+void timing_ipoint_asm(uint16_t id)
 {   
        timestamp_t *p, *pinc; 
        uint32_t tbu, tb, tbu2;
 
+       if(!timestamp_finished) {
        /* Store current TB */
        asm volatile (
                "1:\n"  
@@ -192,11 +202,12 @@ void timing_ipoint_asm(unsigned char id)
        p->id = id;
        p->tbu = tbu;
        p->tbl = tb;
+       }
 }
 #endif
 
 #ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
-void timing_ipoint_clock_gettime(unsigned char id)
+void timing_ipoint_clock_gettime(uint16_t id)
 {
        timestamp_t *p, *pinc;
        
@@ -226,6 +237,7 @@ void timing_init(void)
 #ifdef CONFIG_TIMING_IPOINT_ASM
        timing_ipoint = timing_ipoint_asm;
        timing_statistics = timing_statistics_asm;
+       boot_tb = get_boot_tb();
 #endif
 #ifdef CONFIG_TIMING_IPOINT_CLOCK_GETTIME
        timing_ipoint = timing_ipoint_clock_gettime;
@@ -269,6 +281,7 @@ void timing_init(void)
 
 void timing_finish()
 {
+       timing_ipoint = timing_ipoint_finished;
        system("echo 0 > /debug/tracing/tracing_enabled");
 #ifdef CONFIG_TIMING_OUTPUT_FILE
        system("cat /debug/tracing/trace > taskswitch.log");