ia64/xen-unstable

view xen/common/time.c @ 17062:0769835cf50f

x86 shadow: Reduce scope of shadow lock.

emulate_map_dest doesn't require holding lock, since
only shadow related operation possibly involved is to
remove shadow which is less frequent and can acquire
lock inside. Rest are either guest table walk or
per-vcpu monitor table manipulation

Signed-off-by Kevin Tian <kevin.tian@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 14 10:33:12 2008 +0000 (2008-02-14)
parents 3e2d3d737624
children
line source
1 /******************************************************************************
2 * time.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
19 #include <xen/config.h>
20 #include <xen/time.h>
22 /* Nonzero if YEAR is a leap year (every 4 years,
23 except every 100th isn't, and every 400th is). */
24 #define __isleap(year) \
25 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
27 /* How many days are in each month. */
28 const unsigned short int __mon_lengths[2][12] = {
29 /* Normal years. */
30 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
31 /* Leap years. */
32 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
33 };
35 #define SECS_PER_HOUR (60 * 60)
36 #define SECS_PER_DAY (SECS_PER_HOUR * 24)
38 struct tm gmtime(unsigned long t)
39 {
40 struct tm tbuf;
41 long days, rem;
42 int y;
43 const unsigned short int *ip;
45 days = t / SECS_PER_DAY;
46 rem = t % SECS_PER_DAY;
48 tbuf.tm_hour = rem / SECS_PER_HOUR;
49 rem %= SECS_PER_HOUR;
50 tbuf.tm_min = rem / 60;
51 tbuf.tm_sec = rem % 60;
52 /* January 1, 1970 was a Thursday. */
53 tbuf.tm_wday = (4 + days) % 7;
54 if ( tbuf.tm_wday < 0 )
55 tbuf.tm_wday += 7;
56 y = 1970;
57 while ( days >= (rem = __isleap(y) ? 366 : 365) )
58 {
59 ++y;
60 days -= rem;
61 }
62 while ( days < 0 )
63 {
64 --y;
65 days += __isleap(y) ? 366 : 365;
66 }
67 tbuf.tm_year = y - 1900;
68 tbuf.tm_yday = days;
69 ip = (const unsigned short int *)__mon_lengths[__isleap(y)];
70 for ( y = 0; days >= ip[y]; ++y )
71 days -= ip[y];
72 tbuf.tm_mon = y;
73 tbuf.tm_mday = days + 1;
74 tbuf.tm_isdst = -1;
76 return tbuf;
77 }