intel_rdt.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #ifndef _ASM_X86_INTEL_RDT_H
  2. #define _ASM_X86_INTEL_RDT_H
  3. #ifdef CONFIG_INTEL_RDT_A
  4. #include <linux/sched.h>
  5. #include <linux/kernfs.h>
  6. #include <linux/jump_label.h>
  7. #include <asm/intel_rdt_common.h>
  8. #define IA32_L3_QOS_CFG 0xc81
  9. #define IA32_L3_CBM_BASE 0xc90
  10. #define IA32_L2_CBM_BASE 0xd10
  11. #define L3_QOS_CDP_ENABLE 0x01ULL
  12. /**
  13. * struct rdtgroup - store rdtgroup's data in resctrl file system.
  14. * @kn: kernfs node
  15. * @rdtgroup_list: linked list for all rdtgroups
  16. * @closid: closid for this rdtgroup
  17. * @cpu_mask: CPUs assigned to this rdtgroup
  18. * @flags: status bits
  19. * @waitcount: how many cpus expect to find this
  20. * group when they acquire rdtgroup_mutex
  21. */
  22. struct rdtgroup {
  23. struct kernfs_node *kn;
  24. struct list_head rdtgroup_list;
  25. int closid;
  26. struct cpumask cpu_mask;
  27. int flags;
  28. atomic_t waitcount;
  29. };
  30. /* rdtgroup.flags */
  31. #define RDT_DELETED 1
  32. /* List of all resource groups */
  33. extern struct list_head rdt_all_groups;
  34. int __init rdtgroup_init(void);
  35. /**
  36. * struct rftype - describe each file in the resctrl file system
  37. * @name: file name
  38. * @mode: access mode
  39. * @kf_ops: operations
  40. * @seq_show: show content of the file
  41. * @write: write to the file
  42. */
  43. struct rftype {
  44. char *name;
  45. umode_t mode;
  46. struct kernfs_ops *kf_ops;
  47. int (*seq_show)(struct kernfs_open_file *of,
  48. struct seq_file *sf, void *v);
  49. /*
  50. * write() is the generic write callback which maps directly to
  51. * kernfs write operation and overrides all other operations.
  52. * Maximum write size is determined by ->max_write_len.
  53. */
  54. ssize_t (*write)(struct kernfs_open_file *of,
  55. char *buf, size_t nbytes, loff_t off);
  56. };
  57. /**
  58. * struct rdt_resource - attributes of an RDT resource
  59. * @enabled: Is this feature enabled on this machine
  60. * @capable: Is this feature available on this machine
  61. * @name: Name to use in "schemata" file
  62. * @num_closid: Number of CLOSIDs available
  63. * @max_cbm: Largest Cache Bit Mask allowed
  64. * @min_cbm_bits: Minimum number of consecutive bits to be set
  65. * in a cache bit mask
  66. * @domains: All domains for this resource
  67. * @num_domains: Number of domains active
  68. * @msr_base: Base MSR address for CBMs
  69. * @tmp_cbms: Scratch space when updating schemata
  70. * @num_tmp_cbms: Number of CBMs in tmp_cbms
  71. * @cache_level: Which cache level defines scope of this domain
  72. * @cbm_idx_multi: Multiplier of CBM index
  73. * @cbm_idx_offset: Offset of CBM index. CBM index is computed by:
  74. * closid * cbm_idx_multi + cbm_idx_offset
  75. */
  76. struct rdt_resource {
  77. bool enabled;
  78. bool capable;
  79. char *name;
  80. int num_closid;
  81. int cbm_len;
  82. int min_cbm_bits;
  83. u32 max_cbm;
  84. struct list_head domains;
  85. int num_domains;
  86. int msr_base;
  87. u32 *tmp_cbms;
  88. int num_tmp_cbms;
  89. int cache_level;
  90. int cbm_idx_multi;
  91. int cbm_idx_offset;
  92. };
  93. /**
  94. * struct rdt_domain - group of cpus sharing an RDT resource
  95. * @list: all instances of this resource
  96. * @id: unique id for this instance
  97. * @cpu_mask: which cpus share this resource
  98. * @cbm: array of cache bit masks (indexed by CLOSID)
  99. */
  100. struct rdt_domain {
  101. struct list_head list;
  102. int id;
  103. struct cpumask cpu_mask;
  104. u32 *cbm;
  105. };
  106. /**
  107. * struct msr_param - set a range of MSRs from a domain
  108. * @res: The resource to use
  109. * @low: Beginning index from base MSR
  110. * @high: End index
  111. */
  112. struct msr_param {
  113. struct rdt_resource *res;
  114. int low;
  115. int high;
  116. };
  117. extern struct mutex rdtgroup_mutex;
  118. extern struct rdt_resource rdt_resources_all[];
  119. extern struct rdtgroup rdtgroup_default;
  120. DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
  121. int __init rdtgroup_init(void);
  122. enum {
  123. RDT_RESOURCE_L3,
  124. RDT_RESOURCE_L3DATA,
  125. RDT_RESOURCE_L3CODE,
  126. RDT_RESOURCE_L2,
  127. /* Must be the last */
  128. RDT_NUM_RESOURCES,
  129. };
  130. #define for_each_capable_rdt_resource(r) \
  131. for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
  132. r++) \
  133. if (r->capable)
  134. #define for_each_enabled_rdt_resource(r) \
  135. for (r = rdt_resources_all; r < rdt_resources_all + RDT_NUM_RESOURCES;\
  136. r++) \
  137. if (r->enabled)
  138. /* CPUID.(EAX=10H, ECX=ResID=1).EAX */
  139. union cpuid_0x10_1_eax {
  140. struct {
  141. unsigned int cbm_len:5;
  142. } split;
  143. unsigned int full;
  144. };
  145. /* CPUID.(EAX=10H, ECX=ResID=1).EDX */
  146. union cpuid_0x10_1_edx {
  147. struct {
  148. unsigned int cos_max:16;
  149. } split;
  150. unsigned int full;
  151. };
  152. DECLARE_PER_CPU_READ_MOSTLY(int, cpu_closid);
  153. void rdt_cbm_update(void *arg);
  154. struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn);
  155. void rdtgroup_kn_unlock(struct kernfs_node *kn);
  156. ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
  157. char *buf, size_t nbytes, loff_t off);
  158. int rdtgroup_schemata_show(struct kernfs_open_file *of,
  159. struct seq_file *s, void *v);
  160. /*
  161. * intel_rdt_sched_in() - Writes the task's CLOSid to IA32_PQR_MSR
  162. *
  163. * Following considerations are made so that this has minimal impact
  164. * on scheduler hot path:
  165. * - This will stay as no-op unless we are running on an Intel SKU
  166. * which supports resource control and we enable by mounting the
  167. * resctrl file system.
  168. * - Caches the per cpu CLOSid values and does the MSR write only
  169. * when a task with a different CLOSid is scheduled in.
  170. *
  171. * Must be called with preemption disabled.
  172. */
  173. static inline void intel_rdt_sched_in(void)
  174. {
  175. if (static_branch_likely(&rdt_enable_key)) {
  176. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  177. int closid;
  178. /*
  179. * If this task has a closid assigned, use it.
  180. * Else use the closid assigned to this cpu.
  181. */
  182. closid = current->closid;
  183. if (closid == 0)
  184. closid = this_cpu_read(cpu_closid);
  185. if (closid != state->closid) {
  186. state->closid = closid;
  187. wrmsr(MSR_IA32_PQR_ASSOC, state->rmid, closid);
  188. }
  189. }
  190. }
  191. #else
  192. static inline void intel_rdt_sched_in(void) {}
  193. #endif /* CONFIG_INTEL_RDT_A */
  194. #endif /* _ASM_X86_INTEL_RDT_H */