~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/time/vsyscall.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /kernel/time/vsyscall.c (Architecture i386) and /kernel/time/vsyscall.c (Architecture mips)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * Copyright 2019 ARM Ltd.                          3  * Copyright 2019 ARM Ltd.
  4  *                                                  4  *
  5  * Generic implementation of update_vsyscall a      5  * Generic implementation of update_vsyscall and update_vsyscall_tz.
  6  *                                                  6  *
  7  * Based on the x86 specific implementation.        7  * Based on the x86 specific implementation.
  8  */                                                 8  */
  9                                                     9 
 10 #include <linux/hrtimer.h>                         10 #include <linux/hrtimer.h>
 11 #include <linux/timekeeper_internal.h>             11 #include <linux/timekeeper_internal.h>
 12 #include <vdso/datapage.h>                         12 #include <vdso/datapage.h>
 13 #include <vdso/helpers.h>                          13 #include <vdso/helpers.h>
 14 #include <vdso/vsyscall.h>                         14 #include <vdso/vsyscall.h>
 15                                                    15 
 16 #include "timekeeping_internal.h"                  16 #include "timekeeping_internal.h"
 17                                                    17 
 18 static inline void update_vdso_data(struct vds     18 static inline void update_vdso_data(struct vdso_data *vdata,
 19                                     struct tim     19                                     struct timekeeper *tk)
 20 {                                                  20 {
 21         struct vdso_timestamp *vdso_ts;            21         struct vdso_timestamp *vdso_ts;
 22         u64 nsec, sec;                             22         u64 nsec, sec;
 23                                                    23 
 24         vdata[CS_HRES_COARSE].cycle_last           24         vdata[CS_HRES_COARSE].cycle_last        = tk->tkr_mono.cycle_last;
 25 #ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT        25 #ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
 26         vdata[CS_HRES_COARSE].max_cycles           26         vdata[CS_HRES_COARSE].max_cycles        = tk->tkr_mono.clock->max_cycles;
 27 #endif                                             27 #endif
 28         vdata[CS_HRES_COARSE].mask                 28         vdata[CS_HRES_COARSE].mask              = tk->tkr_mono.mask;
 29         vdata[CS_HRES_COARSE].mult                 29         vdata[CS_HRES_COARSE].mult              = tk->tkr_mono.mult;
 30         vdata[CS_HRES_COARSE].shift                30         vdata[CS_HRES_COARSE].shift             = tk->tkr_mono.shift;
 31         vdata[CS_RAW].cycle_last                   31         vdata[CS_RAW].cycle_last                = tk->tkr_raw.cycle_last;
 32 #ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT        32 #ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
 33         vdata[CS_RAW].max_cycles                   33         vdata[CS_RAW].max_cycles                = tk->tkr_raw.clock->max_cycles;
 34 #endif                                             34 #endif
 35         vdata[CS_RAW].mask                         35         vdata[CS_RAW].mask                      = tk->tkr_raw.mask;
 36         vdata[CS_RAW].mult                         36         vdata[CS_RAW].mult                      = tk->tkr_raw.mult;
 37         vdata[CS_RAW].shift                        37         vdata[CS_RAW].shift                     = tk->tkr_raw.shift;
 38                                                    38 
 39         /* CLOCK_MONOTONIC */                      39         /* CLOCK_MONOTONIC */
 40         vdso_ts         = &vdata[CS_HRES_COARS     40         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC];
 41         vdso_ts->sec    = tk->xtime_sec + tk->     41         vdso_ts->sec    = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
 42                                                    42 
 43         nsec = tk->tkr_mono.xtime_nsec;            43         nsec = tk->tkr_mono.xtime_nsec;
 44         nsec += ((u64)tk->wall_to_monotonic.tv     44         nsec += ((u64)tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
 45         while (nsec >= (((u64)NSEC_PER_SEC) <<     45         while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
 46                 nsec -= (((u64)NSEC_PER_SEC) <     46                 nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
 47                 vdso_ts->sec++;                    47                 vdso_ts->sec++;
 48         }                                          48         }
 49         vdso_ts->nsec   = nsec;                    49         vdso_ts->nsec   = nsec;
 50                                                    50 
 51         /* Copy MONOTONIC time for BOOTTIME */     51         /* Copy MONOTONIC time for BOOTTIME */
 52         sec     = vdso_ts->sec;                    52         sec     = vdso_ts->sec;
 53         /* Add the boot offset */                  53         /* Add the boot offset */
 54         sec     += tk->monotonic_to_boot.tv_se     54         sec     += tk->monotonic_to_boot.tv_sec;
 55         nsec    += (u64)tk->monotonic_to_boot.     55         nsec    += (u64)tk->monotonic_to_boot.tv_nsec << tk->tkr_mono.shift;
 56                                                    56 
 57         /* CLOCK_BOOTTIME */                       57         /* CLOCK_BOOTTIME */
 58         vdso_ts         = &vdata[CS_HRES_COARS     58         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_BOOTTIME];
 59         vdso_ts->sec    = sec;                     59         vdso_ts->sec    = sec;
 60                                                    60 
 61         while (nsec >= (((u64)NSEC_PER_SEC) <<     61         while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
 62                 nsec -= (((u64)NSEC_PER_SEC) <     62                 nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
 63                 vdso_ts->sec++;                    63                 vdso_ts->sec++;
 64         }                                          64         }
 65         vdso_ts->nsec   = nsec;                    65         vdso_ts->nsec   = nsec;
 66                                                    66 
 67         /* CLOCK_MONOTONIC_RAW */                  67         /* CLOCK_MONOTONIC_RAW */
 68         vdso_ts         = &vdata[CS_RAW].baset     68         vdso_ts         = &vdata[CS_RAW].basetime[CLOCK_MONOTONIC_RAW];
 69         vdso_ts->sec    = tk->raw_sec;             69         vdso_ts->sec    = tk->raw_sec;
 70         vdso_ts->nsec   = tk->tkr_raw.xtime_ns     70         vdso_ts->nsec   = tk->tkr_raw.xtime_nsec;
 71                                                    71 
 72         /* CLOCK_TAI */                            72         /* CLOCK_TAI */
 73         vdso_ts         = &vdata[CS_HRES_COARS     73         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_TAI];
 74         vdso_ts->sec    = tk->xtime_sec + (s64     74         vdso_ts->sec    = tk->xtime_sec + (s64)tk->tai_offset;
 75         vdso_ts->nsec   = tk->tkr_mono.xtime_n     75         vdso_ts->nsec   = tk->tkr_mono.xtime_nsec;
 76 }                                                  76 }
 77                                                    77 
 78 void update_vsyscall(struct timekeeper *tk)        78 void update_vsyscall(struct timekeeper *tk)
 79 {                                                  79 {
 80         struct vdso_data *vdata = __arch_get_k     80         struct vdso_data *vdata = __arch_get_k_vdso_data();
 81         struct vdso_timestamp *vdso_ts;            81         struct vdso_timestamp *vdso_ts;
 82         s32 clock_mode;                            82         s32 clock_mode;
 83         u64 nsec;                                  83         u64 nsec;
 84                                                    84 
 85         /* copy vsyscall data */                   85         /* copy vsyscall data */
 86         vdso_write_begin(vdata);                   86         vdso_write_begin(vdata);
 87                                                    87 
 88         clock_mode = tk->tkr_mono.clock->vdso_     88         clock_mode = tk->tkr_mono.clock->vdso_clock_mode;
 89         vdata[CS_HRES_COARSE].clock_mode           89         vdata[CS_HRES_COARSE].clock_mode        = clock_mode;
 90         vdata[CS_RAW].clock_mode                   90         vdata[CS_RAW].clock_mode                = clock_mode;
 91                                                    91 
 92         /* CLOCK_REALTIME also required for ti     92         /* CLOCK_REALTIME also required for time() */
 93         vdso_ts         = &vdata[CS_HRES_COARS     93         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME];
 94         vdso_ts->sec    = tk->xtime_sec;           94         vdso_ts->sec    = tk->xtime_sec;
 95         vdso_ts->nsec   = tk->tkr_mono.xtime_n     95         vdso_ts->nsec   = tk->tkr_mono.xtime_nsec;
 96                                                    96 
 97         /* CLOCK_REALTIME_COARSE */                97         /* CLOCK_REALTIME_COARSE */
 98         vdso_ts         = &vdata[CS_HRES_COARS     98         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME_COARSE];
 99         vdso_ts->sec    = tk->xtime_sec;           99         vdso_ts->sec    = tk->xtime_sec;
100         vdso_ts->nsec   = tk->tkr_mono.xtime_n    100         vdso_ts->nsec   = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
101                                                   101 
102         /* CLOCK_MONOTONIC_COARSE */              102         /* CLOCK_MONOTONIC_COARSE */
103         vdso_ts         = &vdata[CS_HRES_COARS    103         vdso_ts         = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC_COARSE];
104         vdso_ts->sec    = tk->xtime_sec + tk->    104         vdso_ts->sec    = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
105         nsec            = tk->tkr_mono.xtime_n    105         nsec            = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
106         nsec            = nsec + tk->wall_to_m    106         nsec            = nsec + tk->wall_to_monotonic.tv_nsec;
107         vdso_ts->sec    += __iter_div_u64_rem(    107         vdso_ts->sec    += __iter_div_u64_rem(nsec, NSEC_PER_SEC, &vdso_ts->nsec);
108                                                   108 
109         /*                                        109         /*
110          * Read without the seqlock held by cl    110          * Read without the seqlock held by clock_getres().
111          * Note: No need to have a second copy    111          * Note: No need to have a second copy.
112          */                                       112          */
113         WRITE_ONCE(vdata[CS_HRES_COARSE].hrtim    113         WRITE_ONCE(vdata[CS_HRES_COARSE].hrtimer_res, hrtimer_resolution);
114                                                   114 
115         /*                                        115         /*
116          * If the current clocksource is not V    116          * If the current clocksource is not VDSO capable, then spare the
117          * update of the high resolution parts    117          * update of the high resolution parts.
118          */                                       118          */
119         if (clock_mode != VDSO_CLOCKMODE_NONE)    119         if (clock_mode != VDSO_CLOCKMODE_NONE)
120                 update_vdso_data(vdata, tk);      120                 update_vdso_data(vdata, tk);
121                                                   121 
122         __arch_update_vsyscall(vdata, tk);        122         __arch_update_vsyscall(vdata, tk);
123                                                   123 
124         vdso_write_end(vdata);                    124         vdso_write_end(vdata);
125                                                   125 
126         __arch_sync_vdso_data(vdata);             126         __arch_sync_vdso_data(vdata);
127 }                                                 127 }
128                                                   128 
129 void update_vsyscall_tz(void)                     129 void update_vsyscall_tz(void)
130 {                                                 130 {
131         struct vdso_data *vdata = __arch_get_k    131         struct vdso_data *vdata = __arch_get_k_vdso_data();
132                                                   132 
133         vdata[CS_HRES_COARSE].tz_minuteswest =    133         vdata[CS_HRES_COARSE].tz_minuteswest = sys_tz.tz_minuteswest;
134         vdata[CS_HRES_COARSE].tz_dsttime = sys    134         vdata[CS_HRES_COARSE].tz_dsttime = sys_tz.tz_dsttime;
135                                                   135 
136         __arch_sync_vdso_data(vdata);             136         __arch_sync_vdso_data(vdata);
137 }                                                 137 }
138                                                   138 
139 /**                                               139 /**
140  * vdso_update_begin - Start of a VDSO update     140  * vdso_update_begin - Start of a VDSO update section
141  *                                                141  *
142  * Allows architecture code to safely update t    142  * Allows architecture code to safely update the architecture specific VDSO
143  * data. Disables interrupts, acquires timekee    143  * data. Disables interrupts, acquires timekeeper lock to serialize against
144  * concurrent updates from timekeeping and inv    144  * concurrent updates from timekeeping and invalidates the VDSO data
145  * sequence counter to prevent concurrent read    145  * sequence counter to prevent concurrent readers from accessing
146  * inconsistent data.                             146  * inconsistent data.
147  *                                                147  *
148  * Returns: Saved interrupt flags which need t    148  * Returns: Saved interrupt flags which need to be handed in to
149  * vdso_update_end().                             149  * vdso_update_end().
150  */                                               150  */
151 unsigned long vdso_update_begin(void)             151 unsigned long vdso_update_begin(void)
152 {                                                 152 {
153         struct vdso_data *vdata = __arch_get_k    153         struct vdso_data *vdata = __arch_get_k_vdso_data();
154         unsigned long flags;                      154         unsigned long flags;
155                                                   155 
156         raw_spin_lock_irqsave(&timekeeper_lock    156         raw_spin_lock_irqsave(&timekeeper_lock, flags);
157         vdso_write_begin(vdata);                  157         vdso_write_begin(vdata);
158         return flags;                             158         return flags;
159 }                                                 159 }
160                                                   160 
161 /**                                               161 /**
162  * vdso_update_end - End of a VDSO update sect    162  * vdso_update_end - End of a VDSO update section
163  * @flags:      Interrupt flags as returned fr    163  * @flags:      Interrupt flags as returned from vdso_update_begin()
164  *                                                164  *
165  * Pairs with vdso_update_begin(). Marks vdso     165  * Pairs with vdso_update_begin(). Marks vdso data consistent, invokes data
166  * synchronization if the architecture require    166  * synchronization if the architecture requires it, drops timekeeper lock
167  * and restores interrupt flags.                  167  * and restores interrupt flags.
168  */                                               168  */
169 void vdso_update_end(unsigned long flags)         169 void vdso_update_end(unsigned long flags)
170 {                                                 170 {
171         struct vdso_data *vdata = __arch_get_k    171         struct vdso_data *vdata = __arch_get_k_vdso_data();
172                                                   172 
173         vdso_write_end(vdata);                    173         vdso_write_end(vdata);
174         __arch_sync_vdso_data(vdata);             174         __arch_sync_vdso_data(vdata);
175         raw_spin_unlock_irqrestore(&timekeeper    175         raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
176 }                                                 176 }
177                                                   177 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php