resctrl.rst 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. ===========================================
  4. User Interface for Resource Control feature
  5. ===========================================
  6. :Copyright: |copy| 2016 Intel Corporation
  7. :Authors: - Fenghua Yu <fenghua.yu@intel.com>
  8. - Tony Luck <tony.luck@intel.com>
  9. - Vikas Shivappa <vikas.shivappa@intel.com>
  10. Intel refers to this feature as Intel Resource Director Technology(Intel(R) RDT).
  11. AMD refers to this feature as AMD Platform Quality of Service(AMD QoS).
  12. This feature is enabled by the CONFIG_X86_CPU_RESCTRL and the x86 /proc/cpuinfo
  13. flag bits:
  14. =============================================== ================================
  15. RDT (Resource Director Technology) Allocation "rdt_a"
  16. CAT (Cache Allocation Technology) "cat_l3", "cat_l2"
  17. CDP (Code and Data Prioritization) "cdp_l3", "cdp_l2"
  18. CQM (Cache QoS Monitoring) "cqm_llc", "cqm_occup_llc"
  19. MBM (Memory Bandwidth Monitoring) "cqm_mbm_total", "cqm_mbm_local"
  20. MBA (Memory Bandwidth Allocation) "mba"
  21. SMBA (Slow Memory Bandwidth Allocation) ""
  22. BMEC (Bandwidth Monitoring Event Configuration) ""
  23. =============================================== ================================
  24. Historically, new features were made visible by default in /proc/cpuinfo. This
  25. resulted in the feature flags becoming hard to parse by humans. Adding a new
  26. flag to /proc/cpuinfo should be avoided if user space can obtain information
  27. about the feature from resctrl's info directory.
  28. To use the feature mount the file system::
  29. # mount -t resctrl resctrl [-o cdp[,cdpl2][,mba_MBps][,debug]] /sys/fs/resctrl
  30. mount options are:
  31. "cdp":
  32. Enable code/data prioritization in L3 cache allocations.
  33. "cdpl2":
  34. Enable code/data prioritization in L2 cache allocations.
  35. "mba_MBps":
  36. Enable the MBA Software Controller(mba_sc) to specify MBA
  37. bandwidth in MiBps
  38. "debug":
  39. Make debug files accessible. Available debug files are annotated with
  40. "Available only with debug option".
  41. L2 and L3 CDP are controlled separately.
  42. RDT features are orthogonal. A particular system may support only
  43. monitoring, only control, or both monitoring and control. Cache
  44. pseudo-locking is a unique way of using cache control to "pin" or
  45. "lock" data in the cache. Details can be found in
  46. "Cache Pseudo-Locking".
  47. The mount succeeds if either of allocation or monitoring is present, but
  48. only those files and directories supported by the system will be created.
  49. For more details on the behavior of the interface during monitoring
  50. and allocation, see the "Resource alloc and monitor groups" section.
  51. Info directory
  52. ==============
  53. The 'info' directory contains information about the enabled
  54. resources. Each resource has its own subdirectory. The subdirectory
  55. names reflect the resource names.
  56. Each subdirectory contains the following files with respect to
  57. allocation:
  58. Cache resource(L3/L2) subdirectory contains the following files
  59. related to allocation:
  60. "num_closids":
  61. The number of CLOSIDs which are valid for this
  62. resource. The kernel uses the smallest number of
  63. CLOSIDs of all enabled resources as limit.
  64. "cbm_mask":
  65. The bitmask which is valid for this resource.
  66. This mask is equivalent to 100%.
  67. "min_cbm_bits":
  68. The minimum number of consecutive bits which
  69. must be set when writing a mask.
  70. "shareable_bits":
  71. Bitmask of shareable resource with other executing
  72. entities (e.g. I/O). User can use this when
  73. setting up exclusive cache partitions. Note that
  74. some platforms support devices that have their
  75. own settings for cache use which can over-ride
  76. these bits.
  77. "bit_usage":
  78. Annotated capacity bitmasks showing how all
  79. instances of the resource are used. The legend is:
  80. "0":
  81. Corresponding region is unused. When the system's
  82. resources have been allocated and a "0" is found
  83. in "bit_usage" it is a sign that resources are
  84. wasted.
  85. "H":
  86. Corresponding region is used by hardware only
  87. but available for software use. If a resource
  88. has bits set in "shareable_bits" but not all
  89. of these bits appear in the resource groups'
  90. schematas then the bits appearing in
  91. "shareable_bits" but no resource group will
  92. be marked as "H".
  93. "X":
  94. Corresponding region is available for sharing and
  95. used by hardware and software. These are the
  96. bits that appear in "shareable_bits" as
  97. well as a resource group's allocation.
  98. "S":
  99. Corresponding region is used by software
  100. and available for sharing.
  101. "E":
  102. Corresponding region is used exclusively by
  103. one resource group. No sharing allowed.
  104. "P":
  105. Corresponding region is pseudo-locked. No
  106. sharing allowed.
  107. "sparse_masks":
  108. Indicates if non-contiguous 1s value in CBM is supported.
  109. "0":
  110. Only contiguous 1s value in CBM is supported.
  111. "1":
  112. Non-contiguous 1s value in CBM is supported.
  113. Memory bandwidth(MB) subdirectory contains the following files
  114. with respect to allocation:
  115. "min_bandwidth":
  116. The minimum memory bandwidth percentage which
  117. user can request.
  118. "bandwidth_gran":
  119. The granularity in which the memory bandwidth
  120. percentage is allocated. The allocated
  121. b/w percentage is rounded off to the next
  122. control step available on the hardware. The
  123. available bandwidth control steps are:
  124. min_bandwidth + N * bandwidth_gran.
  125. "delay_linear":
  126. Indicates if the delay scale is linear or
  127. non-linear. This field is purely informational
  128. only.
  129. "thread_throttle_mode":
  130. Indicator on Intel systems of how tasks running on threads
  131. of a physical core are throttled in cases where they
  132. request different memory bandwidth percentages:
  133. "max":
  134. the smallest percentage is applied
  135. to all threads
  136. "per-thread":
  137. bandwidth percentages are directly applied to
  138. the threads running on the core
  139. If RDT monitoring is available there will be an "L3_MON" directory
  140. with the following files:
  141. "num_rmids":
  142. The number of RMIDs available. This is the
  143. upper bound for how many "CTRL_MON" + "MON"
  144. groups can be created.
  145. "mon_features":
  146. Lists the monitoring events if
  147. monitoring is enabled for the resource.
  148. Example::
  149. # cat /sys/fs/resctrl/info/L3_MON/mon_features
  150. llc_occupancy
  151. mbm_total_bytes
  152. mbm_local_bytes
  153. If the system supports Bandwidth Monitoring Event
  154. Configuration (BMEC), then the bandwidth events will
  155. be configurable. The output will be::
  156. # cat /sys/fs/resctrl/info/L3_MON/mon_features
  157. llc_occupancy
  158. mbm_total_bytes
  159. mbm_total_bytes_config
  160. mbm_local_bytes
  161. mbm_local_bytes_config
  162. "mbm_total_bytes_config", "mbm_local_bytes_config":
  163. Read/write files containing the configuration for the mbm_total_bytes
  164. and mbm_local_bytes events, respectively, when the Bandwidth
  165. Monitoring Event Configuration (BMEC) feature is supported.
  166. The event configuration settings are domain specific and affect
  167. all the CPUs in the domain. When either event configuration is
  168. changed, the bandwidth counters for all RMIDs of both events
  169. (mbm_total_bytes as well as mbm_local_bytes) are cleared for that
  170. domain. The next read for every RMID will report "Unavailable"
  171. and subsequent reads will report the valid value.
  172. Following are the types of events supported:
  173. ==== ========================================================
  174. Bits Description
  175. ==== ========================================================
  176. 6 Dirty Victims from the QOS domain to all types of memory
  177. 5 Reads to slow memory in the non-local NUMA domain
  178. 4 Reads to slow memory in the local NUMA domain
  179. 3 Non-temporal writes to non-local NUMA domain
  180. 2 Non-temporal writes to local NUMA domain
  181. 1 Reads to memory in the non-local NUMA domain
  182. 0 Reads to memory in the local NUMA domain
  183. ==== ========================================================
  184. By default, the mbm_total_bytes configuration is set to 0x7f to count
  185. all the event types and the mbm_local_bytes configuration is set to
  186. 0x15 to count all the local memory events.
  187. Examples:
  188. * To view the current configuration::
  189. ::
  190. # cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config
  191. 0=0x7f;1=0x7f;2=0x7f;3=0x7f
  192. # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config
  193. 0=0x15;1=0x15;3=0x15;4=0x15
  194. * To change the mbm_total_bytes to count only reads on domain 0,
  195. the bits 0, 1, 4 and 5 needs to be set, which is 110011b in binary
  196. (in hexadecimal 0x33):
  197. ::
  198. # echo "0=0x33" > /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config
  199. # cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config
  200. 0=0x33;1=0x7f;2=0x7f;3=0x7f
  201. * To change the mbm_local_bytes to count all the slow memory reads on
  202. domain 0 and 1, the bits 4 and 5 needs to be set, which is 110000b
  203. in binary (in hexadecimal 0x30):
  204. ::
  205. # echo "0=0x30;1=0x30" > /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config
  206. # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config
  207. 0=0x30;1=0x30;3=0x15;4=0x15
  208. "max_threshold_occupancy":
  209. Read/write file provides the largest value (in
  210. bytes) at which a previously used LLC_occupancy
  211. counter can be considered for re-use.
  212. Finally, in the top level of the "info" directory there is a file
  213. named "last_cmd_status". This is reset with every "command" issued
  214. via the file system (making new directories or writing to any of the
  215. control files). If the command was successful, it will read as "ok".
  216. If the command failed, it will provide more information that can be
  217. conveyed in the error returns from file operations. E.g.
  218. ::
  219. # echo L3:0=f7 > schemata
  220. bash: echo: write error: Invalid argument
  221. # cat info/last_cmd_status
  222. mask f7 has non-consecutive 1-bits
  223. Resource alloc and monitor groups
  224. =================================
  225. Resource groups are represented as directories in the resctrl file
  226. system. The default group is the root directory which, immediately
  227. after mounting, owns all the tasks and cpus in the system and can make
  228. full use of all resources.
  229. On a system with RDT control features additional directories can be
  230. created in the root directory that specify different amounts of each
  231. resource (see "schemata" below). The root and these additional top level
  232. directories are referred to as "CTRL_MON" groups below.
  233. On a system with RDT monitoring the root directory and other top level
  234. directories contain a directory named "mon_groups" in which additional
  235. directories can be created to monitor subsets of tasks in the CTRL_MON
  236. group that is their ancestor. These are called "MON" groups in the rest
  237. of this document.
  238. Removing a directory will move all tasks and cpus owned by the group it
  239. represents to the parent. Removing one of the created CTRL_MON groups
  240. will automatically remove all MON groups below it.
  241. Moving MON group directories to a new parent CTRL_MON group is supported
  242. for the purpose of changing the resource allocations of a MON group
  243. without impacting its monitoring data or assigned tasks. This operation
  244. is not allowed for MON groups which monitor CPUs. No other move
  245. operation is currently allowed other than simply renaming a CTRL_MON or
  246. MON group.
  247. All groups contain the following files:
  248. "tasks":
  249. Reading this file shows the list of all tasks that belong to
  250. this group. Writing a task id to the file will add a task to the
  251. group. Multiple tasks can be added by separating the task ids
  252. with commas. Tasks will be assigned sequentially. Multiple
  253. failures are not supported. A single failure encountered while
  254. attempting to assign a task will cause the operation to abort and
  255. already added tasks before the failure will remain in the group.
  256. Failures will be logged to /sys/fs/resctrl/info/last_cmd_status.
  257. If the group is a CTRL_MON group the task is removed from
  258. whichever previous CTRL_MON group owned the task and also from
  259. any MON group that owned the task. If the group is a MON group,
  260. then the task must already belong to the CTRL_MON parent of this
  261. group. The task is removed from any previous MON group.
  262. "cpus":
  263. Reading this file shows a bitmask of the logical CPUs owned by
  264. this group. Writing a mask to this file will add and remove
  265. CPUs to/from this group. As with the tasks file a hierarchy is
  266. maintained where MON groups may only include CPUs owned by the
  267. parent CTRL_MON group.
  268. When the resource group is in pseudo-locked mode this file will
  269. only be readable, reflecting the CPUs associated with the
  270. pseudo-locked region.
  271. "cpus_list":
  272. Just like "cpus", only using ranges of CPUs instead of bitmasks.
  273. When control is enabled all CTRL_MON groups will also contain:
  274. "schemata":
  275. A list of all the resources available to this group.
  276. Each resource has its own line and format - see below for details.
  277. "size":
  278. Mirrors the display of the "schemata" file to display the size in
  279. bytes of each allocation instead of the bits representing the
  280. allocation.
  281. "mode":
  282. The "mode" of the resource group dictates the sharing of its
  283. allocations. A "shareable" resource group allows sharing of its
  284. allocations while an "exclusive" resource group does not. A
  285. cache pseudo-locked region is created by first writing
  286. "pseudo-locksetup" to the "mode" file before writing the cache
  287. pseudo-locked region's schemata to the resource group's "schemata"
  288. file. On successful pseudo-locked region creation the mode will
  289. automatically change to "pseudo-locked".
  290. "ctrl_hw_id":
  291. Available only with debug option. The identifier used by hardware
  292. for the control group. On x86 this is the CLOSID.
  293. When monitoring is enabled all MON groups will also contain:
  294. "mon_data":
  295. This contains a set of files organized by L3 domain and by
  296. RDT event. E.g. on a system with two L3 domains there will
  297. be subdirectories "mon_L3_00" and "mon_L3_01". Each of these
  298. directories have one file per event (e.g. "llc_occupancy",
  299. "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these
  300. files provide a read out of the current value of the event for
  301. all tasks in the group. In CTRL_MON groups these files provide
  302. the sum for all tasks in the CTRL_MON group and all tasks in
  303. MON groups. Please see example section for more details on usage.
  304. On systems with Sub-NUMA Cluster (SNC) enabled there are extra
  305. directories for each node (located within the "mon_L3_XX" directory
  306. for the L3 cache they occupy). These are named "mon_sub_L3_YY"
  307. where "YY" is the node number.
  308. "mon_hw_id":
  309. Available only with debug option. The identifier used by hardware
  310. for the monitor group. On x86 this is the RMID.
  311. Resource allocation rules
  312. -------------------------
  313. When a task is running the following rules define which resources are
  314. available to it:
  315. 1) If the task is a member of a non-default group, then the schemata
  316. for that group is used.
  317. 2) Else if the task belongs to the default group, but is running on a
  318. CPU that is assigned to some specific group, then the schemata for the
  319. CPU's group is used.
  320. 3) Otherwise the schemata for the default group is used.
  321. Resource monitoring rules
  322. -------------------------
  323. 1) If a task is a member of a MON group, or non-default CTRL_MON group
  324. then RDT events for the task will be reported in that group.
  325. 2) If a task is a member of the default CTRL_MON group, but is running
  326. on a CPU that is assigned to some specific group, then the RDT events
  327. for the task will be reported in that group.
  328. 3) Otherwise RDT events for the task will be reported in the root level
  329. "mon_data" group.
  330. Notes on cache occupancy monitoring and control
  331. ===============================================
  332. When moving a task from one group to another you should remember that
  333. this only affects *new* cache allocations by the task. E.g. you may have
  334. a task in a monitor group showing 3 MB of cache occupancy. If you move
  335. to a new group and immediately check the occupancy of the old and new
  336. groups you will likely see that the old group is still showing 3 MB and
  337. the new group zero. When the task accesses locations still in cache from
  338. before the move, the h/w does not update any counters. On a busy system
  339. you will likely see the occupancy in the old group go down as cache lines
  340. are evicted and re-used while the occupancy in the new group rises as
  341. the task accesses memory and loads into the cache are counted based on
  342. membership in the new group.
  343. The same applies to cache allocation control. Moving a task to a group
  344. with a smaller cache partition will not evict any cache lines. The
  345. process may continue to use them from the old partition.
  346. Hardware uses CLOSid(Class of service ID) and an RMID(Resource monitoring ID)
  347. to identify a control group and a monitoring group respectively. Each of
  348. the resource groups are mapped to these IDs based on the kind of group. The
  349. number of CLOSid and RMID are limited by the hardware and hence the creation of
  350. a "CTRL_MON" directory may fail if we run out of either CLOSID or RMID
  351. and creation of "MON" group may fail if we run out of RMIDs.
  352. max_threshold_occupancy - generic concepts
  353. ------------------------------------------
  354. Note that an RMID once freed may not be immediately available for use as
  355. the RMID is still tagged the cache lines of the previous user of RMID.
  356. Hence such RMIDs are placed on limbo list and checked back if the cache
  357. occupancy has gone down. If there is a time when system has a lot of
  358. limbo RMIDs but which are not ready to be used, user may see an -EBUSY
  359. during mkdir.
  360. max_threshold_occupancy is a user configurable value to determine the
  361. occupancy at which an RMID can be freed.
  362. The mon_llc_occupancy_limbo tracepoint gives the precise occupancy in bytes
  363. for a subset of RMID that are not immediately available for allocation.
  364. This can't be relied on to produce output every second, it may be necessary
  365. to attempt to create an empty monitor group to force an update. Output may
  366. only be produced if creation of a control or monitor group fails.
  367. Schemata files - general concepts
  368. ---------------------------------
  369. Each line in the file describes one resource. The line starts with
  370. the name of the resource, followed by specific values to be applied
  371. in each of the instances of that resource on the system.
  372. Cache IDs
  373. ---------
  374. On current generation systems there is one L3 cache per socket and L2
  375. caches are generally just shared by the hyperthreads on a core, but this
  376. isn't an architectural requirement. We could have multiple separate L3
  377. caches on a socket, multiple cores could share an L2 cache. So instead
  378. of using "socket" or "core" to define the set of logical cpus sharing
  379. a resource we use a "Cache ID". At a given cache level this will be a
  380. unique number across the whole system (but it isn't guaranteed to be a
  381. contiguous sequence, there may be gaps). To find the ID for each logical
  382. CPU look in /sys/devices/system/cpu/cpu*/cache/index*/id
  383. Cache Bit Masks (CBM)
  384. ---------------------
  385. For cache resources we describe the portion of the cache that is available
  386. for allocation using a bitmask. The maximum value of the mask is defined
  387. by each cpu model (and may be different for different cache levels). It
  388. is found using CPUID, but is also provided in the "info" directory of
  389. the resctrl file system in "info/{resource}/cbm_mask". Some Intel hardware
  390. requires that these masks have all the '1' bits in a contiguous block. So
  391. 0x3, 0x6 and 0xC are legal 4-bit masks with two bits set, but 0x5, 0x9
  392. and 0xA are not. Check /sys/fs/resctrl/info/{resource}/sparse_masks
  393. if non-contiguous 1s value is supported. On a system with a 20-bit mask
  394. each bit represents 5% of the capacity of the cache. You could partition
  395. the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000.
  396. Notes on Sub-NUMA Cluster mode
  397. ==============================
  398. When SNC mode is enabled, Linux may load balance tasks between Sub-NUMA
  399. nodes much more readily than between regular NUMA nodes since the CPUs
  400. on Sub-NUMA nodes share the same L3 cache and the system may report
  401. the NUMA distance between Sub-NUMA nodes with a lower value than used
  402. for regular NUMA nodes.
  403. The top-level monitoring files in each "mon_L3_XX" directory provide
  404. the sum of data across all SNC nodes sharing an L3 cache instance.
  405. Users who bind tasks to the CPUs of a specific Sub-NUMA node can read
  406. the "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes" in the
  407. "mon_sub_L3_YY" directories to get node local data.
  408. Memory bandwidth allocation is still performed at the L3 cache
  409. level. I.e. throttling controls are applied to all SNC nodes.
  410. L3 cache allocation bitmaps also apply to all SNC nodes. But note that
  411. the amount of L3 cache represented by each bit is divided by the number
  412. of SNC nodes per L3 cache. E.g. with a 100MB cache on a system with 10-bit
  413. allocation masks each bit normally represents 10MB. With SNC mode enabled
  414. with two SNC nodes per L3 cache, each bit only represents 5MB.
  415. Memory bandwidth Allocation and monitoring
  416. ==========================================
  417. For Memory bandwidth resource, by default the user controls the resource
  418. by indicating the percentage of total memory bandwidth.
  419. The minimum bandwidth percentage value for each cpu model is predefined
  420. and can be looked up through "info/MB/min_bandwidth". The bandwidth
  421. granularity that is allocated is also dependent on the cpu model and can
  422. be looked up at "info/MB/bandwidth_gran". The available bandwidth
  423. control steps are: min_bw + N * bw_gran. Intermediate values are rounded
  424. to the next control step available on the hardware.
  425. The bandwidth throttling is a core specific mechanism on some of Intel
  426. SKUs. Using a high bandwidth and a low bandwidth setting on two threads
  427. sharing a core may result in both threads being throttled to use the
  428. low bandwidth (see "thread_throttle_mode").
  429. The fact that Memory bandwidth allocation(MBA) may be a core
  430. specific mechanism where as memory bandwidth monitoring(MBM) is done at
  431. the package level may lead to confusion when users try to apply control
  432. via the MBA and then monitor the bandwidth to see if the controls are
  433. effective. Below are such scenarios:
  434. 1. User may *not* see increase in actual bandwidth when percentage
  435. values are increased:
  436. This can occur when aggregate L2 external bandwidth is more than L3
  437. external bandwidth. Consider an SKL SKU with 24 cores on a package and
  438. where L2 external is 10GBps (hence aggregate L2 external bandwidth is
  439. 240GBps) and L3 external bandwidth is 100GBps. Now a workload with '20
  440. threads, having 50% bandwidth, each consuming 5GBps' consumes the max L3
  441. bandwidth of 100GBps although the percentage value specified is only 50%
  442. << 100%. Hence increasing the bandwidth percentage will not yield any
  443. more bandwidth. This is because although the L2 external bandwidth still
  444. has capacity, the L3 external bandwidth is fully used. Also note that
  445. this would be dependent on number of cores the benchmark is run on.
  446. 2. Same bandwidth percentage may mean different actual bandwidth
  447. depending on # of threads:
  448. For the same SKU in #1, a 'single thread, with 10% bandwidth' and '4
  449. thread, with 10% bandwidth' can consume upto 10GBps and 40GBps although
  450. they have same percentage bandwidth of 10%. This is simply because as
  451. threads start using more cores in an rdtgroup, the actual bandwidth may
  452. increase or vary although user specified bandwidth percentage is same.
  453. In order to mitigate this and make the interface more user friendly,
  454. resctrl added support for specifying the bandwidth in MiBps as well. The
  455. kernel underneath would use a software feedback mechanism or a "Software
  456. Controller(mba_sc)" which reads the actual bandwidth using MBM counters
  457. and adjust the memory bandwidth percentages to ensure::
  458. "actual bandwidth < user specified bandwidth".
  459. By default, the schemata would take the bandwidth percentage values
  460. where as user can switch to the "MBA software controller" mode using
  461. a mount option 'mba_MBps'. The schemata format is specified in the below
  462. sections.
  463. L3 schemata file details (code and data prioritization disabled)
  464. ----------------------------------------------------------------
  465. With CDP disabled the L3 schemata format is::
  466. L3:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  467. L3 schemata file details (CDP enabled via mount option to resctrl)
  468. ------------------------------------------------------------------
  469. When CDP is enabled L3 control is split into two separate resources
  470. so you can specify independent masks for code and data like this::
  471. L3DATA:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  472. L3CODE:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  473. L2 schemata file details
  474. ------------------------
  475. CDP is supported at L2 using the 'cdpl2' mount option. The schemata
  476. format is either::
  477. L2:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  478. or
  479. L2DATA:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  480. L2CODE:<cache_id0>=<cbm>;<cache_id1>=<cbm>;...
  481. Memory bandwidth Allocation (default mode)
  482. ------------------------------------------
  483. Memory b/w domain is L3 cache.
  484. ::
  485. MB:<cache_id0>=bandwidth0;<cache_id1>=bandwidth1;...
  486. Memory bandwidth Allocation specified in MiBps
  487. ----------------------------------------------
  488. Memory bandwidth domain is L3 cache.
  489. ::
  490. MB:<cache_id0>=bw_MiBps0;<cache_id1>=bw_MiBps1;...
  491. Slow Memory Bandwidth Allocation (SMBA)
  492. ---------------------------------------
  493. AMD hardware supports Slow Memory Bandwidth Allocation (SMBA).
  494. CXL.memory is the only supported "slow" memory device. With the
  495. support of SMBA, the hardware enables bandwidth allocation on
  496. the slow memory devices. If there are multiple such devices in
  497. the system, the throttling logic groups all the slow sources
  498. together and applies the limit on them as a whole.
  499. The presence of SMBA (with CXL.memory) is independent of slow memory
  500. devices presence. If there are no such devices on the system, then
  501. configuring SMBA will have no impact on the performance of the system.
  502. The bandwidth domain for slow memory is L3 cache. Its schemata file
  503. is formatted as:
  504. ::
  505. SMBA:<cache_id0>=bandwidth0;<cache_id1>=bandwidth1;...
  506. Reading/writing the schemata file
  507. ---------------------------------
  508. Reading the schemata file will show the state of all resources
  509. on all domains. When writing you only need to specify those values
  510. which you wish to change. E.g.
  511. ::
  512. # cat schemata
  513. L3DATA:0=fffff;1=fffff;2=fffff;3=fffff
  514. L3CODE:0=fffff;1=fffff;2=fffff;3=fffff
  515. # echo "L3DATA:2=3c0;" > schemata
  516. # cat schemata
  517. L3DATA:0=fffff;1=fffff;2=3c0;3=fffff
  518. L3CODE:0=fffff;1=fffff;2=fffff;3=fffff
  519. Reading/writing the schemata file (on AMD systems)
  520. --------------------------------------------------
  521. Reading the schemata file will show the current bandwidth limit on all
  522. domains. The allocated resources are in multiples of one eighth GB/s.
  523. When writing to the file, you need to specify what cache id you wish to
  524. configure the bandwidth limit.
  525. For example, to allocate 2GB/s limit on the first cache id:
  526. ::
  527. # cat schemata
  528. MB:0=2048;1=2048;2=2048;3=2048
  529. L3:0=ffff;1=ffff;2=ffff;3=ffff
  530. # echo "MB:1=16" > schemata
  531. # cat schemata
  532. MB:0=2048;1= 16;2=2048;3=2048
  533. L3:0=ffff;1=ffff;2=ffff;3=ffff
  534. Reading/writing the schemata file (on AMD systems) with SMBA feature
  535. --------------------------------------------------------------------
  536. Reading and writing the schemata file is the same as without SMBA in
  537. above section.
  538. For example, to allocate 8GB/s limit on the first cache id:
  539. ::
  540. # cat schemata
  541. SMBA:0=2048;1=2048;2=2048;3=2048
  542. MB:0=2048;1=2048;2=2048;3=2048
  543. L3:0=ffff;1=ffff;2=ffff;3=ffff
  544. # echo "SMBA:1=64" > schemata
  545. # cat schemata
  546. SMBA:0=2048;1= 64;2=2048;3=2048
  547. MB:0=2048;1=2048;2=2048;3=2048
  548. L3:0=ffff;1=ffff;2=ffff;3=ffff
  549. Cache Pseudo-Locking
  550. ====================
  551. CAT enables a user to specify the amount of cache space that an
  552. application can fill. Cache pseudo-locking builds on the fact that a
  553. CPU can still read and write data pre-allocated outside its current
  554. allocated area on a cache hit. With cache pseudo-locking, data can be
  555. preloaded into a reserved portion of cache that no application can
  556. fill, and from that point on will only serve cache hits. The cache
  557. pseudo-locked memory is made accessible to user space where an
  558. application can map it into its virtual address space and thus have
  559. a region of memory with reduced average read latency.
  560. The creation of a cache pseudo-locked region is triggered by a request
  561. from the user to do so that is accompanied by a schemata of the region
  562. to be pseudo-locked. The cache pseudo-locked region is created as follows:
  563. - Create a CAT allocation CLOSNEW with a CBM matching the schemata
  564. from the user of the cache region that will contain the pseudo-locked
  565. memory. This region must not overlap with any current CAT allocation/CLOS
  566. on the system and no future overlap with this cache region is allowed
  567. while the pseudo-locked region exists.
  568. - Create a contiguous region of memory of the same size as the cache
  569. region.
  570. - Flush the cache, disable hardware prefetchers, disable preemption.
  571. - Make CLOSNEW the active CLOS and touch the allocated memory to load
  572. it into the cache.
  573. - Set the previous CLOS as active.
  574. - At this point the closid CLOSNEW can be released - the cache
  575. pseudo-locked region is protected as long as its CBM does not appear in
  576. any CAT allocation. Even though the cache pseudo-locked region will from
  577. this point on not appear in any CBM of any CLOS an application running with
  578. any CLOS will be able to access the memory in the pseudo-locked region since
  579. the region continues to serve cache hits.
  580. - The contiguous region of memory loaded into the cache is exposed to
  581. user-space as a character device.
  582. Cache pseudo-locking increases the probability that data will remain
  583. in the cache via carefully configuring the CAT feature and controlling
  584. application behavior. There is no guarantee that data is placed in
  585. cache. Instructions like INVD, WBINVD, CLFLUSH, etc. can still evict
  586. “locked” data from cache. Power management C-states may shrink or
  587. power off cache. Deeper C-states will automatically be restricted on
  588. pseudo-locked region creation.
  589. It is required that an application using a pseudo-locked region runs
  590. with affinity to the cores (or a subset of the cores) associated
  591. with the cache on which the pseudo-locked region resides. A sanity check
  592. within the code will not allow an application to map pseudo-locked memory
  593. unless it runs with affinity to cores associated with the cache on which the
  594. pseudo-locked region resides. The sanity check is only done during the
  595. initial mmap() handling, there is no enforcement afterwards and the
  596. application self needs to ensure it remains affine to the correct cores.
  597. Pseudo-locking is accomplished in two stages:
  598. 1) During the first stage the system administrator allocates a portion
  599. of cache that should be dedicated to pseudo-locking. At this time an
  600. equivalent portion of memory is allocated, loaded into allocated
  601. cache portion, and exposed as a character device.
  602. 2) During the second stage a user-space application maps (mmap()) the
  603. pseudo-locked memory into its address space.
  604. Cache Pseudo-Locking Interface
  605. ------------------------------
  606. A pseudo-locked region is created using the resctrl interface as follows:
  607. 1) Create a new resource group by creating a new directory in /sys/fs/resctrl.
  608. 2) Change the new resource group's mode to "pseudo-locksetup" by writing
  609. "pseudo-locksetup" to the "mode" file.
  610. 3) Write the schemata of the pseudo-locked region to the "schemata" file. All
  611. bits within the schemata should be "unused" according to the "bit_usage"
  612. file.
  613. On successful pseudo-locked region creation the "mode" file will contain
  614. "pseudo-locked" and a new character device with the same name as the resource
  615. group will exist in /dev/pseudo_lock. This character device can be mmap()'ed
  616. by user space in order to obtain access to the pseudo-locked memory region.
  617. An example of cache pseudo-locked region creation and usage can be found below.
  618. Cache Pseudo-Locking Debugging Interface
  619. ----------------------------------------
  620. The pseudo-locking debugging interface is enabled by default (if
  621. CONFIG_DEBUG_FS is enabled) and can be found in /sys/kernel/debug/resctrl.
  622. There is no explicit way for the kernel to test if a provided memory
  623. location is present in the cache. The pseudo-locking debugging interface uses
  624. the tracing infrastructure to provide two ways to measure cache residency of
  625. the pseudo-locked region:
  626. 1) Memory access latency using the pseudo_lock_mem_latency tracepoint. Data
  627. from these measurements are best visualized using a hist trigger (see
  628. example below). In this test the pseudo-locked region is traversed at
  629. a stride of 32 bytes while hardware prefetchers and preemption
  630. are disabled. This also provides a substitute visualization of cache
  631. hits and misses.
  632. 2) Cache hit and miss measurements using model specific precision counters if
  633. available. Depending on the levels of cache on the system the pseudo_lock_l2
  634. and pseudo_lock_l3 tracepoints are available.
  635. When a pseudo-locked region is created a new debugfs directory is created for
  636. it in debugfs as /sys/kernel/debug/resctrl/<newdir>. A single
  637. write-only file, pseudo_lock_measure, is present in this directory. The
  638. measurement of the pseudo-locked region depends on the number written to this
  639. debugfs file:
  640. 1:
  641. writing "1" to the pseudo_lock_measure file will trigger the latency
  642. measurement captured in the pseudo_lock_mem_latency tracepoint. See
  643. example below.
  644. 2:
  645. writing "2" to the pseudo_lock_measure file will trigger the L2 cache
  646. residency (cache hits and misses) measurement captured in the
  647. pseudo_lock_l2 tracepoint. See example below.
  648. 3:
  649. writing "3" to the pseudo_lock_measure file will trigger the L3 cache
  650. residency (cache hits and misses) measurement captured in the
  651. pseudo_lock_l3 tracepoint.
  652. All measurements are recorded with the tracing infrastructure. This requires
  653. the relevant tracepoints to be enabled before the measurement is triggered.
  654. Example of latency debugging interface
  655. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  656. In this example a pseudo-locked region named "newlock" was created. Here is
  657. how we can measure the latency in cycles of reading from this region and
  658. visualize this data with a histogram that is available if CONFIG_HIST_TRIGGERS
  659. is set::
  660. # :> /sys/kernel/tracing/trace
  661. # echo 'hist:keys=latency' > /sys/kernel/tracing/events/resctrl/pseudo_lock_mem_latency/trigger
  662. # echo 1 > /sys/kernel/tracing/events/resctrl/pseudo_lock_mem_latency/enable
  663. # echo 1 > /sys/kernel/debug/resctrl/newlock/pseudo_lock_measure
  664. # echo 0 > /sys/kernel/tracing/events/resctrl/pseudo_lock_mem_latency/enable
  665. # cat /sys/kernel/tracing/events/resctrl/pseudo_lock_mem_latency/hist
  666. # event histogram
  667. #
  668. # trigger info: hist:keys=latency:vals=hitcount:sort=hitcount:size=2048 [active]
  669. #
  670. { latency: 456 } hitcount: 1
  671. { latency: 50 } hitcount: 83
  672. { latency: 36 } hitcount: 96
  673. { latency: 44 } hitcount: 174
  674. { latency: 48 } hitcount: 195
  675. { latency: 46 } hitcount: 262
  676. { latency: 42 } hitcount: 693
  677. { latency: 40 } hitcount: 3204
  678. { latency: 38 } hitcount: 3484
  679. Totals:
  680. Hits: 8192
  681. Entries: 9
  682. Dropped: 0
  683. Example of cache hits/misses debugging
  684. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  685. In this example a pseudo-locked region named "newlock" was created on the L2
  686. cache of a platform. Here is how we can obtain details of the cache hits
  687. and misses using the platform's precision counters.
  688. ::
  689. # :> /sys/kernel/tracing/trace
  690. # echo 1 > /sys/kernel/tracing/events/resctrl/pseudo_lock_l2/enable
  691. # echo 2 > /sys/kernel/debug/resctrl/newlock/pseudo_lock_measure
  692. # echo 0 > /sys/kernel/tracing/events/resctrl/pseudo_lock_l2/enable
  693. # cat /sys/kernel/tracing/trace
  694. # tracer: nop
  695. #
  696. # _-----=> irqs-off
  697. # / _----=> need-resched
  698. # | / _---=> hardirq/softirq
  699. # || / _--=> preempt-depth
  700. # ||| / delay
  701. # TASK-PID CPU# |||| TIMESTAMP FUNCTION
  702. # | | | |||| | |
  703. pseudo_lock_mea-1672 [002] .... 3132.860500: pseudo_lock_l2: hits=4097 miss=0
  704. Examples for RDT allocation usage
  705. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  706. 1) Example 1
  707. On a two socket machine (one L3 cache per socket) with just four bits
  708. for cache bit masks, minimum b/w of 10% with a memory bandwidth
  709. granularity of 10%.
  710. ::
  711. # mount -t resctrl resctrl /sys/fs/resctrl
  712. # cd /sys/fs/resctrl
  713. # mkdir p0 p1
  714. # echo "L3:0=3;1=c\nMB:0=50;1=50" > /sys/fs/resctrl/p0/schemata
  715. # echo "L3:0=3;1=3\nMB:0=50;1=50" > /sys/fs/resctrl/p1/schemata
  716. The default resource group is unmodified, so we have access to all parts
  717. of all caches (its schemata file reads "L3:0=f;1=f").
  718. Tasks that are under the control of group "p0" may only allocate from the
  719. "lower" 50% on cache ID 0, and the "upper" 50% of cache ID 1.
  720. Tasks in group "p1" use the "lower" 50% of cache on both sockets.
  721. Similarly, tasks that are under the control of group "p0" may use a
  722. maximum memory b/w of 50% on socket0 and 50% on socket 1.
  723. Tasks in group "p1" may also use 50% memory b/w on both sockets.
  724. Note that unlike cache masks, memory b/w cannot specify whether these
  725. allocations can overlap or not. The allocations specifies the maximum
  726. b/w that the group may be able to use and the system admin can configure
  727. the b/w accordingly.
  728. If resctrl is using the software controller (mba_sc) then user can enter the
  729. max b/w in MB rather than the percentage values.
  730. ::
  731. # echo "L3:0=3;1=c\nMB:0=1024;1=500" > /sys/fs/resctrl/p0/schemata
  732. # echo "L3:0=3;1=3\nMB:0=1024;1=500" > /sys/fs/resctrl/p1/schemata
  733. In the above example the tasks in "p1" and "p0" on socket 0 would use a max b/w
  734. of 1024MB where as on socket 1 they would use 500MB.
  735. 2) Example 2
  736. Again two sockets, but this time with a more realistic 20-bit mask.
  737. Two real time tasks pid=1234 running on processor 0 and pid=5678 running on
  738. processor 1 on socket 0 on a 2-socket and dual core machine. To avoid noisy
  739. neighbors, each of the two real-time tasks exclusively occupies one quarter
  740. of L3 cache on socket 0.
  741. ::
  742. # mount -t resctrl resctrl /sys/fs/resctrl
  743. # cd /sys/fs/resctrl
  744. First we reset the schemata for the default group so that the "upper"
  745. 50% of the L3 cache on socket 0 and 50% of memory b/w cannot be used by
  746. ordinary tasks::
  747. # echo "L3:0=3ff;1=fffff\nMB:0=50;1=100" > schemata
  748. Next we make a resource group for our first real time task and give
  749. it access to the "top" 25% of the cache on socket 0.
  750. ::
  751. # mkdir p0
  752. # echo "L3:0=f8000;1=fffff" > p0/schemata
  753. Finally we move our first real time task into this resource group. We
  754. also use taskset(1) to ensure the task always runs on a dedicated CPU
  755. on socket 0. Most uses of resource groups will also constrain which
  756. processors tasks run on.
  757. ::
  758. # echo 1234 > p0/tasks
  759. # taskset -cp 1 1234
  760. Ditto for the second real time task (with the remaining 25% of cache)::
  761. # mkdir p1
  762. # echo "L3:0=7c00;1=fffff" > p1/schemata
  763. # echo 5678 > p1/tasks
  764. # taskset -cp 2 5678
  765. For the same 2 socket system with memory b/w resource and CAT L3 the
  766. schemata would look like(Assume min_bandwidth 10 and bandwidth_gran is
  767. 10):
  768. For our first real time task this would request 20% memory b/w on socket 0.
  769. ::
  770. # echo -e "L3:0=f8000;1=fffff\nMB:0=20;1=100" > p0/schemata
  771. For our second real time task this would request an other 20% memory b/w
  772. on socket 0.
  773. ::
  774. # echo -e "L3:0=f8000;1=fffff\nMB:0=20;1=100" > p0/schemata
  775. 3) Example 3
  776. A single socket system which has real-time tasks running on core 4-7 and
  777. non real-time workload assigned to core 0-3. The real-time tasks share text
  778. and data, so a per task association is not required and due to interaction
  779. with the kernel it's desired that the kernel on these cores shares L3 with
  780. the tasks.
  781. ::
  782. # mount -t resctrl resctrl /sys/fs/resctrl
  783. # cd /sys/fs/resctrl
  784. First we reset the schemata for the default group so that the "upper"
  785. 50% of the L3 cache on socket 0, and 50% of memory bandwidth on socket 0
  786. cannot be used by ordinary tasks::
  787. # echo "L3:0=3ff\nMB:0=50" > schemata
  788. Next we make a resource group for our real time cores and give it access
  789. to the "top" 50% of the cache on socket 0 and 50% of memory bandwidth on
  790. socket 0.
  791. ::
  792. # mkdir p0
  793. # echo "L3:0=ffc00\nMB:0=50" > p0/schemata
  794. Finally we move core 4-7 over to the new group and make sure that the
  795. kernel and the tasks running there get 50% of the cache. They should
  796. also get 50% of memory bandwidth assuming that the cores 4-7 are SMT
  797. siblings and only the real time threads are scheduled on the cores 4-7.
  798. ::
  799. # echo F0 > p0/cpus
  800. 4) Example 4
  801. The resource groups in previous examples were all in the default "shareable"
  802. mode allowing sharing of their cache allocations. If one resource group
  803. configures a cache allocation then nothing prevents another resource group
  804. to overlap with that allocation.
  805. In this example a new exclusive resource group will be created on a L2 CAT
  806. system with two L2 cache instances that can be configured with an 8-bit
  807. capacity bitmask. The new exclusive resource group will be configured to use
  808. 25% of each cache instance.
  809. ::
  810. # mount -t resctrl resctrl /sys/fs/resctrl/
  811. # cd /sys/fs/resctrl
  812. First, we observe that the default group is configured to allocate to all L2
  813. cache::
  814. # cat schemata
  815. L2:0=ff;1=ff
  816. We could attempt to create the new resource group at this point, but it will
  817. fail because of the overlap with the schemata of the default group::
  818. # mkdir p0
  819. # echo 'L2:0=0x3;1=0x3' > p0/schemata
  820. # cat p0/mode
  821. shareable
  822. # echo exclusive > p0/mode
  823. -sh: echo: write error: Invalid argument
  824. # cat info/last_cmd_status
  825. schemata overlaps
  826. To ensure that there is no overlap with another resource group the default
  827. resource group's schemata has to change, making it possible for the new
  828. resource group to become exclusive.
  829. ::
  830. # echo 'L2:0=0xfc;1=0xfc' > schemata
  831. # echo exclusive > p0/mode
  832. # grep . p0/*
  833. p0/cpus:0
  834. p0/mode:exclusive
  835. p0/schemata:L2:0=03;1=03
  836. p0/size:L2:0=262144;1=262144
  837. A new resource group will on creation not overlap with an exclusive resource
  838. group::
  839. # mkdir p1
  840. # grep . p1/*
  841. p1/cpus:0
  842. p1/mode:shareable
  843. p1/schemata:L2:0=fc;1=fc
  844. p1/size:L2:0=786432;1=786432
  845. The bit_usage will reflect how the cache is used::
  846. # cat info/L2/bit_usage
  847. 0=SSSSSSEE;1=SSSSSSEE
  848. A resource group cannot be forced to overlap with an exclusive resource group::
  849. # echo 'L2:0=0x1;1=0x1' > p1/schemata
  850. -sh: echo: write error: Invalid argument
  851. # cat info/last_cmd_status
  852. overlaps with exclusive group
  853. Example of Cache Pseudo-Locking
  854. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  855. Lock portion of L2 cache from cache id 1 using CBM 0x3. Pseudo-locked
  856. region is exposed at /dev/pseudo_lock/newlock that can be provided to
  857. application for argument to mmap().
  858. ::
  859. # mount -t resctrl resctrl /sys/fs/resctrl/
  860. # cd /sys/fs/resctrl
  861. Ensure that there are bits available that can be pseudo-locked, since only
  862. unused bits can be pseudo-locked the bits to be pseudo-locked needs to be
  863. removed from the default resource group's schemata::
  864. # cat info/L2/bit_usage
  865. 0=SSSSSSSS;1=SSSSSSSS
  866. # echo 'L2:1=0xfc' > schemata
  867. # cat info/L2/bit_usage
  868. 0=SSSSSSSS;1=SSSSSS00
  869. Create a new resource group that will be associated with the pseudo-locked
  870. region, indicate that it will be used for a pseudo-locked region, and
  871. configure the requested pseudo-locked region capacity bitmask::
  872. # mkdir newlock
  873. # echo pseudo-locksetup > newlock/mode
  874. # echo 'L2:1=0x3' > newlock/schemata
  875. On success the resource group's mode will change to pseudo-locked, the
  876. bit_usage will reflect the pseudo-locked region, and the character device
  877. exposing the pseudo-locked region will exist::
  878. # cat newlock/mode
  879. pseudo-locked
  880. # cat info/L2/bit_usage
  881. 0=SSSSSSSS;1=SSSSSSPP
  882. # ls -l /dev/pseudo_lock/newlock
  883. crw------- 1 root root 243, 0 Apr 3 05:01 /dev/pseudo_lock/newlock
  884. ::
  885. /*
  886. * Example code to access one page of pseudo-locked cache region
  887. * from user space.
  888. */
  889. #define _GNU_SOURCE
  890. #include <fcntl.h>
  891. #include <sched.h>
  892. #include <stdio.h>
  893. #include <stdlib.h>
  894. #include <unistd.h>
  895. #include <sys/mman.h>
  896. /*
  897. * It is required that the application runs with affinity to only
  898. * cores associated with the pseudo-locked region. Here the cpu
  899. * is hardcoded for convenience of example.
  900. */
  901. static int cpuid = 2;
  902. int main(int argc, char *argv[])
  903. {
  904. cpu_set_t cpuset;
  905. long page_size;
  906. void *mapping;
  907. int dev_fd;
  908. int ret;
  909. page_size = sysconf(_SC_PAGESIZE);
  910. CPU_ZERO(&cpuset);
  911. CPU_SET(cpuid, &cpuset);
  912. ret = sched_setaffinity(0, sizeof(cpuset), &cpuset);
  913. if (ret < 0) {
  914. perror("sched_setaffinity");
  915. exit(EXIT_FAILURE);
  916. }
  917. dev_fd = open("/dev/pseudo_lock/newlock", O_RDWR);
  918. if (dev_fd < 0) {
  919. perror("open");
  920. exit(EXIT_FAILURE);
  921. }
  922. mapping = mmap(0, page_size, PROT_READ | PROT_WRITE, MAP_SHARED,
  923. dev_fd, 0);
  924. if (mapping == MAP_FAILED) {
  925. perror("mmap");
  926. close(dev_fd);
  927. exit(EXIT_FAILURE);
  928. }
  929. /* Application interacts with pseudo-locked memory @mapping */
  930. ret = munmap(mapping, page_size);
  931. if (ret < 0) {
  932. perror("munmap");
  933. close(dev_fd);
  934. exit(EXIT_FAILURE);
  935. }
  936. close(dev_fd);
  937. exit(EXIT_SUCCESS);
  938. }
  939. Locking between applications
  940. ----------------------------
  941. Certain operations on the resctrl filesystem, composed of read/writes
  942. to/from multiple files, must be atomic.
  943. As an example, the allocation of an exclusive reservation of L3 cache
  944. involves:
  945. 1. Read the cbmmasks from each directory or the per-resource "bit_usage"
  946. 2. Find a contiguous set of bits in the global CBM bitmask that is clear
  947. in any of the directory cbmmasks
  948. 3. Create a new directory
  949. 4. Set the bits found in step 2 to the new directory "schemata" file
  950. If two applications attempt to allocate space concurrently then they can
  951. end up allocating the same bits so the reservations are shared instead of
  952. exclusive.
  953. To coordinate atomic operations on the resctrlfs and to avoid the problem
  954. above, the following locking procedure is recommended:
  955. Locking is based on flock, which is available in libc and also as a shell
  956. script command
  957. Write lock:
  958. A) Take flock(LOCK_EX) on /sys/fs/resctrl
  959. B) Read/write the directory structure.
  960. C) funlock
  961. Read lock:
  962. A) Take flock(LOCK_SH) on /sys/fs/resctrl
  963. B) If success read the directory structure.
  964. C) funlock
  965. Example with bash::
  966. # Atomically read directory structure
  967. $ flock -s /sys/fs/resctrl/ find /sys/fs/resctrl
  968. # Read directory contents and create new subdirectory
  969. $ cat create-dir.sh
  970. find /sys/fs/resctrl/ > output.txt
  971. mask = function-of(output.txt)
  972. mkdir /sys/fs/resctrl/newres/
  973. echo mask > /sys/fs/resctrl/newres/schemata
  974. $ flock /sys/fs/resctrl/ ./create-dir.sh
  975. Example with C::
  976. /*
  977. * Example code do take advisory locks
  978. * before accessing resctrl filesystem
  979. */
  980. #include <sys/file.h>
  981. #include <stdlib.h>
  982. void resctrl_take_shared_lock(int fd)
  983. {
  984. int ret;
  985. /* take shared lock on resctrl filesystem */
  986. ret = flock(fd, LOCK_SH);
  987. if (ret) {
  988. perror("flock");
  989. exit(-1);
  990. }
  991. }
  992. void resctrl_take_exclusive_lock(int fd)
  993. {
  994. int ret;
  995. /* release lock on resctrl filesystem */
  996. ret = flock(fd, LOCK_EX);
  997. if (ret) {
  998. perror("flock");
  999. exit(-1);
  1000. }
  1001. }
  1002. void resctrl_release_lock(int fd)
  1003. {
  1004. int ret;
  1005. /* take shared lock on resctrl filesystem */
  1006. ret = flock(fd, LOCK_UN);
  1007. if (ret) {
  1008. perror("flock");
  1009. exit(-1);
  1010. }
  1011. }
  1012. void main(void)
  1013. {
  1014. int fd, ret;
  1015. fd = open("/sys/fs/resctrl", O_DIRECTORY);
  1016. if (fd == -1) {
  1017. perror("open");
  1018. exit(-1);
  1019. }
  1020. resctrl_take_shared_lock(fd);
  1021. /* code to read directory contents */
  1022. resctrl_release_lock(fd);
  1023. resctrl_take_exclusive_lock(fd);
  1024. /* code to read and write directory contents */
  1025. resctrl_release_lock(fd);
  1026. }
  1027. Examples for RDT Monitoring along with allocation usage
  1028. =======================================================
  1029. Reading monitored data
  1030. ----------------------
  1031. Reading an event file (for ex: mon_data/mon_L3_00/llc_occupancy) would
  1032. show the current snapshot of LLC occupancy of the corresponding MON
  1033. group or CTRL_MON group.
  1034. Example 1 (Monitor CTRL_MON group and subset of tasks in CTRL_MON group)
  1035. ------------------------------------------------------------------------
  1036. On a two socket machine (one L3 cache per socket) with just four bits
  1037. for cache bit masks::
  1038. # mount -t resctrl resctrl /sys/fs/resctrl
  1039. # cd /sys/fs/resctrl
  1040. # mkdir p0 p1
  1041. # echo "L3:0=3;1=c" > /sys/fs/resctrl/p0/schemata
  1042. # echo "L3:0=3;1=3" > /sys/fs/resctrl/p1/schemata
  1043. # echo 5678 > p1/tasks
  1044. # echo 5679 > p1/tasks
  1045. The default resource group is unmodified, so we have access to all parts
  1046. of all caches (its schemata file reads "L3:0=f;1=f").
  1047. Tasks that are under the control of group "p0" may only allocate from the
  1048. "lower" 50% on cache ID 0, and the "upper" 50% of cache ID 1.
  1049. Tasks in group "p1" use the "lower" 50% of cache on both sockets.
  1050. Create monitor groups and assign a subset of tasks to each monitor group.
  1051. ::
  1052. # cd /sys/fs/resctrl/p1/mon_groups
  1053. # mkdir m11 m12
  1054. # echo 5678 > m11/tasks
  1055. # echo 5679 > m12/tasks
  1056. fetch data (data shown in bytes)
  1057. ::
  1058. # cat m11/mon_data/mon_L3_00/llc_occupancy
  1059. 16234000
  1060. # cat m11/mon_data/mon_L3_01/llc_occupancy
  1061. 14789000
  1062. # cat m12/mon_data/mon_L3_00/llc_occupancy
  1063. 16789000
  1064. The parent ctrl_mon group shows the aggregated data.
  1065. ::
  1066. # cat /sys/fs/resctrl/p1/mon_data/mon_l3_00/llc_occupancy
  1067. 31234000
  1068. Example 2 (Monitor a task from its creation)
  1069. --------------------------------------------
  1070. On a two socket machine (one L3 cache per socket)::
  1071. # mount -t resctrl resctrl /sys/fs/resctrl
  1072. # cd /sys/fs/resctrl
  1073. # mkdir p0 p1
  1074. An RMID is allocated to the group once its created and hence the <cmd>
  1075. below is monitored from its creation.
  1076. ::
  1077. # echo $$ > /sys/fs/resctrl/p1/tasks
  1078. # <cmd>
  1079. Fetch the data::
  1080. # cat /sys/fs/resctrl/p1/mon_data/mon_l3_00/llc_occupancy
  1081. 31789000
  1082. Example 3 (Monitor without CAT support or before creating CAT groups)
  1083. ---------------------------------------------------------------------
  1084. Assume a system like HSW has only CQM and no CAT support. In this case
  1085. the resctrl will still mount but cannot create CTRL_MON directories.
  1086. But user can create different MON groups within the root group thereby
  1087. able to monitor all tasks including kernel threads.
  1088. This can also be used to profile jobs cache size footprint before being
  1089. able to allocate them to different allocation groups.
  1090. ::
  1091. # mount -t resctrl resctrl /sys/fs/resctrl
  1092. # cd /sys/fs/resctrl
  1093. # mkdir mon_groups/m01
  1094. # mkdir mon_groups/m02
  1095. # echo 3478 > /sys/fs/resctrl/mon_groups/m01/tasks
  1096. # echo 2467 > /sys/fs/resctrl/mon_groups/m02/tasks
  1097. Monitor the groups separately and also get per domain data. From the
  1098. below its apparent that the tasks are mostly doing work on
  1099. domain(socket) 0.
  1100. ::
  1101. # cat /sys/fs/resctrl/mon_groups/m01/mon_L3_00/llc_occupancy
  1102. 31234000
  1103. # cat /sys/fs/resctrl/mon_groups/m01/mon_L3_01/llc_occupancy
  1104. 34555
  1105. # cat /sys/fs/resctrl/mon_groups/m02/mon_L3_00/llc_occupancy
  1106. 31234000
  1107. # cat /sys/fs/resctrl/mon_groups/m02/mon_L3_01/llc_occupancy
  1108. 32789
  1109. Example 4 (Monitor real time tasks)
  1110. -----------------------------------
  1111. A single socket system which has real time tasks running on cores 4-7
  1112. and non real time tasks on other cpus. We want to monitor the cache
  1113. occupancy of the real time threads on these cores.
  1114. ::
  1115. # mount -t resctrl resctrl /sys/fs/resctrl
  1116. # cd /sys/fs/resctrl
  1117. # mkdir p1
  1118. Move the cpus 4-7 over to p1::
  1119. # echo f0 > p1/cpus
  1120. View the llc occupancy snapshot::
  1121. # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy
  1122. 11234000
  1123. Intel RDT Errata
  1124. ================
  1125. Intel MBM Counters May Report System Memory Bandwidth Incorrectly
  1126. -----------------------------------------------------------------
  1127. Errata SKX99 for Skylake server and BDF102 for Broadwell server.
  1128. Problem: Intel Memory Bandwidth Monitoring (MBM) counters track metrics
  1129. according to the assigned Resource Monitor ID (RMID) for that logical
  1130. core. The IA32_QM_CTR register (MSR 0xC8E), used to report these
  1131. metrics, may report incorrect system bandwidth for certain RMID values.
  1132. Implication: Due to the errata, system memory bandwidth may not match
  1133. what is reported.
  1134. Workaround: MBM total and local readings are corrected according to the
  1135. following correction factor table:
  1136. +---------------+---------------+---------------+-----------------+
  1137. |core count |rmid count |rmid threshold |correction factor|
  1138. +---------------+---------------+---------------+-----------------+
  1139. |1 |8 |0 |1.000000 |
  1140. +---------------+---------------+---------------+-----------------+
  1141. |2 |16 |0 |1.000000 |
  1142. +---------------+---------------+---------------+-----------------+
  1143. |3 |24 |15 |0.969650 |
  1144. +---------------+---------------+---------------+-----------------+
  1145. |4 |32 |0 |1.000000 |
  1146. +---------------+---------------+---------------+-----------------+
  1147. |6 |48 |31 |0.969650 |
  1148. +---------------+---------------+---------------+-----------------+
  1149. |7 |56 |47 |1.142857 |
  1150. +---------------+---------------+---------------+-----------------+
  1151. |8 |64 |0 |1.000000 |
  1152. +---------------+---------------+---------------+-----------------+
  1153. |9 |72 |63 |1.185115 |
  1154. +---------------+---------------+---------------+-----------------+
  1155. |10 |80 |63 |1.066553 |
  1156. +---------------+---------------+---------------+-----------------+
  1157. |11 |88 |79 |1.454545 |
  1158. +---------------+---------------+---------------+-----------------+
  1159. |12 |96 |0 |1.000000 |
  1160. +---------------+---------------+---------------+-----------------+
  1161. |13 |104 |95 |1.230769 |
  1162. +---------------+---------------+---------------+-----------------+
  1163. |14 |112 |95 |1.142857 |
  1164. +---------------+---------------+---------------+-----------------+
  1165. |15 |120 |95 |1.066667 |
  1166. +---------------+---------------+---------------+-----------------+
  1167. |16 |128 |0 |1.000000 |
  1168. +---------------+---------------+---------------+-----------------+
  1169. |17 |136 |127 |1.254863 |
  1170. +---------------+---------------+---------------+-----------------+
  1171. |18 |144 |127 |1.185255 |
  1172. +---------------+---------------+---------------+-----------------+
  1173. |19 |152 |0 |1.000000 |
  1174. +---------------+---------------+---------------+-----------------+
  1175. |20 |160 |127 |1.066667 |
  1176. +---------------+---------------+---------------+-----------------+
  1177. |21 |168 |0 |1.000000 |
  1178. +---------------+---------------+---------------+-----------------+
  1179. |22 |176 |159 |1.454334 |
  1180. +---------------+---------------+---------------+-----------------+
  1181. |23 |184 |0 |1.000000 |
  1182. +---------------+---------------+---------------+-----------------+
  1183. |24 |192 |127 |0.969744 |
  1184. +---------------+---------------+---------------+-----------------+
  1185. |25 |200 |191 |1.280246 |
  1186. +---------------+---------------+---------------+-----------------+
  1187. |26 |208 |191 |1.230921 |
  1188. +---------------+---------------+---------------+-----------------+
  1189. |27 |216 |0 |1.000000 |
  1190. +---------------+---------------+---------------+-----------------+
  1191. |28 |224 |191 |1.143118 |
  1192. +---------------+---------------+---------------+-----------------+
  1193. If rmid > rmid threshold, MBM total and local values should be multiplied
  1194. by the correction factor.
  1195. See:
  1196. 1. Erratum SKX99 in Intel Xeon Processor Scalable Family Specification Update:
  1197. http://web.archive.org/web/20200716124958/https://www.intel.com/content/www/us/en/processors/xeon/scalable/xeon-scalable-spec-update.html
  1198. 2. Erratum BDF102 in Intel Xeon E5-2600 v4 Processor Product Family Specification Update:
  1199. http://web.archive.org/web/20191125200531/https://www.intel.com/content/dam/www/public/us/en/documents/specification-updates/xeon-e5-v4-spec-update.pdf
  1200. 3. The errata in Intel Resource Director Technology (Intel RDT) on 2nd Generation Intel Xeon Scalable Processors Reference Manual:
  1201. https://software.intel.com/content/www/us/en/develop/articles/intel-resource-director-technology-rdt-reference-manual.html
  1202. for further information.