intel_rdt_sched.h 1.9 KB

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