idle.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Idle functions for s390.
  4. *
  5. * Copyright IBM Corp. 2014
  6. *
  7. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/kernel_stat.h>
  11. #include <linux/notifier.h>
  12. #include <linux/init.h>
  13. #include <linux/cpu.h>
  14. #include <trace/events/power.h>
  15. #include <asm/cpu_mf.h>
  16. #include <asm/cputime.h>
  17. #include <asm/nmi.h>
  18. #include <asm/smp.h>
  19. #include "entry.h"
  20. static DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
  21. void account_idle_time_irq(void)
  22. {
  23. struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
  24. struct lowcore *lc = get_lowcore();
  25. unsigned long idle_time;
  26. u64 cycles_new[8];
  27. int i;
  28. if (smp_cpu_mtid) {
  29. stcctm(MT_DIAG, smp_cpu_mtid, cycles_new);
  30. for (i = 0; i < smp_cpu_mtid; i++)
  31. this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
  32. }
  33. idle_time = lc->int_clock - idle->clock_idle_enter;
  34. lc->steal_timer += idle->clock_idle_enter - lc->last_update_clock;
  35. lc->last_update_clock = lc->int_clock;
  36. lc->system_timer += lc->last_update_timer - idle->timer_idle_enter;
  37. lc->last_update_timer = lc->sys_enter_timer;
  38. /* Account time spent with enabled wait psw loaded as idle time. */
  39. WRITE_ONCE(idle->idle_time, READ_ONCE(idle->idle_time) + idle_time);
  40. WRITE_ONCE(idle->idle_count, READ_ONCE(idle->idle_count) + 1);
  41. account_idle_time(cputime_to_nsecs(idle_time));
  42. }
  43. void noinstr arch_cpu_idle(void)
  44. {
  45. struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
  46. unsigned long psw_mask;
  47. /* Wait for external, I/O or machine check interrupt. */
  48. psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT |
  49. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  50. clear_cpu_flag(CIF_NOHZ_DELAY);
  51. set_cpu_flag(CIF_ENABLED_WAIT);
  52. if (smp_cpu_mtid)
  53. stcctm(MT_DIAG, smp_cpu_mtid, (u64 *)&idle->mt_cycles_enter);
  54. idle->clock_idle_enter = get_tod_clock_fast();
  55. idle->timer_idle_enter = get_cpu_timer();
  56. bpon();
  57. __load_psw_mask(psw_mask);
  58. }
  59. static ssize_t show_idle_count(struct device *dev,
  60. struct device_attribute *attr, char *buf)
  61. {
  62. struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
  63. return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_count));
  64. }
  65. DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
  66. static ssize_t show_idle_time(struct device *dev,
  67. struct device_attribute *attr, char *buf)
  68. {
  69. struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
  70. return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_time) >> 12);
  71. }
  72. DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
  73. void arch_cpu_idle_enter(void)
  74. {
  75. }
  76. void arch_cpu_idle_exit(void)
  77. {
  78. }
  79. void __noreturn arch_cpu_idle_dead(void)
  80. {
  81. cpu_die();
  82. }