46 #include <linux/module.h>
47 #include <linux/slab.h>
48 #include <linux/sysctl.h>
49 #include <linux/device.h>
51 #include <linux/reboot.h>
64 .driver = &xpc_dbg_name
69 .driver = &xpc_dbg_name
75 static int xpc_kdebug_ignore;
80 static int xpc_hb_min_interval = 1;
81 static int xpc_hb_max_interval = 10;
84 static int xpc_hb_check_min_interval = 10;
85 static int xpc_hb_check_max_interval = 120;
88 static int xpc_disengage_min_timelimit;
89 static int xpc_disengage_max_timelimit = 120;
94 .data = &xpc_hb_interval,
95 .maxlen =
sizeof(
int),
98 .extra1 = &xpc_hb_min_interval,
99 .extra2 = &xpc_hb_max_interval},
101 .procname =
"hb_check_interval",
102 .data = &xpc_hb_check_interval,
103 .maxlen =
sizeof(
int),
106 .extra1 = &xpc_hb_check_min_interval,
107 .extra2 = &xpc_hb_check_max_interval},
114 .child = xpc_sys_xpc_hb_dir},
118 .maxlen =
sizeof(
int),
121 .extra1 = &xpc_disengage_min_timelimit,
122 .extra2 = &xpc_disengage_max_timelimit},
129 .child = xpc_sys_xpc_dir},
144 static unsigned long xpc_hb_check_timeout;
155 static int xpc_system_reboot(
struct notifier_block *,
unsigned long,
void *);
157 .notifier_call = xpc_system_reboot,
160 static int xpc_system_die(
struct notifier_block *,
unsigned long,
void *);
162 .notifier_call = xpc_system_die,
171 xpc_timeout_partition_disengage(
unsigned long data)
189 xpc_hb_beater(
unsigned long dummy)
196 xpc_hb_timer.expires =
jiffies + (xpc_hb_interval *
HZ);
201 xpc_start_hb_beater(
void)
205 xpc_hb_timer.function = xpc_hb_beater;
210 xpc_stop_hb_beater(
void)
221 xpc_check_remote_hb(
void)
253 xpc_hb_checker(
void *ignore)
262 xpc_hb_check_timeout =
jiffies + (xpc_hb_check_interval *
HZ);
263 xpc_start_hb_beater();
267 dev_dbg(xpc_part,
"woke up with %d ticks rem; %d IRQs have "
269 (
int)(xpc_hb_check_timeout - jiffies),
270 xpc_activate_IRQ_rcvd);
274 xpc_hb_check_timeout =
jiffies +
275 (xpc_hb_check_interval *
HZ);
277 dev_dbg(xpc_part,
"checking remote heartbeats\n");
278 xpc_check_remote_hb();
289 if (xpc_activate_IRQ_rcvd > 0 || force_IRQ != 0) {
291 dev_dbg(xpc_part,
"processing activate IRQs "
299 xpc_hb_check_timeout) ||
300 xpc_activate_IRQ_rcvd > 0 ||
304 xpc_stop_hb_beater();
306 dev_dbg(xpc_part,
"heartbeat checker is exiting\n");
319 xpc_initiate_discovery(
void *ignore)
323 dev_dbg(xpc_part,
"discovery thread is exiting\n");
382 *base = kzalloc(size, flags);
419 dev_err(xpc_chan,
"can't get memory for channels\n");
428 remote_openclose_args_base);
430 dev_err(xpc_chan,
"can't get memory for remote connect args\n");
446 for (ch_number = 0; ch_number < part->
nchannels; ch_number++) {
534 xpc_activating(
void *__partid)
536 short partid = (
u64)__partid;
538 unsigned long irq_flags;
546 spin_unlock_irqrestore(&part->
act_lock, irq_flags);
556 spin_unlock_irqrestore(&part->
act_lock, irq_flags);
558 dev_dbg(xpc_part,
"activating partition %d\n", partid);
562 if (xpc_setup_ch_structures(part) ==
xpSuccess) {
563 (
void)xpc_part_ref(part);
567 xpc_channel_mgr(part);
571 xpc_part_deref(part);
572 xpc_teardown_ch_structures(part);
590 unsigned long irq_flags;
600 spin_unlock_irqrestore(&part->
act_lock, irq_flags);
602 kthread =
kthread_run(xpc_activating, (
void *)((
u64)partid),
"xpc%02d",
604 if (IS_ERR(kthread)) {
608 spin_unlock_irqrestore(&part->
act_lock, irq_flags);
622 wakeup = (needed >
idle) ? idle : needed;
625 dev_dbg(xpc_chan,
"wakeup %d idle kthreads, partid=%d, "
641 dev_dbg(xpc_chan,
"create %d new kthreads, partid=%d, channel=%d\n",
659 while (n_of_deliverable_payloads(ch) > 0 &&
671 dev_dbg(xpc_chan,
"idle kthread calling "
672 "wait_event_interruptible_exclusive()\n");
675 (n_of_deliverable_payloads(ch) > 0 ||
684 xpc_kthread_start(
void *args)
691 unsigned long irq_flags;
695 dev_dbg(xpc_chan,
"kthread starting, partid=%d, channel=%d\n",
707 spin_unlock_irqrestore(&ch->
lock, irq_flags);
713 spin_unlock_irqrestore(&ch->
lock, irq_flags);
722 n_needed = n_of_deliverable_payloads(ch) - 1;
727 spin_unlock_irqrestore(&ch->
lock, irq_flags);
730 xpc_kthread_waitmsgs(part, ch);
739 spin_unlock_irqrestore(&ch->
lock, irq_flags);
746 spin_unlock_irqrestore(&ch->
lock, irq_flags);
753 xpc_msgqueue_deref(ch);
755 dev_dbg(xpc_chan,
"kthread exiting, partid=%d, channel=%d\n",
758 xpc_part_deref(part);
776 int ignore_disconnecting)
778 unsigned long irq_flags;
785 while (needed-- > 0) {
792 if (ignore_disconnecting) {
807 (
void)xpc_part_ref(part);
808 xpc_msgqueue_ref(ch);
810 kthread =
kthread_run(xpc_kthread_start, (
void *)args,
812 if (IS_ERR(kthread)) {
827 indicate_partition_disengaged(part);
829 xpc_msgqueue_deref(ch);
830 xpc_part_deref(part);
842 spin_unlock_irqrestore(&ch->
lock, irq_flags);
852 unsigned long irq_flags;
856 int wakeup_channel_mgr;
862 if (!xpc_part_ref(part))
868 xpc_part_deref(part);
876 wakeup_channel_mgr = 0;
884 wakeup_channel_mgr = 1;
890 spin_unlock_irqrestore(&ch->
lock, irq_flags);
892 if (wakeup_channel_mgr)
893 xpc_wakeup_channel_mgr(part);
895 xpc_part_deref(part);
900 xpc_setup_partitions(
void)
908 dev_err(xpc_part,
"can't get memory for partition structure\n");
932 xpc_timeout_partition_disengage;
944 xpc_teardown_partitions(
void)
954 int active_part_count, printed_waiting_msg = 0;
981 xpc_disengage_timedout = 0;
984 active_part_count = 0;
1004 dev_info(xpc_part,
"waiting for remote "
1005 "partitions to deactivate, timeout in "
1006 "%ld seconds\n", (disengage_timeout -
1010 printed_waiting_msg = 1;
1013 }
else if (active_part_count > 0) {
1014 if (printed_waiting_msg) {
1015 dev_info(xpc_part,
"waiting for local partition"
1016 " to deactivate\n");
1017 printed_waiting_msg = 0;
1021 if (!xpc_disengage_timedout) {
1022 dev_info(xpc_part,
"all partitions have "
1048 xpc_teardown_partitions();
1078 xpc_do_exit(reason);
1087 xpc_die_deactivate(
void)
1125 dev_info(xpc_part,
"all partitions have deactivated\n");
1129 if (!keep_waiting--) {
1133 dev_info(xpc_part,
"deactivate from "
1134 "remote partition %d timed "
1141 if (!wait_to_print--) {
1142 dev_info(xpc_part,
"waiting for remote partitions to "
1143 "deactivate, timeout in %ld seconds\n",
1144 keep_waiting / (1000 * 5));
1162 xpc_system_die(
struct notifier_block *nb,
unsigned long event,
void *unused)
1168 xpc_die_deactivate();
1173 if (!xpc_kdebug_ignore)
1184 if (!xpc_kdebug_ignore)
1194 xpc_die_deactivate();
1216 if (xp_max_npartitions != 64) {
1217 dev_err(xpc_part,
"max #of partitions not set to 64\n");
1223 }
else if (
is_uv()) {
1233 ret = xpc_setup_partitions();
1235 dev_err(xpc_part,
"can't get memory for partition structure\n");
1248 dev_err(xpc_part,
"can't setup our reserved page\n");
1255 dev_warn(xpc_part,
"can't register reboot notifier\n");
1260 dev_warn(xpc_part,
"can't register die notifier\n");
1267 if (IS_ERR(kthread)) {
1268 dev_err(xpc_part,
"failed while forking hb check thread\n");
1280 if (IS_ERR(kthread)) {
1281 dev_err(xpc_part,
"failed while forking discovery thread\n");
1307 xpc_teardown_partitions();
1332 "heartbeat increments.");
1336 "heartbeat checks.");
1340 "for disengage to complete.");
1343 MODULE_PARM_DESC(xpc_kdebug_ignore,
"Should lack of heartbeat be ignored by "
1344 "other partitions when dropping into kdebug.");