cputime.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Definitions for measuring cputime on powerpc machines.
  3. *
  4. * Copyright (C) 2006 Paul Mackerras, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in
  12. * the same units as the timebase. Otherwise we measure cpu time
  13. * in jiffies using the generic definitions.
  14. */
  15. #ifndef __POWERPC_CPUTIME_H
  16. #define __POWERPC_CPUTIME_H
  17. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  18. #include <linux/types.h>
  19. #include <linux/time.h>
  20. #include <asm/div64.h>
  21. #include <asm/time.h>
  22. #include <asm/param.h>
  23. typedef u64 __nocast cputime_t;
  24. typedef u64 __nocast cputime64_t;
  25. #define cmpxchg_cputime(ptr, old, new) cmpxchg(ptr, old, new)
  26. #ifdef __KERNEL__
  27. /*
  28. * Convert cputime <-> microseconds
  29. */
  30. extern u64 __cputime_usec_factor;
  31. static inline unsigned long cputime_to_usecs(const cputime_t ct)
  32. {
  33. return mulhdu((__force u64) ct, __cputime_usec_factor);
  34. }
  35. /*
  36. * PPC64 uses PACA which is task independent for storing accounting data while
  37. * PPC32 uses struct thread_info, therefore at task switch the accounting data
  38. * has to be populated in the new task
  39. */
  40. #ifdef CONFIG_PPC64
  41. #define get_accounting(tsk) (&get_paca()->accounting)
  42. static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
  43. #else
  44. #define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
  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. #endif /* __KERNEL__ */
  58. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  59. #endif /* __POWERPC_CPUTIME_H */