time.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /*
  2. * Common time routines among all ppc machines.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) to merge
  5. * Paul Mackerras' version and mine for PReP and Pmac.
  6. * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net).
  7. * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com)
  8. *
  9. * First round of bugfixes by Gabriel Paubert (paubert@iram.es)
  10. * to make clock more stable (2.4.0-test5). The only thing
  11. * that this code assumes is that the timebases have been synchronized
  12. * by firmware on SMP and are never stopped (never do sleep
  13. * on SMP then, nap and doze are OK).
  14. *
  15. * Speeded up do_gettimeofday by getting rid of references to
  16. * xtime (which required locks for consistency). (mikejc@us.ibm.com)
  17. *
  18. * TODO (not necessarily in this file):
  19. * - improve precision and reproducibility of timebase frequency
  20. * measurement at boot time. (for iSeries, we calibrate the timebase
  21. * against the Titan chip's clock.)
  22. * - for astronomical applications: add a new function to get
  23. * non ambiguous timestamps even around leap seconds. This needs
  24. * a new timestamp format and a good name.
  25. *
  26. * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
  27. * "A Kernel Model for Precision Timekeeping" by Dave Mills
  28. *
  29. * This program is free software; you can redistribute it and/or
  30. * modify it under the terms of the GNU General Public License
  31. * as published by the Free Software Foundation; either version
  32. * 2 of the License, or (at your option) any later version.
  33. */
  34. #include <linux/config.h>
  35. #include <linux/errno.h>
  36. #include <linux/module.h>
  37. #include <linux/sched.h>
  38. #include <linux/kernel.h>
  39. #include <linux/param.h>
  40. #include <linux/string.h>
  41. #include <linux/mm.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/timex.h>
  44. #include <linux/kernel_stat.h>
  45. #include <linux/time.h>
  46. #include <linux/init.h>
  47. #include <linux/profile.h>
  48. #include <linux/cpu.h>
  49. #include <linux/security.h>
  50. #include <linux/percpu.h>
  51. #include <linux/rtc.h>
  52. #include <linux/jiffies.h>
  53. #include <linux/posix-timers.h>
  54. #include <asm/io.h>
  55. #include <asm/processor.h>
  56. #include <asm/nvram.h>
  57. #include <asm/cache.h>
  58. #include <asm/machdep.h>
  59. #include <asm/uaccess.h>
  60. #include <asm/time.h>
  61. #include <asm/prom.h>
  62. #include <asm/irq.h>
  63. #include <asm/div64.h>
  64. #include <asm/smp.h>
  65. #include <asm/vdso_datapage.h>
  66. #ifdef CONFIG_PPC64
  67. #include <asm/firmware.h>
  68. #endif
  69. #ifdef CONFIG_PPC_ISERIES
  70. #include <asm/iseries/it_lp_queue.h>
  71. #include <asm/iseries/hv_call_xm.h>
  72. #endif
  73. #include <asm/smp.h>
  74. /* keep track of when we need to update the rtc */
  75. time_t last_rtc_update;
  76. extern int piranha_simulator;
  77. #ifdef CONFIG_PPC_ISERIES
  78. unsigned long iSeries_recal_titan = 0;
  79. unsigned long iSeries_recal_tb = 0;
  80. static unsigned long first_settimeofday = 1;
  81. #endif
  82. /* The decrementer counts down by 128 every 128ns on a 601. */
  83. #define DECREMENTER_COUNT_601 (1000000000 / HZ)
  84. #define XSEC_PER_SEC (1024*1024)
  85. #ifdef CONFIG_PPC64
  86. #define SCALE_XSEC(xsec, max) (((xsec) * max) / XSEC_PER_SEC)
  87. #else
  88. /* compute ((xsec << 12) * max) >> 32 */
  89. #define SCALE_XSEC(xsec, max) mulhwu((xsec) << 12, max)
  90. #endif
  91. unsigned long tb_ticks_per_jiffy;
  92. unsigned long tb_ticks_per_usec = 100; /* sane default */
  93. EXPORT_SYMBOL(tb_ticks_per_usec);
  94. unsigned long tb_ticks_per_sec;
  95. u64 tb_to_xs;
  96. unsigned tb_to_us;
  97. #define TICKLEN_SCALE (SHIFT_SCALE - 10)
  98. u64 last_tick_len; /* units are ns / 2^TICKLEN_SCALE */
  99. u64 ticklen_to_xs; /* 0.64 fraction */
  100. /* If last_tick_len corresponds to about 1/HZ seconds, then
  101. last_tick_len << TICKLEN_SHIFT will be about 2^63. */
  102. #define TICKLEN_SHIFT (63 - 30 - TICKLEN_SCALE + SHIFT_HZ)
  103. DEFINE_SPINLOCK(rtc_lock);
  104. EXPORT_SYMBOL_GPL(rtc_lock);
  105. u64 tb_to_ns_scale;
  106. unsigned tb_to_ns_shift;
  107. struct gettimeofday_struct do_gtod;
  108. extern unsigned long wall_jiffies;
  109. extern struct timezone sys_tz;
  110. static long timezone_offset;
  111. unsigned long ppc_proc_freq;
  112. unsigned long ppc_tb_freq;
  113. u64 tb_last_jiffy __cacheline_aligned_in_smp;
  114. unsigned long tb_last_stamp;
  115. /*
  116. * Note that on ppc32 this only stores the bottom 32 bits of
  117. * the timebase value, but that's enough to tell when a jiffy
  118. * has passed.
  119. */
  120. DEFINE_PER_CPU(unsigned long, last_jiffy);
  121. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  122. /*
  123. * Factors for converting from cputime_t (timebase ticks) to
  124. * jiffies, milliseconds, seconds, and clock_t (1/USER_HZ seconds).
  125. * These are all stored as 0.64 fixed-point binary fractions.
  126. */
  127. u64 __cputime_jiffies_factor;
  128. u64 __cputime_msec_factor;
  129. u64 __cputime_sec_factor;
  130. u64 __cputime_clockt_factor;
  131. static void calc_cputime_factors(void)
  132. {
  133. struct div_result res;
  134. div128_by_32(HZ, 0, tb_ticks_per_sec, &res);
  135. __cputime_jiffies_factor = res.result_low;
  136. div128_by_32(1000, 0, tb_ticks_per_sec, &res);
  137. __cputime_msec_factor = res.result_low;
  138. div128_by_32(1, 0, tb_ticks_per_sec, &res);
  139. __cputime_sec_factor = res.result_low;
  140. div128_by_32(USER_HZ, 0, tb_ticks_per_sec, &res);
  141. __cputime_clockt_factor = res.result_low;
  142. }
  143. /*
  144. * Read the PURR on systems that have it, otherwise the timebase.
  145. */
  146. static u64 read_purr(void)
  147. {
  148. if (cpu_has_feature(CPU_FTR_PURR))
  149. return mfspr(SPRN_PURR);
  150. return mftb();
  151. }
  152. /*
  153. * Account time for a transition between system, hard irq
  154. * or soft irq state.
  155. */
  156. void account_system_vtime(struct task_struct *tsk)
  157. {
  158. u64 now, delta;
  159. unsigned long flags;
  160. local_irq_save(flags);
  161. now = read_purr();
  162. delta = now - get_paca()->startpurr;
  163. get_paca()->startpurr = now;
  164. if (!in_interrupt()) {
  165. delta += get_paca()->system_time;
  166. get_paca()->system_time = 0;
  167. }
  168. account_system_time(tsk, 0, delta);
  169. local_irq_restore(flags);
  170. }
  171. /*
  172. * Transfer the user and system times accumulated in the paca
  173. * by the exception entry and exit code to the generic process
  174. * user and system time records.
  175. * Must be called with interrupts disabled.
  176. */
  177. void account_process_vtime(struct task_struct *tsk)
  178. {
  179. cputime_t utime;
  180. utime = get_paca()->user_time;
  181. get_paca()->user_time = 0;
  182. account_user_time(tsk, utime);
  183. }
  184. static void account_process_time(struct pt_regs *regs)
  185. {
  186. int cpu = smp_processor_id();
  187. account_process_vtime(current);
  188. run_local_timers();
  189. if (rcu_pending(cpu))
  190. rcu_check_callbacks(cpu, user_mode(regs));
  191. scheduler_tick();
  192. run_posix_cpu_timers(current);
  193. }
  194. #ifdef CONFIG_PPC_SPLPAR
  195. /*
  196. * Stuff for accounting stolen time.
  197. */
  198. struct cpu_purr_data {
  199. int initialized; /* thread is running */
  200. u64 tb0; /* timebase at origin time */
  201. u64 purr0; /* PURR at origin time */
  202. u64 tb; /* last TB value read */
  203. u64 purr; /* last PURR value read */
  204. u64 stolen; /* stolen time so far */
  205. spinlock_t lock;
  206. };
  207. static DEFINE_PER_CPU(struct cpu_purr_data, cpu_purr_data);
  208. static void snapshot_tb_and_purr(void *data)
  209. {
  210. struct cpu_purr_data *p = &__get_cpu_var(cpu_purr_data);
  211. p->tb0 = mftb();
  212. p->purr0 = mfspr(SPRN_PURR);
  213. p->tb = p->tb0;
  214. p->purr = 0;
  215. wmb();
  216. p->initialized = 1;
  217. }
  218. /*
  219. * Called during boot when all cpus have come up.
  220. */
  221. void snapshot_timebases(void)
  222. {
  223. int cpu;
  224. if (!cpu_has_feature(CPU_FTR_PURR))
  225. return;
  226. for_each_cpu(cpu)
  227. spin_lock_init(&per_cpu(cpu_purr_data, cpu).lock);
  228. on_each_cpu(snapshot_tb_and_purr, NULL, 0, 1);
  229. }
  230. void calculate_steal_time(void)
  231. {
  232. u64 tb, purr, t0;
  233. s64 stolen;
  234. struct cpu_purr_data *p0, *pme, *phim;
  235. int cpu;
  236. if (!cpu_has_feature(CPU_FTR_PURR))
  237. return;
  238. cpu = smp_processor_id();
  239. pme = &per_cpu(cpu_purr_data, cpu);
  240. if (!pme->initialized)
  241. return; /* this can happen in early boot */
  242. p0 = &per_cpu(cpu_purr_data, cpu & ~1);
  243. phim = &per_cpu(cpu_purr_data, cpu ^ 1);
  244. spin_lock(&p0->lock);
  245. tb = mftb();
  246. purr = mfspr(SPRN_PURR) - pme->purr0;
  247. if (!phim->initialized || !cpu_online(cpu ^ 1)) {
  248. stolen = (tb - pme->tb) - (purr - pme->purr);
  249. } else {
  250. t0 = pme->tb0;
  251. if (phim->tb0 < t0)
  252. t0 = phim->tb0;
  253. stolen = phim->tb - t0 - phim->purr - purr - p0->stolen;
  254. }
  255. if (stolen > 0) {
  256. account_steal_time(current, stolen);
  257. p0->stolen += stolen;
  258. }
  259. pme->tb = tb;
  260. pme->purr = purr;
  261. spin_unlock(&p0->lock);
  262. }
  263. /*
  264. * Must be called before the cpu is added to the online map when
  265. * a cpu is being brought up at runtime.
  266. */
  267. static void snapshot_purr(void)
  268. {
  269. int cpu;
  270. u64 purr;
  271. struct cpu_purr_data *p0, *pme, *phim;
  272. unsigned long flags;
  273. if (!cpu_has_feature(CPU_FTR_PURR))
  274. return;
  275. cpu = smp_processor_id();
  276. pme = &per_cpu(cpu_purr_data, cpu);
  277. p0 = &per_cpu(cpu_purr_data, cpu & ~1);
  278. phim = &per_cpu(cpu_purr_data, cpu ^ 1);
  279. spin_lock_irqsave(&p0->lock, flags);
  280. pme->tb = pme->tb0 = mftb();
  281. purr = mfspr(SPRN_PURR);
  282. if (!phim->initialized) {
  283. pme->purr = 0;
  284. pme->purr0 = purr;
  285. } else {
  286. /* set p->purr and p->purr0 for no change in p0->stolen */
  287. pme->purr = phim->tb - phim->tb0 - phim->purr - p0->stolen;
  288. pme->purr0 = purr - pme->purr;
  289. }
  290. pme->initialized = 1;
  291. spin_unlock_irqrestore(&p0->lock, flags);
  292. }
  293. #endif /* CONFIG_PPC_SPLPAR */
  294. #else /* ! CONFIG_VIRT_CPU_ACCOUNTING */
  295. #define calc_cputime_factors()
  296. #define account_process_time(regs) update_process_times(user_mode(regs))
  297. #define calculate_steal_time() do { } while (0)
  298. #endif
  299. #if !(defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(CONFIG_PPC_SPLPAR))
  300. #define snapshot_purr() do { } while (0)
  301. #endif
  302. /*
  303. * Called when a cpu comes up after the system has finished booting,
  304. * i.e. as a result of a hotplug cpu action.
  305. */
  306. void snapshot_timebase(void)
  307. {
  308. __get_cpu_var(last_jiffy) = get_tb();
  309. snapshot_purr();
  310. }
  311. void __delay(unsigned long loops)
  312. {
  313. unsigned long start;
  314. int diff;
  315. if (__USE_RTC()) {
  316. start = get_rtcl();
  317. do {
  318. /* the RTCL register wraps at 1000000000 */
  319. diff = get_rtcl() - start;
  320. if (diff < 0)
  321. diff += 1000000000;
  322. } while (diff < loops);
  323. } else {
  324. start = get_tbl();
  325. while (get_tbl() - start < loops)
  326. HMT_low();
  327. HMT_medium();
  328. }
  329. }
  330. EXPORT_SYMBOL(__delay);
  331. void udelay(unsigned long usecs)
  332. {
  333. __delay(tb_ticks_per_usec * usecs);
  334. }
  335. EXPORT_SYMBOL(udelay);
  336. static __inline__ void timer_check_rtc(void)
  337. {
  338. /*
  339. * update the rtc when needed, this should be performed on the
  340. * right fraction of a second. Half or full second ?
  341. * Full second works on mk48t59 clocks, others need testing.
  342. * Note that this update is basically only used through
  343. * the adjtimex system calls. Setting the HW clock in
  344. * any other way is a /dev/rtc and userland business.
  345. * This is still wrong by -0.5/+1.5 jiffies because of the
  346. * timer interrupt resolution and possible delay, but here we
  347. * hit a quantization limit which can only be solved by higher
  348. * resolution timers and decoupling time management from timer
  349. * interrupts. This is also wrong on the clocks
  350. * which require being written at the half second boundary.
  351. * We should have an rtc call that only sets the minutes and
  352. * seconds like on Intel to avoid problems with non UTC clocks.
  353. */
  354. if (ppc_md.set_rtc_time && ntp_synced() &&
  355. xtime.tv_sec - last_rtc_update >= 659 &&
  356. abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ) {
  357. struct rtc_time tm;
  358. to_tm(xtime.tv_sec + 1 + timezone_offset, &tm);
  359. tm.tm_year -= 1900;
  360. tm.tm_mon -= 1;
  361. if (ppc_md.set_rtc_time(&tm) == 0)
  362. last_rtc_update = xtime.tv_sec + 1;
  363. else
  364. /* Try again one minute later */
  365. last_rtc_update += 60;
  366. }
  367. }
  368. /*
  369. * This version of gettimeofday has microsecond resolution.
  370. */
  371. static inline void __do_gettimeofday(struct timeval *tv, u64 tb_val)
  372. {
  373. unsigned long sec, usec;
  374. u64 tb_ticks, xsec;
  375. struct gettimeofday_vars *temp_varp;
  376. u64 temp_tb_to_xs, temp_stamp_xsec;
  377. /*
  378. * These calculations are faster (gets rid of divides)
  379. * if done in units of 1/2^20 rather than microseconds.
  380. * The conversion to microseconds at the end is done
  381. * without a divide (and in fact, without a multiply)
  382. */
  383. temp_varp = do_gtod.varp;
  384. tb_ticks = tb_val - temp_varp->tb_orig_stamp;
  385. temp_tb_to_xs = temp_varp->tb_to_xs;
  386. temp_stamp_xsec = temp_varp->stamp_xsec;
  387. xsec = temp_stamp_xsec + mulhdu(tb_ticks, temp_tb_to_xs);
  388. sec = xsec / XSEC_PER_SEC;
  389. usec = (unsigned long)xsec & (XSEC_PER_SEC - 1);
  390. usec = SCALE_XSEC(usec, 1000000);
  391. tv->tv_sec = sec;
  392. tv->tv_usec = usec;
  393. }
  394. void do_gettimeofday(struct timeval *tv)
  395. {
  396. if (__USE_RTC()) {
  397. /* do this the old way */
  398. unsigned long flags, seq;
  399. unsigned int sec, nsec, usec;
  400. do {
  401. seq = read_seqbegin_irqsave(&xtime_lock, flags);
  402. sec = xtime.tv_sec;
  403. nsec = xtime.tv_nsec + tb_ticks_since(tb_last_stamp);
  404. } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
  405. usec = nsec / 1000;
  406. while (usec >= 1000000) {
  407. usec -= 1000000;
  408. ++sec;
  409. }
  410. tv->tv_sec = sec;
  411. tv->tv_usec = usec;
  412. return;
  413. }
  414. __do_gettimeofday(tv, get_tb());
  415. }
  416. EXPORT_SYMBOL(do_gettimeofday);
  417. /*
  418. * There are two copies of tb_to_xs and stamp_xsec so that no
  419. * lock is needed to access and use these values in
  420. * do_gettimeofday. We alternate the copies and as long as a
  421. * reasonable time elapses between changes, there will never
  422. * be inconsistent values. ntpd has a minimum of one minute
  423. * between updates.
  424. */
  425. static inline void update_gtod(u64 new_tb_stamp, u64 new_stamp_xsec,
  426. u64 new_tb_to_xs)
  427. {
  428. unsigned temp_idx;
  429. struct gettimeofday_vars *temp_varp;
  430. temp_idx = (do_gtod.var_idx == 0);
  431. temp_varp = &do_gtod.vars[temp_idx];
  432. temp_varp->tb_to_xs = new_tb_to_xs;
  433. temp_varp->tb_orig_stamp = new_tb_stamp;
  434. temp_varp->stamp_xsec = new_stamp_xsec;
  435. smp_mb();
  436. do_gtod.varp = temp_varp;
  437. do_gtod.var_idx = temp_idx;
  438. /*
  439. * tb_update_count is used to allow the userspace gettimeofday code
  440. * to assure itself that it sees a consistent view of the tb_to_xs and
  441. * stamp_xsec variables. It reads the tb_update_count, then reads
  442. * tb_to_xs and stamp_xsec and then reads tb_update_count again. If
  443. * the two values of tb_update_count match and are even then the
  444. * tb_to_xs and stamp_xsec values are consistent. If not, then it
  445. * loops back and reads them again until this criteria is met.
  446. */
  447. ++(vdso_data->tb_update_count);
  448. smp_wmb();
  449. vdso_data->tb_orig_stamp = new_tb_stamp;
  450. vdso_data->stamp_xsec = new_stamp_xsec;
  451. vdso_data->tb_to_xs = new_tb_to_xs;
  452. vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec;
  453. vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec;
  454. smp_wmb();
  455. ++(vdso_data->tb_update_count);
  456. }
  457. /*
  458. * When the timebase - tb_orig_stamp gets too big, we do a manipulation
  459. * between tb_orig_stamp and stamp_xsec. The goal here is to keep the
  460. * difference tb - tb_orig_stamp small enough to always fit inside a
  461. * 32 bits number. This is a requirement of our fast 32 bits userland
  462. * implementation in the vdso. If we "miss" a call to this function
  463. * (interrupt latency, CPU locked in a spinlock, ...) and we end up
  464. * with a too big difference, then the vdso will fallback to calling
  465. * the syscall
  466. */
  467. static __inline__ void timer_recalc_offset(u64 cur_tb)
  468. {
  469. unsigned long offset;
  470. u64 new_stamp_xsec;
  471. u64 tlen, t2x;
  472. if (__USE_RTC())
  473. return;
  474. tlen = current_tick_length();
  475. offset = cur_tb - do_gtod.varp->tb_orig_stamp;
  476. if (tlen == last_tick_len && offset < 0x80000000u) {
  477. /* check that we're still in sync; if not, resync */
  478. struct timeval tv;
  479. __do_gettimeofday(&tv, cur_tb);
  480. if (tv.tv_sec <= xtime.tv_sec &&
  481. (tv.tv_sec < xtime.tv_sec ||
  482. tv.tv_usec * 1000 <= xtime.tv_nsec))
  483. return;
  484. }
  485. if (tlen != last_tick_len) {
  486. t2x = mulhdu(tlen << TICKLEN_SHIFT, ticklen_to_xs);
  487. last_tick_len = tlen;
  488. } else
  489. t2x = do_gtod.varp->tb_to_xs;
  490. new_stamp_xsec = (u64) xtime.tv_nsec * XSEC_PER_SEC;
  491. do_div(new_stamp_xsec, 1000000000);
  492. new_stamp_xsec += (u64) xtime.tv_sec * XSEC_PER_SEC;
  493. update_gtod(cur_tb, new_stamp_xsec, t2x);
  494. }
  495. #ifdef CONFIG_SMP
  496. unsigned long profile_pc(struct pt_regs *regs)
  497. {
  498. unsigned long pc = instruction_pointer(regs);
  499. if (in_lock_functions(pc))
  500. return regs->link;
  501. return pc;
  502. }
  503. EXPORT_SYMBOL(profile_pc);
  504. #endif
  505. #ifdef CONFIG_PPC_ISERIES
  506. /*
  507. * This function recalibrates the timebase based on the 49-bit time-of-day
  508. * value in the Titan chip. The Titan is much more accurate than the value
  509. * returned by the service processor for the timebase frequency.
  510. */
  511. static void iSeries_tb_recal(void)
  512. {
  513. struct div_result divres;
  514. unsigned long titan, tb;
  515. tb = get_tb();
  516. titan = HvCallXm_loadTod();
  517. if ( iSeries_recal_titan ) {
  518. unsigned long tb_ticks = tb - iSeries_recal_tb;
  519. unsigned long titan_usec = (titan - iSeries_recal_titan) >> 12;
  520. unsigned long new_tb_ticks_per_sec = (tb_ticks * USEC_PER_SEC)/titan_usec;
  521. unsigned long new_tb_ticks_per_jiffy = (new_tb_ticks_per_sec+(HZ/2))/HZ;
  522. long tick_diff = new_tb_ticks_per_jiffy - tb_ticks_per_jiffy;
  523. char sign = '+';
  524. /* make sure tb_ticks_per_sec and tb_ticks_per_jiffy are consistent */
  525. new_tb_ticks_per_sec = new_tb_ticks_per_jiffy * HZ;
  526. if ( tick_diff < 0 ) {
  527. tick_diff = -tick_diff;
  528. sign = '-';
  529. }
  530. if ( tick_diff ) {
  531. if ( tick_diff < tb_ticks_per_jiffy/25 ) {
  532. printk( "Titan recalibrate: new tb_ticks_per_jiffy = %lu (%c%ld)\n",
  533. new_tb_ticks_per_jiffy, sign, tick_diff );
  534. tb_ticks_per_jiffy = new_tb_ticks_per_jiffy;
  535. tb_ticks_per_sec = new_tb_ticks_per_sec;
  536. calc_cputime_factors();
  537. div128_by_32( XSEC_PER_SEC, 0, tb_ticks_per_sec, &divres );
  538. do_gtod.tb_ticks_per_sec = tb_ticks_per_sec;
  539. tb_to_xs = divres.result_low;
  540. do_gtod.varp->tb_to_xs = tb_to_xs;
  541. vdso_data->tb_ticks_per_sec = tb_ticks_per_sec;
  542. vdso_data->tb_to_xs = tb_to_xs;
  543. }
  544. else {
  545. printk( "Titan recalibrate: FAILED (difference > 4 percent)\n"
  546. " new tb_ticks_per_jiffy = %lu\n"
  547. " old tb_ticks_per_jiffy = %lu\n",
  548. new_tb_ticks_per_jiffy, tb_ticks_per_jiffy );
  549. }
  550. }
  551. }
  552. iSeries_recal_titan = titan;
  553. iSeries_recal_tb = tb;
  554. }
  555. #endif
  556. /*
  557. * For iSeries shared processors, we have to let the hypervisor
  558. * set the hardware decrementer. We set a virtual decrementer
  559. * in the lppaca and call the hypervisor if the virtual
  560. * decrementer is less than the current value in the hardware
  561. * decrementer. (almost always the new decrementer value will
  562. * be greater than the current hardware decementer so the hypervisor
  563. * call will not be needed)
  564. */
  565. /*
  566. * timer_interrupt - gets called when the decrementer overflows,
  567. * with interrupts disabled.
  568. */
  569. void timer_interrupt(struct pt_regs * regs)
  570. {
  571. int next_dec;
  572. int cpu = smp_processor_id();
  573. unsigned long ticks;
  574. #ifdef CONFIG_PPC32
  575. if (atomic_read(&ppc_n_lost_interrupts) != 0)
  576. do_IRQ(regs);
  577. #endif
  578. irq_enter();
  579. profile_tick(CPU_PROFILING, regs);
  580. calculate_steal_time();
  581. #ifdef CONFIG_PPC_ISERIES
  582. get_lppaca()->int_dword.fields.decr_int = 0;
  583. #endif
  584. while ((ticks = tb_ticks_since(per_cpu(last_jiffy, cpu)))
  585. >= tb_ticks_per_jiffy) {
  586. /* Update last_jiffy */
  587. per_cpu(last_jiffy, cpu) += tb_ticks_per_jiffy;
  588. /* Handle RTCL overflow on 601 */
  589. if (__USE_RTC() && per_cpu(last_jiffy, cpu) >= 1000000000)
  590. per_cpu(last_jiffy, cpu) -= 1000000000;
  591. /*
  592. * We cannot disable the decrementer, so in the period
  593. * between this cpu's being marked offline in cpu_online_map
  594. * and calling stop-self, it is taking timer interrupts.
  595. * Avoid calling into the scheduler rebalancing code if this
  596. * is the case.
  597. */
  598. if (!cpu_is_offline(cpu))
  599. account_process_time(regs);
  600. /*
  601. * No need to check whether cpu is offline here; boot_cpuid
  602. * should have been fixed up by now.
  603. */
  604. if (cpu != boot_cpuid)
  605. continue;
  606. write_seqlock(&xtime_lock);
  607. tb_last_jiffy += tb_ticks_per_jiffy;
  608. tb_last_stamp = per_cpu(last_jiffy, cpu);
  609. do_timer(regs);
  610. timer_recalc_offset(tb_last_jiffy);
  611. timer_check_rtc();
  612. write_sequnlock(&xtime_lock);
  613. }
  614. next_dec = tb_ticks_per_jiffy - ticks;
  615. set_dec(next_dec);
  616. #ifdef CONFIG_PPC_ISERIES
  617. if (hvlpevent_is_pending())
  618. process_hvlpevents(regs);
  619. #endif
  620. #ifdef CONFIG_PPC64
  621. /* collect purr register values often, for accurate calculations */
  622. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  623. struct cpu_usage *cu = &__get_cpu_var(cpu_usage_array);
  624. cu->current_tb = mfspr(SPRN_PURR);
  625. }
  626. #endif
  627. irq_exit();
  628. }
  629. void wakeup_decrementer(void)
  630. {
  631. unsigned long ticks;
  632. /*
  633. * The timebase gets saved on sleep and restored on wakeup,
  634. * so all we need to do is to reset the decrementer.
  635. */
  636. ticks = tb_ticks_since(__get_cpu_var(last_jiffy));
  637. if (ticks < tb_ticks_per_jiffy)
  638. ticks = tb_ticks_per_jiffy - ticks;
  639. else
  640. ticks = 1;
  641. set_dec(ticks);
  642. }
  643. #ifdef CONFIG_SMP
  644. void __init smp_space_timers(unsigned int max_cpus)
  645. {
  646. int i;
  647. unsigned long half = tb_ticks_per_jiffy / 2;
  648. unsigned long offset = tb_ticks_per_jiffy / max_cpus;
  649. unsigned long previous_tb = per_cpu(last_jiffy, boot_cpuid);
  650. /* make sure tb > per_cpu(last_jiffy, cpu) for all cpus always */
  651. previous_tb -= tb_ticks_per_jiffy;
  652. /*
  653. * The stolen time calculation for POWER5 shared-processor LPAR
  654. * systems works better if the two threads' timebase interrupts
  655. * are staggered by half a jiffy with respect to each other.
  656. */
  657. for_each_cpu(i) {
  658. if (i == boot_cpuid)
  659. continue;
  660. if (i == (boot_cpuid ^ 1))
  661. per_cpu(last_jiffy, i) =
  662. per_cpu(last_jiffy, boot_cpuid) - half;
  663. else if (i & 1)
  664. per_cpu(last_jiffy, i) =
  665. per_cpu(last_jiffy, i ^ 1) + half;
  666. else {
  667. previous_tb += offset;
  668. per_cpu(last_jiffy, i) = previous_tb;
  669. }
  670. }
  671. }
  672. #endif
  673. /*
  674. * Scheduler clock - returns current time in nanosec units.
  675. *
  676. * Note: mulhdu(a, b) (multiply high double unsigned) returns
  677. * the high 64 bits of a * b, i.e. (a * b) >> 64, where a and b
  678. * are 64-bit unsigned numbers.
  679. */
  680. unsigned long long sched_clock(void)
  681. {
  682. if (__USE_RTC())
  683. return get_rtc();
  684. return mulhdu(get_tb(), tb_to_ns_scale) << tb_to_ns_shift;
  685. }
  686. int do_settimeofday(struct timespec *tv)
  687. {
  688. time_t wtm_sec, new_sec = tv->tv_sec;
  689. long wtm_nsec, new_nsec = tv->tv_nsec;
  690. unsigned long flags;
  691. u64 new_xsec;
  692. unsigned long tb_delta;
  693. if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
  694. return -EINVAL;
  695. write_seqlock_irqsave(&xtime_lock, flags);
  696. /*
  697. * Updating the RTC is not the job of this code. If the time is
  698. * stepped under NTP, the RTC will be updated after STA_UNSYNC
  699. * is cleared. Tools like clock/hwclock either copy the RTC
  700. * to the system time, in which case there is no point in writing
  701. * to the RTC again, or write to the RTC but then they don't call
  702. * settimeofday to perform this operation.
  703. */
  704. #ifdef CONFIG_PPC_ISERIES
  705. if (first_settimeofday) {
  706. iSeries_tb_recal();
  707. first_settimeofday = 0;
  708. }
  709. #endif
  710. /*
  711. * Subtract off the number of nanoseconds since the
  712. * beginning of the last tick.
  713. * Note that since we don't increment jiffies_64 anywhere other
  714. * than in do_timer (since we don't have a lost tick problem),
  715. * wall_jiffies will always be the same as jiffies,
  716. * and therefore the (jiffies - wall_jiffies) computation
  717. * has been removed.
  718. */
  719. tb_delta = tb_ticks_since(tb_last_stamp);
  720. tb_delta = mulhdu(tb_delta, do_gtod.varp->tb_to_xs); /* in xsec */
  721. new_nsec -= SCALE_XSEC(tb_delta, 1000000000);
  722. wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - new_sec);
  723. wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - new_nsec);
  724. set_normalized_timespec(&xtime, new_sec, new_nsec);
  725. set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
  726. /* In case of a large backwards jump in time with NTP, we want the
  727. * clock to be updated as soon as the PLL is again in lock.
  728. */
  729. last_rtc_update = new_sec - 658;
  730. ntp_clear();
  731. new_xsec = xtime.tv_nsec;
  732. if (new_xsec != 0) {
  733. new_xsec *= XSEC_PER_SEC;
  734. do_div(new_xsec, NSEC_PER_SEC);
  735. }
  736. new_xsec += (u64)xtime.tv_sec * XSEC_PER_SEC;
  737. update_gtod(tb_last_jiffy, new_xsec, do_gtod.varp->tb_to_xs);
  738. vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
  739. vdso_data->tz_dsttime = sys_tz.tz_dsttime;
  740. write_sequnlock_irqrestore(&xtime_lock, flags);
  741. clock_was_set();
  742. return 0;
  743. }
  744. EXPORT_SYMBOL(do_settimeofday);
  745. void __init generic_calibrate_decr(void)
  746. {
  747. struct device_node *cpu;
  748. unsigned int *fp;
  749. int node_found;
  750. /*
  751. * The cpu node should have a timebase-frequency property
  752. * to tell us the rate at which the decrementer counts.
  753. */
  754. cpu = of_find_node_by_type(NULL, "cpu");
  755. ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
  756. node_found = 0;
  757. if (cpu) {
  758. fp = (unsigned int *)get_property(cpu, "timebase-frequency",
  759. NULL);
  760. if (fp) {
  761. node_found = 1;
  762. ppc_tb_freq = *fp;
  763. }
  764. }
  765. if (!node_found)
  766. printk(KERN_ERR "WARNING: Estimating decrementer frequency "
  767. "(not found)\n");
  768. ppc_proc_freq = DEFAULT_PROC_FREQ;
  769. node_found = 0;
  770. if (cpu) {
  771. fp = (unsigned int *)get_property(cpu, "clock-frequency",
  772. NULL);
  773. if (fp) {
  774. node_found = 1;
  775. ppc_proc_freq = *fp;
  776. }
  777. }
  778. #ifdef CONFIG_BOOKE
  779. /* Set the time base to zero */
  780. mtspr(SPRN_TBWL, 0);
  781. mtspr(SPRN_TBWU, 0);
  782. /* Clear any pending timer interrupts */
  783. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
  784. /* Enable decrementer interrupt */
  785. mtspr(SPRN_TCR, TCR_DIE);
  786. #endif
  787. if (!node_found)
  788. printk(KERN_ERR "WARNING: Estimating processor frequency "
  789. "(not found)\n");
  790. of_node_put(cpu);
  791. }
  792. unsigned long get_boot_time(void)
  793. {
  794. struct rtc_time tm;
  795. if (ppc_md.get_boot_time)
  796. return ppc_md.get_boot_time();
  797. if (!ppc_md.get_rtc_time)
  798. return 0;
  799. ppc_md.get_rtc_time(&tm);
  800. return mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
  801. tm.tm_hour, tm.tm_min, tm.tm_sec);
  802. }
  803. /* This function is only called on the boot processor */
  804. void __init time_init(void)
  805. {
  806. unsigned long flags;
  807. unsigned long tm = 0;
  808. struct div_result res;
  809. u64 scale, x;
  810. unsigned shift;
  811. if (ppc_md.time_init != NULL)
  812. timezone_offset = ppc_md.time_init();
  813. if (__USE_RTC()) {
  814. /* 601 processor: dec counts down by 128 every 128ns */
  815. ppc_tb_freq = 1000000000;
  816. tb_last_stamp = get_rtcl();
  817. tb_last_jiffy = tb_last_stamp;
  818. } else {
  819. /* Normal PowerPC with timebase register */
  820. ppc_md.calibrate_decr();
  821. printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
  822. ppc_tb_freq / 1000000, ppc_tb_freq % 1000000);
  823. printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
  824. ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
  825. tb_last_stamp = tb_last_jiffy = get_tb();
  826. }
  827. tb_ticks_per_jiffy = ppc_tb_freq / HZ;
  828. tb_ticks_per_sec = ppc_tb_freq;
  829. tb_ticks_per_usec = ppc_tb_freq / 1000000;
  830. tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
  831. calc_cputime_factors();
  832. /*
  833. * Calculate the length of each tick in ns. It will not be
  834. * exactly 1e9/HZ unless ppc_tb_freq is divisible by HZ.
  835. * We compute 1e9 * tb_ticks_per_jiffy / ppc_tb_freq,
  836. * rounded up.
  837. */
  838. x = (u64) NSEC_PER_SEC * tb_ticks_per_jiffy + ppc_tb_freq - 1;
  839. do_div(x, ppc_tb_freq);
  840. tick_nsec = x;
  841. last_tick_len = x << TICKLEN_SCALE;
  842. /*
  843. * Compute ticklen_to_xs, which is a factor which gets multiplied
  844. * by (last_tick_len << TICKLEN_SHIFT) to get a tb_to_xs value.
  845. * It is computed as:
  846. * ticklen_to_xs = 2^N / (tb_ticks_per_jiffy * 1e9)
  847. * where N = 64 + 20 - TICKLEN_SCALE - TICKLEN_SHIFT
  848. * so as to give the result as a 0.64 fixed-point fraction.
  849. */
  850. div128_by_32(1ULL << (64 + 20 - TICKLEN_SCALE - TICKLEN_SHIFT), 0,
  851. tb_ticks_per_jiffy, &res);
  852. div128_by_32(res.result_high, res.result_low, NSEC_PER_SEC, &res);
  853. ticklen_to_xs = res.result_low;
  854. /* Compute tb_to_xs from tick_nsec */
  855. tb_to_xs = mulhdu(last_tick_len << TICKLEN_SHIFT, ticklen_to_xs);
  856. /*
  857. * Compute scale factor for sched_clock.
  858. * The calibrate_decr() function has set tb_ticks_per_sec,
  859. * which is the timebase frequency.
  860. * We compute 1e9 * 2^64 / tb_ticks_per_sec and interpret
  861. * the 128-bit result as a 64.64 fixed-point number.
  862. * We then shift that number right until it is less than 1.0,
  863. * giving us the scale factor and shift count to use in
  864. * sched_clock().
  865. */
  866. div128_by_32(1000000000, 0, tb_ticks_per_sec, &res);
  867. scale = res.result_low;
  868. for (shift = 0; res.result_high != 0; ++shift) {
  869. scale = (scale >> 1) | (res.result_high << 63);
  870. res.result_high >>= 1;
  871. }
  872. tb_to_ns_scale = scale;
  873. tb_to_ns_shift = shift;
  874. #ifdef CONFIG_PPC_ISERIES
  875. if (!piranha_simulator)
  876. #endif
  877. tm = get_boot_time();
  878. write_seqlock_irqsave(&xtime_lock, flags);
  879. /* If platform provided a timezone (pmac), we correct the time */
  880. if (timezone_offset) {
  881. sys_tz.tz_minuteswest = -timezone_offset / 60;
  882. sys_tz.tz_dsttime = 0;
  883. tm -= timezone_offset;
  884. }
  885. xtime.tv_sec = tm;
  886. xtime.tv_nsec = 0;
  887. do_gtod.varp = &do_gtod.vars[0];
  888. do_gtod.var_idx = 0;
  889. do_gtod.varp->tb_orig_stamp = tb_last_jiffy;
  890. __get_cpu_var(last_jiffy) = tb_last_stamp;
  891. do_gtod.varp->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC;
  892. do_gtod.tb_ticks_per_sec = tb_ticks_per_sec;
  893. do_gtod.varp->tb_to_xs = tb_to_xs;
  894. do_gtod.tb_to_us = tb_to_us;
  895. vdso_data->tb_orig_stamp = tb_last_jiffy;
  896. vdso_data->tb_update_count = 0;
  897. vdso_data->tb_ticks_per_sec = tb_ticks_per_sec;
  898. vdso_data->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC;
  899. vdso_data->tb_to_xs = tb_to_xs;
  900. time_freq = 0;
  901. last_rtc_update = xtime.tv_sec;
  902. set_normalized_timespec(&wall_to_monotonic,
  903. -xtime.tv_sec, -xtime.tv_nsec);
  904. write_sequnlock_irqrestore(&xtime_lock, flags);
  905. /* Not exact, but the timer interrupt takes care of this */
  906. set_dec(tb_ticks_per_jiffy);
  907. }
  908. #define FEBRUARY 2
  909. #define STARTOFTIME 1970
  910. #define SECDAY 86400L
  911. #define SECYR (SECDAY * 365)
  912. #define leapyear(year) ((year) % 4 == 0 && \
  913. ((year) % 100 != 0 || (year) % 400 == 0))
  914. #define days_in_year(a) (leapyear(a) ? 366 : 365)
  915. #define days_in_month(a) (month_days[(a) - 1])
  916. static int month_days[12] = {
  917. 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  918. };
  919. /*
  920. * This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
  921. */
  922. void GregorianDay(struct rtc_time * tm)
  923. {
  924. int leapsToDate;
  925. int lastYear;
  926. int day;
  927. int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
  928. lastYear = tm->tm_year - 1;
  929. /*
  930. * Number of leap corrections to apply up to end of last year
  931. */
  932. leapsToDate = lastYear / 4 - lastYear / 100 + lastYear / 400;
  933. /*
  934. * This year is a leap year if it is divisible by 4 except when it is
  935. * divisible by 100 unless it is divisible by 400
  936. *
  937. * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 was
  938. */
  939. day = tm->tm_mon > 2 && leapyear(tm->tm_year);
  940. day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] +
  941. tm->tm_mday;
  942. tm->tm_wday = day % 7;
  943. }
  944. void to_tm(int tim, struct rtc_time * tm)
  945. {
  946. register int i;
  947. register long hms, day;
  948. day = tim / SECDAY;
  949. hms = tim % SECDAY;
  950. /* Hours, minutes, seconds are easy */
  951. tm->tm_hour = hms / 3600;
  952. tm->tm_min = (hms % 3600) / 60;
  953. tm->tm_sec = (hms % 3600) % 60;
  954. /* Number of years in days */
  955. for (i = STARTOFTIME; day >= days_in_year(i); i++)
  956. day -= days_in_year(i);
  957. tm->tm_year = i;
  958. /* Number of months in days left */
  959. if (leapyear(tm->tm_year))
  960. days_in_month(FEBRUARY) = 29;
  961. for (i = 1; day >= days_in_month(i); i++)
  962. day -= days_in_month(i);
  963. days_in_month(FEBRUARY) = 28;
  964. tm->tm_mon = i;
  965. /* Days are what is left over (+1) from all that. */
  966. tm->tm_mday = day + 1;
  967. /*
  968. * Determine the day of week
  969. */
  970. GregorianDay(tm);
  971. }
  972. /* Auxiliary function to compute scaling factors */
  973. /* Actually the choice of a timebase running at 1/4 the of the bus
  974. * frequency giving resolution of a few tens of nanoseconds is quite nice.
  975. * It makes this computation very precise (27-28 bits typically) which
  976. * is optimistic considering the stability of most processor clock
  977. * oscillators and the precision with which the timebase frequency
  978. * is measured but does not harm.
  979. */
  980. unsigned mulhwu_scale_factor(unsigned inscale, unsigned outscale)
  981. {
  982. unsigned mlt=0, tmp, err;
  983. /* No concern for performance, it's done once: use a stupid
  984. * but safe and compact method to find the multiplier.
  985. */
  986. for (tmp = 1U<<31; tmp != 0; tmp >>= 1) {
  987. if (mulhwu(inscale, mlt|tmp) < outscale)
  988. mlt |= tmp;
  989. }
  990. /* We might still be off by 1 for the best approximation.
  991. * A side effect of this is that if outscale is too large
  992. * the returned value will be zero.
  993. * Many corner cases have been checked and seem to work,
  994. * some might have been forgotten in the test however.
  995. */
  996. err = inscale * (mlt+1);
  997. if (err <= inscale/2)
  998. mlt++;
  999. return mlt;
  1000. }
  1001. /*
  1002. * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit
  1003. * result.
  1004. */
  1005. void div128_by_32(u64 dividend_high, u64 dividend_low,
  1006. unsigned divisor, struct div_result *dr)
  1007. {
  1008. unsigned long a, b, c, d;
  1009. unsigned long w, x, y, z;
  1010. u64 ra, rb, rc;
  1011. a = dividend_high >> 32;
  1012. b = dividend_high & 0xffffffff;
  1013. c = dividend_low >> 32;
  1014. d = dividend_low & 0xffffffff;
  1015. w = a / divisor;
  1016. ra = ((u64)(a - (w * divisor)) << 32) + b;
  1017. rb = ((u64) do_div(ra, divisor) << 32) + c;
  1018. x = ra;
  1019. rc = ((u64) do_div(rb, divisor) << 32) + d;
  1020. y = rb;
  1021. do_div(rc, divisor);
  1022. z = rc;
  1023. dr->result_high = ((u64)w << 32) + x;
  1024. dr->result_low = ((u64)y << 32) + z;
  1025. }