From: Xiang Chen chenxiang66@hisilicon.com
The first patch is to release those rcache when rmmod the driver of the last device to save memory.
And patch2~6 is add support for IOMMU debugfs related to IOVA as follows: /sys/kernel/debug/iommu/iovad/iommu_domainx
Under iommu_domainx dir, add debugfs file iova_rcache and drop_rcache. From debugfs file iova_rcache, we can get how many cpu_rcache / share rcache / iovas are used, and also we can drop those rcache by debugfs file drop_rcache:
For cpu_rcache, [i]=x|y indicates that there are x iova in load iova_magazine and y iova in prev iova_magazine (128 at most). For share rcache, [i]=x indicates that there are x iova_magazines in use.
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$ cat iova_rcache [ 272.814457] cpu0 [0]=60|0 [1]=7|0 [2]=32|0 [3]=0|0 [4]=97|0 [5]=104|0 [ 272.820982] cpu1 [0]=0|0 [1]=3|0 [2]=14|0 [3]=76|0 [4]=15|0 [5]=64|0 [ 272.827399] cpu2 [0]=85|128 [1]=84|128 [2]=83|128 [3]=112|128 [4]=22|128 [5]=116|128 [ 272.835197] cpu3 [0]=0|0 [1]=91|0 [2]=101|0 [3]=29|0 [4]=0|0 [5]=36|0 [ 272.841699] cpu4 [0]=0|0 [1]=39|0 [2]=113|0 [3]=75|0 [4]=95|0 [5]=0|0 [ 272.848201] cpu5 [0]=27|0 [1]=48|0 [2]=82|0 [3]=0|0 [4]=19|0 [5]=36|0 [ 272.854702] cpu6 [0]=30|0 [1]=0|0 [2]=48|0 [3]=2|0 [4]=18|0 [5]=56|0 [ 272.861117] cpu7 [0]=27|0 [1]=89|0 [2]=101|0 [3]=59|0 [4]=28|0 [5]=0|0 [ 272.867706] cpu8 [0]=66|0 [1]=114|0 [2]=42|0 [3]=123|0 [4]=96|0 [5]=68|0 [ 272.874466] cpu9 [0]=71|0 [1]=61|0 [2]=28|0 [3]=118|0 [4]=116|0 [5]=41|0 [ 272.881227] cpu10 [0]=83|128 [1]=63|128 [2]=109|128 [3]=79|128 [4]=7|128 [5]=54|128 [ 272.888938] cpu11 [0]=90|0 [1]=34|0 [2]=88|0 [3]=58|0 [4]=20|0 [5]=35|0 [ 272.895611] cpu12 [0]=64|0 [1]=20|0 [2]=18|0 [3]=33|0 [4]=42|0 [5]=22|0 [ 272.902285] cpu13 [0]=17|0 [1]=70|0 [2]=115|0 [3]=59|0 [4]=108|0 [5]=58|0 [ 272.909132] cpu14 [0]=28|0 [1]=18|0 [2]=27|0 [3]=105|0 [4]=65|0 [5]=81|0 [ 272.915892] cpu15 [0]=75|0 [1]=3|0 [2]=73|0 [3]=104|0 [4]=127|0 [5]=102|0 [ 272.922738] cpu16 [0]=54|0 [1]=116|0 [2]=90|0 [3]=31|0 [4]=108|0 [5]=41|0 [ 272.929590] cpu17 [0]=47|0 [1]=82|0 [2]=3|0 [3]=66|0 [4]=68|0 [5]=66|0 [ 272.936179] cpu18 [0]=126|128 [1]=110|128 [2]=48|128 [3]=118|128 [4]=54|128 [5]=73|128 [ 272.944156] cpu19 [0]=31|0 [1]=13|0 [2]=104|0 [3]=45|0 [4]=108|0 [5]=96|0 [ 272.951006] cpu20 [0]=58|0 [1]=113|0 [2]=14|0 [3]=123|0 [4]=52|0 [5]=54|0 [ 272.957856] cpu21 [0]=116|0 [1]=47|0 [2]=96|0 [3]=60|0 [4]=47|0 [5]=126|0 [ 272.964701] cpu22 [0]=84|0 [1]=87|0 [2]=88|0 [3]=68|0 [4]=37|0 [5]=119|0 [ 272.971462] cpu23 [0]=13|0 [1]=63|0 [2]=124|0 [3]=3|0 [4]=7|0 [5]=38|0 [ 272.978051] cpu24 [0]=15|0 [1]=64|0 [2]=65|0 [3]=53|0 [4]=102|0 [5]=69|0 [ 272.984812] cpu25 [0]=94|0 [1]=108|0 [2]=67|0 [3]=125|0 [4]=107|0 [5]=8|0 [ 272.991663] cpu26 [0]=84|128 [1]=86|128 [2]=91|128 [3]=121|128 [4]=77|128 [5]=25|128 [ 272.999464] cpu27 [0]=60|0 [1]=105|0 [2]=61|0 [3]=91|0 [4]=79|0 [5]=6|0 [ 273.006141] cpu28 [0]=39|0 [1]=91|0 [2]=11|0 [3]=87|0 [4]=112|0 [5]=10|0 [ 273.012904] cpu29 [0]=88|0 [1]=43|0 [2]=0|0 [3]=77|0 [4]=10|0 [5]=79|0 [ 273.019492] cpu30 [0]=65|0 [1]=24|0 [2]=125|0 [3]=24|0 [4]=54|0 [5]=21|0 [ 273.026254] cpu31 [0]=26|0 [1]=90|0 [2]=42|0 [3]=17|0 [4]=73|0 [5]=35|0 [ 273.032929] cpu32 [0]=1|0 [1]=83|0 [2]=76|0 [3]=62|0 [4]=117|0 [5]=96|0 [ 273.039612] cpu33 [0]=50|0 [1]=55|0 [2]=63|0 [3]=79|0 [4]=86|0 [5]=15|0 [ 273.046293] cpu34 [0]=122|128 [1]=36|128 [2]=36|128 [3]=79|128 [4]=113|128 [5]=80|128 [ 273.054179] cpu35 [0]=101|0 [1]=18|0 [2]=7|0 [3]=10|0 [4]=7|0 [5]=112|0 [ 273.060854] cpu36 [0]=12|0 [1]=107|0 [2]=43|0 [3]=60|0 [4]=19|0 [5]=110|0 [ 273.067703] cpu37 [0]=90|0 [1]=34|0 [2]=66|0 [3]=91|0 [4]=85|0 [5]=31|0 [ 273.074378] cpu38 [0]=0|0 [1]=22|0 [2]=18|0 [3]=73|0 [4]=54|0 [5]=96|0 [ 273.080968] cpu39 [0]=109|0 [1]=54|0 [2]=124|0 [3]=21|0 [4]=88|0 [5]=61|0 [ 273.087816] cpu40 [0]=95|0 [1]=50|0 [2]=45|0 [3]=66|0 [4]=30|0 [5]=84|0 [ 273.094490] cpu41 [0]=99|0 [1]=47|0 [2]=8|0 [3]=81|0 [4]=0|0 [5]=95|0 [ 273.100992] cpu42 [0]=25|128 [1]=92|128 [2]=53|128 [3]=49|128 [4]=43|128 [5]=78|128 [ 273.108704] cpu43 [0]=88|0 [1]=42|0 [2]=10|0 [3]=124|0 [4]=4|0 [5]=105|0 [ 273.115464] cpu44 [0]=80|0 [1]=63|0 [2]=1|0 [3]=123|0 [4]=35|0 [5]=17|0 [ 273.122139] cpu45 [0]=31|0 [1]=92|0 [2]=8|0 [3]=60|0 [4]=74|0 [5]=92|0 [ 273.128727] cpu46 [0]=78|0 [1]=40|0 [2]=95|0 [3]=33|0 [4]=67|0 [5]=63|0 [ 273.135401] cpu47 [0]=112|0 [1]=93|0 [2]=96|0 [3]=24|0 [4]=93|0 [5]=15|0 [ 273.142162] cpu48 [0]=92|0 [1]=120|0 [2]=49|0 [3]=118|0 [4]=1|0 [5]=83|0 [ 273.148923] cpu49 [0]=101|0 [1]=7|0 [2]=108|0 [3]=15|0 [4]=69|0 [5]=116|0 [ 273.155771] cpu50 [0]=111|128 [1]=98|128 [2]=21|128 [3]=27|128 [4]=109|128 [5]=21|128 [ 273.163655] cpu51 [0]=31|0 [1]=33|0 [2]=82|0 [3]=117|0 [4]=98|0 [5]=1|0 [ 273.170329] cpu52 [0]=113|0 [1]=64|0 [2]=16|0 [3]=48|0 [4]=97|0 [5]=80|0 [ 273.177090] cpu53 [0]=95|0 [1]=39|0 [2]=26|0 [3]=107|0 [4]=2|0 [5]=18|0 [ 273.183764] cpu54 [0]=114|0 [1]=94|0 [2]=110|0 [3]=85|0 [4]=66|0 [5]=45|0 [ 273.190611] cpu55 [0]=52|0 [1]=89|0 [2]=43|0 [3]=117|0 [4]=115|0 [5]=91|0 [ 273.197460] cpu56 [0]=0|0 [1]=51|0 [2]=81|0 [3]=60|0 [4]=20|0 [5]=27|0 [ 273.204048] cpu57 [0]=124|0 [1]=121|0 [2]=56|0 [3]=0|0 [4]=77|0 [5]=59|0 [ 273.210807] cpu58 [0]=109|128 [1]=98|128 [2]=6|128 [3]=39|128 [4]=64|128 [5]=24|128 [ 273.218518] cpu59 [0]=57|0 [1]=62|0 [2]=66|0 [3]=55|0 [4]=95|0 [5]=47|0 [ 273.225192] cpu60 [0]=29|0 [1]=12|0 [2]=112|0 [3]=23|0 [4]=65|0 [5]=34|0 [ 273.231955] cpu61 [0]=92|0 [1]=5|0 [2]=19|0 [3]=91|0 [4]=101|0 [5]=97|0 [ 273.238629] cpu62 [0]=97|0 [1]=42|0 [2]=30|0 [3]=111|0 [4]=99|0 [5]=2|0 [ 273.245304] cpu63 [0]=77|0 [1]=79|0 [2]=62|0 [3]=56|0 [4]=17|0 [5]=76|0 [ 273.251982] cpu64 [0]=0|0 [1]=108|0 [2]=87|0 [3]=58|0 [4]=26|0 [5]=0|0 [ 273.258582] cpu65 [0]=0|0 [1]=114|0 [2]=99|0 [3]=73|0 [4]=33|0 [5]=0|0 [ 273.265174] cpu66 [0]=39|128 [1]=52|128 [2]=82|128 [3]=107|128 [4]=73|128 [5]=13|128 [ 273.272974] cpu67 [0]=0|0 [1]=123|0 [2]=87|0 [3]=49|0 [4]=27|0 [5]=98|0 [ 273.279651] cpu68 [0]=108|0 [1]=0|0 [2]=123|0 [3]=47|0 [4]=30|0 [5]=109|0 [ 273.286500] cpu69 [0]=92|0 [1]=110|0 [2]=92|0 [3]=59|0 [4]=42|0 [5]=104|0 [ 273.293351] cpu70 [0]=105|0 [1]=106|0 [2]=99|0 [3]=57|0 [4]=15|0 [5]=111|0 [ 273.300287] cpu71 [0]=106|0 [1]=108|0 [2]=108|0 [3]=58|0 [4]=35|0 [5]=98|0 [ 273.307222] cpu72 [0]=0|0 [1]=0|0 [2]=114|0 [3]=118|0 [4]=95|0 [5]=0|0 [ 273.313813] cpu73 [0]=0|0 [1]=0|0 [2]=0|0 [3]=98|0 [4]=95|0 [5]=124|0 [ 273.320318] cpu74 [0]=65|0 [1]=76|0 [2]=109|0 [3]=58|128 [4]=115|128 [5]=105|0 [ 273.327603] cpu75 [0]=0|0 [1]=0|0 [2]=123|0 [3]=102|0 [4]=109|0 [5]=0|0 [ 273.334279] cpu76 [0]=125|0 [1]=0|0 [2]=0|0 [3]=101|0 [4]=112|0 [5]=0|0 [ 273.340954] cpu77 [0]=124|0 [1]=124|0 [2]=0|0 [3]=103|0 [4]=100|0 [5]=0|0 [ 273.347803] cpu78 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=118|0 [5]=0|0 [ 273.354134] cpu79 [0]=124|0 [1]=0|0 [2]=116|0 [3]=104|0 [4]=120|0 [5]=0|0 [ 273.360981] cpu80 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.367138] cpu81 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.373292] cpu82 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.379447] cpu83 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.385601] cpu84 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.391755] cpu85 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.397910] cpu86 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.404065] cpu87 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.410220] cpu88 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.416376] cpu89 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.422532] cpu90 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.428687] cpu91 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.434841] cpu92 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.440997] cpu93 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.447152] cpu94 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.453311] cpu95 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.459468] cpu96 [0]=78|0 [1]=95|0 [2]=117|0 [3]=120|0 [4]=37|0 [5]=31|0 [ 273.466317] cpu97 [0]=105|0 [1]=99|0 [2]=37|0 [3]=24|0 [4]=86|0 [5]=39|0 [ 273.473080] cpu98 [0]=37|128 [1]=13|128 [2]=102|128 [3]=124|128 [4]=60|128 [5]=36|128 [ 273.480967] cpu99 [0]=69|0 [1]=12|0 [2]=84|0 [3]=49|0 [4]=108|0 [5]=127|0 [ 273.487818] cpu100 [0]=92|0 [1]=104|0 [2]=22|0 [3]=31|0 [4]=2|0 [5]=72|0 [ 273.494581] cpu101 [0]=0|0 [1]=31|0 [2]=44|0 [3]=8|0 [4]=13|0 [5]=50|0 [ 273.501170] cpu102 [0]=79|0 [1]=14|0 [2]=88|0 [3]=53|0 [4]=7|0 [5]=44|0 [ 273.507846] cpu103 [0]=10|0 [1]=117|0 [2]=53|0 [3]=112|0 [4]=11|0 [5]=71|0 [ 273.514781] cpu104 [0]=123|0 [1]=30|0 [2]=9|0 [3]=2|0 [4]=30|0 [5]=24|0 [ 273.521462] cpu105 [0]=116|0 [1]=44|0 [2]=29|0 [3]=104|0 [4]=71|0 [5]=3|0 [ 273.528309] cpu106 [0]=38|128 [1]=127|128 [2]=21|128 [3]=83|128 [4]=59|128 [5]=81|128 [ 273.536195] cpu107 [0]=127|0 [1]=126|0 [2]=125|0 [3]=79|0 [4]=12|0 [5]=115|0 [ 273.543303] cpu108 [0]=0|0 [1]=43|0 [2]=111|0 [3]=10|0 [4]=51|0 [5]=68|0 [ 273.550065] cpu109 [0]=37|0 [1]=63|0 [2]=11|0 [3]=10|0 [4]=58|0 [5]=9|0 [ 273.556742] cpu110 [0]=86|0 [1]=44|0 [2]=83|0 [3]=85|0 [4]=82|0 [5]=119|0 [ 273.563590] cpu111 [0]=114|0 [1]=27|0 [2]=111|0 [3]=11|0 [4]=45|0 [5]=56|0 [ 273.570524] cpu112 [0]=74|0 [1]=86|0 [2]=93|0 [3]=122|0 [4]=126|0 [5]=31|0 [ 273.577458] cpu113 [0]=51|0 [1]=81|0 [2]=7|0 [3]=124|0 [4]=71|0 [5]=5|0 [ 273.584133] cpu114 [0]=58|128 [1]=95|128 [2]=14|128 [3]=119|128 [4]=85|128 [5]=23|128 [ 273.592018] cpu115 [0]=59|0 [1]=66|0 [2]=1|0 [3]=50|0 [4]=77|0 [5]=6|0 [ 273.598607] cpu116 [0]=65|0 [1]=81|0 [2]=22|0 [3]=18|0 [4]=96|0 [5]=2|0 [ 273.605282] cpu117 [0]=23|0 [1]=41|0 [2]=19|0 [3]=69|0 [4]=108|0 [5]=126|0 [ 273.612216] cpu118 [0]=74|0 [1]=40|0 [2]=0|0 [3]=100|0 [4]=109|0 [5]=7|0 [ 273.618979] cpu119 [0]=47|0 [1]=31|0 [2]=103|0 [3]=65|0 [4]=84|0 [5]=124|0 [ 273.625914] cpu120 [0]=74|0 [1]=18|0 [2]=87|0 [3]=117|0 [4]=17|0 [5]=62|0 [ 273.632762] cpu121 [0]=64|0 [1]=73|0 [2]=3|0 [3]=127|0 [4]=120|0 [5]=105|0 [ 273.639698] cpu122 [0]=46|128 [1]=89|128 [2]=22|128 [3]=78|128 [4]=100|128 [5]=106|128 [ 273.647671] cpu123 [0]=36|0 [1]=71|0 [2]=25|0 [3]=23|0 [4]=126|0 [5]=86|0 [ 273.654521] cpu124 [0]=26|0 [1]=93|0 [2]=101|0 [3]=103|0 [4]=54|0 [5]=100|0 [ 273.661542] cpu125 [0]=58|0 [1]=57|0 [2]=116|0 [3]=35|0 [4]=73|0 [5]=12|0 [ 273.668392] cpu126 [0]=11|0 [1]=54|0 [2]=41|0 [3]=0|0 [4]=27|0 [5]=54|0 [ 273.675067] cpu127 [0]=70|0 [1]=38|0 [2]=58|0 [3]=123|0 [4]=47|0 [5]=21|0 [ 273.681913] share cache: [0]=0 [1]=4 [2]=9 [3]=3 [4]=6 [5]=5 [ 273.687633] rb_total: 59443
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$ echo 1 > drop_rca che estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$ cat iova_rcache [ 295.489690] cpu0 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.495786] cpu1 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.501861] cpu2 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.507929] cpu3 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.514004] cpu4 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.520074] cpu5 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.526142] cpu6 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.532212] cpu7 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.538287] cpu8 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.544355] cpu9 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.550423] cpu10 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.556581] cpu11 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.562739] cpu12 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.568897] cpu13 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.575054] cpu14 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.581209] cpu15 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.587368] cpu16 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.593525] cpu17 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.599680] cpu18 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.605837] cpu19 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.611999] cpu20 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.618159] cpu21 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.624313] cpu22 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.630467] cpu23 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.636624] cpu24 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.642779] cpu25 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.648933] cpu26 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.655088] cpu27 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.661241] cpu28 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.667396] cpu29 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.673549] cpu30 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.679703] cpu31 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.685857] cpu32 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.692010] cpu33 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.698165] cpu34 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.704319] cpu35 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.710474] cpu36 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.716628] cpu37 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.722782] cpu38 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.728936] cpu39 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.735091] cpu40 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.741246] cpu41 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.747400] cpu42 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.753553] cpu43 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.759707] cpu44 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.765860] cpu45 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.772014] cpu46 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.778168] cpu47 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.784322] cpu48 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.790476] cpu49 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.796632] cpu50 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.802786] cpu51 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.808941] cpu52 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.815095] cpu53 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.821250] cpu54 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.827405] cpu55 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.833561] cpu56 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.839716] cpu57 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.845870] cpu58 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.852024] cpu59 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.858181] cpu60 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.864336] cpu61 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.870492] cpu62 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.876646] cpu63 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.882801] cpu64 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.888956] cpu65 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.895109] cpu66 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.901265] cpu67 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.907419] cpu68 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.913574] cpu69 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.919729] cpu70 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.925882] cpu71 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.932037] cpu72 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.938191] cpu73 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.944345] cpu74 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.950499] cpu75 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.956653] cpu76 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.962807] cpu77 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.968961] cpu78 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.975115] cpu79 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.981269] cpu80 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.987423] cpu81 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.993578] cpu82 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 295.999731] cpu83 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.005885] cpu84 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.012040] cpu85 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.018196] cpu86 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.024350] cpu87 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.030504] cpu88 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.036659] cpu89 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.042814] cpu90 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.048968] cpu91 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.055122] cpu92 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.061275] cpu93 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.067429] cpu94 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.073582] cpu95 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.079736] cpu96 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.085890] cpu97 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.092043] cpu98 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.098198] cpu99 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.104352] cpu100 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.110593] cpu101 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.116834] cpu102 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.123076] cpu103 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.129315] cpu104 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.135555] cpu105 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.141795] cpu106 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.148035] cpu107 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.154275] cpu108 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.160515] cpu109 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.166757] cpu110 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.172997] cpu111 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.179237] cpu112 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.185477] cpu113 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.191717] cpu114 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.197958] cpu115 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.204198] cpu116 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.210438] cpu117 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.216677] cpu118 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.222917] cpu119 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.229157] cpu120 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.235398] cpu121 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.241638] cpu122 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.247879] cpu123 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.254121] cpu124 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.260361] cpu125 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.266601] cpu126 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.272843] cpu127 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 296.279083] share cache: [0]=0 [1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [ 296.284804] rb_total: 4134 estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$
We can add more debugfs interfaces if we want to.
c00284940 (6): {topost} iommu: free rcache iovas when rmmod the driver of the last device {topost} iommu/iova: create iovad debugfs dir under iommu debugfs dir {topost} iommu/iova: create iommu domain debugfs dir under iovad debugfs dir {topost} iommu/iova: create debugfs file related to iova {topost} iommu/iova: trace how many iovas are in use {topost} iommu/iova: add a debugfs file drop_rcache to drop rcache
drivers/iommu/dma-iommu.c | 9 +++++ drivers/iommu/iommu-debugfs.c | 93 +++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 26 +++++------- drivers/iommu/iova.c | 43 ++++++++------------ include/linux/dma-iommu.h | 6 ++- include/linux/iommu.h | 32 ++++++++++++++- include/linux/iova.h | 29 +++++++++++++- 7 files changed, 193 insertions(+), 45 deletions(-)
From: Xiang Chen chenxiang66@hisilicon.com
Currently even if rmmod the driver of the last device, the rcache iovas still occupies the memory and doesn't release them. Actually we can free them when rmmod the driver of the last device.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/dma-iommu.c | 7 +++++++ drivers/iommu/iommu.c | 7 +++++++ drivers/iommu/iova.c | 17 ++++++++++++----- include/linux/dma-iommu.h | 6 +++++- include/linux/iova.h | 5 +++++ 5 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7bcdd12..a1431a9 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -54,6 +54,13 @@ struct iommu_dma_cookie { static DEFINE_STATIC_KEY_FALSE(iommu_deferred_attach_enabled); bool iommu_dma_forcedac __read_mostly;
+struct iova_domain *iommu_domain_to_iova(struct iommu_domain *domain) +{ + struct iommu_dma_cookie *cookie = domain->iova_cookie; + + return &cookie->iovad; +} + static int __init iommu_dma_forcedac_setup(char *str) { int ret = kstrtobool(str, &iommu_dma_forcedac); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 808ab70..9a7ced0 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -9,12 +9,14 @@ #include <linux/device.h> #include <linux/kernel.h> #include <linux/bug.h> +#include <linux/dma-iommu.h> #include <linux/types.h> #include <linux/init.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/iommu.h> +#include <linux/iova.h> #include <linux/idr.h> #include <linux/notifier.h> #include <linux/err.h> @@ -1667,6 +1669,11 @@ static int iommu_bus_notifier(struct notifier_block *nb, group_action = IOMMU_GROUP_NOTIFY_UNBIND_DRIVER; break; case BUS_NOTIFY_UNBOUND_DRIVER: + if (iommu_group_device_count(group) == 1) { + struct iommu_domain *domain = group->domain; + + free_rcache_cached_iovas(iommu_domain_to_iova(domain)); + } group_action = IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER; break; } diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index b7ecd5b..59926d5 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -503,16 +503,12 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size, retry: new_iova = alloc_iova(iovad, size, limit_pfn, true); if (!new_iova) { - unsigned int cpu; - if (!flush_rcache) return 0;
/* Try replenishing IOVAs by flushing rcache. */ flush_rcache = false; - for_each_online_cpu(cpu) - free_cpu_cached_iovas(cpu, iovad); - free_global_cached_iovas(iovad); + free_rcache_cached_iovas(iovad); goto retry; }
@@ -1077,5 +1073,16 @@ static void free_global_cached_iovas(struct iova_domain *iovad) spin_unlock_irqrestore(&rcache->lock, flags); } } + +void free_rcache_cached_iovas(struct iova_domain *iovad) +{ + unsigned int cpu; + + for_each_online_cpu(cpu) + free_cpu_cached_iovas(cpu, iovad); + free_global_cached_iovas(iovad); +} +EXPORT_SYMBOL_GPL(free_rcache_cached_iovas); + MODULE_AUTHOR("Anil S Keshavamurthy anil.s.keshavamurthy@intel.com"); MODULE_LICENSE("GPL"); diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 6e75a2d..82c4ec8 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -41,7 +41,7 @@ void iommu_dma_free_cpu_cached_iovas(unsigned int cpu, struct iommu_domain *domain);
extern bool iommu_dma_forcedac; - +struct iova_domain *iommu_domain_to_iova(struct iommu_domain *domain); #else /* CONFIG_IOMMU_DMA */
struct iommu_domain; @@ -83,5 +83,9 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { }
+struct iova_domain *iommu_domain_to_iova(struct iommu_domain *domain) +{ +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/include/linux/iova.h b/include/linux/iova.h index 71d8a2d..7006d9f 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -157,6 +157,7 @@ int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb, iova_entry_dtor entry_dtor); struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); void put_iova_domain(struct iova_domain *iovad); +void free_rcache_cached_iovas(struct iova_domain *iovad); #else static inline int iova_cache_get(void) { @@ -233,6 +234,10 @@ static inline void put_iova_domain(struct iova_domain *iovad) { }
+static inline void free_rcache_cached_iovas(struct iova_domain *iovad) +{ +} + #endif
#endif
From: Xiang Chen chenxiang66@hisilicon.com
We plan to create debugfs dir related to iova as follows: /sys/kernel/debug/iommu/iovad/domainx/<properties> So create a iovad debugfs dir under iommu debugfs dir.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/iommu-debugfs.c | 12 ++++++++++++ drivers/iommu/iova.c | 2 ++ include/linux/iommu.h | 6 ++++++ include/linux/iova.h | 1 + 4 files changed, 21 insertions(+)
diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index f035489..75d9b9a 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -13,6 +13,8 @@
struct dentry *iommu_debugfs_dir; EXPORT_SYMBOL_GPL(iommu_debugfs_dir); +struct dentry *iovad_debugfs_dir; +EXPORT_SYMBOL_GPL(iovad_debugfs_dir);
/** * iommu_debugfs_setup - create the top-level iommu directory in debugfs @@ -49,3 +51,13 @@ void iommu_debugfs_setup(void) pr_warn("*************************************************************\n"); } } + +void debugfs_create_iovad_dir(void) +{ + iovad_debugfs_dir = debugfs_create_dir("iovad", iommu_debugfs_dir); +} + +void debugfs_destroy_iovad_dir(void) +{ + debugfs_remove_recursive(iovad_debugfs_dir); +} diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 59926d5..0374e23b 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -336,6 +336,7 @@ int iova_cache_get(void) iova_cache_users++; mutex_unlock(&iova_cache_mutex);
+ debugfs_create_iovad_dir(); return 0; } EXPORT_SYMBOL_GPL(iova_cache_get); @@ -353,6 +354,7 @@ void iova_cache_put(void) kmem_cache_destroy(iova_cache); } mutex_unlock(&iova_cache_mutex); + debugfs_destroy_iovad_dir(); } EXPORT_SYMBOL_GPL(iova_cache_put);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d4480..8dbc5cf 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1020,8 +1020,14 @@ static inline size_t iommu_map_sgtable(struct iommu_domain *domain, #ifdef CONFIG_IOMMU_DEBUGFS extern struct dentry *iommu_debugfs_dir; void iommu_debugfs_setup(void); +extern struct dentry *iovad_debugfs_dir; +void debugfs_create_iovad_dir(void); +void debugfs_destroy_iovad_dir(void); + #else static inline void iommu_debugfs_setup(void) {} +static inline void debugfs_create_iovad_dir(void) {} +static inline void debugfs_destroy_iovad_dir(void) {} #endif
#endif /* __LINUX_IOMMU_H */ diff --git a/include/linux/iova.h b/include/linux/iova.h index 7006d9f..9386e77 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -14,6 +14,7 @@ #include <linux/rbtree.h> #include <linux/atomic.h> #include <linux/dma-mapping.h> +#include <linux/iommu.h>
/* iova structure */ struct iova {
From: Xiang Chen chenxiang66@hisilicon.com
Create iommu domain debugfs dir under ivoad debugfs dir, and the domain id is the same as the group id.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/iommu-debugfs.c | 16 ++++++++++++++++ drivers/iommu/iommu.c | 19 ++++--------------- include/linux/iommu.h | 23 ++++++++++++++++++++++- 3 files changed, 42 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index 75d9b9a..224b90f 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -61,3 +61,19 @@ void debugfs_destroy_iovad_dir(void) { debugfs_remove_recursive(iovad_debugfs_dir); } + +void debugfs_create_domain_dir(struct iommu_group *group) +{ + struct iommu_domain *domain = group->domain; + char name[1024]; + + snprintf(name, 1024, "iommu_domain%d", group->id); + domain->domain_dir = debugfs_create_dir(name, iovad_debugfs_dir); +} + +void debugfs_destroy_domain_dir(struct iommu_group *group) +{ + struct iommu_domain *domain = group->domain; + + debugfs_remove_recursive(domain->domain_dir); +} diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9a7ced0..3f328ae 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -34,21 +34,6 @@ static unsigned int iommu_def_domain_type __read_mostly; static bool iommu_dma_strict __read_mostly = true; static u32 iommu_cmd_line __read_mostly;
-struct iommu_group { - struct kobject kobj; - struct kobject *devices_kobj; - struct list_head devices; - struct mutex mutex; - struct blocking_notifier_head notifier; - void *iommu_data; - void (*iommu_data_release)(void *iommu_data); - char *name; - int id; - struct iommu_domain *default_domain; - struct iommu_domain *domain; - struct list_head entry; -}; - struct group_device { struct list_head list; struct device *dev; @@ -292,6 +277,8 @@ int iommu_probe_device(struct device *dev) if (ops->probe_finalize) ops->probe_finalize(dev);
+ debugfs_create_domain_dir(group); + return 0;
err_release: @@ -570,6 +557,8 @@ static void iommu_group_release(struct kobject *kobj)
pr_debug("Releasing group %d\n", group->id);
+ debugfs_destroy_domain_dir(group); + if (group->iommu_data_release) group->iommu_data_release(group->iommu_data);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 8dbc5cf..ef75bdb6 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -33,7 +33,21 @@ #define IOMMU_PRIV (1 << 5)
struct iommu_ops; -struct iommu_group; +struct iommu_group { + struct kobject kobj; + struct kobject *devices_kobj; + struct list_head devices; + struct mutex mutex; + struct blocking_notifier_head notifier; + void *iommu_data; + void (*iommu_data_release)(void *iommu_data); + char *name; + int id; + struct iommu_domain *default_domain; + struct iommu_domain *domain; + struct list_head entry; +}; + struct bus_type; struct device; struct iommu_domain; @@ -87,6 +101,9 @@ struct iommu_domain { void *handler_token; struct iommu_domain_geometry geometry; void *iova_cookie; +#ifdef CONFIG_IOMMU_DEBUGFS + struct dentry *domain_dir; +#endif };
enum iommu_cap { @@ -1023,11 +1040,15 @@ void iommu_debugfs_setup(void); extern struct dentry *iovad_debugfs_dir; void debugfs_create_iovad_dir(void); void debugfs_destroy_iovad_dir(void); +void debugfs_create_domain_dir(struct iommu_group *group); +void debugfs_destroy_domain_dir(struct iommu_group *group);
#else static inline void iommu_debugfs_setup(void) {} static inline void debugfs_create_iovad_dir(void) {} static inline void debugfs_destroy_iovad_dir(void) {} +static inline void debugfs_create_domain_dir(struct iommu_group *group) {} +static inline void debugfs_destroy_domain_dir(struct iommu_group *group) {} #endif
#endif /* __LINUX_IOMMU_H */
From: Xiang Chen chenxiang66@hisilicon.com
Create iova_rcache to show how many cpu_rcache and share cache are used for the domain.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/dma-iommu.c | 2 ++ drivers/iommu/iommu-debugfs.c | 51 +++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/iova.c | 21 ------------------ include/linux/iommu.h | 3 +++ include/linux/iova.h | 22 +++++++++++++++++-- 5 files changed, 76 insertions(+), 23 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index a1431a9..4cb63b2 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -387,6 +387,8 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, if (!dev) return 0;
+ debugfs_create_iova_file(domain); + return iova_reserve_iommu_regions(dev, domain); }
diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index 224b90f..6489430 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -10,6 +10,8 @@ #include <linux/pci.h> #include <linux/iommu.h> #include <linux/debugfs.h> +#include <linux/iova.h> +#include <linux/dma-iommu.h>
struct dentry *iommu_debugfs_dir; EXPORT_SYMBOL_GPL(iommu_debugfs_dir); @@ -77,3 +79,52 @@ void debugfs_destroy_domain_dir(struct iommu_group *group)
debugfs_remove_recursive(domain->domain_dir); } + +static int debugfs_iova_rcache_show(struct seq_file *s, void *p) +{ + struct iommu_domain *iommu_domain = s->private; + struct iova_domain *iovad = iommu_domain_to_iova(iommu_domain); + char string[1024]; + unsigned long flags; + unsigned int cpu; + int i; + + for_each_online_cpu(cpu) { + sprintf(string, "cpu%d ", cpu); + for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + struct iova_rcache *rcache = &iovad->rcaches[i]; + struct iova_cpu_rcache *cpu_rcache; + unsigned long loaded_size, prev_size; + + cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); + spin_lock_irqsave(&cpu_rcache->lock, flags); + loaded_size = cpu_rcache->loaded->size; + prev_size = cpu_rcache->prev->size; + spin_unlock_irqrestore(&cpu_rcache->lock, flags); + sprintf(string + strlen(string), "[%d]=%ld|%ld ", + i, loaded_size, prev_size); + } + pr_err("%s\n", string); + } + + sprintf(string, "share cache: "); + for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; i++) { + struct iova_rcache *rcache = &iovad->rcaches[i]; + int size; + + spin_lock(&rcache->lock); + size = rcache->depot_size; + spin_unlock(&rcache->lock); + sprintf(string + strlen(string), "[%d]=%d ", i, size); + } + pr_err("%s\n", string); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(debugfs_iova_rcache); + +void debugfs_create_iova_file(struct iommu_domain *domain) +{ + debugfs_create_file("iova_rcache", 0400, domain->domain_dir, + domain, &debugfs_iova_rcache_fops); +} + diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 0374e23b..ecdebcd 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -775,27 +775,6 @@ reserve_iova(struct iova_domain *iovad, } EXPORT_SYMBOL_GPL(reserve_iova);
-/* - * Magazine caches for IOVA ranges. For an introduction to magazines, - * see the USENIX 2001 paper "Magazines and Vmem: Extending the Slab - * Allocator to Many CPUs and Arbitrary Resources" by Bonwick and Adams. - * For simplicity, we use a static magazine size and don't implement the - * dynamic size tuning described in the paper. - */ - -#define IOVA_MAG_SIZE 128 - -struct iova_magazine { - unsigned long size; - unsigned long pfns[IOVA_MAG_SIZE]; -}; - -struct iova_cpu_rcache { - spinlock_t lock; - struct iova_magazine *loaded; - struct iova_magazine *prev; -}; - static struct iova_magazine *iova_magazine_alloc(gfp_t flags) { return kzalloc(sizeof(struct iova_magazine), flags); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ef75bdb6..905a0ee 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1042,6 +1042,7 @@ void debugfs_create_iovad_dir(void); void debugfs_destroy_iovad_dir(void); void debugfs_create_domain_dir(struct iommu_group *group); void debugfs_destroy_domain_dir(struct iommu_group *group); +void debugfs_create_iova_file(struct iommu_domain *domain);
#else static inline void iommu_debugfs_setup(void) {} @@ -1049,6 +1050,8 @@ static inline void debugfs_create_iovad_dir(void) {} static inline void debugfs_destroy_iovad_dir(void) {} static inline void debugfs_create_domain_dir(struct iommu_group *group) {} static inline void debugfs_destroy_domain_dir(struct iommu_group *group) {} +static inline void debugfs_create_iova_file(struct iommu_domain *domain) {} + #endif
#endif /* __LINUX_IOMMU_H */ diff --git a/include/linux/iova.h b/include/linux/iova.h index 9386e77..8d935e3 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -23,8 +23,26 @@ struct iova { unsigned long pfn_lo; /* Lowest allocated pfn */ };
-struct iova_magazine; -struct iova_cpu_rcache; +/* + * Magazine caches for IOVA ranges. For an introduction to magazines, + * see the USENIX 2001 paper "Magazines and Vmem: Extending the Slab + * Allocator to Many CPUs and Arbitrary Resources" by Bonwick and Adams. + * For simplicity, we use a static magazine size and don't implement the + * dynamic size tuning described in the paper. + */ + +#define IOVA_MAG_SIZE 128 + +struct iova_magazine { + unsigned long size; + unsigned long pfns[IOVA_MAG_SIZE]; +}; + +struct iova_cpu_rcache { + spinlock_t lock; + struct iova_magazine *loaded; + struct iova_magazine *prev; +};
#define IOVA_RANGE_CACHE_MAX_SIZE 6 /* log of max cached IOVA range size (in pages) */ #define MAX_GLOBAL_MAGS 32 /* magazines per bin */
From: Xiang Chen chenxiang66@hisilicon.com
Add a print in iova_rcache to trace how many iovas are in use.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/iommu-debugfs.c | 2 ++ drivers/iommu/iova.c | 3 +++ include/linux/iova.h | 1 + 3 files changed, 6 insertions(+)
diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index 6489430..1904fe9 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -118,6 +118,8 @@ static int debugfs_iova_rcache_show(struct seq_file *s, void *p) sprintf(string + strlen(string), "[%d]=%d ", i, size); } pr_err("%s\n", string); + pr_err("rb_total: %lld\n", iovad->rb_total); + return 0; } DEFINE_SHOW_ATTRIBUTE(debugfs_iova_rcache); diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index ecdebcd..f09755a 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -66,6 +66,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule, iovad->flush_cb = NULL; iovad->fq = NULL; iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR; + iovad->rb_total = 0; rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node); rb_insert_color(&iovad->anchor.node, &iovad->rbroot); cpuhp_state_add_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, &iovad->cpuhp_dead); @@ -284,6 +285,7 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, /* If we have 'prev', it's a valid place to start the insertion. */ iova_insert_rbtree(&iovad->rbroot, new, prev); __cached_rbnode_insert_update(iovad, new); + iovad->rb_total++;
spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); return 0; @@ -419,6 +421,7 @@ static void private_free_iova(struct iova_domain *iovad, struct iova *iova) assert_spin_locked(&iovad->iova_rbtree_lock); __cached_rbnode_delete_update(iovad, iova); rb_erase(&iova->node, &iovad->rbroot); + iovad->rb_total--; free_iova_mem(iova); }
diff --git a/include/linux/iova.h b/include/linux/iova.h index 8d935e3..1eb4628 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -115,6 +115,7 @@ struct iova_domain { atomic_t fq_timer_on; /* 1 when timer is active, 0 when not */ struct hlist_node cpuhp_dead; + u64 rb_total; };
static inline unsigned long iova_size(struct iova *iova)
From: Xiang Chen chenxiang66@hisilicon.com
Add a debugfs file drop_rcache to drop rcache manually.
Signed-off-by: Xiang Chen chenxiang66@hisilicon.com --- drivers/iommu/iommu-debugfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index 1904fe9..4e479f9 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -124,9 +124,21 @@ static int debugfs_iova_rcache_show(struct seq_file *s, void *p) } DEFINE_SHOW_ATTRIBUTE(debugfs_iova_rcache);
+static int debugfs_drop_rcache_set(void *data, u64 value) +{ + struct iommu_domain *domain = data; + struct iova_domain *iovad = iommu_domain_to_iova(domain); + + free_rcache_cached_iovas(iovad); + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(debugfs_drop_rcache_fops, NULL, debugfs_drop_rcache_set, "%llu\n"); + void debugfs_create_iova_file(struct iommu_domain *domain) { debugfs_create_file("iova_rcache", 0400, domain->domain_dir, domain, &debugfs_iova_rcache_fops); + debugfs_create_file("drop_rcache", 0200, domain->domain_dir, + domain, &debugfs_drop_rcache_fops); }
On 28/05/2021 08:12, chenxiang wrote:
From: Xiang Chen chenxiang66@hisilicon.com
The first patch is to release those rcache when rmmod the driver of the last device to save memory.
And patch2~6 is add support for IOMMU debugfs related to IOVA as follows: /sys/kernel/debug/iommu/iovad/iommu_domainx
Under iommu_domainx dir, add debugfs file iova_rcache and drop_rcache.
From debugfs file iova_rcache, we can get how many cpu_rcache / share
rcache / iovas are used, and also we can drop those rcache by debugfs file drop_rcache:
For cpu_rcache, [i]=x|y indicates that there are x iova in load iova_magazine and y iova in prev iova_magazine (128 at most). For share rcache, [i]=x indicates that there are x iova_magazines in use.
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$
How do we know the relation to the IOMMU group?
And it could be nice to show 'ls -l' output, even if you did mention it, above.
I would also like to see additional info, specifically allocation attempts per rcache range and also allocation attempts which were "too_big" to be cached.
cat iova_rcache [ 272.814457] cpu0 [0]=60|0 [1]=7|0 [2]=32|0 [3]=0|0 [4]=97|0 [5]=104|0
I suppose this is ok, but the output is becoming huge with many CPUs and possibly increasing rcache range.
You possibly could consider breaking it down to sub files or folders, which may be better, like:
ls iovad/iommu_domain2: 0 1 2 3 4 ... too_big
ls iovad/iommu_domain2/0 rcache allocations depot
more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
more iovad/iommu_domain2/0/allocations 1244
more iovad/iommu_domain2/0/depot 28 44 22
ls iovad/iommu_domain2/too_big allocations
As for the rcache file, you could even have separate per-cpu files in a rcache folder, like:
ls iovad/iommu_domain2/0/rcache cpu0 cpu1 cpu2 ...cpu127
more iovad/iommu_domain2/0/rcache/cpu0 0|3
But then we need have more files and folders to examine. Need to find a good balance.
[ 272.820982] cpu1 [0]=0|0 [1]=3|0 [2]=14|0 [3]=76|0 [4]=15|0 [5]=64|0 [ 272.827399] cpu2 [0]=85|128 [1]=84|128 [2]=83|128 [3]=112|128 [4]=22|128 [5]=116|128 [ 272.835197] cpu3 [0]=0|0 [1]=91|0 [2]=101|0 [3]=29|0 [4]=0|0 [5]=36|0 [ 272.841699] cpu4 [0]=0|0 [1]=39|0 [2]=113|0 [3]=75|0 [4]=95|0 [5]=0|0 [ 272.848201] cpu5 [0]=27|0 [1]=48|0 [2]=82|0 [3]=0|0 [4]=19|0 [5]=36|0 [ 272.854702] cpu6 [0]=30|0 [1]=0|0 [2]=48|0 [3]=2|0 [4]=18|0 [5]=56|0 [ 272.861117] cpu7 [0]=27|0 [1]=89|0 [2]=101|0 [3]=59|0 [4]=28|0 [5]=0|0 [ 272.867706] cpu8 [0]=66|0 [1]=114|0 [2]=42|0 [3]=123|0 [4]=96|0 [5]=68|0 [ 272.874466] cpu9 [0]=71|0 [1]=61|0 [2]=28|0 [3]=118|0 [4]=116|0 [5]=41|0 [ 272.881227] cpu10 [0]=83|128 [1]=63|128 [2]=109|128 [3]=79|128 [4]=7|128 [5]=54|128 [ 272.888938] cpu11 [0]=90|0 [1]=34|0 [2]=88|0 [3]=58|0 [4]=20|0 [5]=35|0 [ 272.895611] cpu12 [0]=64|0 [1]=20|0 [2]=18|0 [3]=33|0 [4]=42|0 [5]=22|0 [ 272.902285] cpu13 [0]=17|0 [1]=70|0 [2]=115|0 [3]=59|0 [4]=108|0 [5]=58|0 [ 272.909132] cpu14 [0]=28|0 [1]=18|0 [2]=27|0 [3]=105|0 [4]=65|0 [5]=81|0 [ 272.915892] cpu15 [0]=75|0 [1]=3|0 [2]=73|0 [3]=104|0 [4]=127|0 [5]=102|0 [ 272.922738] cpu16 [0]=54|0 [1]=116|0 [2]=90|0 [3]=31|0 [4]=108|0 [5]=41|0 [ 272.929590] cpu17 [0]=47|0 [1]=82|0 [2]=3|0 [3]=66|0 [4]=68|0 [5]=66|0 [ 272.936179] cpu18 [0]=126|128 [1]=110|128 [2]=48|128 [3]=118|128 [4]=54|128 [5]=73|128 [ 272.944156] cpu19 [0]=31|0 [1]=13|0 [2]=104|0 [3]=45|0 [4]=108|0 [5]=96|0 [ 272.951006] cpu20 [0]=58|0 [1]=113|0 [2]=14|0 [3]=123|0 [4]=52|0 [5]=54|0 [ 272.957856] cpu21 [0]=116|0 [1]=47|0 [2]=96|0 [3]=60|0 [4]=47|0 [5]=126|0 [ 272.964701] cpu22 [0]=84|0 [1]=87|0 [2]=88|0 [3]=68|0 [4]=37|0 [5]=119|0 [ 272.971462] cpu23 [0]=13|0 [1]=63|0 [2]=124|0 [3]=3|0 [4]=7|0 [5]=38|0 [ 272.978051] cpu24 [0]=15|0 [1]=64|0 [2]=65|0 [3]=53|0 [4]=102|0 [5]=69|0 [ 272.984812] cpu25 [0]=94|0 [1]=108|0 [2]=67|0 [3]=125|0 [4]=107|0 [5]=8|0 [ 272.991663] cpu26 [0]=84|128 [1]=86|128 [2]=91|128 [3]=121|128 [4]=77|128 [5]=25|128 [ 272.999464] cpu27 [0]=60|0 [1]=105|0 [2]=61|0 [3]=91|0 [4]=79|0 [5]=6|0 [ 273.006141] cpu28 [0]=39|0 [1]=91|0 [2]=11|0 [3]=87|0 [4]=112|0 [5]=10|0 [ 273.012904] cpu29 [0]=88|0 [1]=43|0 [2]=0|0 [3]=77|0 [4]=10|0 [5]=79|0 [ 273.019492] cpu30 [0]=65|0 [1]=24|0 [2]=125|0 [3]=24|0 [4]=54|0 [5]=21|0 [ 273.026254] cpu31 [0]=26|0 [1]=90|0 [2]=42|0 [3]=17|0 [4]=73|0 [5]=35|0 [ 273.032929] cpu32 [0]=1|0 [1]=83|0 [2]=76|0 [3]=62|0 [4]=117|0 [5]=96|0 [ 273.039612] cpu33 [0]=50|0 [1]=55|0 [2]=63|0 [3]=79|0 [4]=86|0 [5]=15|0 [ 273.046293] cpu34 [0]=122|128 [1]=36|128 [2]=36|128 [3]=79|128 [4]=113|128 [5]=80|128 [ 273.054179] cpu35 [0]=101|0 [1]=18|0 [2]=7|0 [3]=10|0 [4]=7|0 [5]=112|0 [ 273.060854] cpu36 [0]=12|0 [1]=107|0 [2]=43|0 [3]=60|0 [4]=19|0 [5]=110|0 [ 273.067703] cpu37 [0]=90|0 [1]=34|0 [2]=66|0 [3]=91|0 [4]=85|0 [5]=31|0 [ 273.074378] cpu38 [0]=0|0 [1]=22|0 [2]=18|0 [3]=73|0 [4]=54|0 [5]=96|0 [ 273.080968] cpu39 [0]=109|0 [1]=54|0 [2]=124|0 [3]=21|0 [4]=88|0 [5]=61|0 [ 273.087816] cpu40 [0]=95|0 [1]=50|0 [2]=45|0 [3]=66|0 [4]=30|0 [5]=84|0 [ 273.094490] cpu41 [0]=99|0 [1]=47|0 [2]=8|0 [3]=81|0 [4]=0|0 [5]=95|0 [ 273.100992] cpu42 [0]=25|128 [1]=92|128 [2]=53|128 [3]=49|128 [4]=43|128 [5]=78|128 [ 273.108704] cpu43 [0]=88|0 [1]=42|0 [2]=10|0 [3]=124|0 [4]=4|0 [5]=105|0 [ 273.115464] cpu44 [0]=80|0 [1]=63|0 [2]=1|0 [3]=123|0 [4]=35|0 [5]=17|0 [ 273.122139] cpu45 [0]=31|0 [1]=92|0 [2]=8|0 [3]=60|0 [4]=74|0 [5]=92|0 [ 273.128727] cpu46 [0]=78|0 [1]=40|0 [2]=95|0 [3]=33|0 [4]=67|0 [5]=63|0 [ 273.135401] cpu47 [0]=112|0 [1]=93|0 [2]=96|0 [3]=24|0 [4]=93|0 [5]=15|0 [ 273.142162] cpu48 [0]=92|0 [1]=120|0 [2]=49|0 [3]=118|0 [4]=1|0 [5]=83|0 [ 273.148923] cpu49 [0]=101|0 [1]=7|0 [2]=108|0 [3]=15|0 [4]=69|0 [5]=116|0 [ 273.155771] cpu50 [0]=111|128 [1]=98|128 [2]=21|128 [3]=27|128 [4]=109|128 [5]=21|128 [ 273.163655] cpu51 [0]=31|0 [1]=33|0 [2]=82|0 [3]=117|0 [4]=98|0 [5]=1|0 [ 273.170329] cpu52 [0]=113|0 [1]=64|0 [2]=16|0 [3]=48|0 [4]=97|0 [5]=80|0 [ 273.177090] cpu53 [0]=95|0 [1]=39|0 [2]=26|0 [3]=107|0 [4]=2|0 [5]=18|0 [ 273.183764] cpu54 [0]=114|0 [1]=94|0 [2]=110|0 [3]=85|0 [4]=66|0 [5]=45|0 [ 273.190611] cpu55 [0]=52|0 [1]=89|0 [2]=43|0 [3]=117|0 [4]=115|0 [5]=91|0 [ 273.197460] cpu56 [0]=0|0 [1]=51|0 [2]=81|0 [3]=60|0 [4]=20|0 [5]=27|0 [ 273.204048] cpu57 [0]=124|0 [1]=121|0 [2]=56|0 [3]=0|0 [4]=77|0 [5]=59|0 [ 273.210807] cpu58 [0]=109|128 [1]=98|128 [2]=6|128 [3]=39|128 [4]=64|128 [5]=24|128 [ 273.218518] cpu59 [0]=57|0 [1]=62|0 [2]=66|0 [3]=55|0 [4]=95|0 [5]=47|0 [ 273.225192] cpu60 [0]=29|0 [1]=12|0 [2]=112|0 [3]=23|0 [4]=65|0 [5]=34|0 [ 273.231955] cpu61 [0]=92|0 [1]=5|0 [2]=19|0 [3]=91|0 [4]=101|0 [5]=97|0 [ 273.238629] cpu62 [0]=97|0 [1]=42|0 [2]=30|0 [3]=111|0 [4]=99|0 [5]=2|0 [ 273.245304] cpu63 [0]=77|0 [1]=79|0 [2]=62|0 [3]=56|0 [4]=17|0 [5]=76|0 [ 273.251982] cpu64 [0]=0|0 [1]=108|0 [2]=87|0 [3]=58|0 [4]=26|0 [5]=0|0 [ 273.258582] cpu65 [0]=0|0 [1]=114|0 [2]=99|0 [3]=73|0 [4]=33|0 [5]=0|0 [ 273.265174] cpu66 [0]=39|128 [1]=52|128 [2]=82|128 [3]=107|128 [4]=73|128 [5]=13|128 [ 273.272974] cpu67 [0]=0|0 [1]=123|0 [2]=87|0 [3]=49|0 [4]=27|0 [5]=98|0 [ 273.279651] cpu68 [0]=108|0 [1]=0|0 [2]=123|0 [3]=47|0 [4]=30|0 [5]=109|0 [ 273.286500] cpu69 [0]=92|0 [1]=110|0 [2]=92|0 [3]=59|0 [4]=42|0 [5]=104|0 [ 273.293351] cpu70 [0]=105|0 [1]=106|0 [2]=99|0 [3]=57|0 [4]=15|0 [5]=111|0 [ 273.300287] cpu71 [0]=106|0 [1]=108|0 [2]=108|0 [3]=58|0 [4]=35|0 [5]=98|0 [ 273.307222] cpu72 [0]=0|0 [1]=0|0 [2]=114|0 [3]=118|0 [4]=95|0 [5]=0|0 [ 273.313813] cpu73 [0]=0|0 [1]=0|0 [2]=0|0 [3]=98|0 [4]=95|0 [5]=124|0 [ 273.320318] cpu74 [0]=65|0 [1]=76|0 [2]=109|0 [3]=58|128 [4]=115|128 [5]=105|0 [ 273.327603] cpu75 [0]=0|0 [1]=0|0 [2]=123|0 [3]=102|0 [4]=109|0 [5]=0|0 [ 273.334279] cpu76 [0]=125|0 [1]=0|0 [2]=0|0 [3]=101|0 [4]=112|0 [5]=0|0 [ 273.340954] cpu77 [0]=124|0 [1]=124|0 [2]=0|0 [3]=103|0 [4]=100|0 [5]=0|0 [ 273.347803] cpu78 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=118|0 [5]=0|0 [ 273.354134] cpu79 [0]=124|0 [1]=0|0 [2]=116|0 [3]=104|0 [4]=120|0 [5]=0|0 [ 273.360981] cpu80 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.367138] cpu81 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.373292] cpu82 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.379447] cpu83 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.385601] cpu84 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.391755] cpu85 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.397910] cpu86 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.404065] cpu87 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.410220] cpu88 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.416376] cpu89 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.422532] cpu90 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.428687] cpu91 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.434841] cpu92 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.440997] cpu93 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.447152] cpu94 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.453311] cpu95 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.459468] cpu96 [0]=78|0 [1]=95|0 [2]=117|0 [3]=120|0 [4]=37|0 [5]=31|0 [ 273.466317] cpu97 [0]=105|0 [1]=99|0 [2]=37|0 [3]=24|0 [4]=86|0 [5]=39|0 [ 273.473080] cpu98 [0]=37|128 [1]=13|128 [2]=102|128 [3]=124|128 [4]=60|128 [5]=36|128 [ 273.480967] cpu99 [0]=69|0 [1]=12|0 [2]=84|0 [3]=49|0 [4]=108|0 [5]=127|0 [ 273.487818] cpu100 [0]=92|0 [1]=104|0 [2]=22|0 [3]=31|0 [4]=2|0 [5]=72|0 [ 273.494581] cpu101 [0]=0|0 [1]=31|0 [2]=44|0 [3]=8|0 [4]=13|0 [5]=50|0 [ 273.501170] cpu102 [0]=79|0 [1]=14|0 [2]=88|0 [3]=53|0 [4]=7|0 [5]=44|0 [ 273.507846] cpu103 [0]=10|0 [1]=117|0 [2]=53|0 [3]=112|0 [4]=11|0 [5]=71|0 [ 273.514781] cpu104 [0]=123|0 [1]=30|0 [2]=9|0 [3]=2|0 [4]=30|0 [5]=24|0 [ 273.521462] cpu105 [0]=116|0 [1]=44|0 [2]=29|0 [3]=104|0 [4]=71|0 [5]=3|0 [ 273.528309] cpu106 [0]=38|128 [1]=127|128 [2]=21|128 [3]=83|128 [4]=59|128 [5]=81|128 [ 273.536195] cpu107 [0]=127|0 [1]=126|0 [2]=125|0 [3]=79|0 [4]=12|0 [5]=115|0 [ 273.543303] cpu108 [0]=0|0 [1]=43|0 [2]=111|0 [3]=10|0 [4]=51|0 [5]=68|0 [ 273.550065] cpu109 [0]=37|0 [1]=63|0 [2]=11|0 [3]=10|0 [4]=58|0 [5]=9|0 [ 273.556742] cpu110 [0]=86|0 [1]=44|0 [2]=83|0 [3]=85|0 [4]=82|0 [5]=119|0 [ 273.563590] cpu111 [0]=114|0 [1]=27|0 [2]=111|0 [3]=11|0 [4]=45|0 [5]=56|0 [ 273.570524] cpu112 [0]=74|0 [1]=86|0 [2]=93|0 [3]=122|0 [4]=126|0 [5]=31|0 [ 273.577458] cpu113 [0]=51|0 [1]=81|0 [2]=7|0 [3]=124|0 [4]=71|0 [5]=5|0 [ 273.584133] cpu114 [0]=58|128 [1]=95|128 [2]=14|128 [3]=119|128 [4]=85|128 [5]=23|128 [ 273.592018] cpu115 [0]=59|0 [1]=66|0 [2]=1|0 [3]=50|0 [4]=77|0 [5]=6|0 [ 273.598607] cpu116 [0]=65|0 [1]=81|0 [2]=22|0 [3]=18|0 [4]=96|0 [5]=2|0 [ 273.605282] cpu117 [0]=23|0 [1]=41|0 [2]=19|0 [3]=69|0 [4]=108|0 [5]=126|0 [ 273.612216] cpu118 [0]=74|0 [1]=40|0 [2]=0|0 [3]=100|0 [4]=109|0 [5]=7|0 [ 273.618979] cpu119 [0]=47|0 [1]=31|0 [2]=103|0 [3]=65|0 [4]=84|0 [5]=124|0 [ 273.625914] cpu120 [0]=74|0 [1]=18|0 [2]=87|0 [3]=117|0 [4]=17|0 [5]=62|0 [ 273.632762] cpu121 [0]=64|0 [1]=73|0 [2]=3|0 [3]=127|0 [4]=120|0 [5]=105|0 [ 273.639698] cpu122 [0]=46|128 [1]=89|128 [2]=22|128 [3]=78|128 [4]=100|128 [5]=106|128 [ 273.647671] cpu123 [0]=36|0 [1]=71|0 [2]=25|0 [3]=23|0 [4]=126|0 [5]=86|0 [ 273.654521] cpu124 [0]=26|0 [1]=93|0 [2]=101|0 [3]=103|0 [4]=54|0 [5]=100|0 [ 273.661542] cpu125 [0]=58|0 [1]=57|0 [2]=116|0 [3]=35|0 [4]=73|0 [5]=12|0 [ 273.668392] cpu126 [0]=11|0 [1]=54|0 [2]=41|0 [3]=0|0 [4]=27|0 [5]=54|0 [ 273.675067] cpu127 [0]=70|0 [1]=38|0 [2]=58|0 [3]=123|0 [4]=47|0 [5]=21|0 [ 273.681913] share cache: [0]=0 [1]=4 [2]=9 [3]=3 [4]=6 [5]=5
let's call this the depot
[ 273.687633] rb_total: 59443
Hi john,
在 2021/5/28 22:23, John Garry 写道:
On 28/05/2021 08:12, chenxiang wrote:
From: Xiang Chen chenxiang66@hisilicon.com
The first patch is to release those rcache when rmmod the driver of the last device to save memory.
And patch2~6 is add support for IOMMU debugfs related to IOVA as follows: /sys/kernel/debug/iommu/iovad/iommu_domainx
Under iommu_domainx dir, add debugfs file iova_rcache and drop_rcache.
From debugfs file iova_rcache, we can get how many cpu_rcache / share
rcache / iovas are used, and also we can drop those rcache by debugfs file drop_rcache:
For cpu_rcache, [i]=x|y indicates that there are x iova in load iova_magazine and y iova in prev iova_magazine (128 at most). For share rcache, [i]=x indicates that there are x iova_magazines in use.
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$
How do we know the relation to the IOMMU group?
And it could be nice to show 'ls -l' output, even if you did mention it, above.
The domain id(actually there is no domain id in IOMMU code) is the same as the group id, so "iommu_domain2" is related to "iommu_group2".
I would also like to see additional info, specifically allocation attempts per rcache range and also allocation attempts which were "too_big" to be cached.
I did add those additional info (including retry cnt when allocating iova in rbtree, you can see them on attachment). But i fount it had a little affect on performance (1750K -> 1700K), so remove them.
cat iova_rcache [ 272.814457] cpu0 [0]=60|0 [1]=7|0 [2]=32|0 [3]=0|0 [4]=97|0 [5]=104|0
I suppose this is ok, but the output is becoming huge with many CPUs and possibly increasing rcache range.
You possibly could consider breaking it down to sub files or folders, which may be better, like:
ls iovad/iommu_domain2: 0 1 2 3 4 ... too_big
Right, this is a good idea to break it into sub folders according to the size of rcache.
ls iovad/iommu_domain2/0 rcache allocations depot
more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
more iovad/iommu_domain2/0/allocations 1244
more iovad/iommu_domain2/0/depot 28 44 22
ls iovad/iommu_domain2/too_big allocations
As for the rcache file, you could even have separate per-cpu files in a rcache folder, like:
ls iovad/iommu_domain2/0/rcache cpu0 cpu1 cpu2 ...cpu127
more iovad/iommu_domain2/0/rcache/cpu0 0|3
But then we need have more files and folders to examine. Need to find a good balance.
Yes, if adding per-cpu file in a rcache folder, there are too many files need to examine, and user don't know which cpu he should focus on, so need to check it one by one. And i prefer to print all of them once a time as you suggest: more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
[ 272.820982] cpu1 [0]=0|0 [1]=3|0 [2]=14|0 [3]=76|0 [4]=15|0 [5]=64|0 [ 272.827399] cpu2 [0]=85|128 [1]=84|128 [2]=83|128 [3]=112|128 [4]=22|128 [5]=116|128 [ 272.835197] cpu3 [0]=0|0 [1]=91|0 [2]=101|0 [3]=29|0 [4]=0|0 [5]=36|0 [ 272.841699] cpu4 [0]=0|0 [1]=39|0 [2]=113|0 [3]=75|0 [4]=95|0 [5]=0|0 [ 272.848201] cpu5 [0]=27|0 [1]=48|0 [2]=82|0 [3]=0|0 [4]=19|0 [5]=36|0 [ 272.854702] cpu6 [0]=30|0 [1]=0|0 [2]=48|0 [3]=2|0 [4]=18|0 [5]=56|0 [ 272.861117] cpu7 [0]=27|0 [1]=89|0 [2]=101|0 [3]=59|0 [4]=28|0 [5]=0|0 [ 272.867706] cpu8 [0]=66|0 [1]=114|0 [2]=42|0 [3]=123|0 [4]=96|0 [5]=68|0 [ 272.874466] cpu9 [0]=71|0 [1]=61|0 [2]=28|0 [3]=118|0 [4]=116|0 [5]=41|0 [ 272.881227] cpu10 [0]=83|128 [1]=63|128 [2]=109|128 [3]=79|128 [4]=7|128 [5]=54|128 [ 272.888938] cpu11 [0]=90|0 [1]=34|0 [2]=88|0 [3]=58|0 [4]=20|0 [5]=35|0 [ 272.895611] cpu12 [0]=64|0 [1]=20|0 [2]=18|0 [3]=33|0 [4]=42|0 [5]=22|0 [ 272.902285] cpu13 [0]=17|0 [1]=70|0 [2]=115|0 [3]=59|0 [4]=108|0 [5]=58|0 [ 272.909132] cpu14 [0]=28|0 [1]=18|0 [2]=27|0 [3]=105|0 [4]=65|0 [5]=81|0 [ 272.915892] cpu15 [0]=75|0 [1]=3|0 [2]=73|0 [3]=104|0 [4]=127|0 [5]=102|0 [ 272.922738] cpu16 [0]=54|0 [1]=116|0 [2]=90|0 [3]=31|0 [4]=108|0 [5]=41|0 [ 272.929590] cpu17 [0]=47|0 [1]=82|0 [2]=3|0 [3]=66|0 [4]=68|0 [5]=66|0 [ 272.936179] cpu18 [0]=126|128 [1]=110|128 [2]=48|128 [3]=118|128 [4]=54|128 [5]=73|128 [ 272.944156] cpu19 [0]=31|0 [1]=13|0 [2]=104|0 [3]=45|0 [4]=108|0 [5]=96|0 [ 272.951006] cpu20 [0]=58|0 [1]=113|0 [2]=14|0 [3]=123|0 [4]=52|0 [5]=54|0 [ 272.957856] cpu21 [0]=116|0 [1]=47|0 [2]=96|0 [3]=60|0 [4]=47|0 [5]=126|0 [ 272.964701] cpu22 [0]=84|0 [1]=87|0 [2]=88|0 [3]=68|0 [4]=37|0 [5]=119|0 [ 272.971462] cpu23 [0]=13|0 [1]=63|0 [2]=124|0 [3]=3|0 [4]=7|0 [5]=38|0 [ 272.978051] cpu24 [0]=15|0 [1]=64|0 [2]=65|0 [3]=53|0 [4]=102|0 [5]=69|0 [ 272.984812] cpu25 [0]=94|0 [1]=108|0 [2]=67|0 [3]=125|0 [4]=107|0 [5]=8|0 [ 272.991663] cpu26 [0]=84|128 [1]=86|128 [2]=91|128 [3]=121|128 [4]=77|128 [5]=25|128 [ 272.999464] cpu27 [0]=60|0 [1]=105|0 [2]=61|0 [3]=91|0 [4]=79|0 [5]=6|0 [ 273.006141] cpu28 [0]=39|0 [1]=91|0 [2]=11|0 [3]=87|0 [4]=112|0 [5]=10|0 [ 273.012904] cpu29 [0]=88|0 [1]=43|0 [2]=0|0 [3]=77|0 [4]=10|0 [5]=79|0 [ 273.019492] cpu30 [0]=65|0 [1]=24|0 [2]=125|0 [3]=24|0 [4]=54|0 [5]=21|0 [ 273.026254] cpu31 [0]=26|0 [1]=90|0 [2]=42|0 [3]=17|0 [4]=73|0 [5]=35|0 [ 273.032929] cpu32 [0]=1|0 [1]=83|0 [2]=76|0 [3]=62|0 [4]=117|0 [5]=96|0 [ 273.039612] cpu33 [0]=50|0 [1]=55|0 [2]=63|0 [3]=79|0 [4]=86|0 [5]=15|0 [ 273.046293] cpu34 [0]=122|128 [1]=36|128 [2]=36|128 [3]=79|128 [4]=113|128 [5]=80|128 [ 273.054179] cpu35 [0]=101|0 [1]=18|0 [2]=7|0 [3]=10|0 [4]=7|0 [5]=112|0 [ 273.060854] cpu36 [0]=12|0 [1]=107|0 [2]=43|0 [3]=60|0 [4]=19|0 [5]=110|0 [ 273.067703] cpu37 [0]=90|0 [1]=34|0 [2]=66|0 [3]=91|0 [4]=85|0 [5]=31|0 [ 273.074378] cpu38 [0]=0|0 [1]=22|0 [2]=18|0 [3]=73|0 [4]=54|0 [5]=96|0 [ 273.080968] cpu39 [0]=109|0 [1]=54|0 [2]=124|0 [3]=21|0 [4]=88|0 [5]=61|0 [ 273.087816] cpu40 [0]=95|0 [1]=50|0 [2]=45|0 [3]=66|0 [4]=30|0 [5]=84|0 [ 273.094490] cpu41 [0]=99|0 [1]=47|0 [2]=8|0 [3]=81|0 [4]=0|0 [5]=95|0 [ 273.100992] cpu42 [0]=25|128 [1]=92|128 [2]=53|128 [3]=49|128 [4]=43|128 [5]=78|128 [ 273.108704] cpu43 [0]=88|0 [1]=42|0 [2]=10|0 [3]=124|0 [4]=4|0 [5]=105|0 [ 273.115464] cpu44 [0]=80|0 [1]=63|0 [2]=1|0 [3]=123|0 [4]=35|0 [5]=17|0 [ 273.122139] cpu45 [0]=31|0 [1]=92|0 [2]=8|0 [3]=60|0 [4]=74|0 [5]=92|0 [ 273.128727] cpu46 [0]=78|0 [1]=40|0 [2]=95|0 [3]=33|0 [4]=67|0 [5]=63|0 [ 273.135401] cpu47 [0]=112|0 [1]=93|0 [2]=96|0 [3]=24|0 [4]=93|0 [5]=15|0 [ 273.142162] cpu48 [0]=92|0 [1]=120|0 [2]=49|0 [3]=118|0 [4]=1|0 [5]=83|0 [ 273.148923] cpu49 [0]=101|0 [1]=7|0 [2]=108|0 [3]=15|0 [4]=69|0 [5]=116|0 [ 273.155771] cpu50 [0]=111|128 [1]=98|128 [2]=21|128 [3]=27|128 [4]=109|128 [5]=21|128 [ 273.163655] cpu51 [0]=31|0 [1]=33|0 [2]=82|0 [3]=117|0 [4]=98|0 [5]=1|0 [ 273.170329] cpu52 [0]=113|0 [1]=64|0 [2]=16|0 [3]=48|0 [4]=97|0 [5]=80|0 [ 273.177090] cpu53 [0]=95|0 [1]=39|0 [2]=26|0 [3]=107|0 [4]=2|0 [5]=18|0 [ 273.183764] cpu54 [0]=114|0 [1]=94|0 [2]=110|0 [3]=85|0 [4]=66|0 [5]=45|0 [ 273.190611] cpu55 [0]=52|0 [1]=89|0 [2]=43|0 [3]=117|0 [4]=115|0 [5]=91|0 [ 273.197460] cpu56 [0]=0|0 [1]=51|0 [2]=81|0 [3]=60|0 [4]=20|0 [5]=27|0 [ 273.204048] cpu57 [0]=124|0 [1]=121|0 [2]=56|0 [3]=0|0 [4]=77|0 [5]=59|0 [ 273.210807] cpu58 [0]=109|128 [1]=98|128 [2]=6|128 [3]=39|128 [4]=64|128 [5]=24|128 [ 273.218518] cpu59 [0]=57|0 [1]=62|0 [2]=66|0 [3]=55|0 [4]=95|0 [5]=47|0 [ 273.225192] cpu60 [0]=29|0 [1]=12|0 [2]=112|0 [3]=23|0 [4]=65|0 [5]=34|0 [ 273.231955] cpu61 [0]=92|0 [1]=5|0 [2]=19|0 [3]=91|0 [4]=101|0 [5]=97|0 [ 273.238629] cpu62 [0]=97|0 [1]=42|0 [2]=30|0 [3]=111|0 [4]=99|0 [5]=2|0 [ 273.245304] cpu63 [0]=77|0 [1]=79|0 [2]=62|0 [3]=56|0 [4]=17|0 [5]=76|0 [ 273.251982] cpu64 [0]=0|0 [1]=108|0 [2]=87|0 [3]=58|0 [4]=26|0 [5]=0|0 [ 273.258582] cpu65 [0]=0|0 [1]=114|0 [2]=99|0 [3]=73|0 [4]=33|0 [5]=0|0 [ 273.265174] cpu66 [0]=39|128 [1]=52|128 [2]=82|128 [3]=107|128 [4]=73|128 [5]=13|128 [ 273.272974] cpu67 [0]=0|0 [1]=123|0 [2]=87|0 [3]=49|0 [4]=27|0 [5]=98|0 [ 273.279651] cpu68 [0]=108|0 [1]=0|0 [2]=123|0 [3]=47|0 [4]=30|0 [5]=109|0 [ 273.286500] cpu69 [0]=92|0 [1]=110|0 [2]=92|0 [3]=59|0 [4]=42|0 [5]=104|0 [ 273.293351] cpu70 [0]=105|0 [1]=106|0 [2]=99|0 [3]=57|0 [4]=15|0 [5]=111|0 [ 273.300287] cpu71 [0]=106|0 [1]=108|0 [2]=108|0 [3]=58|0 [4]=35|0 [5]=98|0 [ 273.307222] cpu72 [0]=0|0 [1]=0|0 [2]=114|0 [3]=118|0 [4]=95|0 [5]=0|0 [ 273.313813] cpu73 [0]=0|0 [1]=0|0 [2]=0|0 [3]=98|0 [4]=95|0 [5]=124|0 [ 273.320318] cpu74 [0]=65|0 [1]=76|0 [2]=109|0 [3]=58|128 [4]=115|128 [5]=105|0 [ 273.327603] cpu75 [0]=0|0 [1]=0|0 [2]=123|0 [3]=102|0 [4]=109|0 [5]=0|0 [ 273.334279] cpu76 [0]=125|0 [1]=0|0 [2]=0|0 [3]=101|0 [4]=112|0 [5]=0|0 [ 273.340954] cpu77 [0]=124|0 [1]=124|0 [2]=0|0 [3]=103|0 [4]=100|0 [5]=0|0 [ 273.347803] cpu78 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=118|0 [5]=0|0 [ 273.354134] cpu79 [0]=124|0 [1]=0|0 [2]=116|0 [3]=104|0 [4]=120|0 [5]=0|0 [ 273.360981] cpu80 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.367138] cpu81 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.373292] cpu82 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.379447] cpu83 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.385601] cpu84 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.391755] cpu85 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.397910] cpu86 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.404065] cpu87 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.410220] cpu88 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.416376] cpu89 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.422532] cpu90 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.428687] cpu91 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.434841] cpu92 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.440997] cpu93 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.447152] cpu94 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.453311] cpu95 [0]=0|0 [1]=0|0 [2]=0|0 [3]=0|0 [4]=0|0 [5]=0|0 [ 273.459468] cpu96 [0]=78|0 [1]=95|0 [2]=117|0 [3]=120|0 [4]=37|0 [5]=31|0 [ 273.466317] cpu97 [0]=105|0 [1]=99|0 [2]=37|0 [3]=24|0 [4]=86|0 [5]=39|0 [ 273.473080] cpu98 [0]=37|128 [1]=13|128 [2]=102|128 [3]=124|128 [4]=60|128 [5]=36|128 [ 273.480967] cpu99 [0]=69|0 [1]=12|0 [2]=84|0 [3]=49|0 [4]=108|0 [5]=127|0 [ 273.487818] cpu100 [0]=92|0 [1]=104|0 [2]=22|0 [3]=31|0 [4]=2|0 [5]=72|0 [ 273.494581] cpu101 [0]=0|0 [1]=31|0 [2]=44|0 [3]=8|0 [4]=13|0 [5]=50|0 [ 273.501170] cpu102 [0]=79|0 [1]=14|0 [2]=88|0 [3]=53|0 [4]=7|0 [5]=44|0 [ 273.507846] cpu103 [0]=10|0 [1]=117|0 [2]=53|0 [3]=112|0 [4]=11|0 [5]=71|0 [ 273.514781] cpu104 [0]=123|0 [1]=30|0 [2]=9|0 [3]=2|0 [4]=30|0 [5]=24|0 [ 273.521462] cpu105 [0]=116|0 [1]=44|0 [2]=29|0 [3]=104|0 [4]=71|0 [5]=3|0 [ 273.528309] cpu106 [0]=38|128 [1]=127|128 [2]=21|128 [3]=83|128 [4]=59|128 [5]=81|128 [ 273.536195] cpu107 [0]=127|0 [1]=126|0 [2]=125|0 [3]=79|0 [4]=12|0 [5]=115|0 [ 273.543303] cpu108 [0]=0|0 [1]=43|0 [2]=111|0 [3]=10|0 [4]=51|0 [5]=68|0 [ 273.550065] cpu109 [0]=37|0 [1]=63|0 [2]=11|0 [3]=10|0 [4]=58|0 [5]=9|0 [ 273.556742] cpu110 [0]=86|0 [1]=44|0 [2]=83|0 [3]=85|0 [4]=82|0 [5]=119|0 [ 273.563590] cpu111 [0]=114|0 [1]=27|0 [2]=111|0 [3]=11|0 [4]=45|0 [5]=56|0 [ 273.570524] cpu112 [0]=74|0 [1]=86|0 [2]=93|0 [3]=122|0 [4]=126|0 [5]=31|0 [ 273.577458] cpu113 [0]=51|0 [1]=81|0 [2]=7|0 [3]=124|0 [4]=71|0 [5]=5|0 [ 273.584133] cpu114 [0]=58|128 [1]=95|128 [2]=14|128 [3]=119|128 [4]=85|128 [5]=23|128 [ 273.592018] cpu115 [0]=59|0 [1]=66|0 [2]=1|0 [3]=50|0 [4]=77|0 [5]=6|0 [ 273.598607] cpu116 [0]=65|0 [1]=81|0 [2]=22|0 [3]=18|0 [4]=96|0 [5]=2|0 [ 273.605282] cpu117 [0]=23|0 [1]=41|0 [2]=19|0 [3]=69|0 [4]=108|0 [5]=126|0 [ 273.612216] cpu118 [0]=74|0 [1]=40|0 [2]=0|0 [3]=100|0 [4]=109|0 [5]=7|0 [ 273.618979] cpu119 [0]=47|0 [1]=31|0 [2]=103|0 [3]=65|0 [4]=84|0 [5]=124|0 [ 273.625914] cpu120 [0]=74|0 [1]=18|0 [2]=87|0 [3]=117|0 [4]=17|0 [5]=62|0 [ 273.632762] cpu121 [0]=64|0 [1]=73|0 [2]=3|0 [3]=127|0 [4]=120|0 [5]=105|0 [ 273.639698] cpu122 [0]=46|128 [1]=89|128 [2]=22|128 [3]=78|128 [4]=100|128 [5]=106|128 [ 273.647671] cpu123 [0]=36|0 [1]=71|0 [2]=25|0 [3]=23|0 [4]=126|0 [5]=86|0 [ 273.654521] cpu124 [0]=26|0 [1]=93|0 [2]=101|0 [3]=103|0 [4]=54|0 [5]=100|0 [ 273.661542] cpu125 [0]=58|0 [1]=57|0 [2]=116|0 [3]=35|0 [4]=73|0 [5]=12|0 [ 273.668392] cpu126 [0]=11|0 [1]=54|0 [2]=41|0 [3]=0|0 [4]=27|0 [5]=54|0 [ 273.675067] cpu127 [0]=70|0 [1]=38|0 [2]=58|0 [3]=123|0 [4]=47|0 [5]=21|0 [ 273.681913] share cache: [0]=0 [1]=4 [2]=9 [3]=3 [4]=6 [5]=5
let's call this the depot
ok
[ 273.687633] rb_total: 59443
.
On 29/05/2021 02:31, chenxiang (M) wrote:
Hi john,
在 2021/5/28 22:23, John Garry 写道:
On 28/05/2021 08:12, chenxiang wrote:
From: Xiang Chen chenxiang66@hisilicon.com
The first patch is to release those rcache when rmmod the driver of the last device to save memory.
And patch2~6 is add support for IOMMU debugfs related to IOVA as follows: /sys/kernel/debug/iommu/iovad/iommu_domainx
Under iommu_domainx dir, add debugfs file iova_rcache and drop_rcache.
From debugfs file iova_rcache, we can get how many cpu_rcache / share
rcache / iovas are used, and also we can drop those rcache by debugfs file drop_rcache:
For cpu_rcache, [i]=x|y indicates that there are x iova in load iova_magazine and y iova in prev iova_magazine (128 at most). For share rcache, [i]=x indicates that there are x iova_magazines in use.
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$
How do we know the relation to the IOMMU group?
And it could be nice to show 'ls -l' output, even if you did mention it, above.
The domain id(actually there is no domain id in IOMMU code) is the same as the group id, so "iommu_domain2" is related to "iommu_group2".
ok, but I would then just name the folder as "iommu_group2", which is makes it quite clear.
I need to check the code how you set this name (which I'll do next), as we would need to support non-IOMMU group IOVA domains as well.
I would also like to see additional info, specifically allocation attempts per rcache range and also allocation attempts which were "too_big" to be cached.
I did add those additional info (including retry cnt when allocating iova in rbtree, you can see them on attachment). But i fount it had a little affect on performance (1750K -> 1700K), so remove them.
hmmm... maybe we can have a per-cpu count for each item. But then it would be getting more complicated...
If we have only a "too_big", then it should not touch hotpath (as too big means going to IOVA RB tree, which can be slow).
cat iova_rcache [ 272.814457] cpu0 [0]=60|0 [1]=7|0 [2]=32|0 [3]=0|0 [4]=97|0 [5]=104|0
I suppose this is ok, but the output is becoming huge with many CPUs and possibly increasing rcache range.
You possibly could consider breaking it down to sub files or folders, which may be better, like:
ls iovad/iommu_domain2: 0 1 2 3 4 ... too_big
Right, this is a good idea to break it into sub folders according to the size of rcache.
ls iovad/iommu_domain2/0 rcache allocations depot
more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
more iovad/iommu_domain2/0/allocations 1244
more iovad/iommu_domain2/0/depot 28 44 22
ls iovad/iommu_domain2/too_big allocations
As for the rcache file, you could even have separate per-cpu files in a rcache folder, like:
ls iovad/iommu_domain2/0/rcache cpu0 cpu1 cpu2 ...cpu127
more iovad/iommu_domain2/0/rcache/cpu0 0|3
But then we need have more files and folders to examine. Need to find a good balance.
Yes, if adding per-cpu file in a rcache folder, there are too many files need to examine, and user don't know which cpu he should focus on, so need to check it one by one. And i prefer to print all of them once a time as you suggest: more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
在 2021/6/1 19:45, John Garry 写道:
On 29/05/2021 02:31, chenxiang (M) wrote:
Hi john,
在 2021/5/28 22:23, John Garry 写道:
On 28/05/2021 08:12, chenxiang wrote:
From: Xiang Chen chenxiang66@hisilicon.com
The first patch is to release those rcache when rmmod the driver of the last device to save memory.
And patch2~6 is add support for IOMMU debugfs related to IOVA as follows: /sys/kernel/debug/iommu/iovad/iommu_domainx
Under iommu_domainx dir, add debugfs file iova_rcache and drop_rcache.
From debugfs file iova_rcache, we can get how many cpu_rcache / share
rcache / iovas are used, and also we can drop those rcache by debugfs file drop_rcache:
For cpu_rcache, [i]=x|y indicates that there are x iova in load iova_magazine and y iova in prev iova_magazine (128 at most). For share rcache, [i]=x indicates that there are x iova_magazines in use.
estuary:/sys/kernel/debug/iommu/iovad/iommu_domain2$
How do we know the relation to the IOMMU group?
And it could be nice to show 'ls -l' output, even if you did mention it, above.
The domain id(actually there is no domain id in IOMMU code) is the same as the group id, so "iommu_domain2" is related to "iommu_group2".
ok, but I would then just name the folder as "iommu_group2", which is makes it quite clear.
I need to check the code how you set this name (which I'll do next), as we would need to support non-IOMMU group IOVA domains as well.
I would also like to see additional info, specifically allocation attempts per rcache range and also allocation attempts which were "too_big" to be cached.
I did add those additional info (including retry cnt when allocating iova in rbtree, you can see them on attachment). But i fount it had a little affect on performance (1750K -> 1700K), so remove them.
hmmm... maybe we can have a per-cpu count for each item. But then it would be getting more complicated...
If we have only a "too_big", then it should not touch hotpath (as too big means going to IOVA RB tree, which can be slow).
Yes, if only have "too_big", it should not affect the performance, but not sure whether it is ok not know the ratio too_big/total_cnt.
cat iova_rcache [ 272.814457] cpu0 [0]=60|0 [1]=7|0 [2]=32|0 [3]=0|0 [4]=97|0 [5]=104|0
I suppose this is ok, but the output is becoming huge with many CPUs and possibly increasing rcache range.
You possibly could consider breaking it down to sub files or folders, which may be better, like:
ls iovad/iommu_domain2: 0 1 2 3 4 ... too_big
Right, this is a good idea to break it into sub folders according to the size of rcache.
ls iovad/iommu_domain2/0 rcache allocations depot
more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
more iovad/iommu_domain2/0/allocations 1244
more iovad/iommu_domain2/0/depot 28 44 22
ls iovad/iommu_domain2/too_big allocations
As for the rcache file, you could even have separate per-cpu files in a rcache folder, like:
ls iovad/iommu_domain2/0/rcache cpu0 cpu1 cpu2 ...cpu127
more iovad/iommu_domain2/0/rcache/cpu0 0|3
But then we need have more files and folders to examine. Need to find a good balance.
Yes, if adding per-cpu file in a rcache folder, there are too many files need to examine, and user don't know which cpu he should focus on, so need to check it one by one. And i prefer to print all of them once a time as you suggest: more iovad/iommu_domain2/0/rcache cpu0: 0|1 cpu1: 2|4 ... cpuMax: 0|0
.