timer: Make the ticks timer run at 10hz not at a platform rate
authorAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 20:00:03 +0000 (20:00 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 2 Jan 2015 20:00:03 +0000 (20:00 +0000)
We now get a sensible time between rollovers and more importantly we can
do much better in the C library with division by 10 than random per platform
numbers.

Kernel/include/timer.h
Kernel/platform-socz80/devsd.c
Kernel/process.c

index 6db1a83..8766c03 100644 (file)
@@ -7,8 +7,8 @@
 
 typedef uint16_t timer_t;
 
-#define set_timer_ms(msec) (set_timer_duration(((msec * TICKSPERSEC) / 1000U) == 0 ? 1 : ((msec * TICKSPERSEC) / 1000U)))
-#define set_timer_sec(sec) (set_timer_duration(sec * TICKSPERSEC))
+#define set_timer_ms(msec) (set_timer_duration(msec < 100U ? 1 : ((msec) / 100U))
+#define set_timer_sec(sec) (set_timer_duration((sec) * 10))
 timer_t set_timer_duration(uint16_t duration); /* good for up to 32K ticks */
 bool timer_expired(timer_t timer_val);
 
index cec8f91..7bd9e62 100644 (file)
@@ -201,7 +201,7 @@ int sd_spi_init(void)
     /* Enter Idle state */
     if (sd_send_command(CMD0, 0) == 1) {
         /* initialisation timeout 1 second */
-        timer = set_timer_duration(TICKSPERSEC);
+        timer = set_timer_sec(1);
         if (sd_send_command(CMD8, (uint32_t)0x1AA) == 1) {    /* SDHC */
             /* Get trailing return value of R7 resp */
             for (n = 0; n < 4; n++) ocr[n] = sd_spi_receive_byte();
@@ -256,7 +256,7 @@ int sd_spi_wait_ready(void)
     unsigned char res;
     timer_t timer;
 
-    timer = set_timer_duration(TICKSPERSEC/10); /* 100ms */
+    timer = set_timer_ms(100); /* 100ms */
     sd_spi_receive_byte();
     do{
         res = sd_spi_receive_byte();
@@ -287,7 +287,7 @@ int sd_spi_receive_block(void *ptr, int length)
     unsigned int timer;
     unsigned char b;
 
-    timer = set_timer_duration(TICKSPERSEC/5); /* 200ms */
+    timer = set_timer_ms(200); /* 200ms */
 
     do{
         b = sd_spi_receive_byte();
index 7ced59c..f26b1d3 100644 (file)
@@ -328,8 +328,6 @@ void timer_interrupt(void)
                        udata.u_utime++;
        }
 
-       ticks.full++;
-
        /* Do once-per-decisecond things - this doesn't work out well on
           boxes with 64 ticks/second.. need a better approach */
        if (++ticks_this_dsecond == TICKSPERSEC / 10) {
@@ -337,6 +335,7 @@ void timer_interrupt(void)
 
                /* Update global time counters */
                ticks_this_dsecond = 0;
+               ticks.full++;
 
                /* Update process alarm clocks and timeouts */
                for (p = ptab; p < ptab + maxproc; ++p) {