All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carsten Langgaard <carstenl@mips.com>
To: linux-mips@oss.sgi.com
Subject: The do_fast_gettimeoffset function
Date: Mon, 13 Nov 2000 14:20:54 +0100	[thread overview]
Message-ID: <3A0FEAB6.7117CC3C@mips.com> (raw)

The do_fast_gettimeoffset function below (taken from
arch/mips/kernel/time.c) can only be used on 64-bit processors.
I would like to be able to use this on a 32-bit processor. As I'm not
completely sure what this function does, can someone who does please
help me out ?

/Carsten


static unsigned long do_fast_gettimeoffset(void)
{
 u32 count;
 unsigned long res, tmp;

 /* Last jiffy when do_fast_gettimeoffset() was called. */
 static unsigned long last_jiffies=0;
 unsigned long quotient;

 /*
  * Cached "1/(clocks per usec)*2^32" value.
  * It has to be recalculated once each jiffy.
  */
 static unsigned long cached_quotient=0;

 tmp = jiffies;

 quotient = cached_quotient;

 if (tmp && last_jiffies != tmp) {
  last_jiffies = tmp;
  __asm__(".set\tnoreorder\n\t"
   ".set\tnoat\n\t"
   ".set\tmips3\n\t"
   "lwu\t%0,%2\n\t"
   "dsll32\t$1,%1,0\n\t"
   "or\t$1,$1,%0\n\t"
   "ddivu\t$0,$1,%3\n\t"
   "mflo\t$1\n\t"
   "dsll32\t%0,%4,0\n\t"
   "nop\n\t"
   "ddivu\t$0,%0,$1\n\t"
   "mflo\t%0\n\t"
   ".set\tmips0\n\t"
   ".set\tat\n\t"
   ".set\treorder"
   :"=&r" (quotient)
   :"r" (timerhi),
    "m" (timerlo),
    "r" (tmp),
    "r" (USECS_PER_JIFFY)
   :"$1");
  cached_quotient = quotient;
 }

 /* Get last timer tick in absolute kernel time */
 count = read_32bit_cp0_register(CP0_COUNT);

 /* .. relative to previous jiffy (32 bits is enough) */
 count -= timerlo;

 __asm__("multu\t%1,%2\n\t"
  "mfhi\t%0"
  :"=r" (res)
  :"r" (count),
   "r" (quotient));

 /*
   * Due to possible jiffies inconsistencies, we need to check
  * the result so that we'll get a timer that is monotonic.
  */
 if (res >= USECS_PER_JIFFY)
  res = USECS_PER_JIFFY-1;

 return res;
}



--
_    _ ____  ___   Carsten Langgaard   Mailto:carstenl@mips.com
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com

             reply	other threads:[~2000-11-13 15:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-13 13:20 Carsten Langgaard [this message]
2000-11-14 17:24 ` The do_fast_gettimeoffset function Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3A0FEAB6.7117CC3C@mips.com \
    --to=carstenl@mips.com \
    --cc=linux-mips@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.