debuggers.hg

view xen/common/keyhandler.c @ 3522:610068179f96

bitkeeper revision 1.1159.212.24 (41f26e32I9xLcTR7BS9n8xcvRPkmCQ)

Merge ssh://srg//auto/groups/xeno/BK/xeno.bk
into equilibrium.research:/home/irchomes/mwilli2/src/xen-3.0-devel.bk
author mwilli2@equilibrium.research
date Sat Jan 22 15:16:02 2005 +0000 (2005-01-22)
parents f5a6b3a8c9b9 46c14b1a4351
children bb56e77896e7 4294cfa9fad3
line source
1 /******************************************************************************
2 * keyhandler.c
3 */
5 #include <xen/keyhandler.h>
6 #include <xen/reboot.h>
7 #include <xen/event.h>
8 #include <xen/console.h>
9 #include <xen/serial.h>
10 #include <xen/sched.h>
11 #include <xen/softirq.h>
13 #define KEY_MAX 256
14 #define STR_MAX 64
16 static struct {
17 union {
18 keyhandler_t *handler;
19 irq_keyhandler_t *irq_handler;
20 } u;
21 unsigned int flags;
22 char desc[STR_MAX];
23 } key_table[KEY_MAX];
25 #define KEYHANDLER_IRQ_CALLBACK 0x1
27 static unsigned char keypress_key;
29 void keypress_softirq(void)
30 {
31 keyhandler_t *h;
32 unsigned char key = keypress_key;
33 if ( (h = key_table[key].u.handler) != NULL )
34 (*h)(key);
35 }
37 void handle_keypress(unsigned char key, struct xen_regs *regs)
38 {
39 irq_keyhandler_t *h;
41 if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
42 {
43 if ( (h = key_table[key].u.irq_handler) != NULL )
44 (*h)(key, regs);
45 }
46 else
47 {
48 keypress_key = key;
49 raise_softirq(KEYPRESS_SOFTIRQ);
50 }
51 }
53 void register_keyhandler(
54 unsigned char key, keyhandler_t *handler, char *desc)
55 {
56 ASSERT(key_table[key].u.handler == NULL);
57 key_table[key].u.handler = handler;
58 key_table[key].flags = 0;
59 strncpy(key_table[key].desc, desc, STR_MAX);
60 key_table[key].desc[STR_MAX-1] = '\0';
61 }
63 void register_irq_keyhandler(
64 unsigned char key, irq_keyhandler_t *handler, char *desc)
65 {
66 ASSERT(key_table[key].u.irq_handler == NULL);
67 key_table[key].u.irq_handler = handler;
68 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK;
69 strncpy(key_table[key].desc, desc, STR_MAX);
70 key_table[key].desc[STR_MAX-1] = '\0';
71 }
73 static void show_handlers(unsigned char key)
74 {
75 int i;
76 printk("'%c' pressed -> showing installed handlers\n", key);
77 for ( i = 0; i < KEY_MAX; i++ )
78 if ( key_table[i].u.handler != NULL )
79 printk(" key '%c' (ascii '%02x') => %s\n",
80 (i<33 || i>126)?(' '):(i),i,
81 key_table[i].desc);
82 }
84 static void dump_registers(unsigned char key, struct xen_regs *regs)
85 {
86 printk("'%c' pressed -> dumping registers\n", key);
87 show_registers(regs);
88 }
90 static void halt_machine(unsigned char key, struct xen_regs *regs)
91 {
92 printk("'%c' pressed -> rebooting machine\n", key);
93 machine_restart(NULL);
94 }
96 void do_task_queues(unsigned char key)
97 {
98 struct domain *d;
99 struct exec_domain *ed;
100 s_time_t now = NOW();
102 printk("'%c' pressed -> dumping task queues (now=0x%X:%08X)\n", key,
103 (u32)(now>>32), (u32)now);
105 read_lock(&domlist_lock);
107 for_each_domain ( d )
108 {
109 printk("Xen: DOM %u, flags=%lx refcnt=%d nr_pages=%d "
110 "xenheap_pages=%d\n", d->id, d->d_flags,
111 atomic_read(&d->refcnt), d->tot_pages, d->xenheap_pages);
113 dump_pageframe_info(d);
115 for_each_exec_domain ( d, ed ) {
116 printk("Guest: %p CPU %d [has=%c] flags=%lx "
117 "upcall_pend = %02x, upcall_mask = %02x\n", ed,
118 ed->processor,
119 test_bit(EDF_RUNNING, &ed->ed_flags) ? 'T':'F',
120 ed->ed_flags,
121 ed->vcpu_info->evtchn_upcall_pending,
122 ed->vcpu_info->evtchn_upcall_mask);
123 printk("Notifying guest... %d/%d\n", d->id, ed->eid);
124 printk("port %d/%d stat %d %d %d\n",
125 VIRQ_DEBUG, ed->virq_to_evtchn[VIRQ_DEBUG],
126 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG], &d->shared_info->evtchn_pending[0]),
127 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG], &d->shared_info->evtchn_mask[0]),
128 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG]>>5, &ed->vcpu_info->evtchn_pending_sel));
129 send_guest_virq(ed, VIRQ_DEBUG);
130 }
131 }
133 read_unlock(&domlist_lock);
134 }
136 extern void dump_runq(unsigned char key);
137 extern void print_sched_histo(unsigned char key);
138 extern void reset_sched_histo(unsigned char key);
139 #ifndef NDEBUG
140 extern void audit_domains_key(unsigned char key);
141 #endif
143 #ifdef PERF_COUNTERS
144 extern void perfc_printall(unsigned char key);
145 extern void perfc_reset(unsigned char key);
146 #endif
148 void initialize_keytable(void)
149 {
150 open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
152 register_irq_keyhandler(
153 'd', dump_registers, "dump registers");
154 register_keyhandler(
155 'h', show_handlers, "show this message");
156 register_keyhandler(
157 'l', print_sched_histo, "print sched latency histogram");
158 register_keyhandler(
159 'L', reset_sched_histo, "reset sched latency histogram");
160 register_keyhandler(
161 'q', do_task_queues, "dump task queues + guest state");
162 register_keyhandler(
163 'r', dump_runq, "dump run queues");
164 register_irq_keyhandler(
165 'R', halt_machine, "reboot machine");
167 #ifndef NDEBUG
168 register_keyhandler(
169 'o', audit_domains_key, "audit domains >0 EXPERIMENTAL");
170 #endif
172 #ifdef PERF_COUNTERS
173 register_keyhandler(
174 'p', perfc_printall, "print performance counters");
175 register_keyhandler(
176 'P', perfc_reset, "reset performance counters");
177 #endif
178 }