poll_state.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * poll_state.c - Polling idle state
  3. *
  4. * This file is released under the GPLv2.
  5. */
  6. #include <linux/cpuidle.h>
  7. #include <linux/sched.h>
  8. #include <linux/sched/clock.h>
  9. #include <linux/sched/idle.h>
  10. #define POLL_IDLE_TIME_LIMIT (TICK_NSEC / 16)
  11. #define POLL_IDLE_RELAX_COUNT 200
  12. static int __cpuidle poll_idle(struct cpuidle_device *dev,
  13. struct cpuidle_driver *drv, int index)
  14. {
  15. u64 time_start = local_clock();
  16. local_irq_enable();
  17. if (!current_set_polling_and_test()) {
  18. unsigned int loop_count = 0;
  19. while (!need_resched()) {
  20. cpu_relax();
  21. if (loop_count++ < POLL_IDLE_RELAX_COUNT)
  22. continue;
  23. loop_count = 0;
  24. if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT)
  25. break;
  26. }
  27. }
  28. current_clr_polling();
  29. return index;
  30. }
  31. void cpuidle_poll_state_init(struct cpuidle_driver *drv)
  32. {
  33. struct cpuidle_state *state = &drv->states[0];
  34. snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
  35. snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
  36. state->exit_latency = 0;
  37. state->target_residency = 0;
  38. state->power_usage = -1;
  39. state->enter = poll_idle;
  40. state->disabled = false;
  41. state->flags = CPUIDLE_FLAG_POLLING;
  42. }
  43. EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);