Skip to content

Commit 0f85e74

Browse files
Daniil Lunevmartinkpetersen
Daniil Lunev
authored andcommitted
scsi: ufs: core: Use local_clock() for debugging timestamps
CLOCK_MONOTONIC is not advanced when the system is in suspend. This becomes problematic when debugging issues related to suspend-resume: the timestamps printed by ufshcd_print_trs can not be correlated with dmesg entries, which are timestamped with local_clock(). Change the used clock to local_clock() for the informational timestamp variables and adds mirroring *_local_clock instances for variables used in subsequent derevations (to not change the semantics of those derevations). Link: https://lore.kernel.org/r/20220804065019.v5.1.I699244ea7efbd326a34a6dfd9b5a31e78400cf68@changeid Acked-by: Stanley Chu <[email protected]> Acked-by: Avri Altman <[email protected]> Signed-off-by: Daniil Lunev <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent b7dbc68 commit 0f85e74

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/interrupt.h>
2222
#include <linux/module.h>
2323
#include <linux/regulator/consumer.h>
24+
#include <linux/sched/clock.h>
2425
#include <scsi/scsi_cmnd.h>
2526
#include <scsi/scsi_dbg.h>
2627
#include <scsi/scsi_driver.h>
@@ -457,7 +458,7 @@ static void ufshcd_print_evt(struct ufs_hba *hba, u32 id,
457458
if (e->tstamp[p] == 0)
458459
continue;
459460
dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
460-
e->val[p], ktime_to_us(e->tstamp[p]));
461+
e->val[p], div_u64(e->tstamp[p], 1000));
461462
found = true;
462463
}
463464

@@ -502,9 +503,9 @@ void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt)
502503
lrbp = &hba->lrb[tag];
503504

504505
dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n",
505-
tag, ktime_to_us(lrbp->issue_time_stamp));
506+
tag, div_u64(lrbp->issue_time_stamp_local_clock, 1000));
506507
dev_err(hba->dev, "UPIU[%d] - complete time %lld us\n",
507-
tag, ktime_to_us(lrbp->compl_time_stamp));
508+
tag, div_u64(lrbp->compl_time_stamp_local_clock, 1000));
508509
dev_err(hba->dev,
509510
"UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n",
510511
tag, (u64)lrbp->utrd_dma_addr);
@@ -566,10 +567,10 @@ static void ufshcd_print_host_state(struct ufs_hba *hba)
566567
dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
567568
dev_err(hba->dev,
568569
"last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt=%d\n",
569-
ktime_to_us(hba->ufs_stats.last_hibern8_exit_tstamp),
570+
div_u64(hba->ufs_stats.last_hibern8_exit_tstamp, 1000),
570571
hba->ufs_stats.hibern8_exit_cnt);
571572
dev_err(hba->dev, "last intr at %lld us, last intr status=0x%x\n",
572-
ktime_to_us(hba->ufs_stats.last_intr_ts),
573+
div_u64(hba->ufs_stats.last_intr_ts, 1000),
573574
hba->ufs_stats.last_intr_status);
574575
dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n",
575576
hba->eh_flags, hba->req_abort_count);
@@ -2140,7 +2141,9 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
21402141
unsigned long flags;
21412142

21422143
lrbp->issue_time_stamp = ktime_get();
2144+
lrbp->issue_time_stamp_local_clock = local_clock();
21432145
lrbp->compl_time_stamp = ktime_set(0, 0);
2146+
lrbp->compl_time_stamp_local_clock = 0;
21442147
ufshcd_add_command_trace(hba, task_tag, UFS_CMD_SEND);
21452148
ufshcd_clk_scaling_start_busy(hba);
21462149
if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))
@@ -4222,7 +4225,7 @@ int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)
42224225
} else {
42234226
ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_EXIT,
42244227
POST_CHANGE);
4225-
hba->ufs_stats.last_hibern8_exit_tstamp = ktime_get();
4228+
hba->ufs_stats.last_hibern8_exit_tstamp = local_clock();
42264229
hba->ufs_stats.hibern8_exit_cnt++;
42274230
}
42284231

@@ -4724,7 +4727,7 @@ void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val)
47244727

47254728
e = &hba->ufs_stats.event[id];
47264729
e->val[e->pos] = val;
4727-
e->tstamp[e->pos] = ktime_get();
4730+
e->tstamp[e->pos] = local_clock();
47284731
e->cnt += 1;
47294732
e->pos = (e->pos + 1) % UFS_EVENT_HIST_LENGTH;
47304733

@@ -5357,6 +5360,7 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
53575360
for_each_set_bit(index, &completed_reqs, hba->nutrs) {
53585361
lrbp = &hba->lrb[index];
53595362
lrbp->compl_time_stamp = ktime_get();
5363+
lrbp->compl_time_stamp_local_clock = local_clock();
53605364
cmd = lrbp->cmd;
53615365
if (cmd) {
53625366
if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))
@@ -6645,7 +6649,7 @@ static irqreturn_t ufshcd_intr(int irq, void *__hba)
66456649

66466650
intr_status = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
66476651
hba->ufs_stats.last_intr_status = intr_status;
6648-
hba->ufs_stats.last_intr_ts = ktime_get();
6652+
hba->ufs_stats.last_intr_ts = local_clock();
66496653

66506654
/*
66516655
* There could be max of hba->nutrs reqs in flight and in worst case

include/ufs/ufshcd.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ struct ufs_pm_lvl_states {
160160
* @task_tag: Task tag of the command
161161
* @lun: LUN of the command
162162
* @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
163-
* @issue_time_stamp: time stamp for debug purposes
164-
* @compl_time_stamp: time stamp for statistics
163+
* @issue_time_stamp: time stamp for debug purposes (CLOCK_MONOTONIC)
164+
* @issue_time_stamp_local_clock: time stamp for debug purposes (local_clock)
165+
* @compl_time_stamp: time stamp for statistics (CLOCK_MONOTONIC)
166+
* @compl_time_stamp_local_clock: time stamp for debug purposes (local_clock)
165167
* @crypto_key_slot: the key slot to use for inline crypto (-1 if none)
166168
* @data_unit_num: the data unit number for the first block for inline crypto
167169
* @req_abort_skip: skip request abort task flag
@@ -185,7 +187,9 @@ struct ufshcd_lrb {
185187
u8 lun; /* UPIU LUN id field is only 8-bit wide */
186188
bool intr_cmd;
187189
ktime_t issue_time_stamp;
190+
u64 issue_time_stamp_local_clock;
188191
ktime_t compl_time_stamp;
192+
u64 compl_time_stamp_local_clock;
189193
#ifdef CONFIG_SCSI_UFS_CRYPTO
190194
int crypto_key_slot;
191195
u64 data_unit_num;
@@ -430,7 +434,7 @@ struct ufs_clk_scaling {
430434
struct ufs_event_hist {
431435
int pos;
432436
u32 val[UFS_EVENT_HIST_LENGTH];
433-
ktime_t tstamp[UFS_EVENT_HIST_LENGTH];
437+
u64 tstamp[UFS_EVENT_HIST_LENGTH];
434438
unsigned long long cnt;
435439
};
436440

@@ -446,10 +450,10 @@ struct ufs_event_hist {
446450
*/
447451
struct ufs_stats {
448452
u32 last_intr_status;
449-
ktime_t last_intr_ts;
453+
u64 last_intr_ts;
450454

451455
u32 hibern8_exit_cnt;
452-
ktime_t last_hibern8_exit_tstamp;
456+
u64 last_hibern8_exit_tstamp;
453457
struct ufs_event_hist event[UFS_EVT_CNT];
454458
};
455459

0 commit comments

Comments
 (0)