gdbserver: use `gdb::unordered_map`

Message ID 20241126053230.911291-1-simon.marchi@polymtl.ca
State New
Headers
Series gdbserver: use `gdb::unordered_map` |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Simon Marchi Nov. 26, 2024, 5:32 a.m. UTC
  Replace the few uses of `std::unordered_map` in gdbserver with
`gdb::unordered_map`.

The only one of these that is likely to ever see a lot of elements is
probably `process_info::m_ptid_thread_map`.  It was added precisely to
improve performance when there are a lot of threads, so I guess using
`gdb::unordered_map` here won't hurt.  I changed the others too, since
it's easy.

Change-Id: Ibc4ede5245551fdd7717cb349a012d05726f4363
---
 gdbserver/inferiors.h            | 8 +++-----
 gdbserver/linux-aarch64-tdesc.cc | 4 ++--
 gdbserver/server.cc              | 4 ++--
 3 files changed, 7 insertions(+), 9 deletions(-)


base-commit: e1bb778eabc85d262e368fdd6fbcee57b02c1bba
  

Comments

Rohr, Stephan Nov. 26, 2024, 7:47 a.m. UTC | #1
Hi Simon,

Thanks for doing this.  This looks good.

Reviewed-By: Stephan Rohr <stephan.rohr@intel.com>

Stephan 

> -----Original Message-----
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Sent: Tuesday, 26 November 2024 06:32
> To: gdb-patches@sourceware.org
> Cc: Simon Marchi <simon.marchi@polymtl.ca>
> Subject: [PATCH] gdbserver: use `gdb::unordered_map`
> 
> Replace the few uses of `std::unordered_map` in gdbserver with
> `gdb::unordered_map`.
> 
> The only one of these that is likely to ever see a lot of elements is
> probably `process_info::m_ptid_thread_map`.  It was added precisely to
> improve performance when there are a lot of threads, so I guess using
> `gdb::unordered_map` here won't hurt.  I changed the others too, since
> it's easy.
> 
> Change-Id: Ibc4ede5245551fdd7717cb349a012d05726f4363
> ---
>  gdbserver/inferiors.h            | 8 +++-----
>  gdbserver/linux-aarch64-tdesc.cc | 4 ++--
>  gdbserver/server.cc              | 4 ++--
>  3 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h
> index 5372a3cd5b78..a0635de72428 100644
> --- a/gdbserver/inferiors.h
> +++ b/gdbserver/inferiors.h
> @@ -19,13 +19,11 @@
>  #ifndef GDBSERVER_INFERIORS_H
>  #define GDBSERVER_INFERIORS_H
> 
> -#include "gdbsupport/gdb_vecs.h"
>  #include "gdbsupport/owning_intrusive_list.h"
> +#include "gdbsupport/unordered_map.h"
> 
>  #include "dll.h"
> 
> -#include <unordered_map>
> -
>  struct thread_info;
>  struct regcache;
>  struct target_desc;
> @@ -94,7 +92,7 @@ struct process_info : public
> intrusive_list_node<process_info>
>    { return m_thread_list; }
> 
>    /* Return a reference to the private thread map.  */
> -  std::unordered_map<ptid_t, thread_info *> &thread_map ()
> +  gdb::unordered_map<ptid_t, thread_info *> &thread_map ()
>    { return m_ptid_thread_map; }
> 
>    /* Find the first thread for which FUNC returns true.  Return nullptr if no
> @@ -118,7 +116,7 @@ struct process_info : public
> intrusive_list_node<process_info>
> 
>    /* A map of ptid_t to thread_info*, for average O(1) ptid_t lookup.
>       Exited threads do not appear in the map.  */
> -  std::unordered_map<ptid_t, thread_info *> m_ptid_thread_map;
> +  gdb::unordered_map<ptid_t, thread_info *> m_ptid_thread_map;
>  };
> 
>  /* Return a pointer to the current process.  Note that the current
> diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-
> tdesc.cc
> index 39d5bccdce18..52642d52be2d 100644
> --- a/gdbserver/linux-aarch64-tdesc.cc
> +++ b/gdbserver/linux-aarch64-tdesc.cc
> @@ -24,7 +24,7 @@
>  #include "arch/aarch64.h"
>  #include "linux-aarch32-low.h"
>  #include <inttypes.h>
> -#include <unordered_map>
> +#include "gdbsupport/unordered_map.h"
> 
>  /* Create the aarch64 target description.  */
> 
> @@ -35,7 +35,7 @@ aarch64_linux_read_description (const
> aarch64_features &features)
>       this function as the in-process-agent calls this function from a
>       constructor function, when globals might not yet have been
>       initialised.  */
> -  static std::unordered_map<aarch64_features, target_desc *>
> tdesc_aarch64_map;
> +  static gdb::unordered_map<aarch64_features, target_desc *>
> tdesc_aarch64_map;
> 
>    if (features.vq > AARCH64_MAX_SVE_VQ)
>      error (_("VQ is %" PRIu64 ", maximum supported value is %d"), features.vq,
> diff --git a/gdbserver/server.cc b/gdbserver/server.cc
> index 069795650a51..6e11b2e9633c 100644
> --- a/gdbserver/server.cc
> +++ b/gdbserver/server.cc
> @@ -35,7 +35,7 @@
>  #include "dll.h"
>  #include "hostio.h"
>  #include <vector>
> -#include <unordered_map>
> +#include "gdbsupport/unordered_map.h"
>  #include "gdbsupport/common-inferior.h"
>  #include "gdbsupport/job-control.h"
>  #include "gdbsupport/environ.h"
> @@ -947,7 +947,7 @@ handle_general_set (char *own_buf)
>  	 It's nicer if we only print the final options for each TID,
>  	 and if we only print about it if the options changed compared
>  	 to the options that were previously set on the thread.  */
> -      std::unordered_map<thread_info *, gdb_thread_options> set_options;
> +      gdb::unordered_map<thread_info *, gdb_thread_options> set_options;
> 
>        while (*p != '\0')
>  	{
> 
> base-commit: e1bb778eabc85d262e368fdd6fbcee57b02c1bba
> --
> 2.47.0

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h
index 5372a3cd5b78..a0635de72428 100644
--- a/gdbserver/inferiors.h
+++ b/gdbserver/inferiors.h
@@ -19,13 +19,11 @@ 
 #ifndef GDBSERVER_INFERIORS_H
 #define GDBSERVER_INFERIORS_H
 
-#include "gdbsupport/gdb_vecs.h"
 #include "gdbsupport/owning_intrusive_list.h"
+#include "gdbsupport/unordered_map.h"
 
 #include "dll.h"
 
-#include <unordered_map>
-
 struct thread_info;
 struct regcache;
 struct target_desc;
@@ -94,7 +92,7 @@  struct process_info : public intrusive_list_node<process_info>
   { return m_thread_list; }
 
   /* Return a reference to the private thread map.  */
-  std::unordered_map<ptid_t, thread_info *> &thread_map ()
+  gdb::unordered_map<ptid_t, thread_info *> &thread_map ()
   { return m_ptid_thread_map; }
 
   /* Find the first thread for which FUNC returns true.  Return nullptr if no
@@ -118,7 +116,7 @@  struct process_info : public intrusive_list_node<process_info>
 
   /* A map of ptid_t to thread_info*, for average O(1) ptid_t lookup.
      Exited threads do not appear in the map.  */
-  std::unordered_map<ptid_t, thread_info *> m_ptid_thread_map;
+  gdb::unordered_map<ptid_t, thread_info *> m_ptid_thread_map;
 };
 
 /* Return a pointer to the current process.  Note that the current
diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc
index 39d5bccdce18..52642d52be2d 100644
--- a/gdbserver/linux-aarch64-tdesc.cc
+++ b/gdbserver/linux-aarch64-tdesc.cc
@@ -24,7 +24,7 @@ 
 #include "arch/aarch64.h"
 #include "linux-aarch32-low.h"
 #include <inttypes.h>
-#include <unordered_map>
+#include "gdbsupport/unordered_map.h"
 
 /* Create the aarch64 target description.  */
 
@@ -35,7 +35,7 @@  aarch64_linux_read_description (const aarch64_features &features)
      this function as the in-process-agent calls this function from a
      constructor function, when globals might not yet have been
      initialised.  */
-  static std::unordered_map<aarch64_features, target_desc *> tdesc_aarch64_map;
+  static gdb::unordered_map<aarch64_features, target_desc *> tdesc_aarch64_map;
 
   if (features.vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), features.vq,
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 069795650a51..6e11b2e9633c 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -35,7 +35,7 @@ 
 #include "dll.h"
 #include "hostio.h"
 #include <vector>
-#include <unordered_map>
+#include "gdbsupport/unordered_map.h"
 #include "gdbsupport/common-inferior.h"
 #include "gdbsupport/job-control.h"
 #include "gdbsupport/environ.h"
@@ -947,7 +947,7 @@  handle_general_set (char *own_buf)
 	 It's nicer if we only print the final options for each TID,
 	 and if we only print about it if the options changed compared
 	 to the options that were previously set on the thread.  */
-      std::unordered_map<thread_info *, gdb_thread_options> set_options;
+      gdb::unordered_map<thread_info *, gdb_thread_options> set_options;
 
       while (*p != '\0')
 	{