diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2008-10-16 22:18:08 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2008-10-17 13:08:02 -0400 |
commit | dcbbecdad53bd6273891ad018f9c6bb8f2b7813c (patch) | |
tree | 1db1a5ac692428c6ec258c39593647ee78e0d690 /arch/ia64 | |
parent | 7477de989faffd4be4adfa3d3e1bf35bdf2e0f75 (diff) |
ia64/pv_ops/xen: implement xen pv_time_ops.
implement xen pv_time_ops to account steal time.
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'arch/ia64')
-rw-r--r-- | arch/ia64/xen/Makefile | 2 | ||||
-rw-r--r-- | arch/ia64/xen/time.c | 180 | ||||
-rw-r--r-- | arch/ia64/xen/time.h | 23 | ||||
-rw-r--r-- | arch/ia64/xen/xen_pv_ops.c | 2 |
4 files changed, 206 insertions, 1 deletions
diff --git a/arch/ia64/xen/Makefile b/arch/ia64/xen/Makefile index 01c4289f0a40..ed31c76d2bf0 100644 --- a/arch/ia64/xen/Makefile +++ b/arch/ia64/xen/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y := hypercall.o xenivt.o xensetup.o xen_pv_ops.o irq_xen.o \ | 5 | obj-y := hypercall.o xenivt.o xensetup.o xen_pv_ops.o irq_xen.o \ |
6 | hypervisor.o xencomm.o xcom_hcall.o grant-table.o | 6 | hypervisor.o xencomm.o xcom_hcall.o grant-table.o time.o |
7 | 7 | ||
8 | AFLAGS_xenivt.o += -D__IA64_ASM_PARAVIRTUALIZED_XEN | 8 | AFLAGS_xenivt.o += -D__IA64_ASM_PARAVIRTUALIZED_XEN |
9 | 9 | ||
diff --git a/arch/ia64/xen/time.c b/arch/ia64/xen/time.c new file mode 100644 index 000000000000..ec168ec754b2 --- /dev/null +++ b/arch/ia64/xen/time.c | |||
@@ -0,0 +1,180 @@ | |||
1 | /****************************************************************************** | ||
2 | * arch/ia64/xen/time.c | ||
3 | * | ||
4 | * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp> | ||
5 | * VA Linux Systems Japan K.K. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/delay.h> | ||
24 | #include <linux/kernel_stat.h> | ||
25 | #include <linux/posix-timers.h> | ||
26 | #include <linux/irq.h> | ||
27 | #include <linux/clocksource.h> | ||
28 | |||
29 | #include <asm/xen/hypervisor.h> | ||
30 | |||
31 | #include <xen/interface/vcpu.h> | ||
32 | |||
33 | #include "../kernel/fsyscall_gtod_data.h" | ||
34 | |||
35 | DEFINE_PER_CPU(struct vcpu_runstate_info, runstate); | ||
36 | DEFINE_PER_CPU(unsigned long, processed_stolen_time); | ||
37 | DEFINE_PER_CPU(unsigned long, processed_blocked_time); | ||
38 | |||
39 | /* taken from i386/kernel/time-xen.c */ | ||
40 | static void xen_init_missing_ticks_accounting(int cpu) | ||
41 | { | ||
42 | struct vcpu_register_runstate_memory_area area; | ||
43 | struct vcpu_runstate_info *runstate = &per_cpu(runstate, cpu); | ||
44 | int rc; | ||
45 | |||
46 | memset(runstate, 0, sizeof(*runstate)); | ||
47 | |||
48 | area.addr.v = runstate; | ||
49 | rc = HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area, cpu, | ||
50 | &area); | ||
51 | WARN_ON(rc && rc != -ENOSYS); | ||
52 | |||
53 | per_cpu(processed_blocked_time, cpu) = runstate->time[RUNSTATE_blocked]; | ||
54 | per_cpu(processed_stolen_time, cpu) = runstate->time[RUNSTATE_runnable] | ||
55 | + runstate->time[RUNSTATE_offline]; | ||
56 | } | ||
57 | |||
58 | /* | ||
59 | * Runstate accounting | ||
60 | */ | ||
61 | /* stolen from arch/x86/xen/time.c */ | ||
62 | static void get_runstate_snapshot(struct vcpu_runstate_info *res) | ||
63 | { | ||
64 | u64 state_time; | ||
65 | struct vcpu_runstate_info *state; | ||
66 | |||
67 | BUG_ON(preemptible()); | ||
68 | |||
69 | state = &__get_cpu_var(runstate); | ||
70 | |||
71 | /* | ||
72 | * The runstate info is always updated by the hypervisor on | ||
73 | * the current CPU, so there's no need to use anything | ||
74 | * stronger than a compiler barrier when fetching it. | ||
75 | */ | ||
76 | do { | ||
77 | state_time = state->state_entry_time; | ||
78 | rmb(); | ||
79 | *res = *state; | ||
80 | rmb(); | ||
81 | } while (state->state_entry_time != state_time); | ||
82 | } | ||
83 | |||
84 | #define NS_PER_TICK (1000000000LL/HZ) | ||
85 | |||
86 | static unsigned long | ||
87 | consider_steal_time(unsigned long new_itm) | ||
88 | { | ||
89 | unsigned long stolen, blocked; | ||
90 | unsigned long delta_itm = 0, stolentick = 0; | ||
91 | int cpu = smp_processor_id(); | ||
92 | struct vcpu_runstate_info runstate; | ||
93 | struct task_struct *p = current; | ||
94 | |||
95 | get_runstate_snapshot(&runstate); | ||
96 | |||
97 | /* | ||
98 | * Check for vcpu migration effect | ||
99 | * In this case, itc value is reversed. | ||
100 | * This causes huge stolen value. | ||
101 | * This function just checks and reject this effect. | ||
102 | */ | ||
103 | if (!time_after_eq(runstate.time[RUNSTATE_blocked], | ||
104 | per_cpu(processed_blocked_time, cpu))) | ||
105 | blocked = 0; | ||
106 | |||
107 | if (!time_after_eq(runstate.time[RUNSTATE_runnable] + | ||
108 | runstate.time[RUNSTATE_offline], | ||
109 | per_cpu(processed_stolen_time, cpu))) | ||
110 | stolen = 0; | ||
111 | |||
112 | if (!time_after(delta_itm + new_itm, ia64_get_itc())) | ||
113 | stolentick = ia64_get_itc() - new_itm; | ||
114 | |||
115 | do_div(stolentick, NS_PER_TICK); | ||
116 | stolentick++; | ||
117 | |||
118 | do_div(stolen, NS_PER_TICK); | ||
119 | |||
120 | if (stolen > stolentick) | ||
121 | stolen = stolentick; | ||
122 | |||
123 | stolentick -= stolen; | ||
124 | do_div(blocked, NS_PER_TICK); | ||
125 | |||
126 | if (blocked > stolentick) | ||
127 | blocked = stolentick; | ||
128 | |||
129 | if (stolen > 0 || blocked > 0) { | ||
130 | account_steal_time(NULL, jiffies_to_cputime(stolen)); | ||
131 | account_steal_time(idle_task(cpu), jiffies_to_cputime(blocked)); | ||
132 | run_local_timers(); | ||
133 | |||
134 | if (rcu_pending(cpu)) | ||
135 | rcu_check_callbacks(cpu, user_mode(get_irq_regs())); | ||
136 | |||
137 | scheduler_tick(); | ||
138 | run_posix_cpu_timers(p); | ||
139 | delta_itm += local_cpu_data->itm_delta * (stolen + blocked); | ||
140 | |||
141 | if (cpu == time_keeper_id) { | ||
142 | write_seqlock(&xtime_lock); | ||
143 | do_timer(stolen + blocked); | ||
144 | local_cpu_data->itm_next = delta_itm + new_itm; | ||
145 | write_sequnlock(&xtime_lock); | ||
146 | } else { | ||
147 | local_cpu_data->itm_next = delta_itm + new_itm; | ||
148 | } | ||
149 | per_cpu(processed_stolen_time, cpu) += NS_PER_TICK * stolen; | ||
150 | per_cpu(processed_blocked_time, cpu) += NS_PER_TICK * blocked; | ||
151 | } | ||
152 | return delta_itm; | ||
153 | } | ||
154 | |||
155 | static int xen_do_steal_accounting(unsigned long *new_itm) | ||
156 | { | ||
157 | unsigned long delta_itm; | ||
158 | delta_itm = consider_steal_time(*new_itm); | ||
159 | *new_itm += delta_itm; | ||
160 | if (time_after(*new_itm, ia64_get_itc()) && delta_itm) | ||
161 | return 1; | ||
162 | |||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static void xen_itc_jitter_data_reset(void) | ||
167 | { | ||
168 | u64 lcycle, ret; | ||
169 | |||
170 | do { | ||
171 | lcycle = itc_jitter_data.itc_lastcycle; | ||
172 | ret = cmpxchg(&itc_jitter_data.itc_lastcycle, lcycle, 0); | ||
173 | } while (unlikely(ret != lcycle)); | ||
174 | } | ||
175 | |||
176 | struct pv_time_ops xen_time_ops __initdata = { | ||
177 | .init_missing_ticks_accounting = xen_init_missing_ticks_accounting, | ||
178 | .do_steal_accounting = xen_do_steal_accounting, | ||
179 | .clocksource_resume = xen_itc_jitter_data_reset, | ||
180 | }; | ||
diff --git a/arch/ia64/xen/time.h b/arch/ia64/xen/time.h new file mode 100644 index 000000000000..b9c7ec5f9cfa --- /dev/null +++ b/arch/ia64/xen/time.h | |||
@@ -0,0 +1,23 @@ | |||
1 | /****************************************************************************** | ||
2 | * arch/ia64/xen/time.h | ||
3 | * | ||
4 | * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp> | ||
5 | * VA Linux Systems Japan K.K. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | extern struct pv_time_ops xen_time_ops __initdata; | ||
diff --git a/arch/ia64/xen/xen_pv_ops.c b/arch/ia64/xen/xen_pv_ops.c index 4fe4e621b7b6..04cd12350455 100644 --- a/arch/ia64/xen/xen_pv_ops.c +++ b/arch/ia64/xen/xen_pv_ops.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <asm/xen/privop.h> | 30 | #include <asm/xen/privop.h> |
31 | 31 | ||
32 | #include "irq_xen.h" | 32 | #include "irq_xen.h" |
33 | #include "time.h" | ||
33 | 34 | ||
34 | /*************************************************************************** | 35 | /*************************************************************************** |
35 | * general info | 36 | * general info |
@@ -357,6 +358,7 @@ xen_setup_pv_ops(void) | |||
357 | pv_cpu_ops = xen_cpu_ops; | 358 | pv_cpu_ops = xen_cpu_ops; |
358 | pv_iosapic_ops = xen_iosapic_ops; | 359 | pv_iosapic_ops = xen_iosapic_ops; |
359 | pv_irq_ops = xen_irq_ops; | 360 | pv_irq_ops = xen_irq_ops; |
361 | pv_time_ops = xen_time_ops; | ||
360 | 362 | ||
361 | paravirt_cpu_asm_init(&xen_cpu_asm_switch); | 363 | paravirt_cpu_asm_init(&xen_cpu_asm_switch); |
362 | } | 364 | } |