intel_rdt_sched.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_INTEL_RDT_SCHED_H
  3. #define _ASM_X86_INTEL_RDT_SCHED_H
  4. #ifdef CONFIG_INTEL_RDT
  5. #include <linux/sched.h>
  6. #include <linux/jump_label.h>
  7. #define IA32_PQR_ASSOC 0x0c8f
  8. /**
  9. * struct intel_pqr_state - State cache for the PQR MSR
  10. * @cur_rmid: The cached Resource Monitoring ID
  11. * @cur_closid: The cached Class Of Service ID
  12. * @default_rmid: The user assigned Resource Monitoring ID
  13. * @default_closid: The user assigned cached Class Of Service ID
  14. *
  15. * The upper 32 bits of IA32_PQR_ASSOC contain closid and the
  16. * lower 10 bits rmid. The update to IA32_PQR_ASSOC always
  17. * contains both parts, so we need to cache them. This also
  18. * stores the user configured per cpu CLOSID and RMID.
  19. *
  20. * The cache also helps to avoid pointless updates if the value does
  21. * not change.
  22. */
  23. struct intel_pqr_state {
  24. u32 cur_rmid;
  25. u32 cur_closid;
  26. u32 default_rmid;
  27. u32 default_closid;
  28. };
  29. DECLARE_PER_CPU(struct intel_pqr_state, pqr_state);
  30. DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
  31. DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
  32. DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
  33. /*
  34. * __intel_rdt_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
  35. *
  36. * Following considerations are made so that this has minimal impact
  37. * on scheduler hot path:
  38. * - This will stay as no-op unless we are running on an Intel SKU
  39. * which supports resource control or monitoring and we enable by
  40. * mounting the resctrl file system.
  41. * - Caches the per cpu CLOSid/RMID values and does the MSR write only
  42. * when a task with a different CLOSid/RMID is scheduled in.
  43. * - We allocate RMIDs/CLOSids globally in order to keep this as
  44. * simple as possible.
  45. * Must be called with preemption disabled.
  46. */
  47. static void __intel_rdt_sched_in(void)
  48. {
  49. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  50. u32 closid = state->default_closid;
  51. u32 rmid = state->default_rmid;
  52. /*
  53. * If this task has a closid/rmid assigned, use it.
  54. * Else use the closid/rmid assigned to this cpu.
  55. */
  56. if (static_branch_likely(&rdt_alloc_enable_key)) {
  57. if (current->closid)
  58. closid = current->closid;
  59. }
  60. if (static_branch_likely(&rdt_mon_enable_key)) {
  61. if (current->rmid)
  62. rmid = current->rmid;
  63. }
  64. if (closid != state->cur_closid || rmid != state->cur_rmid) {
  65. state->cur_closid = closid;
  66. state->cur_rmid = rmid;
  67. wrmsr(IA32_PQR_ASSOC, rmid, closid);
  68. }
  69. }
  70. static inline void intel_rdt_sched_in(void)
  71. {
  72. if (static_branch_likely(&rdt_enable_key))
  73. __intel_rdt_sched_in();
  74. }
  75. #else
  76. static inline void intel_rdt_sched_in(void) {}
  77. #endif /* CONFIG_INTEL_RDT */
  78. #endif /* _ASM_X86_INTEL_RDT_SCHED_H */