poll_state.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. dev->poll_time_limit = false;
  17. local_irq_enable();
  18. if (!current_set_polling_and_test()) {
  19. unsigned int loop_count = 0;
  20. while (!need_resched()) {
  21. cpu_relax();
  22. if (loop_count++ < POLL_IDLE_RELAX_COUNT)
  23. continue;
  24. loop_count = 0;
  25. if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT) {
  26. dev->poll_time_limit = true;
  27. break;
  28. }
  29. }
  30. }
  31. current_clr_polling();
  32. return index;
  33. }
  34. void cpuidle_poll_state_init(struct cpuidle_driver *drv)
  35. {
  36. struct cpuidle_state *state = &drv->states[0];
  37. snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
  38. snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
  39. state->exit_latency = 0;
  40. state->target_residency = 0;
  41. state->power_usage = -1;
  42. state->enter = poll_idle;
  43. state->disabled = false;
  44. state->flags = CPUIDLE_FLAG_POLLING;
  45. }
  46. EXPORT_SYMBOL_GPL(cpuidle_poll_state_init);