Skip to content

Commit d671bf7

Browse files
TheCrazyLexGalaticStryder
authored andcommitted
msm-tsens: Reschedule work instead of causing uninterruptible sleep
The tsens_poll work causes uninterruptible sleep on the UI thread and thus blocks other tasks from running due to the msleep call. To avoid this condition, we introduce a variable to hold the staging state of the critical polling and reschedule the work itself to be executed again after the same duration as the msleep. Additionally we switch the currently unused wq to a singlethreaded wq and queue the tsens work onto that wq. Change-Id: I0bf48837310decd035d35ac78aa7d51614032b36 Signed-off-by: Alex Naidis <[email protected]> Signed-off-by: Ícaro Hoff <[email protected]>
1 parent caec4c6 commit d671bf7

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

drivers/thermal/msm-tsens.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ struct tsens_tm_device {
867867
u64 qtimer_val_last_detection_interrupt;
868868
u64 qtimer_val_last_polling_check;
869869
bool tsens_critical_poll;
870+
bool tsens_critical_poll_state;
870871
struct tsens_tm_device_sensor sensor[0];
871872
};
872873

@@ -2010,7 +2011,7 @@ static void tsens_poll(struct work_struct *work)
20102011
unsigned int debug_id = 0, cntrl_id = 0;
20112012
uint32_t r1, r2, r3, r4, offset = 0, idx = 0;
20122013
unsigned long temp, flags;
2013-
unsigned int status, int_mask, int_mask_val;
2014+
unsigned int status, int_mask, int_mask_val, resched_ms;
20142015
void __iomem *srot_addr;
20152016
void __iomem *controller_id_addr;
20162017
void __iomem *debug_id_addr;
@@ -2034,6 +2035,10 @@ static void tsens_poll(struct work_struct *work)
20342035
/* Sensor 0 on either of the controllers */
20352036
mask = 0;
20362037

2038+
if (tmdev->tsens_critical_poll_state) {
2039+
goto critical_poll;
2040+
}
2041+
20372042
reinit_completion(&tmdev->tsens_rslt_completion);
20382043

20392044
temp &= TSENS_TM_SN_CRITICAL_THRESHOLD_MASK;
@@ -2069,8 +2074,12 @@ static void tsens_poll(struct work_struct *work)
20692074
}
20702075
spin_unlock_irqrestore(&tmdev->tsens_crit_lock, flags);
20712076

2072-
if (tmdev->tsens_critical_poll) {
2073-
msleep(TSENS_DEBUG_POLL_MS);
2077+
critical_poll:
2078+
if (tmdev->tsens_critical_poll && !tmdev->tsens_critical_poll_state) {
2079+
tmdev->tsens_critical_poll_state = true;
2080+
goto re_schedule;
2081+
} else if (tmdev->tsens_critical_poll) {
2082+
tmdev->tsens_critical_poll_state = false;
20742083
sensor_status_addr = TSENS_TM_SN_STATUS(tmdev->tsens_addr);
20752084

20762085
spin_lock_irqsave(&tmdev->tsens_crit_lock, flags);
@@ -2230,9 +2239,11 @@ static void tsens_poll(struct work_struct *work)
22302239
}
22312240

22322241
re_schedule:
2233-
2234-
schedule_delayed_work(&tmdev->tsens_critical_poll_test,
2235-
msecs_to_jiffies(tsens_sec_to_msec_value));
2242+
resched_ms = tmdev->tsens_critical_poll_state
2243+
? TSENS_DEBUG_POLL_MS : tsens_sec_to_msec_value;
2244+
queue_delayed_work(tmdev->tsens_critical_wq,
2245+
&tmdev->tsens_critical_poll_test,
2246+
msecs_to_jiffies(resched_ms));
22362247
}
22372248

22382249
int tsens_mtc_reset_history_counter(unsigned int zone)
@@ -5744,8 +5755,8 @@ static int tsens_tm_probe(struct platform_device *pdev)
57445755

57455756
tmdev->pdev = pdev;
57465757

5747-
tmdev->tsens_critical_wq = alloc_workqueue("tsens_critical_wq",
5748-
WQ_HIGHPRI, 0);
5758+
tmdev->tsens_critical_wq = create_singlethread_workqueue("tsens_critical_wq");
5759+
57495760
if (!tmdev->tsens_critical_wq) {
57505761
rc = -ENOMEM;
57515762
goto fail;
@@ -5770,6 +5781,7 @@ static int tsens_tm_probe(struct platform_device *pdev)
57705781
spin_lock_init(&tmdev->tsens_upp_low_lock);
57715782
spin_lock_init(&tmdev->tsens_debug_lock);
57725783

5784+
tmdev->tsens_critical_poll_state = false;
57735785
tmdev->is_ready = true;
57745786

57755787
list_add_tail(&tmdev->list, &tsens_device_list);
@@ -5938,7 +5950,8 @@ static int tsens_thermal_zone_register(struct tsens_tm_device *tmdev)
59385950
if (tsens_poll_check) {
59395951
INIT_DEFERRABLE_WORK(&tmdev->tsens_critical_poll_test,
59405952
tsens_poll);
5941-
schedule_delayed_work(&tmdev->tsens_critical_poll_test,
5953+
queue_delayed_work(tmdev->tsens_critical_wq,
5954+
&tmdev->tsens_critical_poll_test,
59425955
msecs_to_jiffies(tsens_sec_to_msec_value));
59435956
init_completion(&tmdev->tsens_rslt_completion);
59445957
tmdev->tsens_critical_poll = true;

0 commit comments

Comments
 (0)