History

ipmi: Make the smi watcher be disabled immediately when not needed

The code to tell the lower layer to enable or disable watching for certain things was lazy in disabling, it waited until a timer tick to see if a disable was necessary. Not a really big deal, but it could be improved. Modify the code to enable and disable watching immediately and don't do it from the background timer any more.

Corey Minyard committed 8 years ago

Commit e1891cf1 parent c65ea994 files · +96 −89Browse files

Unified · Split

4 files
  1. drivers/char/ipmi/ipmi_msghandler.c +90 −74
  2. drivers/char/ipmi/ipmi_si_intf.c +1 −1
  3. drivers/char/ipmi/ipmi_ssif.c +1 −1
  4. include/linux/ipmi_smi.h +4 −13
drivers/char/ipmi/ipmi_msghandler.c+90−74
@@ -534,15 +534,20 @@ struct ipmi_smi { · 533 unmodified lines
534534 atomic_t event_waiters;
535535 unsigned int ticks_to_req_ev;
536536
537+ spinlock_t watch_lock; /* For dealing with watch stuff below. */
538+
537539 /* How many users are waiting for commands? */
538− atomic_t command_waiters;
540+ unsigned int command_waiters;
539541
540542 /* How many users are waiting for watchdogs? */
541− atomic_t watchdog_waiters;
543+ unsigned int watchdog_waiters;
544+
545+ /* How many users are waiting for message responses? */
546+ unsigned int response_waiters;
542547
543548 /*
544549 * Tells what the lower layer has last been asked to watch for,
545− * messages and/or watchdogs. Protected by xmit_msgs_lock.
550+ * messages and/or watchdogs. Protected by watch_lock.
546551 */
547552 unsigned int last_watch_mask;
548553
@@ -938,6 +943,64 @@ static void deliver_err_response(struct ipmi_smi *intf, · 389 unmodified lines
938943 deliver_local_response(intf, msg);
939944 }
940945
946+static void smi_add_watch(struct ipmi_smi *intf, unsigned int flags)
947+{
948+ unsigned long iflags;
949+
950+ if (!intf->handlers->set_need_watch)
951+ return;
952+
953+ spin_lock_irqsave(&intf->watch_lock, iflags);
954+ if (flags & IPMI_WATCH_MASK_CHECK_MESSAGES)
955+ intf->response_waiters++;
956+
957+ if (flags & IPMI_WATCH_MASK_CHECK_WATCHDOG)
958+ intf->watchdog_waiters++;
959+
960+ if (flags & IPMI_WATCH_MASK_CHECK_COMMANDS)
961+ intf->command_waiters++;
962+
963+ if ((intf->last_watch_mask & flags) != flags) {
964+ intf->last_watch_mask |= flags;
965+ intf->handlers->set_need_watch(intf->send_info,
966+ intf->last_watch_mask);
967+ }
968+ spin_unlock_irqrestore(&intf->watch_lock, iflags);
969+}
970+
971+static void smi_remove_watch(struct ipmi_smi *intf, unsigned int flags)
972+{
973+ unsigned long iflags;
974+
975+ if (!intf->handlers->set_need_watch)
976+ return;
977+
978+ spin_lock_irqsave(&intf->watch_lock, iflags);
979+ if (flags & IPMI_WATCH_MASK_CHECK_MESSAGES)
980+ intf->response_waiters--;
981+
982+ if (flags & IPMI_WATCH_MASK_CHECK_WATCHDOG)
983+ intf->watchdog_waiters--;
984+
985+ if (flags & IPMI_WATCH_MASK_CHECK_COMMANDS)
986+ intf->command_waiters--;
987+
988+ flags = 0;
989+ if (intf->response_waiters)
990+ flags |= IPMI_WATCH_MASK_CHECK_MESSAGES;
991+ if (intf->watchdog_waiters)
992+ flags |= IPMI_WATCH_MASK_CHECK_WATCHDOG;
993+ if (intf->command_waiters)
994+ flags |= IPMI_WATCH_MASK_CHECK_COMMANDS;
995+
996+ if (intf->last_watch_mask != flags) {
997+ intf->last_watch_mask = flags;
998+ intf->handlers->set_need_watch(intf->send_info,
999+ intf->last_watch_mask);
1000+ }
1001+ spin_unlock_irqrestore(&intf->watch_lock, iflags);
1002+}
1003+
9411004 /*
9421005 * Find the next sequence number not being used and add the given
9431006 * message with the given timeout to the sequence table. This must be
@@ -981,6 +1044,7 @@ static int intf_next_seq(struct ipmi_smi *intf, · 37 unmodified lines
9811044 *seq = i;
9821045 *seqid = intf->seq_table[i].seqid;
9831046 intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ;
1047+ smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
9841048 need_waiter(intf);
9851049 } else {
9861050 rv = -EAGAIN;
@@ -1019,6 +1083,7 @@ static int intf_find_seq(struct ipmi_smi *intf, · 32 unmodified lines
10191083 && (ipmi_addr_equal(addr, &msg->addr))) {
10201084 *recv_msg = msg;
10211085 intf->seq_table[seq].inuse = 0;
1086+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
10221087 rv = 0;
10231088 }
10241089 }
@@ -1080,6 +1145,7 @@ static int intf_err_seq(struct ipmi_smi *intf, · 55 unmodified lines
10801145 struct seq_table *ent = &intf->seq_table[seq];
10811146
10821147 ent->inuse = 0;
1148+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
10831149 msg = ent->recv_msg;
10841150 rv = 0;
10851151 }
@@ -1091,30 +1157,6 @@ static int intf_err_seq(struct ipmi_smi *intf, · 5 unmodified lines
10911157 return rv;
10921158 }
10931159
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−}
1117−
11181160 int ipmi_create_user(unsigned int if_num,
11191161 const struct ipmi_user_hndl *handler,
11201162 void *handler_data,
@@ -1175,12 +1217,9 @@ int ipmi_create_user(unsigned int if_num, · 54 unmodified lines
11751217 spin_lock_irqsave(&intf->seq_lock, flags);
11761218 list_add_rcu(&new_user->link, &intf->users);
11771219 spin_unlock_irqrestore(&intf->seq_lock, flags);
1178− if (handler->ipmi_watchdog_pretimeout) {
1220+ if (handler->ipmi_watchdog_pretimeout)
11791221 /* User wants pretimeouts, so make sure to watch for them. */
1180− if (atomic_inc_return(&intf->watchdog_waiters) == 1)
1181− smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG,
1182− NULL);
1183− }
1222+ smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG);
11841223 srcu_read_unlock(&ipmi_interfaces_srcu, index);
11851224 *user = new_user;
11861225 return 0;
@@ -1251,7 +1290,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) · 64 unmodified lines
12511290 user->handler->shutdown(user->handler_data);
12521291
12531292 if (user->handler->ipmi_watchdog_pretimeout)
1254− atomic_dec(&intf->watchdog_waiters);
1293+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG);
12551294
12561295 if (user->gets_events)
12571296 atomic_dec(&intf->event_waiters);
@@ -1264,6 +1303,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) · 6 unmodified lines
12641303 if (intf->seq_table[i].inuse
12651304 && (intf->seq_table[i].recv_msg->user == user)) {
12661305 intf->seq_table[i].inuse = 0;
1306+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
12671307 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
12681308 }
12691309 }
@@ -1606,8 +1646,7 @@ int ipmi_register_for_cmd(struct ipmi_user *user, · 336 unmodified lines
16061646 goto out_unlock;
16071647 }
16081648
1609− if (atomic_inc_return(&intf->command_waiters) == 1)
1610− smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS, NULL);
1649+ smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS);
16111650
16121651 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs);
16131652
@@ -1657,7 +1696,7 @@ int ipmi_unregister_for_cmd(struct ipmi_user *user, · 43 unmodified lines
16571696 synchronize_rcu();
16581697 release_ipmi_user(user, index);
16591698 while (rcvrs) {
1660− atomic_dec(&intf->command_waiters);
1699+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_COMMANDS);
16611700 rcvr = rcvrs;
16621701 rcvrs = rcvr->next;
16631702 kfree(rcvr);
@@ -1785,8 +1824,6 @@ static void smi_send(struct ipmi_smi *intf, · 121 unmodified lines
17851824 spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
17861825 smi_msg = smi_add_send_msg(intf, smi_msg, priority);
17871826
1788− smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, smi_msg);
1789−
17901827 if (!run_to_completion)
17911828 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
17921829
@@ -1986,9 +2023,6 @@ static int i_ipmi_req_ipmb(struct ipmi_smi *intf, · 193 unmodified lines
19862023 ipmb_seq, broadcast,
19872024 source_address, source_lun);
19882025
1989− /* We will be getting a response in the BMC message queue. */
1990− smi_msg->needs_response = true;
1991−
19922026 /*
19932027 * Copy the message into the recv message data, so we
19942028 * can retransmit it later if necessary.
@@ -2176,7 +2210,6 @@ static int i_ipmi_request(struct ipmi_user *user, · 181 unmodified lines
21762210 goto out;
21772211 }
21782212 }
2179− smi_msg->needs_response = false;
21802213
21812214 rcu_read_lock();
21822215 if (intf->in_shutdown) {
@@ -3390,9 +3423,8 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, · 1207 unmodified lines
33903423 INIT_LIST_HEAD(&intf->xmit_msgs);
33913424 INIT_LIST_HEAD(&intf->hp_xmit_msgs);
33923425 spin_lock_init(&intf->events_lock);
3426+ spin_lock_init(&intf->watch_lock);
33933427 atomic_set(&intf->event_waiters, 0);
3394− atomic_set(&intf->watchdog_waiters, 0);
3395− atomic_set(&intf->command_waiters, 0);
33963428 intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
33973429 INIT_LIST_HEAD(&intf->waiting_events);
33983430 intf->waiting_events_count = 0;
@@ -4408,8 +4440,6 @@ static void smi_recv_tasklet(unsigned long val) · 1009 unmodified lines
44084440 }
44094441 }
44104442
4411− smi_tell_to_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES, newmsg);
4412−
44134443 if (!run_to_completion)
44144444 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
44154445 if (newmsg)
@@ -4537,7 +4567,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 121 unmodified lines
45374567 struct list_head *timeouts,
45384568 unsigned long timeout_period,
45394569 int slot, unsigned long *flags,
4540− unsigned int *watch_mask)
4570+ bool *need_timer)
45414571 {
45424572 struct ipmi_recv_msg *msg;
45434573
@@ -4549,13 +4579,14 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 5 unmodified lines
45494579
45504580 if (timeout_period < ent->timeout) {
45514581 ent->timeout -= timeout_period;
4552− *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES;
4582+ *need_timer = true;
45534583 return;
45544584 }
45554585
45564586 if (ent->retries_left == 0) {
45574587 /* The message has used all its retries. */
45584588 ent->inuse = 0;
4589+ smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
45594590 msg = ent->recv_msg;
45604591 list_add_tail(&msg->link, timeouts);
45614592 if (ent->broadcast)
@@ -4568,7 +4599,7 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 6 unmodified lines
45684599 struct ipmi_smi_msg *smi_msg;
45694600 /* More retries, send again. */
45704601
4571− *watch_mask |= IPMI_WATCH_MASK_CHECK_MESSAGES;
4602+ *need_timer = true;
45724603
45734604 /*
45744605 * Start with the max timer, set to normal timer after
@@ -4613,20 +4644,20 @@ static void check_msg_timeout(struct ipmi_smi *intf, struct seq_table *ent, · 38 unmodified lines
46134644 }
46144645 }
46154646
4616−static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf,
4617− unsigned long timeout_period)
4647+static bool ipmi_timeout_handler(struct ipmi_smi *intf,
4648+ unsigned long timeout_period)
46184649 {
46194650 struct list_head timeouts;
46204651 struct ipmi_recv_msg *msg, *msg2;
46214652 unsigned long flags;
46224653 int i;
4623− unsigned int watch_mask = 0;
4654+ bool need_timer = false;
46244655
46254656 if (!intf->bmc_registered) {
46264657 kref_get(&intf->refcount);
46274658 if (!schedule_work(&intf->bmc_reg_work)) {
46284659 kref_put(&intf->refcount, intf_free);
4629− watch_mask |= IPMI_WATCH_MASK_INTERNAL;
4660+ need_timer = true;
46304661 }
46314662 }
46324663
@@ -4646,7 +4677,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 13 unmodified lines
46464677 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
46474678 check_msg_timeout(intf, &intf->seq_table[i],
46484679 &timeouts, timeout_period, i,
4649− &flags, &watch_mask);
4680+ &flags, &need_timer);
46504681 spin_unlock_irqrestore(&intf->seq_lock, flags);
46514682
46524683 list_for_each_entry_safe(msg, msg2, &timeouts, link)
@@ -4677,7 +4708,7 @@ static unsigned int ipmi_timeout_handler(struct ipmi_smi *intf, · 24 unmodified lines
46774708
46784709 tasklet_schedule(&intf->recv_tasklet);
46794710
4680− return watch_mask;
4711+ return need_timer;
46814712 }
46824713
46834714 static void ipmi_request_event(struct ipmi_smi *intf)
@@ -4697,9 +4728,8 @@ static atomic_t stop_operation; · 13 unmodified lines
46974728 static void ipmi_timeout(struct timer_list *unused)
46984729 {
46994730 struct ipmi_smi *intf;
4700− unsigned int watch_mask = 0;
4731+ bool need_timer = false;
47014732 int index;
4702− unsigned long flags;
47034733
47044734 if (atomic_read(&stop_operation))
47054735 return;
@@ -4712,28 +4742,14 @@ static void ipmi_timeout(struct timer_list *unused) · 6 unmodified lines
47124742 ipmi_request_event(intf);
47134743 intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
47144744 }
4715− watch_mask |= IPMI_WATCH_MASK_INTERNAL;
4745+ need_timer = true;
47164746 }
47174747
4718− if (atomic_read(&intf->watchdog_waiters))
4719− watch_mask |= IPMI_WATCH_MASK_CHECK_WATCHDOG;
4720−
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);
4725−
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);
4748+ need_timer |= ipmi_timeout_handler(intf, IPMI_TIMEOUT_TIME);
47334749 }
47344750 srcu_read_unlock(&ipmi_interfaces_srcu, index);
47354751
4736− if (watch_mask)
4752+ if (need_timer)
47374753 mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
47384754 }
47394755
drivers/char/ipmi/ipmi_si_intf.c+1−1
@@ -1066,7 +1066,7 @@ static void set_need_watch(void *send_info, unsigned int watch_mask) · 1065 unmodified lines
10661066 unsigned long flags;
10671067 int enable;
10681068
1069− enable = !!(watch_mask & ~IPMI_WATCH_MASK_INTERNAL);
1069+ enable = !!watch_mask;
10701070
10711071 atomic_set(&smi_info->need_watch, enable);
10721072 spin_lock_irqsave(&smi_info->si_lock, flags);
drivers/char/ipmi/ipmi_ssif.c+1−1
@@ -1129,7 +1129,7 @@ static void ssif_set_need_watch(void *send_info, unsigned int watch_mask) · 1128 unmodified lines
11291129
11301130 if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES)
11311131 timeout = SSIF_WATCH_MSG_TIMEOUT;
1132− else if (watch_mask & ~IPMI_WATCH_MASK_INTERNAL)
1132+ else if (watch_mask)
11331133 timeout = SSIF_WATCH_WATCHDOG_TIMEOUT;
11341134
11351135 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
include/linux/ipmi_smi.h+4−13
@@ -32,14 +32,11 @@ struct ipmi_smi; · 31 unmodified lines
3232
3333 /*
3434 * 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.
35+ * waiting for watchdog timeouts, commands and/or messages.
3836 */
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)
37+#define IPMI_WATCH_MASK_CHECK_MESSAGES (1 << 0)
38+#define IPMI_WATCH_MASK_CHECK_WATCHDOG (1 << 1)
39+#define IPMI_WATCH_MASK_CHECK_COMMANDS (1 << 2)
4340
4441 /*
4542 * Messages to/from the lower layer. The smi interface will take one
@@ -66,12 +63,6 @@ struct ipmi_smi_msg { · 20 unmodified lines
6663 int rsp_size;
6764 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
6865
69− /*
70− * There should be a response message coming back in the BMC
71− * message queue.
72− */
73− bool needs_response;
74−
7566 /*
7667 * Will be called when the system is done with the message
7768 * (presumably to free it).

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