cputime.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Definitions for measuring cputime on powerpc machines.
  4. *
  5. * Copyright (C) 2006 Paul Mackerras, IBM Corp.
  6. *
  7. * If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in
  8. * the same units as the timebase. Otherwise we measure cpu time
  9. * in jiffies using the generic definitions.
  10. */
  11. #ifndef __POWERPC_CPUTIME_H
  12. #define __POWERPC_CPUTIME_H
  13. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  14. #include <linux/types.h>
  15. #include <linux/time.h>
  16. #include <asm/div64.h>
  17. #include <asm/time.h>
  18. #include <asm/param.h>
  19. #include <asm/firmware.h>
  20. typedef u64 __nocast cputime_t;
  21. typedef u64 __nocast cputime64_t;
  22. #define cmpxchg_cputime(ptr, old, new) cmpxchg(ptr, old, new)
  23. #ifdef __KERNEL__
  24. /*
  25. * Convert cputime <-> microseconds
  26. */
  27. extern u64 __cputime_usec_factor;
  28. static inline unsigned long cputime_to_usecs(const cputime_t ct)
  29. {
  30. return mulhdu((__force u64) ct, __cputime_usec_factor);
  31. }
  32. #define cputime_to_nsecs(cputime) tb_to_ns((__force u64)cputime)
  33. /*
  34. * PPC64 uses PACA which is task independent for storing accounting data while
  35. * PPC32 uses struct thread_info, therefore at task switch the accounting data
  36. * has to be populated in the new task
  37. */
  38. #ifdef CONFIG_PPC64
  39. #define get_accounting(tsk) (&get_paca()->accounting)
  40. #define raw_get_accounting(tsk) (&local_paca->accounting)
  41. static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
  42. #else
  43. #define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
  44. #define raw_get_accounting(tsk) get_accounting(tsk)
  45. /*
  46. * Called from the context switch with interrupts disabled, to charge all
  47. * accumulated times to the current process, and to prepare accounting on
  48. * the next process.
  49. */
  50. static inline void arch_vtime_task_switch(struct task_struct *prev)
  51. {
  52. struct cpu_accounting_data *acct = get_accounting(current);
  53. struct cpu_accounting_data *acct0 = get_accounting(prev);
  54. acct->starttime = acct0->starttime;
  55. }
  56. #endif
  57. /*
  58. * account_cpu_user_entry/exit runs "unreconciled", so can't trace,
  59. * can't use get_paca()
  60. */
  61. static notrace inline void account_cpu_user_entry(void)
  62. {
  63. unsigned long tb = mftb();
  64. struct cpu_accounting_data *acct = raw_get_accounting(current);
  65. acct->utime += (tb - acct->starttime_user);
  66. acct->starttime = tb;
  67. }
  68. static notrace inline void account_cpu_user_exit(void)
  69. {
  70. unsigned long tb = mftb();
  71. struct cpu_accounting_data *acct = raw_get_accounting(current);
  72. acct->stime += (tb - acct->starttime);
  73. acct->starttime_user = tb;
  74. }
  75. static notrace inline void account_stolen_time(void)
  76. {
  77. #ifdef CONFIG_PPC_SPLPAR
  78. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  79. struct lppaca *lp = local_paca->lppaca_ptr;
  80. if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx)))
  81. pseries_accumulate_stolen_time();
  82. }
  83. #endif
  84. }
  85. #endif /* __KERNEL__ */
  86. #else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  87. static inline void account_cpu_user_entry(void)
  88. {
  89. }
  90. static inline void account_cpu_user_exit(void)
  91. {
  92. }
  93. static notrace inline void account_stolen_time(void)
  94. {
  95. }
  96. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  97. #endif /* __POWERPC_CPUTIME_H */