ia64/xen-unstable

view xen/common/keyhandler.c @ 779:30c521db4c71

bitkeeper revision 1.475 (3f796d3bblNbmAFIYOUxNwNgsLILNg)

network.c, dev.c, keyhandler.c:
Stronger SMP memory barriers in the newtork code.
author kaf24@scramble.cl.cam.ac.uk
date Tue Sep 30 11:47:07 2003 +0000 (2003-09-30)
parents 5e39ada9640f
children 7e78d76f7ba6
line source
1 #include <xeno/keyhandler.h>
2 #include <xeno/reboot.h>
4 #define KEY_MAX 256
5 #define STR_MAX 64
7 typedef struct _key_te {
8 key_handler *handler;
9 char desc[STR_MAX];
10 } key_te_t;
12 static key_te_t key_table[KEY_MAX];
14 void add_key_handler(u_char key, key_handler *handler, char *desc)
15 {
16 int i;
17 char *str;
19 if(key_table[key].handler != NULL)
20 printk("Warning: overwriting handler for key 0x%x\n", key);
22 key_table[key].handler = handler;
24 str = key_table[key].desc;
25 for(i = 0; i < STR_MAX; i++) {
26 if(*desc)
27 *str++ = *desc++;
28 else break;
29 }
30 if (i == STR_MAX)
31 key_table[key].desc[STR_MAX-1] = '\0';
33 return;
34 }
36 key_handler *get_key_handler(u_char key)
37 {
38 return key_table[key].handler;
39 }
42 static void show_handlers(u_char key, void *dev_id, struct pt_regs *regs)
43 {
44 int i;
46 printk("'%c' pressed -> showing installed handlers\n", key);
47 for(i=0; i < KEY_MAX; i++)
48 if(key_table[i].handler)
49 printk(" key '%c' (ascii '%02x') => %s\n",
50 (i<33 || i>126)?(' '):(i),i,
51 key_table[i].desc);
52 return;
53 }
56 static void dump_registers(u_char key, void *dev_id, struct pt_regs *regs)
57 {
58 extern void show_registers(struct pt_regs *regs);
60 printk("'%c' pressed -> dumping registers\n", key);
61 show_registers(regs);
62 return;
63 }
65 static void halt_machine(u_char key, void *dev_id, struct pt_regs *regs)
66 {
67 printk("'%c' pressed -> rebooting machine\n", key);
68 machine_restart(NULL);
69 return;
70 }
72 static void kill_dom0(u_char key, void *dev_id, struct pt_regs *regs)
73 {
74 printk("'%c' pressed -> gracefully rebooting machine\n", key);
75 kill_other_domain(0, 0);
76 return;
77 }
80 /* XXX SMH: this is keir's fault */
81 static char *task_states[] =
82 {
83 "Runnable",
84 "Interruptible Sleep",
85 "Uninterruptible Sleep",
86 NULL, "Stopped",
87 NULL, NULL, NULL, "Dying",
88 };
90 void do_task_queues(u_char key, void *dev_id, struct pt_regs *regs)
91 {
92 unsigned long flags;
93 struct task_struct *p;
94 shared_info_t *s;
95 net_vif_t *v;
97 printk("'%c' pressed -> dumping task queues\n", key);
99 read_lock_irqsave(&tasklist_lock, flags);
101 p = &idle0_task;
102 do {
103 printk("Xen: DOM %d, CPU %d [has=%c], state = %s, "
104 "hyp_events = %08x\n",
105 p->domain, p->processor, p->has_cpu ? 'T':'F',
106 task_states[p->state], p->hyp_events);
107 s = p->shared_info;
108 if( !is_idle_task(p) )
109 {
110 net_vif_t *v = find_vif_by_id((p->domain)<<VIF_DOMAIN_SHIFT);
111 printk("Guest: events = %08lx, events_mask = %08lx\n",
112 s->events, s->events_mask);
114 if ( v != NULL )
115 {
116 printk("rx_prod=%d ,rx_cons=%d, tx_prod=%d, tx_cons=%d\n",
117 v->rx_prod, v->rx_cons, v->tx_prod, v->tx_cons );
118 printk("rx_req_cons=%d, rx_resp_prod=%d, "
119 "tx_req_cons=%d, tx_resp_prod=%d\n",
120 v->rx_req_cons, v->rx_resp_prod,
121 v->tx_req_cons, v->tx_resp_prod);
122 put_vif(v);
123 }
124 printk("Notifying guest...\n");
125 set_bit(_EVENT_DEBUG, &s->events);
126 }
127 } while ( (p = p->next_task) != &idle0_task );
129 read_unlock_irqrestore(&tasklist_lock, flags);
130 }
133 extern void perfc_printall (u_char key, void *dev_id, struct pt_regs *regs);
134 extern void perfc_reset (u_char key, void *dev_id, struct pt_regs *regs);
135 extern void dump_runq(u_char key, void *dev_id, struct pt_regs *regs);
136 extern void print_sched_histo(u_char key, void *dev_id, struct pt_regs *regs);
137 extern void reset_sched_histo(u_char key, void *dev_id, struct pt_regs *regs);
140 void initialize_keytable()
141 {
142 int i;
144 /* first initialize key handler table */
145 for(i = 0; i < KEY_MAX; i++)
146 key_table[i].handler = (key_handler *)NULL;
148 /* setup own handlers */
149 add_key_handler('d', dump_registers, "dump registers");
150 add_key_handler('h', show_handlers, "show this message");
151 add_key_handler('l', print_sched_histo, "print sched latency histogram");
152 add_key_handler('L', reset_sched_histo, "reset sched latency histogram");
153 add_key_handler('p', perfc_printall, "print performance counters");
154 add_key_handler('P', perfc_reset, "reset performance counters");
155 add_key_handler('q', do_task_queues, "dump task queues + guest state");
156 add_key_handler('r', dump_runq, "dump run queues");
157 add_key_handler('B', kill_dom0, "reboot machine gracefully");
158 add_key_handler('R', halt_machine, "reboot machine ungracefully");
160 return;
161 }