public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
@ 2019-09-18  8:40 Pierre-Marie de Rodat
  2019-09-19 14:41 ` Iain Sandoe
  0 siblings, 1 reply; 10+ messages in thread
From: Pierre-Marie de Rodat @ 2019-09-18  8:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Olivier Hainque

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

The dwActiveProcessorMask field in a SYSTEM_INFO structure on Windows
should be DWORD_PTR, an integer the size of a pointer.

In s-win32, it is currently declared as DWORD. This happens to work on
32bit hosts and is wrong on 64bit hosts, causing mishaps in accesses to
this component and all the following ones.

The proposed correction adds a definition for DWORD_PTR and uses it for
dwActiveProcessorMask in System.Win32.SYSTEM_INFO.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-09-18  Olivier Hainque  <hainque@adacore.com>

gcc/ada/

	* libgnat/s-win32.ads (DWORD_PTR): New type, pointer size
	unsigned int.
	(SYSTEM_INFO): Use it for dwActiveProcessorMask.

gcc/testsuite/

	* gnat.dg/system_info1.adb: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2239 bytes --]

--- gcc/ada/libgnat/s-win32.ads
+++ gcc/ada/libgnat/s-win32.ads
@@ -57,15 +57,16 @@ package System.Win32 is
    INVALID_HANDLE_VALUE : constant HANDLE := -1;
    INVALID_FILE_SIZE    : constant := 16#FFFFFFFF#;
 
-   type ULONG  is new Interfaces.C.unsigned_long;
-   type DWORD  is new Interfaces.C.unsigned_long;
-   type WORD   is new Interfaces.C.unsigned_short;
-   type BYTE   is new Interfaces.C.unsigned_char;
-   type LONG   is new Interfaces.C.long;
-   type CHAR   is new Interfaces.C.char;
-   type SIZE_T is new Interfaces.C.size_t;
-
-   type BOOL   is new Interfaces.C.int;
+   type ULONG     is new Interfaces.C.unsigned_long;
+   type DWORD     is new Interfaces.C.unsigned_long;
+   type WORD      is new Interfaces.C.unsigned_short;
+   type BYTE      is new Interfaces.C.unsigned_char;
+   type LONG      is new Interfaces.C.long;
+   type CHAR      is new Interfaces.C.char;
+   type SIZE_T    is new Interfaces.C.size_t;
+   type DWORD_PTR is mod 2 ** Standard'Address_Size;
+
+   type BOOL      is new Interfaces.C.int;
    for BOOL'Size use Interfaces.C.int'Size;
 
    type Bits1  is range 0 .. 2 ** 1 - 1;
@@ -265,7 +266,7 @@ package System.Win32 is
       dwPageSize                  : DWORD;
       lpMinimumApplicationAddress : PVOID;
       lpMaximumApplicationAddress : PVOID;
-      dwActiveProcessorMask       : DWORD;
+      dwActiveProcessorMask       : DWORD_PTR;
       dwNumberOfProcessors        : DWORD;
       dwProcessorType             : DWORD;
       dwAllocationGranularity     : DWORD;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/system_info1.adb
@@ -0,0 +1,23 @@
+--  { dg-do run }
+
+with System.Multiprocessors;
+with System.Task_Info;
+
+procedure System_Info1 is
+   Ncpus : constant System.Multiprocessors.CPU :=
+     System.Multiprocessors.Number_Of_CPUS;
+   Nprocs : constant Integer :=
+     System.Task_Info.Number_Of_Processors;
+
+   use type System.Multiprocessors.CPU;
+begin
+   if Nprocs <= 0 or else Nprocs > 1024 then
+      raise Program_Error;
+   end if;
+   if Ncpus <= 0 or else Ncpus > 1024 then
+      raise Program_Error;
+   end if;
+   if Nprocs /= Integer (Ncpus) then
+      raise Program_Error;
+   end if;
+end;
\ No newline at end of file


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-18  8:40 [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32 Pierre-Marie de Rodat
@ 2019-09-19 14:41 ` Iain Sandoe
  2019-09-19 14:56   ` Rainer Orth
  0 siblings, 1 reply; 10+ messages in thread
From: Iain Sandoe @ 2019-09-19 14:41 UTC (permalink / raw)
  To: Pierre-Marie de Rodat; +Cc: gcc-patches, Olivier Hainque

Hi Folks,

> On 18 Sep 2019, at 09:39, Pierre-Marie de Rodat <derodat@adacore.com> wrote:
> 

> gcc/testsuite/
> 
> 	* gnat.dg/system_info1.adb: New testcase.<patch.diff>

This new test fails everywhere on Darwin, which doesn’t have an implementation for
System.Task_Info.Number_Of_Processors

Given 
"pragma Obsolescent (Task_Info, "use System.Multiprocessors and CPU aspect”);”

is it worth me trying to implement the Task_Info stuff?
or should I just skip this test on Darwin?

(if the latter, then I would plan to apply the patch below)

cheers
Iain


2019-09-19  Iain Sandoe  <iain@sandoe.co.uk>

	* gnat.dg/system_info1.adb: Skip for Darwin.


diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
index 493a18e907..c1523a277f 100644
--- a/gcc/testsuite/gnat.dg/system_info1.adb
+++ b/gcc/testsuite/gnat.dg/system_info1.adb
@@ -1,4 +1,4 @@
---  { dg-do run }
+--  { dg-do run { target { ! *-*-darwin* } } }
 
 with System.Multiprocessors;
 with System.Task_Info;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-19 14:41 ` Iain Sandoe
@ 2019-09-19 14:56   ` Rainer Orth
  2019-09-19 15:02     ` Iain Sandoe
  0 siblings, 1 reply; 10+ messages in thread
From: Rainer Orth @ 2019-09-19 14:56 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Pierre-Marie de Rodat, gcc-patches, Olivier Hainque

Hi Iain,

>> On 18 Sep 2019, at 09:39, Pierre-Marie de Rodat <derodat@adacore.com> wrote:
>> 
>
>> gcc/testsuite/
>> 
>> 	* gnat.dg/system_info1.adb: New testcase.<patch.diff>
>
> This new test fails everywhere on Darwin, which doesn’t have an implementation for
> System.Task_Info.Number_Of_Processors
>
> Given 
> "pragma Obsolescent (Task_Info, "use System.Multiprocessors and CPU aspect”);”
>
> is it worth me trying to implement the Task_Info stuff?

I'm seeing the same on Solaris (will be every non-Linux/MinGW target).
I've implemented Number_Of_Processors using
sysconf(__SC_NPROCESSORS_ONLN), which is also available on Darwin.  Will
submit the patch tomorrow once testing has finished...

> or should I just skip this test on Darwin?
>
> (if the latter, then I would plan to apply the patch below)
[...]
> diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
> index 493a18e907..c1523a277f 100644
> --- a/gcc/testsuite/gnat.dg/system_info1.adb
> +++ b/gcc/testsuite/gnat.dg/system_info1.adb
> @@ -1,4 +1,4 @@
> ---  { dg-do run }
> +--  { dg-do run { target { ! *-*-darwin* } } }

Given that the test cannot compile on anything but *-*-linux* and
*-*-mingw*, I'd rather restrict the test to those two (or more targets
that decide to implement the missing interface).

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-19 14:56   ` Rainer Orth
@ 2019-09-19 15:02     ` Iain Sandoe
  2019-09-19 16:40       ` Olivier Hainque
  2019-09-20 12:57       ` Rainer Orth
  0 siblings, 2 replies; 10+ messages in thread
From: Iain Sandoe @ 2019-09-19 15:02 UTC (permalink / raw)
  To: Rainer Orth; +Cc: Pierre-Marie de Rodat, gcc-patches, Olivier Hainque

Hi Rainer,

> On 19 Sep 2019, at 15:51, Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:
> 

>>> On 18 Sep 2019, at 09:39, Pierre-Marie de Rodat <derodat@adacore.com> wrote:
>>> 
>> 
>>> gcc/testsuite/
>>> 
>>> 	* gnat.dg/system_info1.adb: New testcase.<patch.diff>
>> 
>> This new test fails everywhere on Darwin, which doesn’t have an implementation for
>> System.Task_Info.Number_Of_Processors
>> 
>> Given 
>> "pragma Obsolescent (Task_Info, "use System.Multiprocessors and CPU aspect”);”
>> 
>> is it worth me trying to implement the Task_Info stuff?
> 
> I'm seeing the same on Solaris (will be every non-Linux/MinGW target).
> I've implemented Number_Of_Processors using
> sysconf(__SC_NPROCESSORS_ONLN), which is also available on Darwin.  Will
> submit the patch tomorrow once testing has finished…

OK. it’s likely that the same (almost) patch will work for Darwin which also has that Posix call.

I’ll look at your patch and adapt it for Darwin then,

I don’t *think* we can make:

s-tasinf__posix.ad? 

using that since  I think __SC_NPROCESSORS_ONLN is an optional addition? 
(but ICBW about that)

>> or should I just skip this test on Darwin?
>> 
>> (if the latter, then I would plan to apply the patch below)
> [...]
>> diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
>> index 493a18e907..c1523a277f 100644
>> --- a/gcc/testsuite/gnat.dg/system_info1.adb
>> +++ b/gcc/testsuite/gnat.dg/system_info1.adb
>> @@ -1,4 +1,4 @@
>> ---  { dg-do run }
>> +--  { dg-do run { target { ! *-*-darwin* } } }
> 
> Given that the test cannot compile on anything but *-*-linux* and
> *-*-mingw*, I'd rather restrict the test to those two (or more targets
> that decide to implement the missing interface).

that makes sense, too (targets with support can opt in)

cheers
Iain

> 
> 	Rainer
> 
> -- 
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-19 15:02     ` Iain Sandoe
@ 2019-09-19 16:40       ` Olivier Hainque
  2019-09-20 12:21         ` Olivier Hainque
  2019-09-20 12:57       ` Rainer Orth
  1 sibling, 1 reply; 10+ messages in thread
From: Olivier Hainque @ 2019-09-19 16:40 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Rainer Orth, Pierre-Marie de Rodat, gcc-patches

Hello Iain & Rainer,

Thanks for the heads up and sorry for the disruption from
this one.

> On 19 Sep 2019, at 17:02, Iain Sandoe <idsandoe@googlemail.com> wrote:
> 
>> Given that the test cannot compile on anything but *-*-linux* and
>> *-*-mingw*, I'd rather restrict the test to those two (or more targets
>> that decide to implement the missing interface).
> 
> that makes sense, too (targets with support can opt in)

Works for me as well. The point of the test is really to check
a 32/64 discrepancy initially observed on Windows. It is not meant
as a general representative test of the System.Task_Info feature.

If you get it to work on Darwin or Solaris and wish to opt-in
afterwards, this is also fine of course :)

We can take care of adding the required filter.

Cheers,

Olivier

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-19 16:40       ` Olivier Hainque
@ 2019-09-20 12:21         ` Olivier Hainque
  2019-09-20 13:02           ` Rainer Orth
  0 siblings, 1 reply; 10+ messages in thread
From: Olivier Hainque @ 2019-09-20 12:21 UTC (permalink / raw)
  To: Iain Sandoe
  Cc: Olivier Hainque, Rainer Orth, Pierre-Marie de Rodat, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

Hello Iain & Rainer,

> On 19 Sep 2019, at 18:40, Olivier Hainque <hainque@adacore.com> wrote:

>>> Given that the test cannot compile on anything but *-*-linux* and
>>> *-*-mingw*, I'd rather restrict the test to those two (or more targets
>>> that decide to implement the missing interface).

> Works for me as well.
[...]
> We can take care of adding the required filter.

I have just committed the attached patch to this effect.
Thanks again for the heads-up!

Cheers,

Olivier

---

2019-09-20  Olivier Hainque  <hainque@adacore.com>

	testsuite/

        * gnat.dg/system_info1.adb: Restrict to *-*-linux* and *-*-mingw*.


[-- Attachment #2: system_info1.diff --]
[-- Type: application/octet-stream, Size: 738 bytes --]

diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
index 493a18e..e299bc4 100644
--- a/gcc/testsuite/gnat.dg/system_info1.adb
+++ b/gcc/testsuite/gnat.dg/system_info1.adb
@@ -1,4 +1,9 @@
---  { dg-do run }
+--  A basic test initially intended to check that
+--  System.Task_Info.Number_Of_Processors yields sensible results on
+--  both 32bit and 64bit Windows. Additional configurations where the
+--  feature was verified to work can opt-in.
+
+--  { dg-do run { target *-*-mingw* *-*-linux* } }
 
 with System.Multiprocessors;
 with System.Task_Info;
@@ -20,4 +25,4 @@ begin
    if Nprocs /= Integer (Ncpus) then
       raise Program_Error;
    end if;
-end;
\ No newline at end of file
+end;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-19 15:02     ` Iain Sandoe
  2019-09-19 16:40       ` Olivier Hainque
@ 2019-09-20 12:57       ` Rainer Orth
  1 sibling, 0 replies; 10+ messages in thread
From: Rainer Orth @ 2019-09-20 12:57 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Pierre-Marie de Rodat, gcc-patches, Olivier Hainque

Hi Iain,

>> On 19 Sep 2019, at 15:51, Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:
>> 
>
>>>> On 18 Sep 2019, at 09:39, Pierre-Marie de Rodat <derodat@adacore.com> wrote:
>>>> 
>>> 
>>>> gcc/testsuite/
>>>> 
>>>> 	* gnat.dg/system_info1.adb: New testcase.<patch.diff>
>>> 
>>> This new test fails everywhere on Darwin, which doesn’t have an
>>> implementation for
>>> System.Task_Info.Number_Of_Processors
>>> 
>>> Given 
>>> "pragma Obsolescent (Task_Info, "use System.Multiprocessors and CPU
>>> aspect”);”
>>> 
>>> is it worth me trying to implement the Task_Info stuff?
>> 
>> I'm seeing the same on Solaris (will be every non-Linux/MinGW target).
>> I've implemented Number_Of_Processors using
>> sysconf(__SC_NPROCESSORS_ONLN), which is also available on Darwin.  Will
>> submit the patch tomorrow once testing has finished…
>
> OK. it’s likely that the same (almost) patch will work for Darwin which
> also has that Posix call.
>
> I’ll look at your patch and adapt it for Darwin then,
>
> I don’t *think* we can make:
>
> s-tasinf__posix.ad? 
>
> using that since  I think __SC_NPROCESSORS_ONLN is an optional addition? 
> (but ICBW about that)

there are two issues here:

* _SC_NPROCESSORS_ONLN is not in XPG7 according to
  https://pubs.opengroup.org/onlinepubs/9699919799/.  gnulib
  (lib/nproc.c) lists it as an addition in glibc,
  Mac OS X 10.5, FreeBSD, AIX, OSF/1, Solaris, Cygwin, Haiku.

* In theory, one could at least move the sysconf declaration to a common
  s-osinte__posix.ads since that function *is* part of XPG7.  In fact,
  we already have a couple of duplicate declarations in
  s-osinte__android.ads, s-osinte__kfreebsd-gnu.ads,
  s-osinte__lynxos178.adb, s-osinte__linux.ads, and
  s-taprop__solaris.adb (with a different return type).  While it would
  be good to unify them to avoid the duplication, I don't see how to do
  so: s-osinte.ads is already linked to one of several different
  target-specific versions.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-20 12:21         ` Olivier Hainque
@ 2019-09-20 13:02           ` Rainer Orth
  2019-09-20 14:12             ` Arnaud Charlet
  0 siblings, 1 reply; 10+ messages in thread
From: Rainer Orth @ 2019-09-20 13:02 UTC (permalink / raw)
  To: Olivier Hainque; +Cc: Iain Sandoe, Pierre-Marie de Rodat, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1401 bytes --]

Hi Olivier,

>> On 19 Sep 2019, at 18:40, Olivier Hainque <hainque@adacore.com> wrote:
>
>>>> Given that the test cannot compile on anything but *-*-linux* and
>>>> *-*-mingw*, I'd rather restrict the test to those two (or more targets
>>>> that decide to implement the missing interface).
>
>> Works for me as well.
> [...]
>> We can take care of adding the required filter.
>
> I have just committed the attached patch to this effect.
> Thanks again for the heads-up!

thanks.

> 2019-09-20  Olivier Hainque  <hainque@adacore.com>
>
> 	testsuite/
>
>         * gnat.dg/system_info1.adb: Restrict to *-*-linux* and *-*-mingw*.

I'd keep the target list alphabetical.  Can do so when the Solaris patch
goes in.

Here's what I've successfully tested last night on both
i386-pc-solaris2.11 and sparc-sun-solaris2.11, shamelessly stolen from
the Linux counterparts.  If it is acceptable, I'd add *-*-solaris2.* to
the target list when merging.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2019-09-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* libgnarl/s-osinte__solaris.ads (sysconf): Declare.
	(SC_NPROCESSORS_ONLN): Define.
	* libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
	* libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
	(Number_Of_Processors): New function.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2-libgnat-n_o_p.patch --]
[-- Type: text/x-patch, Size: 1921 bytes --]

# HG changeset patch
# Parent  48b6a952486ff0ee28ce4b9c1bd4f77a4078491d
Provide Task_Info.Number_Of_Processors on Solaris

diff --git a/gcc/ada/libgnarl/s-osinte__solaris.ads b/gcc/ada/libgnarl/s-osinte__solaris.ads
--- a/gcc/ada/libgnarl/s-osinte__solaris.ads
+++ b/gcc/ada/libgnarl/s-osinte__solaris.ads
@@ -259,6 +259,11 @@ package System.OS_Interface is
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
+   function sysconf (name : int) return long;
+   pragma Import (C, sysconf);
+
+   SC_NPROCESSORS_ONLN : constant := 15;
+
    -------------
    -- Process --
    -------------
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.adb b/gcc/ada/libgnarl/s-tasinf__solaris.adb
--- a/gcc/ada/libgnarl/s-tasinf__solaris.adb
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.adb
@@ -84,4 +84,23 @@ package body System.Task_Info is
       return (False, False);
    end Unbound_Thread_Attributes;
 
+   N_CPU : Natural := 0;
+   pragma Atomic (N_CPU);
+   --  Cache CPU number. Use pragma Atomic to avoid a race condition when
+   --  setting N_CPU in Number_Of_Processors below.
+
+   --------------------------
+   -- Number_Of_Processors --
+   --------------------------
+
+   function Number_Of_Processors return Positive is
+   begin
+      if N_CPU = 0 then
+         N_CPU := Natural
+           (OS_Interface.sysconf (OS_Interface.SC_NPROCESSORS_ONLN));
+      end if;
+
+      return N_CPU;
+   end Number_Of_Processors;
+
 end System.Task_Info;
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.ads b/gcc/ada/libgnarl/s-tasinf__solaris.ads
--- a/gcc/ada/libgnarl/s-tasinf__solaris.ads
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.ads
@@ -139,4 +139,7 @@ package System.Task_Info is
 
    Unspecified_Task_Info : constant Task_Info_Type := null;
 
+   function Number_Of_Processors return Positive;
+   --  Returns the number of processors on the running host
+
 end System.Task_Info;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-20 13:02           ` Rainer Orth
@ 2019-09-20 14:12             ` Arnaud Charlet
  2019-09-23 10:12               ` Rainer Orth
  0 siblings, 1 reply; 10+ messages in thread
From: Arnaud Charlet @ 2019-09-20 14:12 UTC (permalink / raw)
  To: Rainer Orth
  Cc: Olivier Hainque, Iain Sandoe, Pierre-Marie de Rodat, gcc-patches

> I'd keep the target list alphabetical.  Can do so when the Solaris patch
> goes in.
> 
> Here's what I've successfully tested last night on both
> i386-pc-solaris2.11 and sparc-sun-solaris2.11, shamelessly stolen from
> the Linux counterparts.  If it is acceptable, I'd add *-*-solaris2.* to
> the target list when merging.

The change is OK.

> 2019-09-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
> 
> 	* libgnarl/s-osinte__solaris.ads (sysconf): Declare.
> 	(SC_NPROCESSORS_ONLN): Define.
> 	* libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
> 	* libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
> 	(Number_Of_Processors): New function.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
  2019-09-20 14:12             ` Arnaud Charlet
@ 2019-09-23 10:12               ` Rainer Orth
  0 siblings, 0 replies; 10+ messages in thread
From: Rainer Orth @ 2019-09-23 10:12 UTC (permalink / raw)
  To: Arnaud Charlet
  Cc: Olivier Hainque, Iain Sandoe, Pierre-Marie de Rodat, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

Hi Arnaud,

>> I'd keep the target list alphabetical.  Can do so when the Solaris patch
>> goes in.
>> 
>> Here's what I've successfully tested last night on both
>> i386-pc-solaris2.11 and sparc-sun-solaris2.11, shamelessly stolen from
>> the Linux counterparts.  If it is acceptable, I'd add *-*-solaris2.* to
>> the target list when merging.
>
> The change is OK.
>
>> 2019-09-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>> 
>> 	* libgnarl/s-osinte__solaris.ads (sysconf): Declare.
>> 	(SC_NPROCESSORS_ONLN): Define.
>> 	* libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
>> 	* libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
>> 	(Number_Of_Processors): New function.

Thanks.  Here's what I've installed.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2019-09-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc/ada:
	* libgnarl/s-osinte__solaris.ads (sysconf): Declare.
	(SC_NPROCESSORS_ONLN): Define.
	* libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
	* libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
	(Number_Of_Processors): New function.

	gcc/testsuite:
	* gnat.dg/system_info1.adb: Sort dg-do target list.
	Add *-*-solaris2.*.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2-libgnat-n_o_p.patch --]
[-- Type: text/x-patch, Size: 2414 bytes --]

# HG changeset patch
# Parent  0d13bfaa0b34084a84b2b12d906b7252383366d4
Provide Task_Info.Number_Of_Processors on Solaris

diff --git a/gcc/ada/libgnarl/s-osinte__solaris.ads b/gcc/ada/libgnarl/s-osinte__solaris.ads
--- a/gcc/ada/libgnarl/s-osinte__solaris.ads
+++ b/gcc/ada/libgnarl/s-osinte__solaris.ads
@@ -259,6 +259,11 @@ package System.OS_Interface is
    function To_Timespec (D : Duration) return timespec;
    pragma Inline (To_Timespec);
 
+   function sysconf (name : int) return long;
+   pragma Import (C, sysconf);
+
+   SC_NPROCESSORS_ONLN : constant := 15;
+
    -------------
    -- Process --
    -------------
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.adb b/gcc/ada/libgnarl/s-tasinf__solaris.adb
--- a/gcc/ada/libgnarl/s-tasinf__solaris.adb
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.adb
@@ -84,4 +84,23 @@ package body System.Task_Info is
       return (False, False);
    end Unbound_Thread_Attributes;
 
+   N_CPU : Natural := 0;
+   pragma Atomic (N_CPU);
+   --  Cache CPU number. Use pragma Atomic to avoid a race condition when
+   --  setting N_CPU in Number_Of_Processors below.
+
+   --------------------------
+   -- Number_Of_Processors --
+   --------------------------
+
+   function Number_Of_Processors return Positive is
+   begin
+      if N_CPU = 0 then
+         N_CPU := Natural
+           (OS_Interface.sysconf (OS_Interface.SC_NPROCESSORS_ONLN));
+      end if;
+
+      return N_CPU;
+   end Number_Of_Processors;
+
 end System.Task_Info;
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.ads b/gcc/ada/libgnarl/s-tasinf__solaris.ads
--- a/gcc/ada/libgnarl/s-tasinf__solaris.ads
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.ads
@@ -139,4 +139,7 @@ package System.Task_Info is
 
    Unspecified_Task_Info : constant Task_Info_Type := null;
 
+   function Number_Of_Processors return Positive;
+   --  Returns the number of processors on the running host
+
 end System.Task_Info;
diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
--- a/gcc/testsuite/gnat.dg/system_info1.adb
+++ b/gcc/testsuite/gnat.dg/system_info1.adb
@@ -3,7 +3,7 @@
 --  both 32bit and 64bit Windows. Additional configurations where the
 --  feature was verified to work can opt-in.
 
---  { dg-do run { target *-*-mingw* *-*-linux* } }
+--  { dg-do run { target *-*-linux* *-*-mingw* *-*-solaris2.* } }
 
 with System.Multiprocessors;
 with System.Task_Info;

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-09-23 10:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-18  8:40 [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32 Pierre-Marie de Rodat
2019-09-19 14:41 ` Iain Sandoe
2019-09-19 14:56   ` Rainer Orth
2019-09-19 15:02     ` Iain Sandoe
2019-09-19 16:40       ` Olivier Hainque
2019-09-20 12:21         ` Olivier Hainque
2019-09-20 13:02           ` Rainer Orth
2019-09-20 14:12             ` Arnaud Charlet
2019-09-23 10:12               ` Rainer Orth
2019-09-20 12:57       ` Rainer Orth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).