History

spi: Go back to immediate teardown

Commit 412e6037324 ("spi: core: avoid waking pump thread from spi_sync instead run teardown delayed") introduced regressions on some boards, apparently connected to spi_mem not triggering shutdown properly any more. Since we've thus far been unable to figure out exactly where the breakage is revert the optimisation for now.

Mark Brown committed 7 years ago

Commit f0125f11 parent 51eea522 files · +33 −91Browse files

Unified · Split

2 files
  1. drivers/spi/spi.c +33 −89
  2. include/linux/spi/spi.h +0 −2
drivers/spi/spi.c+33−89
@@ -1225,7 +1225,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) · 1224 unmodified lines
12251225 return;
12261226 }
12271227
1228− /* If another context is idling the device then defer to kthread */
1228+ /* If another context is idling the device then defer */
12291229 if (ctlr->idling) {
12301230 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
12311231 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
@@ -1239,10 +1239,34 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) · 7 unmodified lines
12391239 return;
12401240 }
12411241
1242− /* schedule idle teardown with a delay of 1 second */
1243− kthread_mod_delayed_work(&ctlr->kworker,
1244− &ctlr->pump_idle_teardown,
1245− HZ);
1242+ /* Only do teardown in the thread */
1243+ if (!in_kthread) {
1244+ kthread_queue_work(&ctlr->kworker,
1245+ &ctlr->pump_messages);
1246+ spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1247+ return;
1248+ }
1249+
1250+ ctlr->busy = false;
1251+ ctlr->idling = true;
1252+ spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1253+
1254+ kfree(ctlr->dummy_rx);
1255+ ctlr->dummy_rx = NULL;
1256+ kfree(ctlr->dummy_tx);
1257+ ctlr->dummy_tx = NULL;
1258+ if (ctlr->unprepare_transfer_hardware &&
1259+ ctlr->unprepare_transfer_hardware(ctlr))
1260+ dev_err(&ctlr->dev,
1261+ "failed to unprepare transfer hardware\n");
1262+ if (ctlr->auto_runtime_pm) {
1263+ pm_runtime_mark_last_busy(ctlr->dev.parent);
1264+ pm_runtime_put_autosuspend(ctlr->dev.parent);
1265+ }
1266+ trace_spi_controller_idle(ctlr);
1267+
1268+ spin_lock_irqsave(&ctlr->queue_lock, flags);
1269+ ctlr->idling = false;
12461270 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
12471271 return;
12481272 }
@@ -1335,77 +1359,6 @@ static void spi_pump_messages(struct kthread_work *work) · 86 unmodified lines
13351359 __spi_pump_messages(ctlr, true);
13361360 }
13371361
1338−/**
1339− * spi_pump_idle_teardown - kthread delayed work function which tears down
1340− * the controller settings after some delay
1341− * @work: pointer to kthread work struct contained in the controller struct
1342− */
1343−static void spi_pump_idle_teardown(struct kthread_work *work)
1344−{
1345− struct spi_controller *ctlr =
1346− container_of(work, struct spi_controller,
1347− pump_idle_teardown.work);
1348− unsigned long flags;
1349−
1350− /* Lock queue */
1351− spin_lock_irqsave(&ctlr->queue_lock, flags);
1352−
1353− /* Make sure we are not already running a message */
1354− if (ctlr->cur_msg)
1355− goto out;
1356−
1357− /* if there is anything in the list then exit */
1358− if (!list_empty(&ctlr->queue))
1359− goto out;
1360−
1361− /* if the controller is running then exit */
1362− if (ctlr->running)
1363− goto out;
1364−
1365− /* if the controller is busy then exit */
1366− if (ctlr->busy)
1367− goto out;
1368−
1369− /* if the controller is idling then exit
1370− * this is actually a bit strange and would indicate that
1371− * this function is scheduled twice, which should not happen
1372− */
1373− if (ctlr->idling)
1374− goto out;
1375−
1376− /* set up the initial states */
1377− ctlr->busy = false;
1378− ctlr->idling = true;
1379− spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1380−
1381− /* free dummy receive buffers */
1382− kfree(ctlr->dummy_rx);
1383− ctlr->dummy_rx = NULL;
1384− kfree(ctlr->dummy_tx);
1385− ctlr->dummy_tx = NULL;
1386−
1387− /* unprepare hardware */
1388− if (ctlr->unprepare_transfer_hardware &&
1389− ctlr->unprepare_transfer_hardware(ctlr))
1390− dev_err(&ctlr->dev,
1391− "failed to unprepare transfer hardware\n");
1392− /* handle pm */
1393− if (ctlr->auto_runtime_pm) {
1394− pm_runtime_mark_last_busy(ctlr->dev.parent);
1395− pm_runtime_put_autosuspend(ctlr->dev.parent);
1396− }
1397−
1398− /* mark controller as idle */
1399− trace_spi_controller_idle(ctlr);
1400−
1401− /* finally put us from idling into stopped */
1402− spin_lock_irqsave(&ctlr->queue_lock, flags);
1403− ctlr->idling = false;
1404−
1405−out:
1406− spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1407−}
1408−
14091362 static int spi_init_queue(struct spi_controller *ctlr)
14101363 {
14111364 struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
@@ -1421,8 +1374,7 @@ static int spi_init_queue(struct spi_controller *ctlr) · 9 unmodified lines
14211374 return PTR_ERR(ctlr->kworker_task);
14221375 }
14231376 kthread_init_work(&ctlr->pump_messages, spi_pump_messages);
1424− kthread_init_delayed_work(&ctlr->pump_idle_teardown,
1425− spi_pump_idle_teardown);
1377+
14261378 /*
14271379 * Controller config will indicate if this controller should run the
14281380 * message pump with high (realtime) priority to reduce the transfer
@@ -1494,16 +1446,7 @@ void spi_finalize_current_message(struct spi_controller *ctlr) · 65 unmodified lines
14941446 spin_lock_irqsave(&ctlr->queue_lock, flags);
14951447 ctlr->cur_msg = NULL;
14961448 ctlr->cur_msg_prepared = false;
1497−
1498− /* if there is something queued, then wake the queue */
1499− if (!list_empty(&ctlr->queue))
1500− kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1501− else
1502− /* otherwise schedule delayed teardown */
1503− kthread_mod_delayed_work(&ctlr->kworker,
1504− &ctlr->pump_idle_teardown,
1505− HZ);
1506−
1449+ kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
15071450 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
15081451
15091452 trace_spi_message_done(mesg);
@@ -1608,7 +1551,7 @@ static int __spi_queued_transfer(struct spi_device *spi, · 98 unmodified lines
16081551 msg->status = -EINPROGRESS;
16091552
16101553 list_add_tail(&msg->queue, &ctlr->queue);
1611− if (need_pump)
1554+ if (!ctlr->busy && need_pump)
16121555 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
16131556
16141557 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
@@ -3783,3 +3726,4 @@ err0: · 2168 unmodified lines
37833726 * include needing to have boardinfo data structures be much more public.
37843727 */
37853728 postcore_initcall(spi_init);
3729+
include/linux/spi/spi.h+0−2
@@ -334,7 +334,6 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 333 unmodified lines
334334 * @kworker: thread struct for message pump
335335 * @kworker_task: pointer to task for message pump kworker thread
336336 * @pump_messages: work struct for scheduling work to the message pump
337− * @pump_idle_teardown: work structure for scheduling a teardown delayed
338337 * @queue_lock: spinlock to syncronise access to message queue
339338 * @queue: message queue
340339 * @idling: the device is entering idle state
@@ -533,7 +532,6 @@ struct spi_controller { · 192 unmodified lines
533532 struct kthread_worker kworker;
534533 struct task_struct *kworker_task;
535534 struct kthread_work pump_messages;
536− struct kthread_delayed_work pump_idle_teardown;
537535 spinlock_t queue_lock;
538536 struct list_head queue;
539537 struct spi_message *cur_msg;

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