diff mbox series

[v3] ufs: core: ufshcd: use local_clock() for debugging timestamps

Message ID 20220802103230.v3.1.I699244ea7efbd326a34a6dfd9b5a31e78400cf68@changeid (mailing list archive)
State Superseded
Headers show
Series [v3] ufs: core: ufshcd: use local_clock() for debugging timestamps | expand

Commit Message

Daniil Lunev Aug. 2, 2022, 12:32 a.m. UTC
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().

This CL changes 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).

Signed-off-by: Daniil Lunev <dlunev@chromium.org>

---

Changes in v3:
- Add missing header

Changes in v2:
- Use local clock to better align with dmesg
- Correct commit message

 drivers/ufs/core/ufshcd.c | 20 ++++++++++++--------
 include/ufs/ufshcd.h      | 14 +++++++++-----
 2 files changed, 21 insertions(+), 13 deletions(-)

Comments

Stanley Jhu Aug. 2, 2022, 2:41 a.m. UTC | #1
On Tue, Aug 2, 2022 at 8:32 AM Daniil Lunev <dlunev@chromium.org> wrote:
>
> 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().
>
> This CL changes 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).
>
> Signed-off-by: Daniil Lunev <dlunev@chromium.org>

Acked-by: Stanley Chu <stanley.chu@mediatek.com>
Avri Altman Aug. 2, 2022, 7:18 a.m. UTC | #2
> 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().
> 
> This CL changes 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).
I agree with this approach because the words of cautious while using sched_clock()
Happens to be true for various ufs platforms, specifically of a required stabilization period.

Acked-by: Avri Altman <avri.altman@wdc.com> 

> 
> Signed-off-by: Daniil Lunev <dlunev@chromium.org>
> 
> ---
> 
> Changes in v3:
> - Add missing header
> 
> Changes in v2:
> - Use local clock to better align with dmesg
> - Correct commit message
> 
>  drivers/ufs/core/ufshcd.c | 20 ++++++++++++--------
>  include/ufs/ufshcd.h      | 14 +++++++++-----
>  2 files changed, 21 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index
> ce86d1b790c05..e61dafb93986f 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -21,6 +21,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/module.h>
>  #include <linux/regulator/consumer.h>
> +#include <linux/sched/clock.h>
>  #include <scsi/scsi_cmnd.h>
>  #include <scsi/scsi_dbg.h>
>  #include <scsi/scsi_driver.h>
> @@ -460,7 +461,7 @@ static void ufshcd_print_evt(struct ufs_hba *hba, u32 id,
>                 if (e->tstamp[p] == 0)
>                         continue;
>                 dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
> -                       e->val[p], ktime_to_us(e->tstamp[p]));
> +                       e->val[p], e->tstamp[p] / 1000);
>                 found = true;
>         }
> 
> @@ -505,9 +506,9 @@ void ufshcd_print_trs(struct ufs_hba *hba, unsigned
> long bitmap, bool pr_prdt)
>                 lrbp = &hba->lrb[tag];
> 
>                 dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n",
> -                               tag, ktime_to_us(lrbp->issue_time_stamp));
> +                               tag, lrbp->issue_time_stamp_local_clock
> + / 1000);
>                 dev_err(hba->dev, "UPIU[%d] - complete time %lld us\n",
> -                               tag, ktime_to_us(lrbp->compl_time_stamp));
> +                               tag, lrbp->compl_time_stamp_local_clock
> + / 1000);
>                 dev_err(hba->dev,
>                         "UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n",
>                         tag, (u64)lrbp->utrd_dma_addr); @@ -569,10 +570,10 @@ static
> void ufshcd_print_host_state(struct ufs_hba *hba)
>         dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
>         dev_err(hba->dev,
>                 "last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt=%d\n",
> -               ktime_to_us(hba->ufs_stats.last_hibern8_exit_tstamp),
> +               hba->ufs_stats.last_hibern8_exit_tstamp / 1000,
>                 hba->ufs_stats.hibern8_exit_cnt);
>         dev_err(hba->dev, "last intr at %lld us, last intr status=0x%x\n",
> -               ktime_to_us(hba->ufs_stats.last_intr_ts),
> +               hba->ufs_stats.last_intr_ts / 1000,
>                 hba->ufs_stats.last_intr_status);
>         dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n",
>                 hba->eh_flags, hba->req_abort_count); @@ -2142,7 +2143,9 @@ void
> ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
>         unsigned long flags;
> 
>         lrbp->issue_time_stamp = ktime_get();
> +       lrbp->issue_time_stamp_local_clock = local_clock();
>         lrbp->compl_time_stamp = ktime_set(0, 0);
> +       lrbp->compl_time_stamp_local_clock = 0;
>         ufshcd_add_command_trace(hba, task_tag, UFS_CMD_SEND);
>         ufshcd_clk_scaling_start_busy(hba);
>         if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) @@ -4199,7 +4202,7
> @@ int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)
>         } else {
>                 ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_EXIT,
>                                                                 POST_CHANGE);
> -               hba->ufs_stats.last_hibern8_exit_tstamp = ktime_get();
> +               hba->ufs_stats.last_hibern8_exit_tstamp = local_clock();
>                 hba->ufs_stats.hibern8_exit_cnt++;
>         }
> 
> @@ -4696,7 +4699,7 @@ void ufshcd_update_evt_hist(struct ufs_hba *hba,
> u32 id, u32 val)
> 
>         e = &hba->ufs_stats.event[id];
>         e->val[e->pos] = val;
> -       e->tstamp[e->pos] = ktime_get();
> +       e->tstamp[e->pos] = local_clock();
>         e->cnt += 1;
>         e->pos = (e->pos + 1) % UFS_EVENT_HIST_LENGTH;
> 
> @@ -5329,6 +5332,7 @@ static void __ufshcd_transfer_req_compl(struct
> ufs_hba *hba,
>         for_each_set_bit(index, &completed_reqs, hba->nutrs) {
>                 lrbp = &hba->lrb[index];
>                 lrbp->compl_time_stamp = ktime_get();
> +               lrbp->compl_time_stamp_local_clock = local_clock();
>                 cmd = lrbp->cmd;
>                 if (cmd) {
>                         if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) @@ -6617,7
> +6621,7 @@ static irqreturn_t ufshcd_intr(int irq, void *__hba)
> 
>         intr_status = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
>         hba->ufs_stats.last_intr_status = intr_status;
> -       hba->ufs_stats.last_intr_ts = ktime_get();
> +       hba->ufs_stats.last_intr_ts = local_clock();
> 
>         /*
>          * There could be max of hba->nutrs reqs in flight and in worst case diff --git
> a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index
> a92271421718e..2de73196bb779 100644
> --- a/include/ufs/ufshcd.h
> +++ b/include/ufs/ufshcd.h
> @@ -160,8 +160,10 @@ struct ufs_pm_lvl_states {
>   * @task_tag: Task tag of the command
>   * @lun: LUN of the command
>   * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
> - * @issue_time_stamp: time stamp for debug purposes
> - * @compl_time_stamp: time stamp for statistics
> + * @issue_time_stamp: time stamp for debug purposes (CLOCK_MONOTONIC)
> + * @issue_time_stamp_local_clock: time stamp for debug purposes
> + (local_clock)
> + * @compl_time_stamp: time stamp for statistics (CLOCK_MONOTONIC)
> + * @compl_time_stamp_local_clock: time stamp for debug purposes
> + (local_clock)
>   * @crypto_key_slot: the key slot to use for inline crypto (-1 if none)
>   * @data_unit_num: the data unit number for the first block for inline crypto
>   * @req_abort_skip: skip request abort task flag @@ -185,7 +187,9 @@ struct
> ufshcd_lrb {
>         u8 lun; /* UPIU LUN id field is only 8-bit wide */
>         bool intr_cmd;
>         ktime_t issue_time_stamp;
> +       u64 issue_time_stamp_local_clock;
>         ktime_t compl_time_stamp;
> +       u64 compl_time_stamp_local_clock;
>  #ifdef CONFIG_SCSI_UFS_CRYPTO
>         int crypto_key_slot;
>         u64 data_unit_num;
> @@ -430,7 +434,7 @@ struct ufs_clk_scaling {  struct ufs_event_hist {
>         int pos;
>         u32 val[UFS_EVENT_HIST_LENGTH];
> -       ktime_t tstamp[UFS_EVENT_HIST_LENGTH];
> +       u64 tstamp[UFS_EVENT_HIST_LENGTH];
>         unsigned long long cnt;
>  };
> 
> @@ -446,10 +450,10 @@ struct ufs_event_hist {
>   */
>  struct ufs_stats {
>         u32 last_intr_status;
> -       ktime_t last_intr_ts;
> +       u64 last_intr_ts;
> 
>         u32 hibern8_exit_cnt;
> -       ktime_t last_hibern8_exit_tstamp;
> +       u64 last_hibern8_exit_tstamp;
>         struct ufs_event_hist event[UFS_EVT_CNT];  };
> 
> --
> 2.31.0
kernel test robot Aug. 2, 2022, 10:17 a.m. UTC | #3
Hi Daniil,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on jejb-scsi/for-next]
[also build test ERROR on mkp-scsi/for-next linus/master v5.19 next-20220728]
[cannot apply to bvanassche/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniil-Lunev/ufs-core-ufshcd-use-local_clock-for-debugging-timestamps/20220802-083420
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: i386-randconfig-a013-20220801 (https://download.01.org/0day-ci/archive/20220802/202208021848.n995UITS-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/c72f82f12e7c9f361f0d13d4ab583f9834384464
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Daniil-Lunev/ufs-core-ufshcd-use-local_clock-for-debugging-timestamps/20220802-083420
        git checkout c72f82f12e7c9f361f0d13d4ab583f9834384464
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_evt':
>> drivers/ufs/core/ufshcd.c:460: undefined reference to `__udivdi3'
   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_host_state':
   drivers/ufs/core/ufshcd.c:568: undefined reference to `__udivdi3'
>> ld: drivers/ufs/core/ufshcd.c:572: undefined reference to `__udivdi3'
   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_trs':
   drivers/ufs/core/ufshcd.c:505: undefined reference to `__udivdi3'
   ld: drivers/ufs/core/ufshcd.c:507: undefined reference to `__udivdi3'


vim +460 drivers/ufs/core/ufshcd.c

ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  442  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  443  static void ufshcd_print_evt(struct ufs_hba *hba, u32 id,
35d11ec239e099 drivers/ufs/core/ufshcd.c Krzysztof Kozlowski 2022-06-23  444  			     const char *err_name)
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  445  {
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  446  	int i;
27752647f88a1b drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-01-28  447  	bool found = false;
35d11ec239e099 drivers/ufs/core/ufshcd.c Krzysztof Kozlowski 2022-06-23  448  	const struct ufs_event_hist *e;
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  449  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  450  	if (id >= UFS_EVT_CNT)
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  451  		return;
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  452  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  453  	e = &hba->ufs_stats.event[id];
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  454  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  455  	for (i = 0; i < UFS_EVENT_HIST_LENGTH; i++) {
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  456  		int p = (i + e->pos) % UFS_EVENT_HIST_LENGTH;
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  457  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  458  		if (e->tstamp[p] == 0)
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  459  			continue;
c5397f13fc744b drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-07-10 @460  		dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
c72f82f12e7c9f drivers/ufs/core/ufshcd.c Daniil Lunev        2022-08-02  461  			e->val[p], e->tstamp[p] / 1000);
27752647f88a1b drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-01-28  462  		found = true;
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  463  	}
27752647f88a1b drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-01-28  464  
27752647f88a1b drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-01-28  465  	if (!found)
fd1fb4d5562a87 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-01-04  466  		dev_err(hba->dev, "No record of %s\n", err_name);
bafd09f8d8ec0a drivers/scsi/ufs/ufshcd.c DooHyun Hwang       2021-02-03  467  	else
bafd09f8d8ec0a drivers/scsi/ufs/ufshcd.c DooHyun Hwang       2021-02-03  468  		dev_err(hba->dev, "%s: total cnt=%llu\n", err_name, e->cnt);
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  469  }
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  470  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  471  static void ufshcd_print_evt_hist(struct ufs_hba *hba)
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  472  {
ba80917d9932da drivers/scsi/ufs/ufshcd.c Tomas Winkler       2018-06-14  473  	ufshcd_dump_regs(hba, 0, UFSHCI_REG_SPACE_SIZE, "host_regs: ");
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  474  
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  475  	ufshcd_print_evt(hba, UFS_EVT_PA_ERR, "pa_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  476  	ufshcd_print_evt(hba, UFS_EVT_DL_ERR, "dl_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  477  	ufshcd_print_evt(hba, UFS_EVT_NL_ERR, "nl_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  478  	ufshcd_print_evt(hba, UFS_EVT_TL_ERR, "tl_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  479  	ufshcd_print_evt(hba, UFS_EVT_DME_ERR, "dme_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  480  	ufshcd_print_evt(hba, UFS_EVT_AUTO_HIBERN8_ERR,
d3c615bf586f27 drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-07-10  481  			 "auto_hibern8_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  482  	ufshcd_print_evt(hba, UFS_EVT_FATAL_ERR, "fatal_err");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  483  	ufshcd_print_evt(hba, UFS_EVT_LINK_STARTUP_FAIL,
8808b4e9dcdc90 drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-07-10  484  			 "link_startup_fail");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  485  	ufshcd_print_evt(hba, UFS_EVT_RESUME_ERR, "resume_fail");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  486  	ufshcd_print_evt(hba, UFS_EVT_SUSPEND_ERR,
8808b4e9dcdc90 drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-07-10  487  			 "suspend_fail");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  488  	ufshcd_print_evt(hba, UFS_EVT_DEV_RESET, "dev_reset");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  489  	ufshcd_print_evt(hba, UFS_EVT_HOST_RESET, "host_reset");
e965e5e00b23c4 drivers/scsi/ufs/ufshcd.c Stanley Chu         2020-12-05  490  	ufshcd_print_evt(hba, UFS_EVT_ABORT, "task_abort");
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  491  
7c486d91f3d191 drivers/scsi/ufs/ufshcd.c Stanley Chu         2019-12-24  492  	ufshcd_vops_dbg_register_dump(hba);
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  493  }
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  494  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  495  static
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  496  void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt)
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  497  {
35d11ec239e099 drivers/ufs/core/ufshcd.c Krzysztof Kozlowski 2022-06-23  498  	const struct ufshcd_lrb *lrbp;
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  499  	int prdt_length;
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  500  	int tag;
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  501  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  502  	for_each_set_bit(tag, &bitmap, hba->nutrs) {
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  503  		lrbp = &hba->lrb[tag];
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  504  
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  505  		dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n",
c72f82f12e7c9f drivers/ufs/core/ufshcd.c Daniil Lunev        2022-08-02  506  				tag, lrbp->issue_time_stamp_local_clock / 1000);
090171885f505e drivers/scsi/ufs/ufshcd.c Zang Leigang        2017-09-27  507  		dev_err(hba->dev, "UPIU[%d] - complete time %lld us\n",
c72f82f12e7c9f drivers/ufs/core/ufshcd.c Daniil Lunev        2022-08-02  508  				tag, lrbp->compl_time_stamp_local_clock / 1000);
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  509  		dev_err(hba->dev,
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  510  			"UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n",
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  511  			tag, (u64)lrbp->utrd_dma_addr);
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  512  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  513  		ufshcd_hex_dump("UPIU TRD: ", lrbp->utr_descriptor_ptr,
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  514  				sizeof(struct utp_transfer_req_desc));
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  515  		dev_err(hba->dev, "UPIU[%d] - Request UPIU phys@0x%llx\n", tag,
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  516  			(u64)lrbp->ucd_req_dma_addr);
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  517  		ufshcd_hex_dump("UPIU REQ: ", lrbp->ucd_req_ptr,
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  518  				sizeof(struct utp_upiu_req));
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  519  		dev_err(hba->dev, "UPIU[%d] - Response UPIU phys@0x%llx\n", tag,
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  520  			(u64)lrbp->ucd_rsp_dma_addr);
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  521  		ufshcd_hex_dump("UPIU RSP: ", lrbp->ucd_rsp_ptr,
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  522  				sizeof(struct utp_upiu_rsp));
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  523  
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  524  		prdt_length = le16_to_cpu(
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  525  			lrbp->utr_descriptor_ptr->prd_table_length);
cc770ce34aeeff drivers/scsi/ufs/ufshcd.c Eric Biggers        2020-08-25  526  		if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN)
cc770ce34aeeff drivers/scsi/ufs/ufshcd.c Eric Biggers        2020-08-25  527  			prdt_length /= sizeof(struct ufshcd_sg_entry);
cc770ce34aeeff drivers/scsi/ufs/ufshcd.c Eric Biggers        2020-08-25  528  
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  529  		dev_err(hba->dev,
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  530  			"UPIU[%d] - PRDT - %d entries  phys@0x%llx\n",
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  531  			tag, prdt_length,
ff8e20c6624921 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  532  			(u64)lrbp->ucd_prdt_dma_addr);
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  533  
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  534  		if (pr_prdt)
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  535  			ufshcd_hex_dump("UPIU PRDT: ", lrbp->ucd_prdt_ptr,
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  536  				sizeof(struct ufshcd_sg_entry) * prdt_length);
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  537  	}
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  538  }
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  539  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  540  static void ufshcd_print_tmrs(struct ufs_hba *hba, unsigned long bitmap)
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  541  {
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  542  	int tag;
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  543  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  544  	for_each_set_bit(tag, &bitmap, hba->nutmrs) {
391e388f853dad drivers/scsi/ufs/ufshcd.c Christoph Hellwig   2018-10-07  545  		struct utp_task_req_desc *tmrdp = &hba->utmrdl_base_addr[tag];
391e388f853dad drivers/scsi/ufs/ufshcd.c Christoph Hellwig   2018-10-07  546  
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  547  		dev_err(hba->dev, "TM[%d] - Task Management Header\n", tag);
391e388f853dad drivers/scsi/ufs/ufshcd.c Christoph Hellwig   2018-10-07  548  		ufshcd_hex_dump("", tmrdp, sizeof(*tmrdp));
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  549  	}
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  550  }
66cc820f9cbf12 drivers/scsi/ufs/ufshcd.c Dolev Raviv         2016-12-22  551  
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  552  static void ufshcd_print_host_state(struct ufs_hba *hba)
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  553  {
35d11ec239e099 drivers/ufs/core/ufshcd.c Krzysztof Kozlowski 2022-06-23  554  	const struct scsi_device *sdev_ufs = hba->ufs_device_wlun;
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  555  
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  556  	dev_err(hba->dev, "UFS Host state=%d\n", hba->ufshcd_state);
7252a3603015f1 drivers/scsi/ufs/ufshcd.c Bart Van Assche     2019-12-09  557  	dev_err(hba->dev, "outstanding reqs=0x%lx tasks=0x%lx\n",
7252a3603015f1 drivers/scsi/ufs/ufshcd.c Bart Van Assche     2019-12-09  558  		hba->outstanding_reqs, hba->outstanding_tasks);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  559  	dev_err(hba->dev, "saved_err=0x%x, saved_uic_err=0x%x\n",
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  560  		hba->saved_err, hba->saved_uic_err);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  561  	dev_err(hba->dev, "Device power mode=%d, UIC link state=%d\n",
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  562  		hba->curr_dev_pwr_mode, hba->uic_link_state);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  563  	dev_err(hba->dev, "PM in progress=%d, sys. suspended=%d\n",
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  564  		hba->pm_op_in_progress, hba->is_sys_suspended);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  565  	dev_err(hba->dev, "Auto BKOPS=%d, Host self-block=%d\n",
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  566  		hba->auto_bkops_enabled, hba->host->host_self_blocked);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  567  	dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  568  	dev_err(hba->dev,
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  569  		"last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt=%d\n",
c72f82f12e7c9f drivers/ufs/core/ufshcd.c Daniil Lunev        2022-08-02  570  		hba->ufs_stats.last_hibern8_exit_tstamp / 1000,
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  571  		hba->ufs_stats.hibern8_exit_cnt);
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09 @572  	dev_err(hba->dev, "last intr at %lld us, last intr status=0x%x\n",
c72f82f12e7c9f drivers/ufs/core/ufshcd.c Daniil Lunev        2022-08-02  573  		hba->ufs_stats.last_intr_ts / 1000,
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  574  		hba->ufs_stats.last_intr_status);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  575  	dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n",
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  576  		hba->eh_flags, hba->req_abort_count);
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  577  	dev_err(hba->dev, "hba->ufs_version=0x%x, Host capabilities=0x%x, caps=0x%x\n",
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  578  		hba->ufs_version, hba->capabilities, hba->caps);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  579  	dev_err(hba->dev, "quirks=0x%x, dev. quirks=0x%x\n", hba->quirks,
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  580  		hba->dev_quirks);
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  581  	if (sdev_ufs)
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  582  		dev_err(hba->dev, "UFS dev info: %.8s %.16s rev %.4s\n",
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  583  			sdev_ufs->vendor, sdev_ufs->model, sdev_ufs->rev);
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  584  
3f8af6044713fa drivers/scsi/ufs/ufshcd.c Can Guo             2020-08-09  585  	ufshcd_print_clk_freqs(hba);
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  586  }
6ba65588381d59 drivers/scsi/ufs/ufshcd.c Gilad Broner        2017-02-03  587
kernel test robot Aug. 2, 2022, 4:26 p.m. UTC | #4
Hi Daniil,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on jejb-scsi/for-next]
[also build test ERROR on mkp-scsi/for-next linus/master v5.19 next-20220728]
[cannot apply to bvanassche/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniil-Lunev/ufs-core-ufshcd-use-local_clock-for-debugging-timestamps/20220802-083420
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: i386-randconfig-s042-20220801 (https://download.01.org/0day-ci/archive/20220803/202208030016.1zdowaT3-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/c72f82f12e7c9f361f0d13d4ab583f9834384464
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Daniil-Lunev/ufs-core-ufshcd-use-local_clock-for-debugging-timestamps/20220802-083420
        git checkout c72f82f12e7c9f361f0d13d4ab583f9834384464
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_evt':
>> ufshcd.c:(.text+0x105f): undefined reference to `__udivdi3'
   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_host_state':
>> ufshcd.c:(.text.unlikely+0xcf): undefined reference to `__udivdi3'
>> ld: ufshcd.c:(.text.unlikely+0x101): undefined reference to `__udivdi3'
   ld: drivers/ufs/core/ufshcd.o: in function `ufshcd_print_trs.cold':
   ufshcd.c:(.text.unlikely+0x6d9): undefined reference to `__udivdi3'
   ld: ufshcd.c:(.text.unlikely+0x712): undefined reference to `__udivdi3'
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index ce86d1b790c05..e61dafb93986f 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -21,6 +21,7 @@ 
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/regulator/consumer.h>
+#include <linux/sched/clock.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_dbg.h>
 #include <scsi/scsi_driver.h>
@@ -460,7 +461,7 @@  static void ufshcd_print_evt(struct ufs_hba *hba, u32 id,
 		if (e->tstamp[p] == 0)
 			continue;
 		dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
-			e->val[p], ktime_to_us(e->tstamp[p]));
+			e->val[p], e->tstamp[p] / 1000);
 		found = true;
 	}
 
@@ -505,9 +506,9 @@  void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt)
 		lrbp = &hba->lrb[tag];
 
 		dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n",
-				tag, ktime_to_us(lrbp->issue_time_stamp));
+				tag, lrbp->issue_time_stamp_local_clock / 1000);
 		dev_err(hba->dev, "UPIU[%d] - complete time %lld us\n",
-				tag, ktime_to_us(lrbp->compl_time_stamp));
+				tag, lrbp->compl_time_stamp_local_clock / 1000);
 		dev_err(hba->dev,
 			"UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n",
 			tag, (u64)lrbp->utrd_dma_addr);
@@ -569,10 +570,10 @@  static void ufshcd_print_host_state(struct ufs_hba *hba)
 	dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
 	dev_err(hba->dev,
 		"last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt=%d\n",
-		ktime_to_us(hba->ufs_stats.last_hibern8_exit_tstamp),
+		hba->ufs_stats.last_hibern8_exit_tstamp / 1000,
 		hba->ufs_stats.hibern8_exit_cnt);
 	dev_err(hba->dev, "last intr at %lld us, last intr status=0x%x\n",
-		ktime_to_us(hba->ufs_stats.last_intr_ts),
+		hba->ufs_stats.last_intr_ts / 1000,
 		hba->ufs_stats.last_intr_status);
 	dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n",
 		hba->eh_flags, hba->req_abort_count);
@@ -2142,7 +2143,9 @@  void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
 	unsigned long flags;
 
 	lrbp->issue_time_stamp = ktime_get();
+	lrbp->issue_time_stamp_local_clock = local_clock();
 	lrbp->compl_time_stamp = ktime_set(0, 0);
+	lrbp->compl_time_stamp_local_clock = 0;
 	ufshcd_add_command_trace(hba, task_tag, UFS_CMD_SEND);
 	ufshcd_clk_scaling_start_busy(hba);
 	if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))
@@ -4199,7 +4202,7 @@  int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)
 	} else {
 		ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_EXIT,
 								POST_CHANGE);
-		hba->ufs_stats.last_hibern8_exit_tstamp = ktime_get();
+		hba->ufs_stats.last_hibern8_exit_tstamp = local_clock();
 		hba->ufs_stats.hibern8_exit_cnt++;
 	}
 
@@ -4696,7 +4699,7 @@  void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val)
 
 	e = &hba->ufs_stats.event[id];
 	e->val[e->pos] = val;
-	e->tstamp[e->pos] = ktime_get();
+	e->tstamp[e->pos] = local_clock();
 	e->cnt += 1;
 	e->pos = (e->pos + 1) % UFS_EVENT_HIST_LENGTH;
 
@@ -5329,6 +5332,7 @@  static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
 	for_each_set_bit(index, &completed_reqs, hba->nutrs) {
 		lrbp = &hba->lrb[index];
 		lrbp->compl_time_stamp = ktime_get();
+		lrbp->compl_time_stamp_local_clock = local_clock();
 		cmd = lrbp->cmd;
 		if (cmd) {
 			if (unlikely(ufshcd_should_inform_monitor(hba, lrbp)))
@@ -6617,7 +6621,7 @@  static irqreturn_t ufshcd_intr(int irq, void *__hba)
 
 	intr_status = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
 	hba->ufs_stats.last_intr_status = intr_status;
-	hba->ufs_stats.last_intr_ts = ktime_get();
+	hba->ufs_stats.last_intr_ts = local_clock();
 
 	/*
 	 * There could be max of hba->nutrs reqs in flight and in worst case
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index a92271421718e..2de73196bb779 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -160,8 +160,10 @@  struct ufs_pm_lvl_states {
  * @task_tag: Task tag of the command
  * @lun: LUN of the command
  * @intr_cmd: Interrupt command (doesn't participate in interrupt aggregation)
- * @issue_time_stamp: time stamp for debug purposes
- * @compl_time_stamp: time stamp for statistics
+ * @issue_time_stamp: time stamp for debug purposes (CLOCK_MONOTONIC)
+ * @issue_time_stamp_local_clock: time stamp for debug purposes (local_clock)
+ * @compl_time_stamp: time stamp for statistics (CLOCK_MONOTONIC)
+ * @compl_time_stamp_local_clock: time stamp for debug purposes (local_clock)
  * @crypto_key_slot: the key slot to use for inline crypto (-1 if none)
  * @data_unit_num: the data unit number for the first block for inline crypto
  * @req_abort_skip: skip request abort task flag
@@ -185,7 +187,9 @@  struct ufshcd_lrb {
 	u8 lun; /* UPIU LUN id field is only 8-bit wide */
 	bool intr_cmd;
 	ktime_t issue_time_stamp;
+	u64 issue_time_stamp_local_clock;
 	ktime_t compl_time_stamp;
+	u64 compl_time_stamp_local_clock;
 #ifdef CONFIG_SCSI_UFS_CRYPTO
 	int crypto_key_slot;
 	u64 data_unit_num;
@@ -430,7 +434,7 @@  struct ufs_clk_scaling {
 struct ufs_event_hist {
 	int pos;
 	u32 val[UFS_EVENT_HIST_LENGTH];
-	ktime_t tstamp[UFS_EVENT_HIST_LENGTH];
+	u64 tstamp[UFS_EVENT_HIST_LENGTH];
 	unsigned long long cnt;
 };
 
@@ -446,10 +450,10 @@  struct ufs_event_hist {
  */
 struct ufs_stats {
 	u32 last_intr_status;
-	ktime_t last_intr_ts;
+	u64 last_intr_ts;
 
 	u32 hibern8_exit_cnt;
-	ktime_t last_hibern8_exit_tstamp;
+	u64 last_hibern8_exit_tstamp;
 	struct ufs_event_hist event[UFS_EVT_CNT];
 };