timex.h 2.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 *  include/asm-s390/timex.h
 *
 *  S390 version
 *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
 *
 *  Derived from "include/asm-i386/timex.h"
 *    Copyright (C) 1992, Linus Torvalds
 */

#ifndef _ASM_S390_TIMEX_H
#define _ASM_S390_TIMEX_H

14 15
#include <asm/lowcore.h>

16 17 18
/* The value of the TOD clock for 1.1.1970. */
#define TOD_UNIX_EPOCH 0x7d91048bca000000ULL

M
Martin Schwidefsky 已提交
19 20 21 22 23 24
/* Inline functions for clock register access. */
static inline int set_clock(__u64 time)
{
	int cc;

	asm volatile(
25
		"   sck   %1\n"
M
Martin Schwidefsky 已提交
26 27
		"   ipm   %0\n"
		"   srl   %0,28\n"
28
		: "=d" (cc) : "Q" (time) : "cc");
M
Martin Schwidefsky 已提交
29 30 31 32 33 34 35 36
	return cc;
}

static inline int store_clock(__u64 *time)
{
	int cc;

	asm volatile(
37
		"   stck  %1\n"
M
Martin Schwidefsky 已提交
38 39
		"   ipm   %0\n"
		"   srl   %0,28\n"
40
		: "=d" (cc), "=Q" (*time) : : "cc");
M
Martin Schwidefsky 已提交
41 42 43 44 45
	return cc;
}

static inline void set_clock_comparator(__u64 time)
{
46
	asm volatile("sckc %0" : : "Q" (time));
M
Martin Schwidefsky 已提交
47 48 49 50
}

static inline void store_clock_comparator(__u64 *time)
{
51
	asm volatile("stckc %0" : "=Q" (*time));
M
Martin Schwidefsky 已提交
52 53
}

54 55 56 57 58 59 60 61
void clock_comparator_work(void);

static inline unsigned long long local_tick_disable(void)
{
	unsigned long long old;

	old = S390_lowcore.clock_comparator;
	S390_lowcore.clock_comparator = -1ULL;
62
	set_clock_comparator(S390_lowcore.clock_comparator);
63 64 65 66 67 68
	return old;
}

static inline void local_tick_enable(unsigned long long comp)
{
	S390_lowcore.clock_comparator = comp;
69
	set_clock_comparator(S390_lowcore.clock_comparator);
70 71
}

L
Linus Torvalds 已提交
72 73 74 75
#define CLOCK_TICK_RATE	1193180 /* Underlying HZ */

typedef unsigned long long cycles_t;

76
static inline unsigned long long get_clock(void)
L
Linus Torvalds 已提交
77 78 79
{
	unsigned long long clk;

80
#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
81 82
	asm volatile(".insn s,0xb27c0000,%0" : "=Q" (clk) : : "cc");
#else
83
	asm volatile("stck %0" : "=Q" (clk) : : "cc");
84
#endif
L
Linus Torvalds 已提交
85 86 87
	return clk;
}

88 89 90 91 92
static inline void get_clock_ext(char *clk)
{
	asm volatile("stcke %0" : "=Q" (*clk) : : "cc");
}

93
static inline unsigned long long get_clock_xt(void)
94
{
95
	unsigned char clk[16];
96
	get_clock_ext(clk);
97
	return *((unsigned long long *)&clk[1]);
98 99
}

100 101 102 103 104
static inline cycles_t get_cycles(void)
{
	return (cycles_t) get_clock() >> 2;
}

M
Martin Schwidefsky 已提交
105
int get_sync_clock(unsigned long long *clock);
106
void init_cpu_timer(void);
107
unsigned long long monotonic_clock(void);
108

109 110 111 112 113 114 115 116
void tod_to_timeval(__u64, struct timespec *);

static inline
void stck_to_timespec(unsigned long long stck, struct timespec *ts)
{
	tod_to_timeval(stck - TOD_UNIX_EPOCH, ts);
}

117 118
extern u64 sched_clock_base_cc;

119 120 121 122 123 124 125 126 127 128 129 130 131 132
/**
 * get_clock_monotonic - returns current time in clock rate units
 *
 * The caller must ensure that preemption is disabled.
 * The clock and sched_clock_base get changed via stop_machine.
 * Therefore preemption must be disabled when calling this
 * function, otherwise the returned value is not guaranteed to
 * be monotonic.
 */
static inline unsigned long long get_clock_monotonic(void)
{
	return get_clock_xt() - sched_clock_base_cc;
}

L
Linus Torvalds 已提交
133
#endif