debuggers.hg

view xen/arch/ia64/xen/oprofile/perfmon.c @ 13702:d2784d93e760

ia64 and ppc: Remove uses of strcpy and strncpy.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author kfraser@localhost.localdomain
date Mon Jan 29 15:01:33 2007 +0000 (2007-01-29)
parents 8ab9b43ad557
children 0803bdfdd9c5
line source
1 /******************************************************************************
2 * perfmon.c for xenoprof
3 * This is based linux/arch/ia64/oprofile/perfmon.c, but heavily rewritten.
4 *
5 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
6 * VA Linux Systems Japan K.K.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23 /**
24 * @file perfmon.c
25 *
26 * @remark Copyright 2003 OProfile authors
27 * @remark Read the file COPYING
28 *
29 * @author John Levon <levon@movementarian.org>
30 */
32 #include <xen/config.h>
33 #include <xen/sched.h>
34 #include <xen/event.h>
35 #include <xen/xenoprof.h>
36 #include <asm/perfmon.h>
37 #include <asm/ptrace.h>
39 // XXX move them to an appropriate header file
40 extern void xenoprof_log_event(struct vcpu *vcpu,
41 unsigned long eip, int mode, int event);
42 extern int is_active(struct domain *d);
44 static int allow_virq;
45 static int allow_ints;
47 static int
48 xenoprof_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg,
49 struct pt_regs *regs, unsigned long stamp)
50 {
51 unsigned long ip = regs->cr_iip;
52 int event = arg->pmd_eventid;
54 arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1;
55 if (!allow_virq || !allow_ints)
56 return 0;
58 xenoprof_log_event(current, ip, xenoprofile_get_mode(task, regs), event);
60 // send VIRQ_XENOPROF
61 if (is_active(current->domain) && !ring_0(regs))
62 send_guest_vcpu_virq(current, VIRQ_XENOPROF);
64 return 0;
65 }
67 // same as linux OPROFILE_FMT_UUID
68 #define XENOPROF_FMT_UUID { \
69 0x77, 0x7a, 0x6e, 0x61, 0x20, 0x65, 0x73, 0x69, 0x74, 0x6e, 0x72, 0x20, 0x61, 0x65, 0x0a, 0x6c }
71 static pfm_buffer_fmt_t xenoprof_fmt = {
72 .fmt_name = "xenoprof_format",
73 .fmt_uuid = XENOPROF_FMT_UUID,
74 .fmt_handler = xenoprof_handler,
75 };
77 static char * get_cpu_type(void)
78 {
79 __u8 family = local_cpu_data->family;
81 switch (family) {
82 case 0x07:
83 return "ia64/itanium";
84 case 0x1f:
85 return "ia64/itanium2";
86 default:
87 return "ia64/ia64";
88 }
89 }
91 static int using_xenoprof;
93 int __init
94 xenprof_perfmon_init(void)
95 {
96 int ret = pfm_register_buffer_fmt(&xenoprof_fmt);
97 if (ret)
98 return -ENODEV;
99 using_xenoprof = 1;
100 printk("xenoprof: using perfmon.\n");
101 return 0;
102 }
103 __initcall(xenprof_perfmon_init);
105 #ifdef notyet
106 void xenoprof_perfmon_exit(void)
107 {
108 if (!using_xenoprof)
109 return;
111 pfm_unregister_buffer_fmt(xenoprof_fmt.fmt_uuid);
112 }
113 __exitcall(xenoprof_perfmon_exit);
114 #endif
116 ///////////////////////////////////////////////////////////////////////////
117 // glue methods for xenoprof and perfmon.
118 int
119 xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type)
120 {
121 *num_events = 0;
122 strlcpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE);
123 cpu_type[XENOPROF_CPU_TYPE_SIZE - 1] = '\0';
125 *is_primary = 0;
126 if (xenoprof_primary_profiler == NULL) {
127 /* For now, only dom0 can be the primary profiler */
128 if (current->domain->domain_id == 0) {
129 *is_primary = 1;
130 }
131 } else if (xenoprof_primary_profiler == current->domain)
132 *is_primary = 1;
133 return 0;
134 }
136 int
137 xenoprof_arch_reserve_counters(void)
138 {
139 // perfmon takes care
140 return 0;
141 }
143 int
144 xenoprof_arch_counter(XEN_GUEST_HANDLE(void) arg)
145 {
146 return -ENOSYS;
147 }
149 int
150 xenoprof_arch_setup_events(void)
151 {
152 // perfmon takes care
153 return 0;
154 }
156 //XXX SMP: sync by IPI?
157 int
158 xenoprof_arch_enable_virq(void)
159 {
160 allow_virq = 1;
161 return 0;
162 }
164 //XXX SMP: sync by IPI?
165 int
166 xenoprof_arch_start(void)
167 {
168 allow_ints = 1;
169 return 0;
170 }
172 //XXX SMP: sync by IPI?
173 void
174 xenoprof_arch_stop(void)
175 {
176 allow_ints = 0;
177 }
179 //XXX SMP: sync by IPI?
180 void
181 xenoprof_arch_disable_virq(void)
182 {
183 allow_virq = 0;
184 }
186 void
187 xenoprof_arch_release_counters(void)
188 {
189 // perfmon takes care
190 }
192 /*
193 * Local variables:
194 * mode: C
195 * c-set-style: "BSD"
196 * c-basic-offset: 4
197 * tab-width: 4
198 * indent-tabs-mode: nil
199 * End:
200 */