emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 619f66f: Use MS-Windows system APIs to get number of


From: Eli Zaretskii
Subject: feature/native-comp 619f66f: Use MS-Windows system APIs to get number of processors
Date: Sun, 7 Mar 2021 08:34:13 -0500 (EST)

branch: feature/native-comp
commit 619f66f423c76d94b2bca728f9c22b536e909108
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Use MS-Windows system APIs to get number of processors
    
    * lisp/emacs-lisp/comp.el: Use 'w32-get-nproc' instead of the
    environment variable NUMBER_OF_PROCESSORS.
    
    * src/w32proc.c (Fw32_get_nproc): New primitive.
    * src/w32.c (w32_get_nproc): New function.
    (sample_system_load): Call w32_get_nproc to initialize the number
    of processors on this system.
    * src/w32.h (w32_get_nproc): Add prototype.
---
 lisp/emacs-lisp/comp.el |  3 +--
 src/w32.c               | 14 +++++++++++---
 src/w32.h               |  3 +++
 src/w32proc.c           | 10 ++++++++++
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 134b5a2..70e1064 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -3824,8 +3824,7 @@ processes from `comp-async-compilations'"
                 ;; the number of processors, see get_native_system_info in 
w32.c.
                 ;; The result needs to be exported to Lisp.
                 (max 1 (/ (cond ((eq 'windows-nt system-type)
-                                 (string-to-number (getenv
-                                                    "NUMBER_OF_PROCESSORS")))
+                                 (w32-get-nproc))
                                 ((executable-find "nproc")
                                  (string-to-number
                                   (shell-command-to-string "nproc")))
diff --git a/src/w32.c b/src/w32.c
index 96eba1e..7ce907d 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1941,11 +1941,10 @@ buf_prev (int from)
   return prev_idx;
 }
 
-static void
-sample_system_load (ULONGLONG *idle, ULONGLONG *kernel, ULONGLONG *user)
+unsigned
+w32_get_nproc (void)
 {
   SYSTEM_INFO sysinfo;
-  FILETIME ft_idle, ft_user, ft_kernel;
 
   /* Initialize the number of processors on this machine.  */
   if (num_of_processors <= 0)
@@ -1960,6 +1959,15 @@ sample_system_load (ULONGLONG *idle, ULONGLONG *kernel, 
ULONGLONG *user)
       if (num_of_processors <= 0)
        num_of_processors = 1;
     }
+  return num_of_processors;
+}
+
+static void
+sample_system_load (ULONGLONG *idle, ULONGLONG *kernel, ULONGLONG *user)
+{
+  FILETIME ft_idle, ft_user, ft_kernel;
+
+  (void) w32_get_nproc ();
 
   /* TODO: Take into account threads that are ready to run, by
      sampling the "\System\Processor Queue Length" performance
diff --git a/src/w32.h b/src/w32.h
index 3f8eb25..a382dbe 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -233,6 +233,9 @@ extern int w32_memory_info (unsigned long long *, unsigned 
long long *,
 /* Compare 2 UTF-8 strings in locale-dependent fashion.  */
 extern int w32_compare_strings (const char *, const char *, char *, int);
 
+/* Return the number of processor execution units on this system.  */
+extern unsigned w32_get_nproc (void);
+
 /* Return a cryptographically secure seed for PRNG.  */
 extern int w32_init_random (void *, ptrdiff_t);
 
diff --git a/src/w32proc.c b/src/w32proc.c
index 2b6cb9c..a50c877 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -3877,6 +3877,14 @@ w32_compare_strings (const char *s1, const char *s2, 
char *locname,
   return val - 2;
 }
 
+DEFUN ("w32-get-nproc", Fw32_get_nproc,
+       Sw32_get_nproc, 0, 0, 0,
+       doc: /* Return the number of system's processor execution units.  */)
+  (void)
+{
+  return make_fixnum (w32_get_nproc ());
+}
+
 
 void
 syms_of_ntproc (void)
@@ -3911,6 +3919,8 @@ syms_of_ntproc (void)
   defsubr (&Sw32_get_keyboard_layout);
   defsubr (&Sw32_set_keyboard_layout);
 
+  defsubr (&Sw32_get_nproc);
+
   DEFVAR_LISP ("w32-quote-process-args", Vw32_quote_process_args,
               doc: /* Non-nil enables quoting of process arguments to ensure 
correct parsing.
 Because Windows does not directly pass argv arrays to child processes,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]