)]}'
{
  "commit": "033906b9f001ad8de67ebafbb9838f968715b74d",
  "tree": "64f7c95fe1cfd45a692eb4b9c54a3a9f63ae43e4",
  "parents": [
    "6be6c584a2e8031375fd3950a9b7bd9a867af5ee"
  ],
  "author": {
    "name": "Aleksa Sarai",
    "email": "cyphar@cyphar.com",
    "time": "Fri Sep 26 15:10:34 2025 +0000"
  },
  "committer": {
    "name": "Cherry Mui",
    "email": "cherryyz@google.com",
    "time": "Fri Sep 26 10:17:15 2025 -0700"
  },
  "message": "unix: add (*CPUSet).Fill helper to enable all CPUs\n\nSome programs (such as container runtimes) want to reset their CPU\naffinity if they are spawned by processes with a particular CPU\naffinity. Container runtimes didn\u0027t really have to deal with this issue\nuntil Linux 6.2 when the cpuset cgroup was changed to no longer\nauto-reset CPU affinity in this case.\n\nA naive approach to resetting your CPU affinity would be to get the\nnumber of CPUs by looking at \"/proc/stat\" or \"/sys/devices/system/cpu\"\n(note that runtime.NumCPU() actually returns the CPU affinity of the\nprocess at startup time, which isn\u0027t useful for this purpose) and then\nasking for all of those CPUs.\n\nHowever, sched_setaffinity(2) will silently ignore any CPU bits set in\nthe provided CPUSet if they do not exist or are not enabled in the\ncpuset cgroup of the process. This means that you can reset your CPU\naffinity by just setting every CPU bit in CPUSet and passing it to\nsched_setaffinity(2).\n\nUnfortunately, setting every CPU bit in CPUSet with (*CPUSet).Set() is\nvery inefficient. If it were possible to just memset(0xFF) the CPUSet\narray, users would be able to reset their CPU affinity even more\ncheaply. However, Go doesn\u0027t have a memset primitive that can be used in\nthat way.\n\nObvious solutions like setting the array elements of CPUSet to (^0) do\nnot work because CPUSet is an array of a private newtype and so the\ncompiler complains if you try to use a constant like (^0) without a\ncast (and we cannot use a cast because the type is private):\n\n    cannot use ^0 (untyped int constant -1) as\n    \"golang.org/x/sys/unix\".cpuMask value in assignment (overflows)\n\nThe only real alternative is to do something quite hacky like:\n\n    cpuset :\u003d unix.CPUSet{}\n    for i :\u003d range cpuset {\n        cpuset[i]-- // underflow to 0xFF..FF\n    }\n\n... which is the solution we use in runc.\n\nIt would be much nicer to have a helper that does this memset for us in\na less hacky way, since resetting CPU affinity seems like a fairly\ncommon operation.\n\nRef: Linux kernel commit da019032819a (\"sched: Enforce user requested affinity\")\nFixes golang/go#75186\n\nChange-Id: I211ddeafd54ce35079a67493123d28e1bb76966a\nGitHub-Last-Rev: 71871db0f339f154dea6ac4d545237f08f70a301\nGitHub-Pull-Request: golang/sys#259\nReviewed-on: https://go-review.googlesource.com/c/sys/+/698015\nLUCI-TryBot-Result: Go LUCI \u003cgolang-scoped@luci-project-accounts.iam.gserviceaccount.com\u003e\nReviewed-by: Kirill Kolyshkin \u003ckolyshkin@gmail.com\u003e\nReviewed-by: Junyang Shao \u003cshaojunyang@google.com\u003e\nReviewed-by: Cherry Mui \u003ccherryyz@google.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "3c7a6d6e2f1d2fcc6291f6b51bda779ffad5bfd3",
      "old_mode": 33188,
      "old_path": "unix/affinity_linux.go",
      "new_id": "3ea470387bcf0832a407c80af2b3b2c02c4c2d4d",
      "new_mode": 33188,
      "new_path": "unix/affinity_linux.go"
    }
  ]
}
