History

ipmi: Fix how the lower layers are told to watch for messages

The IPMI driver has a mechanism to tell the lower layers it needs to watch for messages, commands, and watchdogs (so it doesn't needlessly poll). However, it needed some extensions, it needed a way to tell what is being waited for so it could set the timeout appropriately. The update to the lower layer was also being done once a second at best because it was done in the main timeout handler. However, if a command is sent and a response message is coming back, it needed to be started immediately. So modify the code to update immediately if it needs to be enabled. Disable is still lazy.

Corey Minyard committed 8 years ago

Commit c65ea991 parent a1466ec4 files · +134 −52Browse files

Unified · Split

4 files
  1. drivers/char/ipmi/ipmi_msghandler.c +85 −34
  2. drivers/char/ipmi/ipmi_si_intf.c +4 −1
  3. drivers/char/ipmi/ipmi_ssif.c +16 −10
  4. include/linux/ipmi_smi.h +29 −7
drivers/char/ipmi/ipmi_msghandler.c+85−34
@@ -529,9 +529,22 @@ struct ipmi_smi { · 528 unmodified lines
529529 unsigned int waiting_events_count; /* How many events in queue? */
530530 char delivering_events;
531531 char event_msg_printed;
532+
533+ /* How many users are waiting for events? */
532534 atomic_t event_waiters;
533535 unsigned int ticks_to_req_ev;
534− int last_needs_timer;
536+
537+ /* How many users are waiting for commands? */
538+ atomic_t command_waiters;
539+
540+ /* How many users are waiting for watchdogs? */
541+ atomic_t watchdog_waiters;
542+
543+ /*
544+ * Tells what the lower layer has last been asked to watch for,
545+ * messages and/or watchdogs. Protected by xmit_msgs_lock.
546+ */
547+ unsigned int last_watch_mask;
535548
536549 /*
537550 * The event receiver for my BMC, only really used at panic
@@ -1078,6 +1091,29 @@ static int intf_err_seq(struct ipmi_smi *intf, · 540 unmodified lines
10781091 return rv;
10791092 }
10801093
1094+/* Must be called with xmit_msgs_lock held. */
1095+static void smi_tell_to_watch(struct ipmi_smi *intf,
1096+ unsigned int flags,
1097+ struct ipmi_smi_msg *smi_msg)
1098+{
1099+ if (flags & IPMI_WATCH_MASK_CHECK_MESSAGES) {
1100+ if (!smi_msg)
1101+ return;
1102+
1103+ if (!smi_msg->needs_response)
1104+ return;
1105+ }
1106+
1107+ if (!intf->handlers->set_need_watch)
1108+ return;
1109+
1110+ if ((intf->last_watch_mask & flags) == flags)
1111+ return;
1112+
1113+ intf->last_watch_mask |= flags;
1114+ intf->handlers->set_need_watch(intf->send_info,
1115+ intf->last_watch_mask);
1116+}
10811117
10821118 int ipmi_create_user(unsigned int if_num,
10831119 const struct ipmi_user_hndl *handler,
@@ -1141,8 +1177,9 @@ int ipmi_create_user(unsigned int if_num, · 57 unmodified lines
11411177 spin_unlock_irqrestore(&intf->seq_lock, flags);
11421178 if (handler->ipmi_watchdog_pretimeout) {
11431179 /* User wants pretimeouts, so make sure to watch for them. */
1144− if (atomic_inc_return(&intf->event_waiters) == 1)
1145− need_waiter(intf);
1180+ if (atomic_inc_return(&intf->watchdog_waiters) == 1)
1181+ smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG,
1182+ NULL);
11461183 }
11471184 srcu_read_unlock(&ipmi_interfaces_srcu, index);
11481185 *user = new_user;
@@ -1214,7 +1251,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) · 65 unmodified lines
12141251 user->handler->shutdown(user->handler_data);
12151252
12161253 if (user->handler->ipmi_watchdog_pretimeout)
1217− atomic_dec(&intf->event_waiters);
1254+ atomic_dec(&intf->watchdog_waiters);
12181255
12191256 if (user->gets_events)
12201257 atomic_dec(&intf->event_waiters);
@@ -1569,8 +1606,8 @@ int ipmi_register_for_cmd(struct ipmi_user *user, · 348 unmodified lines
15691606 goto out_unlock;
15701607 }
15711608
1572− if (atomic_inc_return(&intf->event_waiters) == 1)
1573− need_waiter(intf);
1609+ if (atomic_inc_return(&intf->command_waiters) == 1)
1610+ smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS, NULL);
15741611
15751612 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs);
15761613
@@ -1620,7 +1657,7 @@ int ipmi_unregister_for_cmd(struct ipmi_user *user, · 43 unmodified lines
16201657 synchronize_rcu();
16211658 release_ipmi_user(user, index);
16221659 while (rcvrs) {
1623− atomic_dec(&intf->event_waiters);
1660+ atomic_dec(&intf->command_waiters);
16241661 rcvr = rcvrs;
16251662 rcvrs = rcvr->next;
16261663 kfree(rcvr);
@@ -1737,22 +1774,21 @@ static struct ipmi_smi_msg *smi_add_send_msg(struct ipmi_smi *intf, · 110 unmodified lines
17371774 return smi_msg;
17381775 }
17391776
1740−
17411777 static void smi_send(struct ipmi_smi *intf,
17421778 const struct ipmi_smi_handlers *handlers,
17431779 struct ipmi_smi_msg *smi_msg, int priority)
17441780 {
17451781 int run_to_completion = intf->run_to_completion;
1782+ unsigned long flags = 0;
17461783
1747− if (run_to_completion) {
1748− smi_msg = smi_add_send_msg(intf, smi_msg, priority);
1749− } else {
1750− unsigned long flags;
1751−
1784+ if (!run_to_completion)
17521785 spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
1753− smi_msg = smi_add_send_msg(intf, smi_msg, priority);
1786+ smi_msg = smi_add_send_msg(intf, smi_msg, priority);
1787+
1788+ smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, smi_msg);
1789+
1790+ if (!run_to_completion)
17541791 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
1755− }
17561792
17571793 if (smi_msg)
17581794 handlers->sender(intf->send_info, smi_msg);
@@ -1950,6 +1986,9 @@ static int i_ipmi_req_ipmb(struct ipmi_smi *intf, · 191 unmodified lines
19501986 ipmb_seq, broadcast,
19511987 source_address, source_lun);
19521988
1989+ /* We will be getting a response in the BMC message queue. */
1990+ smi_msg->needs_response = true;
1991+
19531992 /*
19541993 * Copy the message into the recv message data, so we
19551994 * can retransmit it later if necessary.
@@ -2137,6 +2176,7 @@ static int i_ipmi_request(struct ipmi_user *user, · 181 unmodified lines
21372176 goto out;
21382177 }
21392178 }
2179+ smi_msg->needs_response = false;
21402180
21412181 rcu_read_lock();
21422182 if (intf->in_shutdown) {
@@ -3351,6 +3391,8 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, · 1208 unmodified lines
33513391 INIT_LIST_HEAD(&intf->hp_xmit_msgs);
33523392 spin_lock_init(&intf->events_lock);
33533393 atomic_set(&intf->event_waiters, 0);
3394+ atomic_set(&intf->watchdog_waiters, 0);
3395+ atomic_set(&intf->command_waiters, 0);
33543396 intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
33553397 INIT_LIST_HEAD(&intf->waiting_events);
33563398 intf->waiting_events_count = 0;
@@ -4365,6 +4407,9 @@ static void smi_recv_tasklet(unsigned long val) · 1008 unmodified lines
43654407 intf->curr_msg = newmsg;
43664408 }
43674409 }
4410+
4411+ smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, newmsg);
4412+
43684413 if (!run_to_completion)
43694414 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
43704415 if (newmsg)
@@ -4492,7 +4537,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 121 unmodified lines
44924537 struct list_head *timeouts,
44934538 unsigned long timeout_period,
44944539 int slot, unsigned long *flags,
4495− unsigned int *waiting_msgs)
4540+ unsigned int *watch_mask)
44964541 {
44974542 struct ipmi_recv_msg *msg;
44984543
@@ -4504,7 +4549,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 5 unmodified lines
45044549
45054550 if (timeout_period < ent->timeout) {
45064551 ent->timeout -= timeout_period;
4507− (*waiting_msgs)++;
4552+ *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES;
45084553 return;
45094554 }
45104555
@@ -4523,7 +4568,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 12 unmodified lines
45234568 struct ipmi_smi_msg *smi_msg;
45244569 /* More retries, send again. */
45254570
4526− (*waiting_msgs)++;
4571+ *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES;
45274572
45284573 /*
45294574 * Start with the max timer, set to normal timer after
@@ -4575,13 +4620,13 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 45 unmodified lines
45754620 struct ipmi_recv_msg *msg, *msg2;
45764621 unsigned long flags;
45774622 int i;
4578− unsigned int waiting_msgs = 0;
4623+ unsigned int watch_mask = 0;
45794624
45804625 if (!intf->bmc_registered) {
45814626 kref_get(&intf->refcount);
45824627 if (!schedule_work(&intf->bmc_reg_work)) {
45834628 kref_put(&intf->refcount, intf_free);
4584− waiting_msgs++;
4629+ watch_mask |= IPMI_WATCH_MASK_INTERNAL;
45854630 }
45864631 }
45874632
@@ -4601,7 +4646,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 13 unmodified lines
46014646 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
46024647 check_msg_timeout(intf, &intf->seq_table[i],
46034648 &timeouts, timeout_period, i,
4604− &flags, &waiting_msgs);
4649+ &flags, &watch_mask);
46054650 spin_unlock_irqrestore(&intf->seq_lock, flags);
46064651
46074652 list_for_each_entry_safe(msg, msg2, &timeouts, link)
@@ -4632,7 +4677,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 24 unmodified lines
46324677
46334678 tasklet_schedule(&intf->recv_tasklet);
46344679
4635− return waiting_msgs;
4680+ return watch_mask;
46364681 }
46374682
46384683 static void ipmi_request_event(struct ipmi_smi *intf)
@@ -4652,37 +4697,43 @@ static atomic_t stop_operation; · 13 unmodified lines
46524697 static void ipmi_timeout(struct timer_list *unused)
46534698 {
46544699 struct ipmi_smi *intf;
4655− int nt = 0, index;
4700+ unsigned int watch_mask = 0;
4701+ int index;
4702+ unsigned long flags;
46564703
46574704 if (atomic_read(&stop_operation))
46584705 return;
46594706
46604707 index = srcu_read_lock(&ipmi_interfaces_srcu);
46614708 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
4662− int lnt = 0;
4663−
46644709 if (atomic_read(&intf->event_waiters)) {
46654710 intf->ticks_to_req_ev--;
46664711 if (intf->ticks_to_req_ev == 0) {
46674712 ipmi_request_event(intf);
46684713 intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
46694714 }
4670− lnt++;
4715+ watch_mask |= IPMI_WATCH_MASK_INTERNAL;
46714716 }
46724717
4673− lnt += ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME);
4718+ if (atomic_read(&intf->watchdog_waiters))
4719+ watch_mask |= IPMI_WATCH_MASK_CHECK_WATCHDOG;
46744720
4675− lnt = !!lnt;
4676− if (lnt != intf->last_needs_timer &&
4677− intf->handlers->set_need_watch)
4678− intf->handlers->set_need_watch(intf->send_info, lnt);
4679− intf->last_needs_timer = lnt;
4721+ if (atomic_read(&intf->command_waiters))
4722+ watch_mask |= IPMI_WATCH_MASK_CHECK_COMMANDS;
4723+
4724+ watch_mask |= ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME);
46804725
4681− nt += lnt;
4726+ spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
4727+ if (watch_mask != intf->last_watch_mask &&
4728+ intf->handlers->set_need_watch)
4729+ intf->handlers->set_need_watch(intf->send_info,
4730+ watch_mask);
4731+ intf->last_watch_mask = watch_mask;
4732+ spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
46824733 }
46834734 srcu_read_unlock(&ipmi_interfaces_srcu, index);
46844735
4685− if (nt)
4736+ if (watch_mask)
46864737 mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
46874738 }
46884739
drivers/char/ipmi/ipmi_si_intf.c+4−1
@@ -1060,10 +1060,13 @@ static void request_events(void *send_info) · 1059 unmodified lines
10601060 atomic_set(&smi_info->req_events, 1);
10611061 }
10621062
1063−static void set_need_watch(void *send_info, bool enable)
1063+static void set_need_watch(void *send_info, unsigned int watch_mask)
10641064 {
10651065 struct smi_info *smi_info = send_info;
10661066 unsigned long flags;
1067+ int enable;
1068+
1069+ enable = !!(watch_mask & ~IPMI_WATCH_MASK_INTERNAL);
10671070
10681071 atomic_set(&smi_info->need_watch, enable);
10691072 spin_lock_irqsave(&smi_info->si_lock, flags);
drivers/char/ipmi/ipmi_ssif.c+16−10
@@ -93,8 +93,8 @@ · 92 unmodified lines
9393 /*
9494 * Timeout for the watch, only used for get flag timer.
9595 */
96−#define SSIF_WATCH_TIMEOUT_MSEC 100
97−#define SSIF_WATCH_TIMEOUT_JIFFIES msecs_to_jiffies(SSIF_WATCH_TIMEOUT_MSEC)
96+#define SSIF_WATCH_MSG_TIMEOUT msecs_to_jiffies(10)
97+#define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250)
9898
9999 enum ssif_intf_state {
100100 SSIF_NORMAL,
@@ -276,7 +276,7 @@ struct ssif_info { · 175 unmodified lines
276276 struct timer_list retry_timer;
277277 int retries_left;
278278
279− bool need_watch; /* Need to look for flags? */
279+ long watch_timeout; /* Timeout for flags check, 0 if off. */
280280 struct timer_list watch_timer; /* Flag fetch timer. */
281281
282282 /* Info from SSIF cmd */
@@ -578,9 +578,9 @@ static void watch_timeout(struct timer_list *t) · 295 unmodified lines
578578 return;
579579
580580 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
581− if (ssif_info->need_watch) {
581+ if (ssif_info->watch_timeout) {
582582 mod_timer(&ssif_info->watch_timer,
583− jiffies + SSIF_WATCH_TIMEOUT_JIFFIES);
583+ jiffies + ssif_info->watch_timeout);
584584 if (SSIF_IDLE(ssif_info)) {
585585 start_flag_fetch(ssif_info, flags); /* Releases lock */
586586 return;
@@ -1121,17 +1121,23 @@ static void request_events(void *send_info) · 534 unmodified lines
11211121 * Upper layer is changing the flag saying whether we need to request
11221122 * flags periodically or not.
11231123 */
1124−static void ssif_set_need_watch(void *send_info, bool enable)
1124+static void ssif_set_need_watch(void *send_info, unsigned int watch_mask)
11251125 {
11261126 struct ssif_info *ssif_info = (struct ssif_info *) send_info;
11271127 unsigned long oflags, *flags;
1128+ long timeout = 0;
1129+
1130+ if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES)
1131+ timeout = SSIF_WATCH_MSG_TIMEOUT;
1132+ else if (watch_mask & ~IPMI_WATCH_MASK_INTERNAL)
1133+ timeout = SSIF_WATCH_WATCHDOG_TIMEOUT;
11281134
11291135 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
1130− if (enable != ssif_info->need_watch) {
1131− ssif_info->need_watch = enable;
1132− if (ssif_info->need_watch)
1136+ if (timeout != ssif_info->watch_timeout) {
1137+ ssif_info->watch_timeout = timeout;
1138+ if (ssif_info->watch_timeout)
11331139 mod_timer(&ssif_info->watch_timer,
1134− jiffies + SSIF_WATCH_TIMEOUT_JIFFIES);
1140+ jiffies + ssif_info->watch_timeout);
11351141 }
11361142 ipmi_ssif_unlock_cond(ssif_info, flags);
11371143 }
include/linux/ipmi_smi.h+29−7
@@ -30,6 +30,17 @@ struct device; · 29 unmodified lines
3030 /* Structure for the low-level drivers. */
3131 struct ipmi_smi;
3232
33+/*
34+ * Flags for set_check_watch() below. Tells if the SMI should be
35+ * waiting for watchdog timeouts, commands and/or messages. There is
36+ * also an internal flag for the message handler, SMIs should ignore
37+ * it.
38+ */
39+#define IPMI_WATCH_MASK_INTERNAL (1 << 0)
40+#define IPMI_WATCH_MASK_CHECK_MESSAGES (1 << 1)
41+#define IPMI_WATCH_MASK_CHECK_WATCHDOG (1 << 2)
42+#define IPMI_WATCH_MASK_CHECK_COMMANDS (1 << 3)
43+
3344 /*
3445 * Messages to/from the lower layer. The smi interface will take one
3546 * of these to send. After the send has occurred and a response has
@@ -55,8 +66,16 @@ struct ipmi_smi_msg { · 19 unmodified lines
5566 int rsp_size;
5667 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
5768
58− /* Will be called when the system is done with the message
59− (presumably to free it). */
69+ /*
70+ * There should be a response message coming back in the BMC
71+ * message queue.
72+ */
73+ bool needs_response;
74+
75+ /*
76+ * Will be called when the system is done with the message
77+ * (presumably to free it).
78+ */
6079 void (*done)(struct ipmi_smi_msg *msg);
6180 };
6281
@@ -105,12 +124,15 @@ struct ipmi_smi_handlers { · 42 unmodified lines
105124
106125 /*
107126 * Called by the upper layer when some user requires that the
108− * interface watch for events, received messages, watchdog
109− * pretimeouts, or not. Used by the SMI to know if it should
110− * watch for these. This may be NULL if the SMI does not
111− * implement it.
127+ * interface watch for received messages and watchdog
128+ * pretimeouts (basically do a "Get Flags", or not. Used by
129+ * the SMI to know if it should watch for these. This may be
130+ * NULL if the SMI does not implement it. watch_mask is from
131+ * IPMI_WATCH_MASK_xxx above. The interface should run slower
132+ * timeouts for just watchdog checking or faster timeouts when
133+ * waiting for the message queue.
112134 */
113− void (*set_need_watch)(void *send_info, bool enable);
135+ void (*set_need_watch)(void *send_info, unsigned int watch_mask);
114136
115137 /*
116138 * Called when flushing all pending messages.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t