)]}'
{
  "commit": "5672720dd1ab2d4e9bf7a7c2f86599df07afa96c",
  "tree": "9667616152b430759a4e8b7fc37b06881e636697",
  "parents": [
    "2dd1cd011c097c6c754c2317fef678bd92efdf72"
  ],
  "author": {
    "name": "Simon Marchi",
    "email": "simon.marchi@efficios.com",
    "time": "Wed Jan 08 11:39:29 2020 -0500"
  },
  "committer": {
    "name": "Simon Marchi",
    "email": "simon.marchi@efficios.com",
    "time": "Wed Aug 05 15:40:20 2020 -0400"
  },
  "message": "gdb: change regcache list to be a map\n\nOne regcache object is created for each stopped thread and is stored in\nthe regcache::regcaches linked list.  Looking up a regcache for a given\nthread is therefore in O(number of threads).  Stopping all threads then\nbecomes O((number of threads) ^ 2).  It becomes noticeable when\ndebugging thousands of threads, which is typical with GPU targets.  This\npatch replaces the linked list with an std::unordered_multimap, indexed\nby (target, ptid).\n\nI originally designed it using an std::unordered_map with (target, ptid,\narch) as the key, because that\u0027s how lookups are done (in\nget_thread_arch_aspace_regcache).  However, the registers_changed_ptid\nfunction, also somewhat on the hot path (it is used when resuming\nthreads), needs to delete all regcaches associated to a given (target,\nptid) tuple.  Using (target, ptid) as a key allows to do this more\nefficiently (see exception below).  If the key of the map was (target,\nptid, arch), we\u0027d have to walk all items of the map.\n\nThe lookup (in get_thread_arch_aspace_regcache), walks over all existing\nregcaches belonging to this (target, ptid), looking to find the one with\nthe right arch.  This is ok, as there will be very few regcaches for a\ngiven key (typically one).  Lookups become faster when the number of\nthreads grows, compared to the linked list.  With a small number of\nthreads, it will probably be a bit slower to do a map lookup than to\nwalk a few linked list nodes, but I don\u0027t think it will be noticeable in\npractice.\n\nThe function registers_changed_ptid deletes all regcaches related to a\ngiven (target, ptid).  We must now handle the different cases\nseparately:\n\n- NULL target and minus_one_ptid: we delete all the entries\n- NULL target and non-minus_one_ptid: invalid (checked by assert)\n- non-NULL target and non-minus_one_ptid: we delete all the entries\n  associated to that tuple, this is done efficiently\n- a non-NULL target and minus_one_ptid: we delete all the entries\n  associated to that target, whatever the ptid.  This is the slightly\n  annoying case, as we can\u0027t easily look up all items having this target\n  in their key.  I implemented it by walking the list, which is not\n  ideal.\n\nThe function regcache_thread_ptid_changed is called when a thread\nchanges ptid.  It is implemented efficiently using the map, although\nthat\u0027s not very important: it is not called often, mostly when creating\nan inferior, on some specific platforms.\n\nNote: In hash_target_ptid, I am combining hash values from std::hash by\nsumming them.  I don\u0027t think it\u0027s ideal, since std::hash is just the\nidentity function for base types.  But I don\u0027t know what would be better\nto reduce the change of collisions.  If anybody has a better idea, I\u0027d\nbe interested.\n\nThis patch is a tiny bit from ROCm GDB [1] we would like to merge\nupstream.  Laurent Morichetti gave be these performance numbers:\n\nThe benchmark used is:\n\n  time ./gdb --data-directory\u003ddata-directory /extra/lmoriche/hip/samples/0_Intro/bit_extract/bit_extract -ex \"set pagination off\" -ex \"set breakpoint pending on\" -ex \"b bit_extract_kernel if \\$_thread \u003d\u003d 5\" -ex run -ex c -batch\n\nIt measures the time it takes to continue from a conditional breakpoint with\n2048 threads at that breakpoint, one of them reporting the breakpoint.\n\nbaseline:\nreal    0m10.227s\nreal    0m10.177s\nreal    0m10.362s\n\nwith patch:\nreal    0m8.356s\nreal    0m8.424s\nreal    0m8.494s\n\n[1] https://github.com/ROCm-Developer-Tools/ROCgdb\n\ngdb/ChangeLog:\n\n\t* regcache.c (struct target_ptid): New struct.\n\t(hash_target_ptid): New struct.\n\t(target_ptid_regcache_map): New type.\n\t(regcaches): Change type to target_ptid_regcache_map.\n\t(get_thread_arch_aspace_regcache): Update to regcaches\u0027 new\n\ttype.\n\t(regcache_thread_ptid_changed): Likewise.\n\t(registers_changed_ptid): Likewise.\n\t(regcaches_size): Likewise.\n\t(regcaches_test): Update.\n\t(regcache_thread_ptid_changed): Update.\n\t* gdbsupport/ptid.h (hash_ptid): New struct.\n\nChange-Id: Iabb0a1111707936ca111ddb13f3b09efa83d3402\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "46fbb074dc0c9dc50bf826d5584884a7fc342d27",
      "old_mode": 33188,
      "old_path": "gdb/regcache.c",
      "new_id": "8ca59fd2bec9de6b554a67bf64c6c7ec56b37798",
      "new_mode": 33188,
      "new_path": "gdb/regcache.c"
    },
    {
      "type": "modify",
      "old_id": "dd0c2f27f95ad03beecf3ecf5b35b9507e258f18",
      "old_mode": 33188,
      "old_path": "gdb/regcache.h",
      "new_id": "9390f5708ea40480e4d33c1cebb2607a9fa3df78",
      "new_mode": 33188,
      "new_path": "gdb/regcache.h"
    },
    {
      "type": "modify",
      "old_id": "ef52d55512600c3b108dcdee8e029523c430501d",
      "old_mode": 33188,
      "old_path": "gdbsupport/ptid.h",
      "new_id": "a528312bad5e79d81d32b5b01d3a541b2d1d2584",
      "new_mode": 33188,
      "new_path": "gdbsupport/ptid.h"
    }
  ]
}
